[vtkusers] building vtkPolyData in a function and return it

David Doria daviddoria at gmail.com
Tue Sep 21 13:54:29 EDT 2010


On Tue, Sep 21, 2010 at 1:50 PM, chrisyeshi <chrisyeshi at gmail.com> wrote:
>
> What I am trying to do is to make a vtkpolydata in a function, and then apply
> some sort of filter, and then return the vtkpolydata.
>
> the actual code would look something like this:
>
> vtkPolyData *poly1 = vtkPolyData::New();
> // generate poly1 here
> vtkPolyData *poly2 = vtkPolyData::New();
> // generate poly2 here
> vtkAppendPolyData *append = vtkAppendPolyData::New();
> vtkPolyData *result = append->GetOutput();     // I tried deepcopy here, but
> it doesn't work.
>
> append->Delete();                                        // If I do not
> delete these, it works, but memory leaks
> poly2->Delete();
> poly1->Delete();
>
> return result;

If you want to deep copy, you have to create the result object first:
vtkPolyData *result = vtkPolyData::New();
result->DeepCopy(append->GetOutput());

David



More information about the vtkusers mailing list