Esempio 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();
    }
  }
Esempio 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);
  }
Esempio n. 3
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();
  }