Esempio n. 1
0
  /** @param args */
  public static void main(String[] args) {

    vtkPLYReader face1 = new vtkPLYReader();
    face1.SetFileName("/home/m2ivi/vanegue/Documents/VisA/tp4/3Dmodels/Model1.ply");
    face1.Update();
    vtkPLYReader face2 = new vtkPLYReader();
    face2.SetFileName("/home/m2ivi/vanegue/Documents/VisA/tp4/3Dmodels/Model2.ply");
    face2.Update();

    vtkIterativeClosestPointTransform recal = new vtkIterativeClosestPointTransform();
    recal.SetSource(face1.GetOutput());
    recal.SetTarget(face2.GetOutput());
    recal.SetMaximumNumberOfLandmarks(5000);
    recal.GetLandmarkTransform().SetModeToRigidBody();
    recal.StartByMatchingCentroidsOn();
    recal.SetMaximumNumberOfIterations(1);
    recal.Modified();
    recal.Update();

    vtkTransformPolyDataFilter tpd = new vtkTransformPolyDataFilter();
    tpd.SetInput(face1.GetOutput());
    tpd.SetTransform(recal);
    tpd.Update();

    vtkPolyDataMapper map = new vtkPolyDataMapper();
    map.SetInput(tpd.GetOutput());
    vtkPolyDataMapper map2 = new vtkPolyDataMapper();
    map2.SetInput(face2.GetOutput());

    vtkActor actorFace1 = new vtkActor();
    actorFace1.SetMapper(map);
    actorFace1.GetProperty().SetColor(0, 0, 1);
    vtkActor actorFace2 = new vtkActor();
    actorFace2.SetMapper(map2);
    actorFace2.GetProperty().SetColor(0, 1, 0);

    vtkRenderer ren1 = new vtkRenderer();
    ren1.AddActor(actorFace1);
    ren1.AddActor(actorFace2);
    ren1.SetBackground(1, 1, 1);

    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(ren1);
    renWin.SetSize(500, 500);

    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);
    renWin.Render();
    iren.Start();
  }
Esempio n. 2
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();
    }
  }
Esempio 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();
   }
 }
Esempio 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();
   }
 }
Esempio n. 5
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);
  }
Esempio n. 6
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();
    }
  }