<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>
<p>package examples;</p>
<p>import vtk.*;</p>
<p>/* This example demonstrates the conversion of point data to cell data.<br> The conversion is necessary because we want to threshold data based<br> on cell scalar values.*/</p>
<p>public class PointToCellData {</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> /* Read some data with point data attributes. The data is from a<br> plastic blow molding process (e.g., to make plastic bottles) and
<br> consists of two logical components: a mold and a parison. The<br> parison is the hot plastic that is being molded, and the mold is<br> clamped around the parison to form its shape. */<br> vtkUnstructuredGridReader reader = new vtkUnstructuredGridReader();
<br> reader.SetFileName("d:/user/VTK/Data/blow.vtk");<br> reader.SetScalarsName("thickness9");<br> reader.SetVectorsName("displacement9");</p>
<p> /* Convert the point data to cell data. The point data is passed<br> through the filter so it can be warped. The vtkThresholdFilter then<br> thresholds based on cell scalar values and extracts a portion of the
<br> parison whose cell scalar values lie between 0.25 and 0.75.*/<br> vtkPointDataToCellData p2c = new vtkPointDataToCellData();<br> p2c.SetInputConnection(reader.GetOutputPort());<br> p2c.PassPointDataOn();
</p>
<p> vtkWarpVector warp = new vtkWarpVector();<br> warp.SetInput(p2c.GetUnstructuredGridOutput());</p>
<p> vtkThreshold thresh = new vtkThreshold();<br> thresh.SetInputConnection(warp.GetOutputPort());<br> thresh.ThresholdBetween(0.25, 0.75);<br> thresh.SetInputArrayToProcess(1, 0, 0, 0, "thickness9");
<br> //thresh.SetAttributeModeToUseCellData();</p>
<p> // This is used to extract the mold from the parison.<br> vtkConnectivityFilter connect = new vtkConnectivityFilter();<br> connect.SetInputConnection(thresh.GetOutputPort());<br> connect.SetExtractionModeToSpecifiedRegions
();<br> connect.AddSpecifiedRegion(0);<br> connect.AddSpecifiedRegion(1);</p>
<p> vtkDataSetMapper moldMapper = new vtkDataSetMapper();<br> moldMapper.SetInputConnection(reader.GetOutputPort());<br> moldMapper.ScalarVisibilityOff();</p>
<p> vtkActor moldActor = new vtkActor();<br> moldActor.SetMapper(moldMapper);<br> moldActor.GetProperty().SetColor(.2, .2, .2);<br> moldActor.GetProperty().SetRepresentationToWireframe();</p>
<p> // The threshold filter has been used to extract the parison.<br> vtkConnectivityFilter connect2 = new vtkConnectivityFilter();<br> connect2.SetInputConnection(thresh.GetOutputPort());</p>
<p> vtkGeometryFilter parison = new vtkGeometryFilter();<br> parison.SetInputConnection(connect2.GetOutputPort());</p>
<p> vtkPolyDataNormals normals2 = new vtkPolyDataNormals();<br> normals2.SetInputConnection(parison.GetOutputPort());<br> normals2.SetFeatureAngle(60);<br> vtkLookupTable lut = new vtkLookupTable();<br> lut.SetHueRange
(0.0, 0.66667);<br> vtkPolyDataMapper parisonMapper = new vtkPolyDataMapper();<br> parisonMapper.SetInputConnection(normals2.GetOutputPort());<br> parisonMapper.SetLookupTable(lut);<br> parisonMapper.SetScalarRange
(0.12, 1.0);</p>
<p> vtkActor parisonActor = new vtkActor();<br> parisonActor.SetMapper(parisonMapper);</p>
<p> // We generate some contour lines on the parison.<br> vtkContourFilter cf = new vtkContourFilter();<br> cf.SetInputConnection(connect2.GetOutputPort());<br> cf.SetValue(0, .5);</p>
<p> vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();<br> contourMapper.SetInputConnection(cf.GetOutputPort());<br> vtkActor contours = new vtkActor();<br> contours.SetMapper(contourMapper);</p>
<p> // Create graphics 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> // Add the actors to the renderer, set the background and size<br> ren.AddActor(moldActor);<br> ren.AddActor(parisonActor);<br> ren.AddActor(contours);</p>
<p> ren.ResetCamera();<br> ren.GetActiveCamera().Azimuth(60);<br> ren.GetActiveCamera().Roll(-90);<br> ren.GetActiveCamera().Dolly(2);<br> ren.ResetCameraClippingRange();</p>
<p> ren.SetBackground(1, 1, 1);<br> renWin.SetSize(750, 400);</p>
<p> iren.Initialize();<br> renWin.Render();<br> iren.Start();</p>
<p> }//main<br>}//class PointToCellData<br></p></div>