[vtkusers] Java Example for ProbeComb

Todd Simons todd.a.simons at gmail.com
Wed Dec 20 10:27:32 EST 2006


 Hello all,

I'm a relatively new VTK developer.  I am using Java as the gui for my VTK
applications.  I had a hard time getting started and finding examples
written in Java.  I have ported a dozen examples to Java to get familiar
with it.  I wanted to post my examples so other Java enthusiasts could get
up to speed on VTK a bit more easily.  I hope this helps.

Best Regards,
Todd




package examples;
/*-----------------------------------------------------------
    ProbeComb.tcl converted to Java
    October 17, 2006

    This shows how to probe a dataset with a plane.
    The probed data is then contoured.
  -----------------------------------------------------------*/
import vtk.*;

public class ProbeComb {
    // in the static contructor we load in the native code
    // The libraries must be in your path to work
    static {
      System.loadLibrary("vtkCommonJava");
      System.loadLibrary("vtkFilteringJava");
      System.loadLibrary("vtkIOJava");
      System.loadLibrary("vtkImagingJava");
      System.loadLibrary("vtkGraphicsJava");
      System.loadLibrary("vtkRenderingJava");
    }


  public static void main(String s[]) {

    //create pipeline
    //----------------
    vtkPLOT3DReader pl3d = new vtkPLOT3DReader();
      pl3d.SetXYZFileName("c:/user/VTK/Data/combxyz.bin");
      pl3d.SetQFileName("c:/user/VTK/Data/combq.bin");
      pl3d.SetScalarFunctionNumber(100);
      pl3d.SetVectorFunctionNumber(202);
      pl3d.Update();


/*  We create three planes and position them in the correct
    position using transform filters. They are then appended
    together and used as a probe. */
    vtkPlaneSource plane = new vtkPlaneSource();
      plane.SetResolution(50,50);

    //Plane 1
    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();
      mapTpd1.SetInput(outTpd1.GetOutput());

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


    //Plane 2
    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);


    //Plane 3
    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());

/*  The vtkProbeFilter takes two inputs. One is a dataset
    to use as the probe geometry (SetInput); the other is
    the data to probe (SetSource). The output dataset
    structure (geometry and topology) of the probe is the
    same as the structure of the input. The probing
    process generates new data values resampled from the
    source.*/
    vtkProbeFilter probe = new vtkProbeFilter();
      probe.SetInput(appendF.GetOutput());
      probe.SetSource(pl3d.GetOutput());

    vtkContourFilter contour = new vtkContourFilter();
      contour.SetInput(probe.GetOutput());
      contour.GenerateValues(50, pl3d.GetOutput().GetScalarRange());

    vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();
      contourMapper.SetInput(contour.GetOutput());
      contourMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange());

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

    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);

    // create planes
    // Create the RenderWindow, Renderer and both Actors
    vtkRenderer renderer = new vtkRenderer ();
    vtkRenderWindow renWin = new vtkRenderWindow();
      renWin.AddRenderer(renderer);
    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
      iren.SetRenderWindow(renWin);

    renderer.AddActor(outlineActor);
    renderer.AddActor(planeActor);
    renderer.AddActor(tpd1Actor);
    renderer.AddActor(tpd2Actor);
    renderer.AddActor(tpd3Actor);
    renderer.SetBackground(1, 1, 1);

    renWin.SetSize(500, 500);

    vtkCamera cam1=renderer.GetActiveCamera();
      cam1.SetClippingRange(3.95297, 50);
      cam1.SetFocalPoint(8.88908, 0.595038, 29.3342);
      cam1.SetPosition(-12.3332, 31.7479, 41.2387);
      cam1.SetViewUp(0.060772, -0.319905, 0.945498);

    renWin.Render();
    iren.Start();

  }//main

}//class ProbeComb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/1bfffeae/attachment.htm>


More information about the vtkusers mailing list