0
点赞
收藏
分享

微信扫一扫

VTK笔记——寻找最近点(vtkKdTree,vtkKdTreePointLocator,vtkOctreePointLocator,vtkCellLocator)

以沫的窝 2023-02-28 阅读 115


1.使用vtkKdTree,可以找到多个,或一个
 

// Create the tree
vtkSmartPointer<vtkKdTree> pointTree =
vtkSmartPointer<vtkKdTree>::New();
pointTree->BuildLocatorFromPoints(points);

// Find the 2 closest points to (0.5,0。5,0.5)
vtkIdType k = 2;
double inPutPoint[3] = {0.5,0。5,0.5};
vtkSmartPointer<vtkIdList> result =
vtkSmartPointer<vtkIdList>::New();
pointTree->FindClosestNPoints(k, inPutPoint, result);



// or
//Create the tree
vtkSmartPointer<vtkKdTree> kDTree =
vtkSmartPointer<vtkKdTree>::New();
kDTree->BuildLocatorFromPoints(points);

double inPutPoint[3] = {0.5,0。5,0.5};

//Find the closest points to inPutPoint
double closestPointDist;
vtkIdType id = kDTree->FindClosestPoint(inPutPoint, closestPointDist); //vtkKdTree::FindClosestPoint: must build locator first
std::cout << "The closest point is point " << id << std::endl;

2.使用vtkKdTreePointLocator 可以找到多个,或一个

//Create the tree
vtkSmartPointer<vtkKdTreePointLocator> pointTree =
vtkSmartPointer<vtkKdTreePointLocator>::New();
pointTree->SetDataSet(pointSource->GetOutput());
pointTree->BuildLocator();

// Find the k closest points to (0.5, 0.5, 0.5)
unsigned int k = 3;
double inPutPoint[3] = {0.5, 0.5, 0.5};
vtkSmartPointer<vtkIdList> result =
vtkSmartPointer<vtkIdList>::New();

pointTree->FindClosestNPoints(k, inPutPoint, result);

3.使用vtkCellLocator  找到最近的cell id 和点 id

// Create the tree
auto cellLocator = vtkSmartPointer<vtkCellLocator>::New();
cellLocator->SetDataSet(sphereSource->GetOutput());
cellLocator->BuildLocator();

double inPutPoint[3] = {0.6, 0.5, 0.0};

//Find the closest points to inPutPoint
auto assistCell = vtkSmartPointer<vtkGenericCell>::New();
double closestPoint[3];//the coordinates of the closest point will be returned here
double closestPointDist2; //the squared distance to the closest point will be returned here
vtkIdType cellId; //the cell id of the cell containing the closest point will be returned here
int subId;
cellLocator->FindClosestPoint(inPutPoint, closestPoint, assistCell, cellId, subId, closestPointDist2);

举报

相关推荐

0 条评论