[vtkusers] Java Example for MultipleIsoComb

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

/*
 * Bare Tcl source: multipleIso.tcl
 * CS Facility path:
/sys/www/classes/cs5630/vtk/tcl/graphics/examplesTcl/multipleIso.tcl
 *
--------------------------------------------------------------------------------
 */

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

    // 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();

    double range[] = pl3d.GetOutput
().GetPointData().GetScalars().GetRange();
    double min=range[0];
    double max=range[1];
    double value=(min+max)/2.0;

    vtkContourFilter cf = new vtkContourFilter();
      cf.SetInput(pl3d.GetOutputDataObject(0));
      cf.SetValue(0, value);
      cf.UseScalarTreeOn();

    int numberOfContours=5;
    double epsilon=  (max - min) / (double)(numberOfContours * 10);
    min=min+epsilon;
    max=max-epsilon;

    vtkPolyData pd[] = new vtkPolyData[numberOfContours];
    vtkPolyDataMapper mapper[] = new vtkPolyDataMapper[numberOfContours];

    for (int i=0; i<numberOfContours; i++) {
      double val=min + ((i - 1) / (double)(numberOfContours - 1) )*(max -
min);
      cf.SetValue(0, val);
      cf.Update();
      pd[i]=new vtkPolyData();
      pd[i].CopyStructure(cf.GetOutput);
      pd[i].GetPointData(DeepCopy(cf.GetOutput().GetPointData()));
        vtkPolyDataMapper mapper$i
          mapper$i SetInput pd$i
          eval mapper$i SetScalarRange \
            [[[[pl3d GetOutput] GetPointData] GetScalars] GetRange]
        vtkActor actor$i
          actor$i AddPosition 0 [expr $i * 12] 0
        actor$i SetMapper mapper$i
        ren1 AddActor actor$i
      }


    }//main
}//class
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/2703b19e/attachment.htm>


More information about the vtkusers mailing list