[vtkusers] Multiple vtkPolygons in a vtkPolyData
pattersonnp at gmail.com
Thu Oct 30 03:31:55 EDT 2014
Thanks for getting in touch. I think this was a good starting point but still not entirely sure that it’s what I need. I created N slices of simple 2D squares, equally spaced on the Z axis - the it was like a stack of contours. But when I add the polygons and points to the vtkPolyData and then render using vtkPolyDataMapper it is one image, but the square slices are connected in some way… (please see the image attached). Realistically the slices are not attached, they are contours drawn on individual z-positions.
Ultimately I want to visualise DICOM images (transverse plane, effectively slice-by-slice) and on each individual slice I would want to overlay a contour/polygon which defines different organ regions. I would also want to be able to check if a voxel (from the dicom image) lies within the bounds of the polygon.
Would the approach of creating N independent vtkPolygon objects and then adding each on to a vtkCellArray be along the correct lines for doing this do you think?
> On 29 Oct 2014, at 12:56, David Cole <dlrdave at aol.com> wrote:
> You should be able to put all of the points and all of the polygons into your existing "points" and "polygons" variables, and have just one polydata that refers to all of them at once.
> See this example:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/CombinePolyData <http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/CombinePolyData>
> And the documentation for the append and clean polydata filters:
> http://www.vtk.org/doc/nightly/html/classvtkAppendPolyData.html <http://www.vtk.org/doc/nightly/html/classvtkAppendPolyData.html>
> http://www.vtk.org/doc/nightly/html/classvtkCleanPolyData.html <http://www.vtk.org/doc/nightly/html/classvtkCleanPolyData.html>
> The vtkAppendPolyData filter produces a single polydata output from many input polydata objects.
> David C.
> On Wed, Oct 29, 2014 at 7:11 AM, Nick Patterson <pattersonnp at gmail.com <mailto:pattersonnp at gmail.com>> wrote:
> 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 <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.
> Powered by www.kitware.com <http://www.kitware.com/>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ <http://www.vtk.org/Wiki/VTK_FAQ>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers <http://public.kitware.com/mailman/listinfo/vtkusers>
-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2014-10-30 at 07.30.02.png
Size: 35387 bytes
Desc: not available
More information about the vtkusers