[vtkusers] Using vtkStructuredGrid using the java API
Stephane Pierret
stephane.pierret at optimalcomputing.be
Mon Aug 17 03:36:29 EDT 2015
Hi,
I’m trying to use vtkStructuredGrid to display a structured grid using the java API. However, I do not succeed in getting the view of the grid.
Here is the sample code I’m using. Could you let me know what is wrong or missing?
BR,
Stéphane
System.out.println("vtkPoints");
vtkPoints points = new vtkPoints();
points.InsertNextPoint(0.0, 0.0, 0.0);
points.InsertNextPoint(1.0, 0.0, 0.0);
points.InsertNextPoint(2.0, 0.0, 0.0);
points.InsertNextPoint(0.0, 1.0, 0.0);
points.InsertNextPoint(1.0, 1.0, 0.0);
points.InsertNextPoint(2.0, 1.0, 0.0);
points.InsertNextPoint(0.0, 0.0, 1.0);
points.InsertNextPoint(1.0, 0.0, 1.0);
points.InsertNextPoint(2.0, 0.0, 1.0);
points.InsertNextPoint(0.0, 1.0, 1.0);
points.InsertNextPoint(1.0, 1.0, 1.0);
points.InsertNextPoint(2.0, 1.0, 1.0);
System.out.println ("vtkStructuredGrid");
vtkStructuredGrid sGrid = new vtkStructuredGrid ();
sGrid.SetDimensions(3,2,2);
sGrid.SetPoints(points);
int cellDims[] = new int[3];
sGrid.GetCellDims( cellDims );
System.out.println ("Cell dims = " + cellDims[0] + ", " + cellDims[1] + ", " + cellDims[2]);
System.out.println ("sGrid.GetNumberOfPoints() = " + sGrid.GetNumberOfPoints());
System.out.println ("sGrid.GetNumberOfCells () = " + sGrid.GetNumberOfCells());
// outline
vtkStructuredGridOutlineFilter of = new vtkStructuredGridOutlineFilter();
of.SetInputData(sGrid);
vtkCompositeDataGeometryFilter geom1 = new vtkCompositeDataGeometryFilter();
geom1.SetInputConnection(0, of.GetOutputPort(0));
vtkPolyDataMapper sgridMapper = new vtkPolyDataMapper();
sgridMapper.SetInputConnection(0, geom1.GetOutputPort(0));
vtkActor actor = new vtkActor();
actor.SetMapper(sgridMapper);
actor.GetProperty().SetColor(0,0,0);
// Create a renderer, render window, and interactor
vtkRenderWindow renderWindow = new vtkRenderWindow();
vtkRenderer renderer = new vtkRenderer();
renderer.SetBackground2(0,1,1);
renderer.SetGradientBackground(true);
renderer.AddActor(actor);
renderWindow.AddRenderer(renderer);
vtkRenderWindowInteractor renderWindowInteractor = new vtkRenderWindowInteractor();
renderWindowInteractor.SetRenderWindow(renderWindow);
// Add the actor to the scene
renderer.AddActor(actor);
renderer.SetBackground(.1, .2, .3);
// Render and interact
renderWindow.Render();
renderWindowInteractor.Start();
More information about the vtkusers
mailing list