我正在导入网格文件,其中每个面都由其顶点的坐标来描述。大多数顶点在点之间共享。因此,我想消除比threshold
已经添加到云中的点更近的点。这意味着我需要同时有效地执行最近点查找和点插入。
我尝试使用vtkPointLocator
我已经用于静态云的方法;但我不知道应该如何增量使用它。文档非常简洁,示例(例如这个)没有涵盖这种情况。这篇文章有点帮助,但我仍然没有一个可行的解决方案 - 我在(下面的情况下)出现段错误,在(使用而不是使用时)出现InsertNextPoint
无限递归,或者一些 VTK 错误(比如,当有零点时) .CheateChildNode
vtkIncrementalOctreePointLocator
vtkPointLocator
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
从阅读源代码来看,如果点集被修改,似乎每次查找时都会调用增量类,这可能会很昂贵。因此,对于组合插入/查找的更好类的建议也将不胜感激。