开发者

remove individual points from vtkPoints

I have a question regarding a VTK class called vtkPoints. The class has the functionality to insert individual points, but doesn't have the functionality to remove individual points. This is inconvenient for the case when the view needs to be updated by calling vtkPoints::Modified() to drive the graphics pipeline again to update/re-render the view. The obvious case of re-initializing vtkPoints, a开发者_如何学JAVAdding all points again and updating/re-rendering the view is too slow and resource intensive.

Is there a possible solution to this problem?

Thanks, timecatcher


The example http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/DeletePoint has a rather simple solution. Copy points to another temporary vtkPoints by filtering the id to remove, and shallow-copy it to the original one:

void ReallyDeletePoint(vtkSmartPointer<vtkPoints> points, vtkIdType id)
{
  vtkSmartPointer<vtkPoints> newPoints = 
    vtkSmartPointer<vtkPoints>::New();

  for(vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
    {
    if(i != id)
      {
      double p[3];
      points->GetPoint(i,p);
      newPoints->InsertNextPoint(p);
      }
    }

  points->ShallowCopy(newPoints);
}


There is no way to remove individual points from vtkPoints. Depending on what your problem is here are some potential solutions:

  1. Store all the points in a single vtkPoint instance, overwrite points you want to get rid of with a value to replace it. This would be useful to cap the max amount of memory a point cloud could use.
  2. Store all the points in a single vtkPoint instance, overwrite points you want to get rid of with a value a value that is far away from your scene.
  3. Create a vtkPoint, vtkCellArray, and vtkPolyData for each point, join them together using vtkAppendPolyData. This has a RemoveInput(vtkPolyData*) so you could remove individual points.


this is a way to remove a point from vtkPoints in python.

def deletePoint(vtk_points, *args):
    if isinstance(args[0], list):
        args = args[0]

    points = vtk.vtkPoints()
    for i in range(vtk_points.GetNumberOfPoints()):
        if i in args: continue
        p = vtk_points.GetPoint(i)
        points.InsertNextPoint(p)
    return points


No: it has the same limitations on mutability as a float[] array. The only way to remove a point is to copy and exclude. Note that you will incur the same copy penalty when doing Insert() operations if you exceed pre-allocated storage.

Other related data structure options include vtkCollection and vtkPolyData. Also, it might be informative to look at the source for some of the PolyData clip filters to get an idea of the way these type of operations are implemented internally - those should be about as fast as they can be within the limitations of the data structure.


Allowing a point to be deleted from vtkPoints can cause a data set that uses the point to become corrupted. You would also have to delete all cells that use that point as well as shrink the point data arrays.

I would suggest that if you have a filter that is creating the vtkPoints to modify the vtkPoints object and anything that depends on that in the RequestData() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