[vtkusers] clean way to replace polydata

David Doria daviddoria+vtk at gmail.com
Thu Mar 4 10:45:27 EST 2010


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
>
>
What happens if you do:

void computeNormals( vtkPolyData* &poly )
{

   vtkSmartPointer<vtkPolyDataNormals> normalsGen =
     vtkSmartPointer<vtkPolyDataNormals>::New();
   normalsGen->SetInput( poly );
   normalsGen->Update();

   poly->ShallowCopy(normalsGen->GetOutput()
}

?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100304/193aab66/attachment.htm>


More information about the vtkusers mailing list