[vtkusers] Java Example for PointToCellData
Todd Simons
todd.a.simons at gmail.com
Wed Dec 20 10:26:35 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.*;
/* This example demonstrates the conversion of point data to cell data.
The conversion is necessary because we want to threshold data based
on cell scalar values.*/
public class PointToCellData {
// 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
/* Read some data with point data attributes. The data is from a
plastic blow molding process (e.g., to make plastic bottles) and
consists of two logical components: a mold and a parison. The
parison is the hot plastic that is being molded, and the mold is
clamped around the parison to form its shape. */
vtkUnstructuredGridReader reader = new vtkUnstructuredGridReader();
reader.SetFileName("d:/user/VTK/Data/blow.vtk");
reader.SetScalarsName("thickness9");
reader.SetVectorsName("displacement9");
/* Convert the point data to cell data. The point data is passed
through the filter so it can be warped. The vtkThresholdFilter then
thresholds based on cell scalar values and extracts a portion of the
parison whose cell scalar values lie between 0.25 and 0.75.*/
vtkPointDataToCellData p2c = new vtkPointDataToCellData();
p2c.SetInputConnection(reader.GetOutputPort());
p2c.PassPointDataOn();
vtkWarpVector warp = new vtkWarpVector();
warp.SetInput(p2c.GetUnstructuredGridOutput());
vtkThreshold thresh = new vtkThreshold();
thresh.SetInputConnection(warp.GetOutputPort());
thresh.ThresholdBetween(0.25, 0.75);
thresh.SetInputArrayToProcess(1, 0, 0, 0, "thickness9");
//thresh.SetAttributeModeToUseCellData();
// This is used to extract the mold from the parison.
vtkConnectivityFilter connect = new vtkConnectivityFilter();
connect.SetInputConnection(thresh.GetOutputPort());
connect.SetExtractionModeToSpecifiedRegions();
connect.AddSpecifiedRegion(0);
connect.AddSpecifiedRegion(1);
vtkDataSetMapper moldMapper = new vtkDataSetMapper();
moldMapper.SetInputConnection(reader.GetOutputPort());
moldMapper.ScalarVisibilityOff();
vtkActor moldActor = new vtkActor();
moldActor.SetMapper(moldMapper);
moldActor.GetProperty().SetColor(.2, .2, .2);
moldActor.GetProperty().SetRepresentationToWireframe();
// The threshold filter has been used to extract the parison.
vtkConnectivityFilter connect2 = new vtkConnectivityFilter();
connect2.SetInputConnection(thresh.GetOutputPort());
vtkGeometryFilter parison = new vtkGeometryFilter();
parison.SetInputConnection(connect2.GetOutputPort());
vtkPolyDataNormals normals2 = new vtkPolyDataNormals();
normals2.SetInputConnection(parison.GetOutputPort());
normals2.SetFeatureAngle(60);
vtkLookupTable lut = new vtkLookupTable();
lut.SetHueRange(0.0, 0.66667);
vtkPolyDataMapper parisonMapper = new vtkPolyDataMapper();
parisonMapper.SetInputConnection(normals2.GetOutputPort());
parisonMapper.SetLookupTable(lut);
parisonMapper.SetScalarRange(0.12, 1.0);
vtkActor parisonActor = new vtkActor();
parisonActor.SetMapper(parisonMapper);
// We generate some contour lines on the parison.
vtkContourFilter cf = new vtkContourFilter();
cf.SetInputConnection(connect2.GetOutputPort());
cf.SetValue(0, .5);
vtkPolyDataMapper contourMapper = new vtkPolyDataMapper();
contourMapper.SetInputConnection(cf.GetOutputPort());
vtkActor contours = new vtkActor();
contours.SetMapper(contourMapper);
// Create graphics stuff
vtkRenderer ren = new vtkRenderer();
vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer(ren);
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
// Add the actors to the renderer, set the background and size
ren.AddActor(moldActor);
ren.AddActor(parisonActor);
ren.AddActor(contours);
ren.ResetCamera();
ren.GetActiveCamera().Azimuth(60);
ren.GetActiveCamera().Roll(-90);
ren.GetActiveCamera().Dolly(2);
ren.ResetCameraClippingRange();
ren.SetBackground(1, 1, 1);
renWin.SetSize(750, 400);
iren.Initialize();
renWin.Render();
iren.Start();
}//main
}//class PointToCellData
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/c347a630/attachment.htm>
More information about the vtkusers
mailing list