45 void Foam::booleanSurface::checkIncluded
47 const intersectedSurface& surf,
49 const label includedFace
52 forAll(surf.intersectionEdges(), intEdgeI)
54 label edgeI = surf.intersectionEdges()[intEdgeI];
56 const labelList& myFaces = surf.edgeFaces()[edgeI];
58 bool usesIncluded =
false;
62 if (faceZone[myFaces[myFaceI]] == faceZone[includedFace])
74 "booleanSurface::checkIncluded(const intersectedSurface&"
75 ", const labelList&, const label)"
76 ) <<
"None of the faces reachable from face " << includedFace
77 <<
" connects to the intersection."
85 Foam::label Foam::booleanSurface::index
93 if (elems[elemI] == elem)
109 forAll(edgeLabels, edgeLabelI)
111 if (edges[edgeLabels[edgeLabelI]] == e)
113 return edgeLabels[edgeLabelI];
118 "booleanSurface::findEdge(const edgeList&, const labelList&"
120 ) <<
"Cannot find edge " << e <<
" in edges " << edgeLabels
131 const triSurface& surf1,
132 const triSurface& surf2,
139 surf1.patches().size()
140 + surf2.patches().size()
144 label combinedPatchI = 0;
145 forAll(surf1.patches(), patchI)
147 combinedPatches[combinedPatchI++] = surf1.patches()[patchI];
151 patchMap2.setSize(surf2.patches().size());
153 forAll(surf2.patches(), patch2I)
157 forAll(surf1.patches(), patch1I)
159 if (surf1.patches()[patch1I] == surf2.patches()[patch2I])
169 combinedPatches[combinedPatchI] = surf2.patches()[patch2I];
170 patchMap2[patch2I] = combinedPatchI;
175 patchMap2[patch2I] = index;
179 combinedPatches.setSize(combinedPatchI);
181 return combinedPatches;
185 void Foam::booleanSurface::propagateEdgeSide
187 const triSurface& surf,
188 const label prevVert0,
189 const label prevFaceI,
190 const label prevState,
195 const labelList& eFaces = surf.sortedEdgeFaces()[edgeI];
198 if (eFaces.size() == 2)
213 if (((eFaces.size() % 2) == 1) && (eFaces.size() != 1))
217 "booleanSurface::propagateEdgeSide(const triSurface&,"
218 "const label, const label, const label, const label,"
220 ) <<
"Don't know how to handle edges with odd number of faces"
222 <<
"edge:" << edgeI <<
" vertices:" << surf.edges()[edgeI]
223 <<
" coming from face:" << prevFaceI
229 label ind = index(eFaces, prevFaceI);
233 const edge& e = surf.edges()[edgeI];
239 if (e.start() == prevVert0)
243 nextInd = eFaces.fcIndex(ind);
244 prevInd = eFaces.rcIndex(ind);
249 nextInd = eFaces.rcIndex(ind);
250 prevInd = eFaces.fcIndex(ind);
254 if (prevState == OUTSIDE)
264 if (eFaceI == nextInd)
293 if (eFaceI == prevInd)
316 void Foam::booleanSurface::propagateSide
318 const triSurface& surf,
319 const label prevState,
324 if (side[faceI] == UNVISITED)
326 side[faceI] = prevState;
328 const labelledTri& tri = surf[faceI];
337 const labelList& myEdges = surf.faceEdges()[faceI];
339 label edgeAB =
findEdge(surf.edges(), myEdges, edge(a, b));
351 label edgeBC =
findEdge(surf.edges(), myEdges, edge(b, c));
363 label edgeCA =
findEdge(surf.edges(), myEdges, edge(c, a));
393 const label includeFace1,
394 const label includeFace2
402 Pout<<
"booleanSurface : Generating intersected surface for surf1"
412 Pout<<
"booleanSurface : Generated cutSurf1: " <<
endl;
415 Pout<<
"Writing to file cutSurf1.ftr" <<
endl;
416 OFstream cutSurf1Stream(
"cutSurf1.ftr");
417 cutSurf1.
write(cutSurf1Stream);
422 Pout<<
"booleanSurface : Generating intersected surface for surf2"
431 Pout<<
"booleanSurface : Generated cutSurf2: " <<
endl;
434 Pout<<
"Writing to file cutSurf2.ftr" <<
endl;
435 OFstream cutSurf2Stream(
"cutSurf2.ftr");
436 cutSurf2.
write(cutSurf2Stream);
441 label cutSurf1FaceI = index(cutSurf1.
faceMap(), includeFace1);
445 Pout<<
"cutSurf1 : starting to fill from face:" << cutSurf1FaceI
449 if (cutSurf1FaceI == -1)
453 "booleanSurface(const triSurfaceSearch&"
454 ", const label, const triSurfaceSearch&, const label)"
455 ) <<
"Did not find face with label " << includeFace1
456 <<
" in intersectedSurface."
461 label cutSurf2FaceI = index(cutSurf2.
faceMap(), includeFace2);
465 Pout<<
"cutSurf2 : starting to fill from face:" << cutSurf2FaceI
468 if (cutSurf2FaceI == -1)
472 "booleanSurface(const triSurfaceSearch&"
473 ", const label, const triSurfaceSearch&, const label)"
474 ) <<
"Did not find face with label " << includeFace2
475 <<
" in intersectedSurface."
489 forAll(int1Edges, intEdgeI)
491 label edgeI = int1Edges[intEdgeI];
492 isIntersectionEdge1[edgeI] =
true;
496 (void)cutSurf1.
markZones(isIntersectionEdge1, faceZone1);
500 checkIncluded(cutSurf1, faceZone1, cutSurf1FaceI);
507 if (faceZone1[faceI] == faceZone1[cutSurf1FaceI])
509 includedFaces1[faceI] =
true;
537 forAll(int2Edges, intEdgeI)
539 label edgeI = int2Edges[intEdgeI];
540 isIntersectionEdge2[edgeI] =
true;
544 (void)cutSurf2.
markZones(isIntersectionEdge2, faceZone2);
548 checkIncluded(cutSurf2, faceZone2, cutSurf2FaceI);
555 if (faceZone2[faceI] == faceZone2[cutSurf2FaceI])
557 includedFaces2[faceI] =
true;
599 label combinedPointI = 0;
601 forAll(subSurf1.points(), pointI)
604 label cutSurfPointI = pointMap1[pointI];
611 intersectionLabels[cutSurfPointI] = combinedPointI;
615 combinedPoints[combinedPointI++] = subSurf1.points()[pointI];
622 forAll(subSurf2.points(), pointI)
625 label cutSurfPointI = pointMap2[pointI];
630 pointMap[pointI] = intersectionLabels[cutSurfPointI];
634 pointMap[pointI] = combinedPointI;
636 combinedPoints[combinedPointI++] = subSurf2.points()[pointI];
664 faceMap_.
setSize(combinedFaces.size());
667 label combinedFaceI = 0;
670 faceMap_[combinedFaceI] = faceMap1[faceI];
671 combinedFaces[combinedFaceI++] = subSurf1[faceI];
679 faceMap_[combinedFaceI] = -faceMap2[faceI]-1;
681 combinedFaces[combinedFaceI++] =
687 patchMap2[f.region()]
709 const label booleanOp
717 Pout<<
"booleanSurface : Testing surf1 and surf2" <<
endl;
724 const labelList& eFaces = edgeFaces[edgeI];
726 if (eFaces.
size() == 1)
728 WarningIn(
"booleanSurface::booleanSurface")
729 <<
"surf1 is open surface at edge " << edgeI
730 <<
" verts:" << surf1.
edges()[edgeI]
731 <<
" connected to faces " << eFaces <<
endl;
740 const labelList& eFaces = edgeFaces[edgeI];
742 if (eFaces.
size() == 1)
744 WarningIn(
"booleanSurface::booleanSurface")
745 <<
"surf2 is open surface at edge " << edgeI
746 <<
" verts:" << surf2.
edges()[edgeI]
747 <<
" connected to faces " << eFaces <<
endl;
760 Pout<<
"booleanSurface : Generating intersected surface for surf1"
769 Pout<<
"booleanSurface : Generated cutSurf1: " <<
endl;
772 Pout<<
"Writing to file cutSurf1.ftr" <<
endl;
773 OFstream cutSurf1Stream(
"cutSurf1.ftr");
774 cutSurf1.
write(cutSurf1Stream);
784 Pout<<
"booleanSurface : Generating intersected surface for surf2"
793 Pout<<
"booleanSurface : Generated cutSurf2: " <<
endl;
796 Pout<<
"Writing to file cutSurf2.ftr" <<
endl;
797 OFstream cutSurf2Stream(
"cutSurf2.ftr");
798 cutSurf2.
write(cutSurf2Stream);
832 label combinedPointI = 0;
836 combinedPoints[combinedPointI++] = cutSurf1.
points()[pointI];
846 combinedPoints[combinedPointI++] = cutSurf2.
points()[pointI];
856 Pout<<
"booleanSurface : generated points:" <<
nl
858 <<
" : original surface1"
861 <<
" .. " << cutSurf1.
nPoints()-1
862 <<
" : intersection points"
864 <<
" " << cutSurf1.
nPoints() <<
" .. "
866 <<
" : surface2 points"
875 label combinedFaceI = 0;
879 combinedFaces[combinedFaceI++] = cutSurf1[faceI];
884 labelledTri& combinedTri = combinedFaces[combinedFaceI++];
893 combinedTri[fp] = tri[fp] + cutSurf1.
nPoints();
921 Pout<<
"booleanSurface : Generated combinedSurf: " <<
endl;
924 Pout<<
"Writing to file combinedSurf.ftr" <<
endl;
925 OFstream combinedSurfStream(
"combinedSurf.ftr");
926 combinedSurf.write(combinedSurfStream);
934 faceMap_.setSize(combinedSurf.
size());
936 label combinedFaceI = 0;
940 faceMap_[combinedFaceI++] = cutSurf1.
faceMap()[faceI];
944 faceMap_[combinedFaceI++] = -cutSurf2.
faceMap()[faceI] - 1;
965 forAll(combinedSurf, faceI)
975 ).nearestPoint(outsidePoint);
987 Pout<<
"booleanSurface : found for point:" << outsidePoint
988 <<
" nearest face:" << minFaceI
989 <<
" nearest point:" << minHit.
rawPoint()
1000 propagateSide(combinedSurf, OUTSIDE, minFaceI, side);
1012 if (side[faceI] == UNVISITED)
1016 "booleanSurface::booleanSurface"
1017 "(const triSurfaceSearch&, const triSurfaceSearch&"
1018 ", const label booleanOp)"
1019 ) <<
"Face " << faceI <<
" has not been reached by walking from"
1020 <<
" nearest point " << minHit.
rawPoint()
1023 else if (side[faceI] == OUTSIDE)
1027 include[faceI] =
true;
1031 include[faceI] =
false;
1035 include[faceI] = (faceI < cutSurf1.
size());
1042 include[faceI] =
false;
1046 include[faceI] =
true;
1050 include[faceI] = (faceI >= cutSurf1.
size());
1069 faceMap_.
setSize(subSurf.size());
1071 forAll(subToCombinedFace, faceI)
1074 label combinedFaceI = subToCombinedFace[faceI];
1078 if (combinedFaceI < cutSurf1.
size())
1080 label cutSurf1Face = combinedFaceI;
1082 faceMap_[faceI] = cutSurf1.
faceMap()[cutSurf1Face];
1086 label cutSurf2Face = combinedFaceI - cutSurf1.
size();
1088 faceMap_[faceI] = - cutSurf2.
faceMap()[cutSurf2Face] - 1;