- 方法一:vtkCellLocator FindClosestPoint
计算两点之间的距离,不过这个方法,返回的参数是距离的平方
bool CheckPointInsidePolyData(vtkPolyData * poly, double* pt)
{
bool isInside=false;
auto cellLocator = vtkSmartPointer<vtkCellLocator>::New();
cellLocator->SetDataSet(poly);
cellLocator->BuildLocator();
auto assistCell = vtkSmartPointer<vtkGenericCell>::New();
double closestPoint[3];
double closestPointDist2;
vtkIdType cellId;
int subId=-1;
cellLocator->FindClosestPoint(point, closestPoint, assistCell, cellId, subId, closestPointDist2);
if (-1!= subId&&closestPointDist2 < 0.001)
{
isInside=true;
}
return isInside;
}
- 方法二:vtkSelectEnclosedPoints
double point[3] = { aPoint[0],aPoint[1],aPoint[2] };
vtkNew<vtkPoints> checkPoint;
checkPoint->InsertNextPoint(point[0], point[1], point[2]);
vtkNew<vtkPolyData> pointsPolyData;
pointsPolyData->SetPoints(checkPoint);
vtkNew<vtkSelectEnclosedPoints> selectEnclosedPoints;
selectEnclosedPoints->SetSurfaceData(myPolyData);
selectEnclosedPoints->SetInputData(pointsPolyData);
selectEnclosedPoints->Update();
bool isInside = selectEnclosedPoints->IsInside(0);
```cpp