我正在導入網格文件,其中每個面由其頂點的座標描述。大多數頂點在點之間共享。因此,我想消除比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