<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;<br>import vtk.*;<br>//import vtk.util.VtkUtil;</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 cutting (vtkCutter) and how it<br> * compares with extracting a plane from a computational grid.<br> */<br>public class CutCombustor extends JPanel {</p>
<p> public CutCombustor() {<br> // Setup VTK rendering panel<br> vtkPanel renWin = new vtkPanel();</p>
<p> // Read some data.<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> // The cutter uses an implicit function to perform the cutting.<br> // Here we define a plane, specifying its center and normal.<br> // Then we assign the plane to the cutter.<br> vtkPlane plane = new vtkPlane();
<br> plane.SetOrigin(pl3d.GetOutput().GetCenter());<br> plane.SetNormal(-0.287, 0, 0.9579);<br> vtkCutter planeCut = new vtkCutter();<br> planeCut.SetInput(pl3d.GetOutput());<br> planeCut.SetCutFunction(plane);
<br> vtkPolyDataMapper cutMapper = new vtkPolyDataMapper();<br> cutMapper.SetInput(planeCut.GetOutput());<br> cutMapper.SetScalarRange(pl3d.GetOutput().GetPointData().GetScalars().GetRange());<br> vtkActor cutActor = new vtkActor();
<br> cutActor.SetMapper(cutMapper);</p>
<p> // Here we extract a computational plane from the structured grid.<br> // We render it as wireframe.<br> vtkStructuredGridGeometryFilter compPlane = new vtkStructuredGridGeometryFilter();<br> compPlane.SetInput
(pl3d.GetOutput());<br> compPlane.SetExtent(0, 100, 0, 100, 9, 9);<br> vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();<br> planeMapper.SetInput(compPlane.GetOutput());<br> planeMapper.ScalarVisibilityOff
();<br> vtkActor planeActor = new vtkActor();<br> planeActor.SetMapper(planeMapper);<br> planeActor.GetProperty().SetRepresentationToWireframe();<br> planeActor.GetProperty().SetColor(0, 0, 0);</p>
<p> // The outline of the data puts the data in context.<br> vtkStructuredGridOutlineFilter outline = new vtkStructuredGridOutlineFilter();<br> outline.SetInput(pl3d.GetOutput());<br> vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper();
<br> outlineMapper.SetInput(outline.GetOutput());<br> vtkActor outlineActor = new vtkActor();<br> outlineActor.SetMapper(outlineMapper);<br> outlineActor.GetProperty().SetColor(0, 0, 0);</p>
<p> // Add the actors to the renderer, set the background and size<br> renWin.GetRenderer().AddActor(outlineActor);<br> renWin.GetRenderer().AddActor(planeActor);<br> renWin.GetRenderer().AddActor(cutActor);</p>
<p> renWin.GetRenderer().SetBackground(1, 1, 1);<br> renWin.setSize(400, 300);</p>
<p> vtkCamera cam1 = renWin.GetRenderer().GetActiveCamera();<br> cam1.SetClippingRange(11.1034, 59.5328);<br> cam1.SetFocalPoint(9.71821, 0.458166, 29.3999);<br> cam1.SetPosition(-2.95748, -26.7271, 44.5309);
<br> cam1.SetViewUp(0.0184785, 0.479657, 0.877262);</p>
<p> // Place renWin in the center of this panel<br> setLayout(new BorderLayout());<br> add(renWin, BorderLayout.CENTER);<br> }</p>
<p><br> public static void main(String s[]) {<br> CutCombustor panel = new CutCombustor();</p>
<p> JFrame frame = new JFrame("CutCombustor");<br> frame.addWindowListener(new WindowAdapter() {<br> public void windowClosing(WindowEvent e) {<br> System.exit(0);<br> }<br> });<br>
frame.getContentPane().add("Center", panel);<br> frame.pack();<br> frame.setVisible(true);<br> }<br>}</p>
<p> </p></div>