[vtkusers] Why delete points set after SetPoints leads to bug

Jana Sefcikova neollie at gmail.com
Sat May 26 08:46:43 EDT 2012


Dear users,
I had implemented a function for programable filter . Inside function I am
deleting already assigned point set but it leads to "Bad access".
If I do not delete them, there is no problem.
Could someone explain me, why deletion is problem. I do not understand when
data are fully copied after assignement and when are only passed by
reference.

My code:

void filter_function(void* arguments)

{

    std::cout << "cos" << std::endl;

    vtkProgrammableFilter* programmableFilter =

    static_cast<vtkProgrammableFilter*>(arguments);



    vtkPoints* inPts = programmableFilter->GetPolyDataInput()->GetPoints();

    vtkIdType numPts = inPts->GetNumberOfPoints();

    vtkSmartPointer<vtkPoints> newPts =

    vtkSmartPointer<vtkPoints>::New();

    newPts->SetNumberOfPoints(numPts);



    for(vtkIdType i = 0; i < numPts; i++)

    {

        double p[3];

        inPts->GetPoint(i, p);

        if (i == 0 ){ cout << "first point = [" << p[0] << "," << p[1] <<
"," << p[2] << "]"<<endl; }

        double p_new[3];

        p_new[0] = p[0];

        p_new[1] = p[1];

        p_new[2] = cos(p[0]);

        newPts->SetPoint(i, p_new);

        // Delete p_new ?

    }



    programmableFilter->GetPolyDataOutput()->CopyStructure
(programmableFilter->GetPolyDataInput());

    programmableFilter->GetPolyDataOutput()->SetPoints(newPts);

    //newPts->Delete(); // Lead to BUG

}


vtkSmartPointer<vtkProgrammableFilter> filter = vtkSmartPointer<
vtkProgrammableFilter>::New();

filter->SetExecuteMethod(filter_function, filter);

Thanks in advance.
Jana
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120526/aaff0cc3/attachment.htm>


More information about the vtkusers mailing list