[vtkusers] Multiple vtkPolygons in a vtkPolyData

Nick Patterson pattersonnp at gmail.com
Wed Oct 29 07:11:33 EDT 2014

Dear VTK Users,
I have been having some trouble with handling polygons in VTK and hoped that someone can offer some guidance. 

I wish to do the following:-
1) Read some contours (structures) from a DICOM file - these are essentially polygons drawn on 2D slices.  ( I have completed this task and have the ability to extract the x,y,z point of each vertex from a DICOM RTStruct) There are approximately 250 polygons.

2) I want to add these coordinate positions to create a vtkPolygon

3) I want add each vtkPolygon object to a vtkPolyData 

4) Render the polygons. ( I can probably deal with this ).

Up until now I have been using the http://www.itk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Polygon example and trying to adapt it. 

Can anyone advise how I would modify this segment of code (taken straight from the code in the link above) so that it would be generic that I can add multiple independent polygons (in the example I am working with there are approximately 250 polygons) to the vtkPolyData.

vtkSmartPointer<vtkPoints> points =
  points->InsertNextPoint(0.0, 0.0, 0.0);
  points->InsertNextPoint(1.0, 0.0, 0.0);
  points->InsertNextPoint(1.0, 1.0, 0.0);
  points->InsertNextPoint(0.0, 1.0, 0.0);
  // Create the polygon
  vtkSmartPointer<vtkPolygon> polygon =
  polygon->GetPointIds()->SetNumberOfIds(4); //make a quad
  polygon->GetPointIds()->SetId(0, 0);
  polygon->GetPointIds()->SetId(1, 1);
  polygon->GetPointIds()->SetId(2, 2);
  polygon->GetPointIds()->SetId(3, 3);
  // Add the polygon to a list of polygons
  vtkSmartPointer<vtkCellArray> polygons =
  // Create a PolyData
  vtkSmartPointer<vtkPolyData> polygonPolyData =

I hope my problem is clear, but am happy to clarify if you think you are able to offer guidance which would be much appreciated.

Regards, Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141029/72752810/attachment.html>

More information about the vtkusers mailing list