<div>
<div>Hello all,</div>
<div>&nbsp;</div>
<div>I&#39;m a relatively new VTK developer.&nbsp; I am using Java as the gui for my VTK applications.&nbsp; I had a hard time getting started and finding examples written in Java.&nbsp; I have ported a dozen examples to Java to get familiar with it.&nbsp; I wanted to post my examples so other Java enthusiasts could get up to speed on VTK a bit more easily.&nbsp; I hope this helps. 
</div>
<div>&nbsp;</div>
<div>Best Regards,</div>
<div>Todd</div></div>
<div>
<p>package examples;</p>
<p>import vtk.*;</p>
<p>/* This example demonstrates the conversion of point data to cell data.<br>&nbsp;&nbsp; The conversion is necessary because we want to threshold data based<br>&nbsp;&nbsp; on cell scalar values.*/</p>
<p>public class PointToCellData {</p>
<p>&nbsp;&nbsp;&nbsp; // in the static contructor we load in the native code<br>&nbsp;&nbsp;&nbsp; // The libraries must be in your path to work<br>&nbsp;&nbsp;&nbsp; static {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkCommonJava&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkFilteringJava&quot;);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkIOJava&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkImagingJava&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkGraphicsJava&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.loadLibrary(&quot;vtkRenderingJava&quot;);
<br>&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; public static void main(String s[]) {<br>&nbsp;&nbsp;&nbsp; // Read the data files<br>&nbsp;&nbsp;&nbsp; /* Read some data with point data attributes. The data is from a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plastic blow molding process (e.g., to make plastic bottles) and
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; consists of two logical components: a mold and a parison. The<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parison is the hot plastic that is being molded, and the mold is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clamped around the parison to form its shape. */<br>&nbsp;&nbsp;&nbsp; vtkUnstructuredGridReader reader = new vtkUnstructuredGridReader();
<br>&nbsp;&nbsp;&nbsp; reader.SetFileName(&quot;d:/user/VTK/Data/blow.vtk&quot;);<br>&nbsp;&nbsp;&nbsp; reader.SetScalarsName(&quot;thickness9&quot;);<br>&nbsp;&nbsp;&nbsp; reader.SetVectorsName(&quot;displacement9&quot;);</p>
<p>&nbsp;&nbsp;&nbsp; /* Convert the point data to cell data. The point data is passed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; through the filter so it can be warped. The vtkThresholdFilter then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thresholds based on cell scalar values and extracts a portion of the
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parison whose cell scalar values lie between 0.25 and 0.75.*/<br>&nbsp;&nbsp;&nbsp; vtkPointDataToCellData p2c = new vtkPointDataToCellData();<br>&nbsp;&nbsp;&nbsp; p2c.SetInputConnection(reader.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; p2c.PassPointDataOn();
</p>
<p>&nbsp;&nbsp;&nbsp; vtkWarpVector warp = new vtkWarpVector();<br>&nbsp;&nbsp;&nbsp; warp.SetInput(p2c.GetUnstructuredGridOutput());</p>
<p>&nbsp;&nbsp;&nbsp; vtkThreshold thresh = new vtkThreshold();<br>&nbsp;&nbsp;&nbsp; thresh.SetInputConnection(warp.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; thresh.ThresholdBetween(0.25, 0.75);<br>&nbsp;&nbsp;&nbsp; thresh.SetInputArrayToProcess(1, 0, 0, 0, &quot;thickness9&quot;);
<br>&nbsp;&nbsp;&nbsp; //thresh.SetAttributeModeToUseCellData();</p>
<p>&nbsp;&nbsp;&nbsp; // This is used to extract the mold from the parison.<br>&nbsp;&nbsp;&nbsp; vtkConnectivityFilter connect = new vtkConnectivityFilter();<br>&nbsp;&nbsp;&nbsp; connect.SetInputConnection(thresh.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; connect.SetExtractionModeToSpecifiedRegions
();<br>&nbsp;&nbsp;&nbsp; connect.AddSpecifiedRegion(0);<br>&nbsp;&nbsp;&nbsp; connect.AddSpecifiedRegion(1);</p>
<p>&nbsp;&nbsp;&nbsp; vtkDataSetMapper moldMapper = new vtkDataSetMapper();<br>&nbsp;&nbsp;&nbsp; moldMapper.SetInputConnection(reader.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; moldMapper.ScalarVisibilityOff();</p>
<p>&nbsp;&nbsp;&nbsp; vtkActor moldActor = new vtkActor();<br>&nbsp;&nbsp;&nbsp; moldActor.SetMapper(moldMapper);<br>&nbsp;&nbsp;&nbsp; moldActor.GetProperty().SetColor(.2, .2, .2);<br>&nbsp;&nbsp;&nbsp; moldActor.GetProperty().SetRepresentationToWireframe();</p>
<p>&nbsp;&nbsp;&nbsp; // The threshold filter has been used to extract the parison.<br>&nbsp;&nbsp;&nbsp; vtkConnectivityFilter connect2 = new vtkConnectivityFilter();<br>&nbsp;&nbsp;&nbsp; connect2.SetInputConnection(thresh.GetOutputPort());</p>
<p>&nbsp;&nbsp;&nbsp; vtkGeometryFilter parison = new vtkGeometryFilter();<br>&nbsp;&nbsp;&nbsp; parison.SetInputConnection(connect2.GetOutputPort());</p>
<p>&nbsp;&nbsp;&nbsp; vtkPolyDataNormals normals2 = new vtkPolyDataNormals();<br>&nbsp;&nbsp;&nbsp; normals2.SetInputConnection(parison.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; normals2.SetFeatureAngle(60);<br>&nbsp;&nbsp;&nbsp; vtkLookupTable lut = new vtkLookupTable();<br>&nbsp;&nbsp;&nbsp; lut.SetHueRange
(0.0, 0.66667);<br>&nbsp;&nbsp;&nbsp; vtkPolyDataMapper parisonMapper = new vtkPolyDataMapper();<br>&nbsp;&nbsp;&nbsp; parisonMapper.SetInputConnection(normals2.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; parisonMapper.SetLookupTable(lut);<br>&nbsp;&nbsp;&nbsp; parisonMapper.SetScalarRange
(0.12, 1.0);</p>
<p>&nbsp;&nbsp;&nbsp; vtkActor parisonActor = new vtkActor();<br>&nbsp;&nbsp;&nbsp; parisonActor.SetMapper(parisonMapper);</p>
<p>&nbsp;&nbsp;&nbsp; // We generate some contour lines on the parison.<br>&nbsp;&nbsp;&nbsp; vtkContourFilter cf = new vtkContourFilter();<br>&nbsp;&nbsp;&nbsp; cf.SetInputConnection(connect2.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; cf.SetValue(0, .5);</p>
<p>&nbsp;&nbsp;&nbsp; vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();<br>&nbsp;&nbsp;&nbsp; contourMapper.SetInputConnection(cf.GetOutputPort());<br>&nbsp;&nbsp;&nbsp; vtkActor contours = new vtkActor();<br>&nbsp;&nbsp;&nbsp; contours.SetMapper(contourMapper);</p>
<p>&nbsp;&nbsp;&nbsp; // Create graphics stuff<br>&nbsp;&nbsp;&nbsp; vtkRenderer ren = new vtkRenderer();<br>&nbsp;&nbsp;&nbsp; vtkRenderWindow renWin = new vtkRenderWindow();<br>&nbsp;&nbsp;&nbsp; renWin.AddRenderer(ren);<br>&nbsp;&nbsp;&nbsp; vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
<br>&nbsp;&nbsp;&nbsp; iren.SetRenderWindow(renWin);</p>
<p>&nbsp;&nbsp;&nbsp; // Add the actors to the renderer, set the background and size<br>&nbsp;&nbsp;&nbsp; ren.AddActor(moldActor);<br>&nbsp;&nbsp;&nbsp; ren.AddActor(parisonActor);<br>&nbsp;&nbsp;&nbsp; ren.AddActor(contours);</p>
<p>&nbsp;&nbsp;&nbsp; ren.ResetCamera();<br>&nbsp;&nbsp;&nbsp; ren.GetActiveCamera().Azimuth(60);<br>&nbsp;&nbsp;&nbsp; ren.GetActiveCamera().Roll(-90);<br>&nbsp;&nbsp;&nbsp; ren.GetActiveCamera().Dolly(2);<br>&nbsp;&nbsp;&nbsp; ren.ResetCameraClippingRange();</p>
<p>&nbsp;&nbsp;&nbsp; ren.SetBackground(1, 1, 1);<br>&nbsp;&nbsp;&nbsp; renWin.SetSize(750, 400);</p>
<p>&nbsp;&nbsp;&nbsp; iren.Initialize();<br>&nbsp;&nbsp;&nbsp; renWin.Render();<br>&nbsp;&nbsp;&nbsp; iren.Start();</p>
<p>&nbsp; }//main<br>}//class PointToCellData<br></p></div>