[vtkusers] vtkCutter/vtkClipPolyData problem

Dean Inglis dean.inglis at sympatico.ca
Mon Jul 28 16:34:45 EDT 2008


vtkClipPolyData problem - part 1

 

I have a multi-planar reformat application developed with

VTK and KWWidgets.  I wrote a widget

that allows the user to lay out a set of 

parallel lines on one of three orthogonal planes

defined and manipulated by vtkImageOrthoPlanes: 

the lines represent the intersections between 

an image slice (possibly oblique) that the widget 

is placed on and the set of perpendicular slices 

that will be generated by vtkImageReslice.  

To preview the location of the new slices, I am using

a pipeline borrowed from vtkImplicitPlaneWidget:

 - create a box dataset: a vtkImageData with dimensions 4x4x4 

 - when an image is input into the application,

   the origin and bounds of the box are updated to be those of the input

 - vtkCutter is used to cut through the box with an implicit function:

   a plane (vtkPlane) that passes through one of the intersection lines.

   This generates a polygon the fits entirely within the 

   bounds of the input image, having edges running along

   the bounds   

 - vtkClipPolyData is used to further clip the output 

   by two planes (vtkPlanes) perpendicular to the layout lines

 

The problem is that the clip data is not being generated

 

correctly;

that is, the edges along the last two planes are not always

congruent with the planes.  In the first attached jpeg you

can see the application reslicing a cadaver forearm: the

panel at top right shows the layout lines.  The panel at

lower left shows the orthoplanes widget and a green plane

corresponding to the vtkCutter output.  On the plane are gold

lines representing the edges of the clip output.  The second

jpeg (see next posting in this thread) 

shows a similar view of this panel: the gold lines

should be straight and with no kinks.  Im stumped on how

to get this working correctly.  Here is the code for the pipleine:

 

// the box that gets cut:

 

  this->Box = vtkImageData::New();

  this->Box->SetDimensions(4,4,4);

  this->Box->SetWholeExtent(0,3,0,3,0,3);

  this->Box->SetExtent(0,3,0,3,0,3);

  this->Box->SetUpdateExtent(0,3,0,3,0,3);

  this->Box->SetSpacing(1,1,1);

  this->Box->SetOrigin(0,0,0);

  this->Box->SetScalarTypeToUnsignedChar();

  this->Box->SetNumberOfScalarComponents(1);

  this->Box->AllocateScalars();

  this->Box->Update();

  unsigned char* ptr = static_cast<unsigned
char*>(this->Box->GetScalarPointer());

  for(int i = 0; i < 64; ++i)

  {

    *(ptr + i) = 0;

  }

 

 

// the large green plane

 

  this->Plane = vtkPlane::New();

 

  this->Cutter = vtkCutter::New();

  this->Cutter->SetInput( this->Box );

  this->Cutter->SetCutFunction(this->Plane);

  this->Cutter->GenerateCutScalarsOff();

  this->Cutter->SetNumberOfContours(0);

 

// the planes to use in the clip

 

  this->Planes = vtkPlanes::New();

 

  vtkDoubleArray* normals = vtkDoubleArray::New();

  normals->SetNumberOfComponents(3);

  normals->SetNumberOfTuples(2);

 

  vtkPoints* points = vtkPoints::New();

  points->SetNumberOfPoints(2);

 

  this->Planes->SetNormals(normals);

  this->Planes->SetPoints(points);

 

// the clipper that will clip the cutter's output

 

  vtkClipPolyData* clip = vtkClipPolyData::New();

  clip->SetInputConnection(this->Cutter->GetOutputPort());

  clip->SetClipFunction(this->Planes);

  clip->GenerateClipScalarsOff();

  clip->GenerateClippedOutputOff();

  clip->InsideOutOn();

 

// the edges of the clipped output

 

  vtkFeatureEdges* edges = vtkFeatureEdges::New();

  edges->BoundaryEdgesOn();

  edges->FeatureEdgesOff();

  edges->NonManifoldEdgesOff();

  edges->ManifoldEdgesOff();

  edges->ColoringOff();

  edges->SetInputConnection(clip->GetOutputPort());

 

 

Dean

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080728/b7eff506/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Image_1.jpg
Type: image/jpeg
Size: 37466 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080728/b7eff506/attachment.jpg>


More information about the vtkusers mailing list