我正在导入网格文件,其中每个面由其顶点的坐标描述。大多数顶点在点之间共享。因此,我想消除比threshold
更接近已经添加到云中的点。这意味着我需要同时有效地执行最近点查找和点插入。从距离阈值距离更近的云中移除点
我尝试使用vtkPointLocator
,这是我已经用于静态云的;但我很失落,它应该如何逐步使用。 documentation非常简洁,例子(例如this one)不包括这种情况。 This post有点帮助,但我仍然没有一个工作解决方案 - 我得到InsertNextPoint
(下面的情况)的段错误,在CheateChildNode
(当使用vtkIncrementalOctreePointLocator
而不是vtkPointLocator
时)无限递归,或一些VTK错误(如no points to subdivide
,是零点)。
这大约是我做的:
// read from input file
std::vector<Vector3d> vertices;
// bounds of the data are known
double bounds[6]={/*...*/};
const double threshold=1e-5;
auto locator=vtkSmartPointer<vtkIncrementalOctreePointLocator>::New();
auto polydata=vtkSmartPointer<vtkPolyData>::New();
auto points=vtkSmartPointer<vtkPoint>::New();
polydata->SetPoints(points);
locator->SetDataSet(polydata);
locator->InitPointInsertion(points,bounds);
for(size_t i=0; i< i<vertices.size(); i++){
double* vertex=vertices[i].data(); // pointer to data
double dist; // unused
vtkIdType id;
// don't search if there are no points yet
// FindClosestPointWithinRadius calls BuildLocator internally,
// which needs some points to be present already
if(points->GetNumberOfPoints()>0) id=locator->FindClosestPointWithinRadius(threshold,vertex,dist);
else id=-1;
if(id<0){
// point not found, insert it into the locator
locator->InsertNextPoint(vertex);
}
}
如果在错误的组织方式明显的错误,我会很高兴的任何建议。如果不是,我尝试做一个MWE。
从阅读来源看来,如果点集已被修改,甚至增量类别在每次查找时都会调用BuildLocator
,这可能会很昂贵。因此,对于组合插入/查找更好的类的建议也将被赞赏。
这会正确重新映射拓扑吗?即如果一个人脸由顶点定义(3,4,5)并且5人与2合并,它会变成(3,4,2)? – eudoxos 2013-03-13 10:26:50
是的。这就是它应该做的。 – shash 2013-03-20 09:30:47