[vtkusers] Java example for CombIso

Todd Simons todd.a.simons at gmail.com
Wed Dec 20 10:23:38 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 javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *  This example shows how to use isosurfaces
 */
public class CombISo {

    // in the static contructor we load in the native code
    // The libraries must be in your path to work
    static {
      System.loadLibrary("vtkCommonJava");
      System.loadLibrary("vtkFilteringJava");
      System.loadLibrary("vtkIOJava");
      System.loadLibrary("vtkImagingJava");
      System.loadLibrary("vtkGraphicsJava");
      System.loadLibrary("vtkRenderingJava");
    }

    public static void main(String s[]) {
      // Read the data files
      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();

    vtkContourFilter iso = new vtkContourFilter();
        iso.SetInput(pl3d.GetOutput());
        iso.SetValue(0, .38);
      vtkPolyDataNormals normals = new vtkPolyDataNormals();
        normals.SetInput(iso.GetOutput());
        normals.SetFeatureAngle(45);
      vtkPolyDataMapper isoMapper = new vtkPolyDataMapper();
        isoMapper.SetInput(normals.GetOutput());
        isoMapper.ScalarVisibilityOff();

    vtkActor isoActor = new vtkActor();
        isoActor.SetMapper(isoMapper);
        isoActor.GetProperty().SetColor(1.0, 0.0, 0.0);

    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.0, 1.0);

//    Add the actors to the renderer, set the background and size
    vtkRenderer renderer = new vtkRenderer ();
    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(renderer);

    renderer.AddActor(outlineActor);
    renderer.AddActor(isoActor);
    renderer.SetBackground(1, 1, 1);

    vtkCamera cam1 = renderer.GetActiveCamera();
      cam1.SetClippingRange( 3.95297, 50);
      cam1.SetFocalPoint( 9.71821, 0.458166, 29.3999);
      cam1.SetPosition( 2.7439, -37.3196, 38.7167);
      cam1.ComputeViewPlaneNormal();
      cam1.SetViewUp(-0.16123, 0.264271, 0.950876);

    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);

    renWin.SetSize(500, 500);
    renWin.Render();
    iren.Start();
  }//main
}//CombIso
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/d1822320/attachment.htm>


More information about the vtkusers mailing list