| 44 | |
| 45 | #if OCC_VERSION_HEX >= 0x70200 |
| 46 | bool split(const TopoDS_Shape& input, const TopTools_ListOfShape& operands, double eps, std::vector<TopoDS_Shape>& slices) { |
| 47 | if (operands.Extent() < 2) { |
| 48 | // Needs to have at least two cutting surfaces for the ordering based on surface containment to work. |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | BRepAlgoAPI_Splitter split; |
| 53 | TopTools_ListOfShape input_list; |
| 54 | input_list.Append(input); |
| 55 | split.SetArguments(input_list); |
| 56 | split.SetTools(operands); |
| 57 | split.SetNonDestructive(true); |
| 58 | split.SetFuzzyValue(eps); |
| 59 | split.Build(); |
| 60 | |
| 61 | if (!split.IsDone()) { |
| 62 | return false; |
| 63 | } else { |
| 64 | |
| 65 | std::map<Geom_Surface*, int> surfaces; |
| 66 | |
| 67 | // NB 1, since first surface has been excluded |
| 68 | int i = 1; |
| 69 | for (TopTools_ListIteratorOfListOfShape it(operands); it.More(); it.Next(), ++i) { |
| 70 | TopExp_Explorer exp(it.Value(), TopAbs_FACE); |
| 71 | for (; exp.More(); exp.Next()) { |
| 72 | surfaces.insert(std::make_pair(BRep_Tool::Surface(TopoDS::Face(exp.Current())).get(), i)); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | auto result_shape = split.Shape(); |
| 77 | std::list<TopoDS_Shape> subs; |
| 78 | subshapes(result_shape, subs); |
| 79 | |
| 80 | // Sometimes there is more nesting of compounds, so when we find a single compound we again try to explode it into a list. |
| 81 | if (subs.size() == 1 && (subs.front().ShapeType() == TopAbs_COMPSOLID || subs.front().ShapeType() == TopAbs_COMPOUND)) { |
| 82 | auto s = subs.front(); |
| 83 | subs.clear(); |
| 84 | subshapes(s, subs); |
| 85 | } |
| 86 | |
| 87 | // Initialize storage |
| 88 | slices.resize(subs.size()); |
| 89 | |
| 90 | for (auto& s : subs) { |
| 91 | |
| 92 | // Iterate over the faces of solid to find correspondence to original |
| 93 | // splitting surfaces. For the outmost slices, there will be a single |
| 94 | // corresponding surface, because the outmost surfaces that align with |
| 95 | // the body geometry have not been added as operands. For intermediate |
| 96 | // slices, two surface indices should be find that should be next to |
| 97 | // each other in the array of input surfaces. |
| 98 | |
| 99 | TopExp_Explorer exp(s, TopAbs_FACE); |
| 100 | int min = std::numeric_limits<int>::max(); |
| 101 | int max = std::numeric_limits<int>::min(); |
| 102 | for (; exp.More(); exp.Next()) { |
| 103 | auto ssrf = BRep_Tool::Surface(TopoDS::Face(exp.Current())); |