[vtkusers] Java Example for VisQuad

Todd Simons todd.a.simons at gmail.com
Wed Dec 20 10:29:52 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;

//This example demonstrates the use of the contour filter, and the use of
//the vtkSampleFunction to generate a volume of data samples from an
//implicit function.

import vtk.*;

public class VisQuad {
//  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[]) {

//    VTK supports implicit functions of the form f(x,y,z)=constant. These
//    functions can represent things spheres, cones, etc. Here we use a
//    general form for a quadric to create an elliptical data field.
    vtkQuadric quadric = new vtkQuadric();
    quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0);

//    vtkSampleFunction samples an implicit function over the x-y-z range
//    specified (here it defaults to -1,1 in the x,y,z directions).
    vtkSampleFunction sample = new vtkSampleFunction();
    sample.SetSampleDimensions(30, 30, 30);
    sample.SetImplicitFunction(quadric);

//    Create five surfaces F(x,y,z) = constant between range specified. The
//    GenerateValues() method creates n isocontour values between the range
//    specified.
    vtkContourFilter contours = new vtkContourFilter();
    contours.SetInput(sample.GetOutput());
    contours.GenerateValues(5, 0.0, 1.2);

    vtkPolyDataMapper contMapper = new vtkPolyDataMapper();
    contMapper.SetInput(contours.GetOutput());
    contMapper.SetScalarRange(0.0, 1.2);

    vtkActor contActor = new vtkActor();
    contActor.SetMapper(contMapper);

//    We'll put a simple outline around the data.
    vtkOutlineFilter outline = new vtkOutlineFilter();
    outline.SetInput(sample.GetOutput());

    vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper();
    outlineMapper.SetInput(outline.GetOutput());

    vtkActor outlineActor = new vtkActor();
    outlineActor.SetMapper(outlineMapper);
    outlineActor.GetProperty().SetColor(0,0,0);

//    The usual rendering stuff.
    vtkRenderer ren = new vtkRenderer();
    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(ren);
    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);

    ren.SetBackground(1, 1, 1);
    ren.AddActor(contActor);
    ren.AddActor(outlineActor);

    iren.Initialize();
    renWin.Render();
    iren.Start();
  }//main
}//class VisQuad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/c0fde215/attachment.htm>


More information about the vtkusers mailing list