Ejemplo n.º 1
0
  /**
   * Update axis display depending the current scene camera view.<br>
   * You should call it after having modified camera settings.
   */
  public void updateAxisView() {
    if (!isWindowSet()) return;

    lock();
    try {
      double pos[] = cam.GetPosition();
      double fp[] = cam.GetFocalPoint();
      double viewup[] = cam.GetViewUp();

      // mimic axis camera position to scene camera position
      axisCam.SetPosition(pos);
      axisCam.SetFocalPoint(fp);
      axisCam.SetViewUp(viewup);
      axisRenderer.ResetCamera();

      final int[] size = rw.GetSize();
      // adjust scale
      final double scale = size[1] / 512d;
      // adjust offset
      final int w = (int) (size[0] - (axisOffset[0] * scale));
      final int h = (int) (size[1] - (axisOffset[1] * scale));
      // zoom and translate
      zoomView(axisCam, axisRenderer, axisScale * (axisCam.GetDistance() / 17d));
      translateView(axisCam, axisRenderer, -w, -h);
    } finally {
      unlock();
    }
  }
Ejemplo n.º 2
0
  public IcyVtkPanel() {
    super();

    // picker
    // picker = new vtkPropPicker();
    // picker.PickFromListOff();

    picker = new vtkCellPicker();
    picker.PickFromListOff();

    // set ambient color to white
    lgt.SetAmbientColor(1d, 1d, 1d);
    lightFollowCamera = true;

    // assign default renderer to layer 0 (should be the case by default)
    ren.SetLayer(0);

    // initialize axis
    axisRenderer = new vtkRenderer();
    // BUG: with OpenGL window the global render window viewport is limited to the last layer
    // viewport dimension
    // axisRenderer.SetViewport(0.0, 0.0, 0.2, 0.2);
    axisRenderer.SetLayer(1);
    axisRenderer.InteractiveOff();

    rw.AddRenderer(axisRenderer);
    rw.SetNumberOfLayers(2);

    axisCam = axisRenderer.GetActiveCamera();

    axis = new vtkAxesActor();
    axisRenderer.AddActor(axis);

    // default axis offset and scale
    axisOffset = new int[] {124, 124};
    axisScale = 1;

    // reset camera
    axisCam.SetViewUp(0, -1, 0);
    axisCam.Elevation(210);
    axisCam.SetParallelProjection(1);
    axisRenderer.ResetCamera();
    axisRenderer.ResetCameraClippingRange();

    // used for restore quality rendering after a given amount of time
    fineRenderingTime = 0;
    renderingMonitor = new Thread(this, "VTK panel rendering monitor");
    renderingMonitor.start();

    addMouseListener(this);
    addMouseMotionListener(this);
    addMouseWheelListener(this);
    addKeyListener(this);
  }
Ejemplo n.º 3
0
 /** Zoom current view by specified factor (negative value means unzoom) */
 public void zoomView(vtkCamera c, vtkRenderer r, double factor) {
   lock();
   try {
     if (c.GetParallelProjection() == 1) c.SetParallelScale(c.GetParallelScale() / factor);
     else {
       c.Dolly(factor);
       r.ResetCameraClippingRange();
     }
   } finally {
     unlock();
   }
 }
Ejemplo n.º 4
0
 /** Rotate specified camera view */
 public void rotateView(vtkCamera c, vtkRenderer r, int dx, int dy) {
   lock();
   try {
     // rotation mode
     c.Azimuth(dx);
     c.Elevation(dy);
     c.OrthogonalizeViewUp();
     r.ResetCameraClippingRange();
   } finally {
     unlock();
   }
 }
Ejemplo n.º 5
0
  /** Translate specified camera view */
  public void translateView(vtkCamera c, vtkRenderer r, double dx, double dy) {
    // translation mode
    double FPoint[];
    double PPoint[];
    double APoint[] = new double[3];
    double RPoint[];
    double focalDepth;

    lock();
    try {
      // get the current focal point and position
      FPoint = c.GetFocalPoint();
      PPoint = c.GetPosition();

      // calculate the focal depth since we'll be using it a lot
      r.SetWorldPoint(FPoint[0], FPoint[1], FPoint[2], 1.0);
      r.WorldToDisplay();
      focalDepth = r.GetDisplayPoint()[2];

      final int[] size = rw.GetSize();
      APoint[0] = (size[0] / 2.0) + dx;
      APoint[1] = (size[1] / 2.0) + dy;
      APoint[2] = focalDepth;
      r.SetDisplayPoint(APoint);
      r.DisplayToWorld();
      RPoint = r.GetWorldPoint();
      if (RPoint[3] != 0.0) {
        RPoint[0] = RPoint[0] / RPoint[3];
        RPoint[1] = RPoint[1] / RPoint[3];
        RPoint[2] = RPoint[2] / RPoint[3];
      }

      /*
       * Compute a translation vector, moving everything 1/2 the distance
       * to the cursor. (Arbitrary scale factor)
       */
      c.SetFocalPoint(
          (FPoint[0] - RPoint[0]) / 2.0 + FPoint[0],
          (FPoint[1] - RPoint[1]) / 2.0 + FPoint[1],
          (FPoint[2] - RPoint[2]) / 2.0 + FPoint[2]);
      c.SetPosition(
          (FPoint[0] - RPoint[0]) / 2.0 + PPoint[0],
          (FPoint[1] - RPoint[1]) / 2.0 + PPoint[1],
          (FPoint[2] - RPoint[2]) / 2.0 + PPoint[2]);
      r.ResetCameraClippingRange();
    } finally {
      unlock();
    }
  }
