<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>
<p>package examples;</p>
<p>//This example demonstrates the use of the contour filter, and the use of<br>//the vtkSampleFunction to generate a volume of data samples from an<br>//implicit function.</p>
<p>import vtk.*;</p>
<p>public class VisQuad {<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> public static void main(String s[]) {</p>
<p>// VTK supports implicit functions of the form f(x,y,z)=constant. These<br>// functions can represent things spheres, cones, etc. Here we use a<br>// general form for a quadric to create an elliptical data field.
<br> vtkQuadric quadric = new vtkQuadric();<br> quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0);</p>
<p>// vtkSampleFunction samples an implicit function over the x-y-z range<br>// specified (here it defaults to -1,1 in the x,y,z directions).<br> vtkSampleFunction sample = new vtkSampleFunction();<br> sample.SetSampleDimensions
(30, 30, 30);<br> sample.SetImplicitFunction(quadric);</p>
<p>// Create five surfaces F(x,y,z) = constant between range specified. The<br>// GenerateValues() method creates n isocontour values between the range<br>// specified.<br> vtkContourFilter contours = new vtkContourFilter();
<br> contours.SetInput(sample.GetOutput());<br> contours.GenerateValues(5, 0.0, 1.2);</p>
<p> vtkPolyDataMapper contMapper = new vtkPolyDataMapper();<br> contMapper.SetInput(contours.GetOutput());<br> contMapper.SetScalarRange(0.0, 1.2);</p>
<p> vtkActor contActor = new vtkActor();<br> contActor.SetMapper(contMapper);</p>
<p>// We'll put a simple outline around the data.<br> vtkOutlineFilter outline = new vtkOutlineFilter();<br> outline.SetInput(sample.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>// The usual rendering stuff.<br> vtkRenderer ren = new vtkRenderer();<br> vtkRenderWindow renWin = new vtkRenderWindow();<br> renWin.AddRenderer(ren);<br> vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
<br> iren.SetRenderWindow(renWin);</p>
<p> ren.SetBackground(1, 1, 1);<br> ren.AddActor(contActor);<br> ren.AddActor(outlineActor);</p>
<p> iren.Initialize();<br> renWin.Render();<br> iren.Start();<br> }//main<br>}//class VisQuad<br></p></div>