[vtkusers] clean way to replace polydata

David E DeMarle dave.demarle at kitware.com
Thu Mar 4 11:39:59 EST 2010


Don't use the internal filter (normalsGen) directly on the input
dataset, that confuses the pipeline. Also, try not to entirely replace
poly, or something outside of this code snippet may end up with a
stale reference.

I'ld try this:

vtkPolyData *myNewPD = vtkPolyData::New();
myNewPD->ShallowCopy(poly);

vtkPolyDataNormals* normalsGen = vtkPolyDataNormals::New();
normalsGen->SetInput( myNewPD );
normalsGen->Update();
poly->ShallowCopy( normalsGen->GetOutput() );

normalsGen->Delete();
myNewPD->Delete();


David E DeMarle
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x109



On Thu, Mar 4, 2010 at 10:41 AM, Marius Erdt <marius.erdt at gmx.de> wrote:
> Hi vtk-users,
>
> I've got a function that should recompute the normals of a vtkPolyData.
> However, if I try to delete the input poly by calling Delete and assign the
> output of the filter to its variable, the program chrashes.
>
> void computeNormals( vtkPolyData* &poly ){
>
>    vtkPolyDataNormals* normalsGen = vtkPolyDataNormals::New();
>    normalsGen->SetInput( poly );
>    normalsGen->Update();
>
>    poly->Delete();
>    poly = NULL;
>    poly = vtkPolyData::New();
>    poly->DeepCopy( normalsGen->GetOutput() );
>
>    normalsGen->Delete();
> }
>
> The codes works if I don't delete the input PolyData. However, then I got a
> memory leak since the data of the original poly is not released.
>
> Does anyone knows a solution?
>
> Thanks,
> Marius
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list