[vtk-developers] question about vtkContourWidget/vtkContourRepresentation?

Nicolas Rannou nicolas_rannou at hms.harvard.edu
Fri May 7 14:27:30 EDT 2010


On 05/07/2010 02:08 PM, Karthik Krishnan wrote:
> On Fri, May 7, 2010 at 2:01 PM, Arnaud GELAS 
> <arnaud_gelas at hms.harvard.edu <mailto:arnaud_gelas at hms.harvard.edu>> 
> wrote:
>
>     Hi Karthik,
>
>     Let me tell you a bit more about the process Nicolas is implementing:
>
>        1. Run a level set on a 2D image
>        2. Apply vtkContourFilter or vtkMarchignSquares
>        3. Decimate the resulting vtkPolyData using vtkDecimatePolyline
>        4. Initialize the contour widget with the resulting polydata
>
>     In such a pipeline when initializing the contour widget, the input
>     polydata points can not be in order, and then we finally ended
>     iterating on the line to sort the order of the point container.
>
>     So, I wonder do you think it could be included in the
>     vtkContourRepresentation class?
>
>
> Sure. Do you have the ordering code around ?
>
> Thanks
> --
> karthik
>
Hi Karthik,

Here is the code to order points, iterating on a polyline:

//------------------------------------------------------------------------------------------

// Reorder points
// Assuming that we have an "unordered" polydata containing "good 
polylines" and "unordered points"

     unorderedPolyData->GetLines()->InitTraversal();

     vtkIdType *pts, npts;

     unorderedPolyData->GetLines()->GetNextCell(npts,pts);

     vtkSmartPointer<vtkPoints> points =
         vtkSmartPointer<vtkPoints>::New();

     for ( int i = 0;  i < static_cast<int>( npts-1 );  i ++)
       {
       points->InsertPoint(i, 
unorderedPolyData->GetPoints()->GetPoint(pts[i]));
       }

     vtkSmartPointer<vtkPolyData> orderedPolyData =
         vtkSmartPointer<vtkPolyData>::New();
     orderedPolyData->SetPoints( points );

//------------------------------------------------------------------------------------------

The output polydata contains the points in the "good order" then we can 
use it to generate the contour in vtkContourWidget.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100507/310fbdee/attachment.html>


More information about the vtk-developers mailing list