[vtkusers] Java example for CutCombustor

Todd Simons todd.a.simons at gmail.com
Wed Dec 20 10:25:03 EST 2006


 Hello all,

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.

Best Regards,
Todd


package examples;
import vtk.*;
//import vtk.util.VtkUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *  This example shows how to use cutting (vtkCutter) and how it
 *  compares with extracting a plane from a computational grid.
 */
public class CutCombustor extends JPanel {

  public CutCombustor() {
    // Setup VTK rendering panel
    vtkPanel renWin = new vtkPanel();

    // Read some data.
    vtkPLOT3DReader pl3d = new vtkPLOT3DReader();
    pl3d.SetXYZFileName("c:/user/VTK/Data/combxyz.bin");
    pl3d.SetQFileName("c:/user/VTK/Data/combq.bin");
    pl3d.SetScalarFunctionNumber(100);
    pl3d.SetVectorFunctionNumber(202);
    pl3d.Update();

    // The cutter uses an implicit function to perform the cutting.
    // Here we define a plane, specifying its center and normal.
    // Then we assign the plane to the cutter.
    vtkPlane plane = new vtkPlane();
    plane.SetOrigin(pl3d.GetOutput().GetCenter());
    plane.SetNormal(-0.287, 0, 0.9579);
    vtkCutter planeCut = new vtkCutter();
    planeCut.SetInput(pl3d.GetOutput());
    planeCut.SetCutFunction(plane);
    vtkPolyDataMapper cutMapper = new vtkPolyDataMapper();
    cutMapper.SetInput(planeCut.GetOutput());
    cutMapper.SetScalarRange(pl3d.GetOutput
().GetPointData().GetScalars().GetRange());
    vtkActor cutActor = new vtkActor();
    cutActor.SetMapper(cutMapper);

    // Here we extract a computational plane from the structured grid.
    // We render it as wireframe.
    vtkStructuredGridGeometryFilter compPlane = new
vtkStructuredGridGeometryFilter();
    compPlane.SetInput(pl3d.GetOutput());
    compPlane.SetExtent(0, 100, 0, 100, 9, 9);
    vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();
    planeMapper.SetInput(compPlane.GetOutput());
    planeMapper.ScalarVisibilityOff();
    vtkActor planeActor = new vtkActor();
    planeActor.SetMapper(planeMapper);
    planeActor.GetProperty().SetRepresentationToWireframe();
    planeActor.GetProperty().SetColor(0, 0, 0);

    // The outline of the data puts the data in context.
    vtkStructuredGridOutlineFilter outline = new
vtkStructuredGridOutlineFilter();
    outline.SetInput(pl3d.GetOutput());
    vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper();
    outlineMapper.SetInput(outline.GetOutput());
    vtkActor outlineActor = new vtkActor();
    outlineActor.SetMapper(outlineMapper);
    outlineActor.GetProperty().SetColor(0, 0, 0);

    // Add the actors to the renderer, set the background and size
    renWin.GetRenderer().AddActor(outlineActor);
    renWin.GetRenderer().AddActor(planeActor);
    renWin.GetRenderer().AddActor(cutActor);

    renWin.GetRenderer().SetBackground(1, 1, 1);
    renWin.setSize(400, 300);

    vtkCamera cam1 = renWin.GetRenderer().GetActiveCamera();
    cam1.SetClippingRange(11.1034, 59.5328);
    cam1.SetFocalPoint(9.71821, 0.458166, 29.3999);
    cam1.SetPosition(-2.95748, -26.7271, 44.5309);
    cam1.SetViewUp(0.0184785, 0.479657, 0.877262);

    // Place renWin in the center of this panel
    setLayout(new BorderLayout());
    add(renWin, BorderLayout.CENTER);
  }


  public static void main(String s[]) {
    CutCombustor panel = new CutCombustor();

    JFrame frame = new JFrame("CutCombustor");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    frame.getContentPane().add("Center", panel);
    frame.pack();
    frame.setVisible(true);
  }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/c4628f9f/attachment.htm>


More information about the vtkusers mailing list