[vtkusers] Java Example for WarpComb

Todd Simons todd.a.simons at gmail.com
Wed Dec 20 10:30:37 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 draw contours on warped surfaces
 */

public class WarpComb {

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

    vtkStructuredGridGeometryFilter plane =  new
vtkStructuredGridGeometryFilter();
      plane.SetInput(pl3d.GetOutput());
      plane.SetExtent( 10, 10, 1, 100, 1, 100);

    vtkStructuredGridGeometryFilter plane2 = new
vtkStructuredGridGeometryFilter();
      plane2.SetInput(pl3d.GetOutput());
      plane2.SetExtent(30, 30, 1, 100, 1, 100);

    vtkStructuredGridGeometryFilter plane3 = new
vtkStructuredGridGeometryFilter();
      plane3.SetInput(pl3d.GetOutput());
      plane3.SetExtent(45, 45, 1, 100, 1, 100);

    vtkAppendPolyData appendF = new vtkAppendPolyData();
      appendF.AddInput (plane.GetOutput());
      appendF.AddInput (plane2.GetOutput());
      appendF.AddInput (plane3.GetOutput());

    vtkWarpScalar warp = new vtkWarpScalar();
      warp.SetInput (appendF.GetOutput());
      warp.UseNormalOn();
      warp.SetNormal (1.0, 0.0, 0.0);
      warp.SetScaleFactor(2.5);

    vtkCastToConcrete caster = new vtkCastToConcrete();
      caster.SetInput (warp.GetOutput());

    vtkPolyDataNormals normals = new vtkPolyDataNormals();
      normals.SetInput (caster.GetPolyDataOutput());
      normals.SetFeatureAngle(60);

    vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();
      planeMapper.SetInput (normals.GetOutput());
      planeMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange());

    vtkActor planeActor = new vtkActor();
      planeActor.SetMapper (planeMapper);

    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, 0.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(planeActor);
  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
}//calss WarpComb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/fad4e345/attachment.htm>


More information about the vtkusers mailing list