[vtkusers] Using vtkTriangleFilter to reduce concave polygons to convex

David Doria daviddoria at gmail.com
Sat Jun 30 08:37:43 EDT 2012


David


On Sat, Jun 30, 2012 at 8:32 AM, Alex Southern <mrapsouthern at gmail.com> wrote:
> Hi,
>
> The pd1 vtkPolyData contains concave polygons, that I would like to reduce
> into triangles.
>
> vtkTriangleFilter was mentioned as being appropriate, but no actual solution
> was posted.
> http://www.vtk.org/pipermail/vtkusers/2009-November/103551.html
>
> I want to apply the filter and put triangulated data back into pd2.
>
> If I view pd1 I can see the model, but with flickering due to the concave
> polygons. But pd2 displays nothing -  could someone give me a nudge in the
> right direction?
>
> Cheers
> A.
>
> vtkSmartPointer<vtkPolyData> pd1 = vtkSmartPointer<vtkPolyData>::New();
> vtkSmartPointer<vtkPolyData> pd2 = vtkSmartPointer<vtkPolyData>::New();
> vtkSmartPointer<vtkTriangleFilter> triFilter =
> vtkSmartPointer<vtkTriangleFilter>::New();
>
> triFilter->SetInput( pd1 );
> pd2= triFilter->GetOutput();

First, it is wrong to allocate pd2, because then you are leaking
memory when you assign the pointer to the triFilter output. You should
do instead:

vtkSmartPointer<vtkPolyData> pd1 = vtkSmartPointer<vtkPolyData>::New();

vtkSmartPointer<vtkTriangleFilter> triFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
triFilter->SetInput( pd1 );
vtkPolyData* pd2 = triFilter->GetOutput();

Second, you need to call Update() because you can use the result in
produced by the filter:

vtkSmartPointer<vtkTriangleFilter> triFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
triFilter->SetInput( pd1 );
triFilter->Update();
vtkPolyData* pd2 = triFilter->GetOutput();

However, depending on what you are doing after that, it might have
been updated even if you didn't call it explicitly. After trying that,
if it still doesn't work I'd suggest you post code that
programmatically generates data and then shows your problem.

David



More information about the vtkusers mailing list