<div>
<div>Hello all,</div>
<div> </div>
<div>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.
</div>
<div> </div>
<div>Best Regards,</div>
<div>Todd</div>
<div> </div></div>
<div> </div>
<div> </div>
<div>
<p>package examples;<br>/*-----------------------------------------------------------<br> ProbeComb.tcl converted to Java<br> October 17, 2006</p>
<p> This shows how to probe a dataset with a plane.<br> The probed data is then contoured.<br> -----------------------------------------------------------*/<br>import vtk.*;</p>
<p>public class ProbeComb {<br> // in the static contructor we load in the native code<br> // The libraries must be in your path to work<br> static {<br> System.loadLibrary("vtkCommonJava");<br>
System.loadLibrary("vtkFilteringJava");<br> System.loadLibrary("vtkIOJava");<br> System.loadLibrary("vtkImagingJava");<br> System.loadLibrary("vtkGraphicsJava");<br>
System.loadLibrary("vtkRenderingJava");<br> }</p>
<p><br> public static void main(String s[]) {</p>
<p> //create pipeline<br> //----------------<br> vtkPLOT3DReader pl3d = new vtkPLOT3DReader();<br> pl3d.SetXYZFileName("c:/user/VTK/Data/combxyz.bin");<br> pl3d.SetQFileName("c:/user/VTK/Data/combq.bin");
<br> pl3d.SetScalarFunctionNumber(100);<br> pl3d.SetVectorFunctionNumber(202);<br> pl3d.Update();</p>
<p><br>/* We create three planes and position them in the correct<br> position using transform filters. They are then appended<br> together and used as a probe. */<br> vtkPlaneSource plane = new vtkPlaneSource();
<br> plane.SetResolution(50,50);</p>
<p> //Plane 1<br> vtkTransform transP1 = new vtkTransform();<br> transP1.Translate(3.7, 0.0, 28.37);<br> transP1.Scale(5, 5, 5);<br> transP1.RotateY(90);</p>
<p> vtkTransformPolyDataFilter tpd1 = new vtkTransformPolyDataFilter();<br> tpd1.SetInput(plane.GetOutput());<br> tpd1.SetTransform(transP1);</p>
<p> vtkOutlineFilter outTpd1 = new vtkOutlineFilter();<br> outTpd1.SetInput(tpd1.GetOutput());</p>
<p> vtkPolyDataMapper mapTpd1 = new vtkPolyDataMapper();<br> mapTpd1.SetInput(outTpd1.GetOutput());</p>
<p> vtkActor tpd1Actor = new vtkActor();<br> tpd1Actor.SetMapper(mapTpd1);<br> tpd1Actor.GetProperty().SetColor(0,0,0);</p>
<p><br> //Plane 2<br> vtkTransform transP2 = new vtkTransform();<br> transP2.Translate(9.2, 0.0, 31.20);<br> transP2.Scale(5, 5, 5);<br> transP2.RotateY(90);</p>
<p> vtkTransformPolyDataFilter tpd2 = new vtkTransformPolyDataFilter();<br> tpd2.SetInput(plane.GetOutput());<br> tpd2.SetTransform(transP2);</p>
<p> vtkOutlineFilter outTpd2 = new vtkOutlineFilter();<br> outTpd2.SetInput(tpd2.GetOutput());</p>
<p> vtkPolyDataMapper mapTpd2 = new vtkPolyDataMapper();<br> mapTpd2.SetInput(outTpd2.GetOutput());</p>
<p> vtkActor tpd2Actor = new vtkActor();<br> tpd2Actor.SetMapper(mapTpd2);<br> tpd2Actor.GetProperty().SetColor(0,0,0);</p>
<p><br> //Plane 3<br> vtkTransform transP3 = new vtkTransform();<br> transP3.Translate(13.27, 0.0, 33.30);<br> transP3.Scale(5, 5, 5);<br> transP3.RotateY(90);</p>
<p> vtkTransformPolyDataFilter tpd3 = new vtkTransformPolyDataFilter();<br> tpd3.SetInput(plane.GetOutput());<br> tpd3.SetTransform(transP3);</p>
<p> vtkOutlineFilter outTpd3 = new vtkOutlineFilter();<br> outTpd3.SetInput(tpd3.GetOutput());</p>
<p> vtkPolyDataMapper mapTpd3 = new vtkPolyDataMapper();<br> mapTpd3.SetInput(outTpd3.GetOutput());</p>
<p> vtkActor tpd3Actor = new vtkActor();<br> tpd3Actor.SetMapper(mapTpd3);<br> tpd3Actor.GetProperty().SetColor(0,0,0);</p>
<p> vtkAppendPolyData appendF = new vtkAppendPolyData();<br> appendF.AddInput(tpd1.GetOutput());<br> appendF.AddInput(tpd2.GetOutput());<br> appendF.AddInput(tpd3.GetOutput());</p>
<p>/* The vtkProbeFilter takes two inputs. One is a dataset<br> to use as the probe geometry (SetInput); the other is<br> the data to probe (SetSource). The output dataset<br> structure (geometry and topology) of the probe is the
<br> same as the structure of the input. The probing<br> process generates new data values resampled from the<br> source.*/<br> vtkProbeFilter probe = new vtkProbeFilter();<br> probe.SetInput(appendF.GetOutput
());<br> probe.SetSource(pl3d.GetOutput());</p>
<p> vtkContourFilter contour = new vtkContourFilter();<br> contour.SetInput(probe.GetOutput());<br> contour.GenerateValues(50, pl3d.GetOutput().GetScalarRange());</p>
<p> vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();<br> contourMapper.SetInput(contour.GetOutput());<br> contourMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange());</p>
<p> vtkActor planeActor = new vtkActor();<br> planeActor.SetMapper(contourMapper);</p>
<p> vtkStructuredGridOutlineFilter outline = new vtkStructuredGridOutlineFilter();<br> outline.SetInput(pl3d.GetOutput());</p>
<p> vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper ();<br> outlineMapper.SetInput(outline.GetOutput());</p>
<p> vtkActor outlineActor = new vtkActor();<br> outlineActor.SetMapper(outlineMapper);<br> outlineActor.GetProperty().SetColor(0, 0, 0);</p>
<p> // create planes<br> // Create the RenderWindow, Renderer and both Actors<br> vtkRenderer renderer = new vtkRenderer ();<br> vtkRenderWindow renWin = new vtkRenderWindow();<br> renWin.AddRenderer(renderer);
<br> vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br> iren.SetRenderWindow(renWin);</p>
<p> renderer.AddActor(outlineActor);<br> renderer.AddActor(planeActor);<br> renderer.AddActor(tpd1Actor);<br> renderer.AddActor(tpd2Actor);<br> renderer.AddActor(tpd3Actor);<br> renderer.SetBackground(1, 1, 1);
</p>
<p> renWin.SetSize(500, 500);</p>
<p> vtkCamera cam1=renderer.GetActiveCamera();<br> cam1.SetClippingRange(3.95297, 50);<br> cam1.SetFocalPoint(8.88908, 0.595038, 29.3342);<br> cam1.SetPosition(-12.3332, 31.7479, 41.2387);<br> cam1.SetViewUp
(0.060772, -0.319905, 0.945498);</p>
<p> renWin.Render();<br> iren.Start();</p>
<p> }//main</p>
<p>}//class ProbeComb</p>
<p><br> </p>
<p> </p></div>