[vtkusers] clipping many holes in a plane is slow....

Enloe, Tim Tim.Enloe at xeroxlabs.com
Fri Apr 21 14:46:12 EDT 2006


Greetings VTK users,
 
I am new to VTK, and this is my first time addressing this forum, so
please forgive any obvious questions.
 
I need to make a plane with a lot of holes in it, which I managed to do
using the vtkClipPolyData function.
 
I combined all the implicit cylinders together with a vtkImplicitBoolean
(union) and fed the result to the clipper.
 
The problem is that it is too slow for my intended purpose.
 
Anyone have any ideas to speed up this task?
 
Sample Java code is listed below.
 
Many thanks,
Cordially,
Tim
 
 
************************************************************************
***********88
 
//
//This example creates a plane pierced by 380 holes 
//
//
 
//we import the vtk wrapped classes first
import java.util.Vector;
 
import vtk.*;
 
//then we define our class
public class Main {
// 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"); 
}
 
// now the main program
public static void main (String []args) throws Exception {
 
  final double planeHeight = .28;
  final double planeWidth = .22;
  final int holeCnt = 380;
  final int rowCount = 38;
  final double holeRadius = 0.0025;
  final double offsetFromTop = 0.005;
  final double offsetFromSide = 0.01075;
  final double holeSpacing = .00725;
     
     
  vtkPlaneSource planeSource = new vtkPlaneSource();
  planeSource.SetOrigin(0,-planeHeight/2,0);
  planeSource.SetPoint1(planeWidth,-planeHeight/2,0);
  planeSource.SetPoint2(0,planeHeight/2,0);
  planeSource.SetResolution(200,200);
  
  vtkPolyDataMapper planeMapper = new vtkPolyDataMapper();
 
  Vector <vtkCylinder> holeList = new Vector<vtkCylinder>(holeCnt);
  vtkGeneralTransform trans = new vtkGeneralTransform();
  trans.RotateX(90);
  
  vtkImplicitBoolean holes = new vtkImplicitBoolean();
  holes.SetOperationTypeToUnion();
  
     for (int i= 0 ; i<holeCnt; i++)
     {
        double currentOffsetFromTop = -planeHeight/2 + offsetFromTop +
i%rowCount*holeSpacing;
        holeList.insertElementAt(new vtkCylinder(), i);
        holeList.elementAt(i).SetCenter(offsetFromSide*(i/rowCount+1),
0, currentOffsetFromTop);
        holeList.elementAt(i).SetRadius(holeRadius);
        holeList.elementAt(i).SetTransform(trans);
        holes.AddFunction(holeList.elementAt(i));
     }     
     
     vtkClipPolyData planeClipper = new vtkClipPolyData();
     planeClipper.InsideOutOn();
     planeClipper.SetInput(planeSource.GetOutput());
     planeClipper.SetClipFunction(holes);
     planeClipper.GenerateClippedOutputOn();
     vtkPolyData planePolyData = planeClipper.GetClippedOutput();  
 
     planeMapper.SetInput(planePolyData);
     vtkActor planeActor = new vtkActor();
     planeActor.SetMapper(planeMapper);
     
     vtkRenderer ren1 = new vtkRenderer();
     ren1.SetBackground(0.1, 0.2, 0.4);
     ren1.AddActor(planeActor);
 //
 // Finally we create the render window which will show up on the
screen.
 // We add our two renderers into the render window using AddRenderer.
We also
 // set the size to be 600 pixels by 300.
 //
 vtkRenderWindow renWin = new vtkRenderWindow();
 renWin.AddRenderer( ren1 );
 renWin.SetSize(600, 600);
 
 ren1.GetActiveCamera().Azimuth(0);
 
 vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
 iren.SetRenderWindow(renWin);
 
 vtkInteractorStyleTrackballCamera style = 
     new vtkInteractorStyleTrackballCamera();
 iren.SetInteractorStyle(style);
 
 iren.Initialize();
 iren.Start();
 }
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060421/700759e2/attachment.htm>


More information about the vtkusers mailing list