<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>import vtk.*;</p>
<p>import javax.swing.*;<br>import java.awt.*;<br>import java.awt.event.WindowAdapter;<br>import java.awt.event.WindowEvent;</p>
<p>/**<br> * This example shows how to use draw contours on warped surfaces<br> */</p>
<p>public class WarpComb {</p>
<p> // 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[]) {<br> // Read the data files<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> vtkStructuredGridGeometryFilter plane = new vtkStructuredGridGeometryFilter();<br> plane.SetInput(pl3d.GetOutput());<br> plane.SetExtent( 10, 10, 1, 100, 1, 100);</p>
<p> vtkStructuredGridGeometryFilter plane2 = new vtkStructuredGridGeometryFilter();<br> plane2.SetInput(pl3d.GetOutput());<br> plane2.SetExtent(30, 30, 1, 100, 1, 100);</p>
<p> vtkStructuredGridGeometryFilter plane3 = new vtkStructuredGridGeometryFilter();<br> plane3.SetInput(pl3d.GetOutput());<br> plane3.SetExtent(45, 45, 1, 100, 1, 100);</p>
<p> vtkAppendPolyData appendF = new vtkAppendPolyData();<br> appendF.AddInput (plane.GetOutput());<br> appendF.AddInput (plane2.GetOutput());<br> appendF.AddInput (plane3.GetOutput());</p>
<p> vtkWarpScalar warp = new vtkWarpScalar();<br> warp.SetInput (appendF.GetOutput());<br> warp.UseNormalOn();<br> warp.SetNormal (1.0, 0.0, 0.0);<br> warp.SetScaleFactor(2.5);</p>
<p> vtkCastToConcrete caster = new vtkCastToConcrete();<br> caster.SetInput (warp.GetOutput());</p>
<p> vtkPolyDataNormals normals = new vtkPolyDataNormals();<br> normals.SetInput (caster.GetPolyDataOutput());<br> normals.SetFeatureAngle(60);</p>
<p> vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();<br> planeMapper.SetInput (normals.GetOutput());<br> planeMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange());</p>
<p> vtkActor planeActor = new vtkActor();<br> planeActor.SetMapper (planeMapper);</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.0, 0.0);</p>
<p>// Add the actors to the renderer, set the background and size<br> vtkRenderer renderer = new vtkRenderer ();<br> vtkRenderWindow renWin = new vtkRenderWindow();<br> renWin.AddRenderer(renderer);</p>
<p> renderer.AddActor(outlineActor);<br> renderer.AddActor(planeActor);<br> renderer.SetBackground(1, 1, 1);</p>
<p> vtkCamera cam1 = renderer.GetActiveCamera();<br> cam1.SetClippingRange( 3.95297, 50);<br> cam1.SetFocalPoint( 9.71821, 0.458166, 29.3999);<br> cam1.SetPosition( 2.7439, -37.3196, 38.7167);<br> cam1.ComputeViewPlaneNormal
();<br> cam1.SetViewUp(-0.16123, 0.264271, 0.950876);</p>
<p> vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br> iren.SetRenderWindow(renWin);</p>
<p> renWin.SetSize(500, 500);<br> renWin.Render();<br> iren.Start();<br> }//main<br>}//calss WarpComb<br></p></div>