因为vtkIntersectionPolyDataFilter 交线算法有问题所以改为 OCCT BRepAlgoAPI_Section交线算法。
OCCT 生成一个正方体和球体
BRepPrimAPI_MakeBox brepBox = new BRepPrimAPI_MakeBox(new Pnt(0,0,0),10,10,10);
vtkPolyData boxData = OcctConvert.TopoDsShapeToPolyData(brepBox.Shape());
BRepPrimAPI_MakeSphere brepSphere = new BRepPrimAPI_MakeSphere(new Pnt(5,5,5),6);
vtkPolyData sphereData = OcctConvert.TopoDsShapeToPolyData(brepSphere.Shape());
执行OCCT 交线算法
BRepAlgoAPI_Section brepSection = new BRepAlgoAPI_Section(brepBox.Shape(), brepSphere.Shape());
brepSection.ComputePCurveOn1(true);
brepSection.Approximation(true);
brepSection.Build();
OCCT 交线 转换为 vtk
因为OCCT 的 Edge 可能是无序的所以先排序,其次几何上明显是相连的Edge Chains存储时却不是相连,Chains 可以 看做是vtk 的连通域,所以要对Edge 进行连通域的分类。
public static vtkPolyData ChainEdgeList(TopoDS_Shape shape)
{
var order = new ShapeAnalysis_WireOrder();
List<TopoDS_Edge> edges = ShapeEdges(shape);
foreach (var edge in edges)
{
var first = BRep_Tool.Pnt(TopExp.FirstVertex(edge));
var last = BRep_Tool.Pnt(TopExp.LastVertex(edge));
if (edge.Orientation() == TopAbs_Orientation.FORWARD)
order.Add(first.Coord, last.Coord);
else