[vtkusers] Deleting points form vtkPolyData object

Bill Lorensen bill.lorensen at gmail.com
Mon Nov 2 12:39:02 EST 2009


Looking at the code in vtkPolydata.h, DeletePoint must be preceeded by
BuildLinks(). I'm not sure why, but here is the current
implementation:
inline void vtkPolyData::DeletePoint(vtkIdType ptId)
{
  this->Links->DeletePoint(ptId);
}

Since Links is NULL until BuildLinks() is called, this will seg fault
as you both discovered.

Bill


On Mon, Nov 2, 2009 at 12:26 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Mon, Nov 2, 2009 at 12:24 PM, da <remywendy at gmail.com> wrote:
>> Its not clear if you're adding multiple points or not...
>>
>> Given the code you've included, you're only inserting one point from the
>> line
>> m_Points->GetPoints()->InsertNextPoint(m_daPointPosition);
>> and then deleting the second point (index 1, but you only have index 0),
>> which would cause a null pointer exception?
>>
>>
>> If you're adding multiple points in the lines of code that are not included,
>> make sure to include them.
>>
>>
>>
>> On Mon, Nov 2, 2009 at 1:30 AM, Lodron, Gerald <Gerald.Lodron at joanneum.at>
>> wrote:
>>>
>>> Hello,
>>>
>>> I stored a point list into the vtkPolyData object using these lines:
>>>
>>> //m_Points ... vtkPolyData Object pointer
>>> //m_daPointPosition ... Three dimensional double array specifying x,y and
>>> z coordinate of the point
>>>
>>> m_Points->GetPoints()->InsertNextPoint(m_daPointPosition);
>>> m_Points->GetVerts()->InsertNextCell(1);
>>>
>>> m_Points->GetVerts()->InsertCellPoint(m_Points->GetPoints()->GetNumberOfPoints()-1);
>>> m_Points->Update();
>>>
>>> This works fine, I also can visualize it. Now I want to delete a specific
>>> point, e.g. the second point which was inserted, but I always get a null
>>> pointer exception:
>>>
>>> m_Points->DeletePoint(1); //Null pointer exception
>>> m_Points->DeleteCell(1);
>>>
>>> vtkCleanPolyData *Cleaner = vtkCleanPolyData::New();
>>> Cleaner->SetInput(m_Points);
>>> Cleaner->Update();
>>>
>>> m_Points = Cleaner->GetOutput();
>>> m_Points->Update();
>>> m_Points->BuildCells();
>>> m_Points->BuildLinks();
>>>
>>> Cleaner = NULL; //Use smart pointers to delete
>>>
>>>
>>> Have anybody a suggestion what i made false?
>>> _______________________________________________
>>> 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
>>
>>
>> _______________________________________________
>> 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
>>
>>
>
> I also get a segfault. Here is my example:
>
> #include <vtkSmartPointer.h>
> #include <vtkPoints.h>
> #include <vtkPolyData.h>
>
> int main(int argc, char *argv[])
> {
>  //create a set of points
>  vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();
>  Points->InsertNextPoint ( 1.0, 0.0, 0.0 );
>  Points->InsertNextPoint ( 0.0, 0.0, 0.0 );
>  Points->InsertNextPoint ( 0.0, 1.0, 0.0 );
>
>  vtkSmartPointer<vtkPolyData> Polydata = vtkSmartPointer<vtkPolyData>::New();
>  Polydata->SetPoints(Points);
>
>  vtkstd::cout << "Number of points: " <<
> Polydata->GetNumberOfPoints() << vtkstd::endl;
>
>  Polydata->DeletePoint(1);//segfault on this line
>
>  vtkstd::cout << "Number of points: " <<
> Polydata->GetNumberOfPoints() << vtkstd::endl;
>
>  return 0;
> }
>
>
> Thanks,
>
> David
> _______________________________________________
> 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