Example #1
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);
  }
Example #2
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();
   }
 }
Example #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();
   }
 }
Example #4
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();
    }
  }