vtk中计算线段与vtkPolyData的交点 及 相交的cell(vtkOBBTree,vtkModifiedBSPTree)

效果图:
vtk中计算线段与vtkPolyData的交点 及 相交的cell(vtkOBBTree,vtkModifiedBSPTree)_第1张图片

1.判断交点
关键代码:

  // Create the locator
  vtkSmartPointer<vtkOBBTree> tree = 
    vtkSmartPointer<vtkOBBTree>::New();
  tree->SetDataSet(sphereSource->GetOutput());
  tree->BuildLocator();

  // Intersect the locator with the line
  double lineP0[3] = {0.0, 0.0, 0.0};
  double lineP1[3] = {0.0, 0.0, 2.0};
  vtkSmartPointer intersectPoints = 
    vtkSmartPointer::New();

  tree->IntersectWithLine(lineP0, lineP1, intersectPoints, NULL);

示例demo:
https://lorensen.github.io/VTKExamples/site/Cxx/DataStructures/OBBTreeIntersectWithLine/
使用vtkModifiedBSPTree判断交点demo:
https://lorensen.github.io/VTKExamples/site/Cxx/DataStructures/ModifiedBSPTreeIntersectWithLine/

2.判断相交cell
关键代码:

  // Create the locator
  vtkSmartPointer<vtkOBBTree> tree =
    vtkSmartPointer<vtkOBBTree>::New();
  tree->SetDataSet(sphereSource->GetOutput());
  tree->BuildLocator();

  // Intersect the locator with the line
  double lineP0[3] = {-0.6, -0.6, -0.6};
  double lineP1[3] = {.6, .6, .6};
  vtkSmartPointer<vtkPoints> intersectPoints =
    vtkSmartPointer<vtkPoints>::New();

  vtkSmartPointer<vtkIdList> intersectCells =
    vtkSmartPointer<vtkIdList>::New();

  double tol = 1.e-8;
  tree->SetTolerance(tol);
  tree->IntersectWithLine(lineP0, lineP1,
                          intersectPoints,
                          intersectCells);

示例demo:
https://lorensen.github.io/VTKExamples/site/Cxx/DataStructures/OBBTreeExtractCells/
使用vtkModifiedBSPTree判断相交cell demo:
https://lorensen.github.io/VTKExamples/site/Cxx/DataStructures/ModifiedBSPTreeExtractCells/

你可能感兴趣的:(VTK,vtkOBBTree)