Ejemplo n.º 6
0
  public static void main(String args[]) {
    vtkCamera camera;
    vtkPanel panel = new vtkPanel();
    Ex94a f = new Ex94a();

    vtkPLOT3DReader pl3d = new vtkPLOT3DReader();
    pl3d.SetXYZFileName("g:/vtkdata/combxyz.bin");
    pl3d.SetQFileName("g:/vtkdata/combq.bin");
    pl3d.SetScalarFunctionNumber(100);
    pl3d.SetVectorFunctionNumber(202);
    pl3d.Update();

    vtkPlaneSource plane = new vtkPlaneSource();
    plane.SetResolution(50, 50);

    vtkTransform transP1 = new vtkTransform();
    transP1.Translate(3.7, 0.0, 28.37);
    transP1.Scale(5, 5, 5);
    transP1.RotateY(90);

    vtkTransformPolyDataFilter tpd1 = new vtkTransformPolyDataFilter();
    tpd1.SetInput(plane.GetOutput());
    tpd1.SetTransform(transP1);

    vtkOutlineFilter outTpd1 = new vtkOutlineFilter();
    outTpd1.SetInput(tpd1.GetOutput());

    vtkPolyDataMapper mapTpd1 = new vtkPolyDataMapper(); // same as vtkPolyMapper in tcl
    mapTpd1.SetInput(outTpd1.GetOutput());

    vtkActor tpd1Actor = new vtkActor();
    tpd1Actor.SetMapper(mapTpd1);
    tpd1Actor.GetProperty().SetColor(0, 0, 0);

    vtkTransform transP2 = new vtkTransform();
    transP2.Translate(9.2, 0.0, 31.20);
    transP2.Scale(5, 5, 5);
    transP2.RotateY(90);

    vtkTransformPolyDataFilter tpd2 = new vtkTransformPolyDataFilter();
    tpd2.SetInput(plane.GetOutput());
    tpd2.SetTransform(transP2);

    vtkOutlineFilter outTpd2 = new vtkOutlineFilter();
    outTpd2.SetInput(tpd2.GetOutput());

    vtkPolyDataMapper mapTpd2 = new vtkPolyDataMapper();
    mapTpd2.SetInput(outTpd2.GetOutput());

    vtkActor tpd2Actor = new vtkActor();
    tpd2Actor.SetMapper(mapTpd2);
    tpd2Actor.GetProperty().SetColor(0, 0, 0);

    vtkTransform transP3 = new vtkTransform();
    transP3.Translate(13.27, 0.0, 33.30);
    transP3.Scale(5, 5, 5);
    transP3.RotateY(90);

    vtkTransformPolyDataFilter tpd3 = new vtkTransformPolyDataFilter();
    tpd3.SetInput(plane.GetOutput());
    tpd3.SetTransform(transP3);

    vtkOutlineFilter outTpd3 = new vtkOutlineFilter();
    outTpd3.SetInput(tpd3.GetOutput());

    vtkPolyDataMapper mapTpd3 = new vtkPolyDataMapper();
    mapTpd3.SetInput(outTpd3.GetOutput());

    vtkActor tpd3Actor = new vtkActor();
    tpd3Actor.SetMapper(mapTpd3);
    tpd3Actor.GetProperty().SetColor(0, 0, 0);

    vtkAppendPolyData appendF = new vtkAppendPolyData();
    appendF.AddInput(tpd1.GetOutput());
    appendF.AddInput(tpd2.GetOutput());
    appendF.AddInput(tpd3.GetOutput());

    vtkProbeFilter probe = new vtkProbeFilter();
    probe.SetInput(appendF.GetOutput());
    probe.SetSource(pl3d.GetOutput());

    vtkHedgeHog hedgehog = new vtkHedgeHog(); // use hedgehog instead of contourfilter
    hedgehog.SetInput(probe.GetOutput());
    hedgehog.SetScaleFactor(0.015);

    vtkPolyDataMapper hedgehogMapper = new vtkPolyDataMapper();
    hedgehogMapper.SetInput(hedgehog.GetOutput());
    hedgehogMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange());

    vtkActor planeActor = new vtkActor();
    planeActor.SetMapper(hedgehogMapper);

    vtkStructuredGridOutlineFilter outline = new vtkStructuredGridOutlineFilter();
    outline.SetInput(pl3d.GetOutput());

    vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper();
    outlineMapper.SetInput(outline.GetOutput());

    vtkActor outlineActor = new vtkActor();
    outlineActor.SetMapper(outlineMapper);
    outlineActor.GetProperty().SetColor(0, 0, 0);

    panel.getRenderer().AddActor(outlineActor);
    panel.getRenderer().AddActor(planeActor);
    panel.getRenderer().AddActor(tpd1Actor);
    panel.getRenderer().AddActor(tpd2Actor);
    panel.getRenderer().AddActor(tpd3Actor);
    panel.getRenderer().SetBackground(1, 1, 1);
    panel.setSize(500, 500);

    camera = panel.getRenderer().GetActiveCamera();
    camera.SetClippingRange(3.95297, 50);
    camera.SetFocalPoint(8.88908, 0.595038, 29.3342);
    camera.SetPosition(-12.3332, 31.7479, 41.2387);
    camera.ComputeViewPlaneNormal();
    camera.SetViewUp(0.060772, -0.319905, 0.945498);

    f.add("Center", panel);
    f.pack();

    // Set up the menu
    MenuBar mb = new MenuBar();
    Menu file = new Menu("File");
    file.add(new MenuItem("Exit"));
    mb.add(file);
    f.setMenuBar(mb);

    f.show();
  }
Ejemplo n.º 7
0
 /** Set the specified light at the same position than the specified camera */
 public static void setLightToCameraPosition(vtkLight l, vtkCamera c) {
   l.SetPosition(c.GetPosition());
   l.SetFocalPoint(c.GetFocalPoint());
 }