0

我正在导入网格文件,其中每个面都由其顶点的坐标来描述。大多数顶点在点之间共享。因此,我想消除比threshold已经添加到云中的点更近的点。这意味着我需要同时有效地执行最近点查找和点插入。

我尝试使用vtkPointLocator我已经用于静态云的方法;但我不知道应该如何增量使用它。文档非常简洁,示例(例​​如这个)没有涵盖这种情况这篇文章有点帮助,但我仍然没有一个可行的解决方案 - 我在(下面的情况下)出现段错误,在(使用而不是使用时)出现InsertNextPoint无限递归,或者一些 VTK 错误(比如,当有零点时) .CheateChildNodevtkIncrementalOctreePointLocatorvtkPointLocatorno 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从阅读源代码来看,如果点集被修改,似乎每次查找时都会调用增量类,这可能会很昂贵。因此,对于组合插入/查找的更好类的建议也将不胜感激。

4

1 回答 1

1

如果我正确理解了您的问题,您可能需要查看vtkCleanPolyData以及 PointMergingOn 和给定的容差。

于 2013-03-06T08:54:49.680 回答