52 bool Foam::surfaceIntersection::excludeEdgeHit
54 const triSurface& surf,
60 const labelledTri&
f = surf.localFaces()[faceI];
62 const edge&
e = surf.edges()[edgeI];
68 || (f[1] == e.start())
70 || (f[2] == e.start())
204 void Foam::surfaceIntersection::storeIntersection
206 const bool isFirstSurf,
209 DynamicList<edge>& allCutEdges,
210 DynamicList<point>& allCutPoints
216 label faceA = facesA[facesAI];
220 FixedList<label, 2> twoFaces;
234 if (iter == facePairToVertex_.end())
237 facePairToVertex_.insert(twoFaces, allCutPoints.size()-1);
246 const point& prevHit = allCutPoints[*iter];
248 const point& thisHit = allCutPoints[allCutPoints.size()-1];
250 if (
mag(prevHit - thisHit) < SMALL)
254 "Foam::surfaceIntersection::storeIntersection"
255 "(const bool isFirstSurf, const labelList& facesA,"
256 "const label faceB, DynamicList<edge>& allCutEdges,"
257 "DynamicList<point>& allCutPoints)"
258 ) <<
"Encountered degenerate edge between face "
259 << twoFaces[0] <<
" on first surface"
260 <<
" and face " << twoFaces[1] <<
" on second surface"
262 <<
"Point on first surface:" << prevHit <<
endl
263 <<
"Point on second surface:" << thisHit <<
endl
268 allCutEdges.append(edge(*iter, allCutPoints.size()-1));
271 facePairToEdge_.insert(twoFaces, allCutEdges.size()-1);
288 void Foam::surfaceIntersection::classifyHit
290 const triSurface& surf1,
292 const triSurface& surf2,
293 const bool isFirstSurf,
298 DynamicList<edge>& allCutEdges,
299 DynamicList<point>& allCutPoints,
300 List<DynamicList<label> >& surfEdgeCuts
303 const edge& e = surf1.edges()[edgeI];
305 const labelList& facesA = surf1.edgeFaces()[edgeI];
308 label surf2FaceI = pHit.index();
312 const labelledTri& f2 = surf2.localFaces()[surf2FaceI];
314 const pointField& surf2Pts = surf2.localPoints();
324 ).classify(pHit.hitPoint(), tolDim, nearType, nearLabel);
330 surf1PointTol[e.start()],
331 surf1PointTol[e.end()],
344 Pout<< pHit.hitPoint() <<
" is surf1:"
345 <<
" end point of edge " << e
346 <<
" surf2: vertex " << f2[nearLabel]
347 <<
" coord:" << surf2Pts[f2[nearLabel]] <<
endl;
355 Pout<< pHit.hitPoint() <<
" is surf1:"
356 <<
" somewhere on edge " << e
357 <<
" surf2: vertex " << f2[nearLabel]
358 <<
" coord:" << surf2Pts[f2[nearLabel]] <<
endl;
361 allCutPoints.append(pHit.hitPoint());
362 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
364 const labelList& facesB = surf2.pointFaces()[f2[nearLabel]];
385 label edge2I = getEdge(surf2, surf2FaceI, nearLabel);
386 const edge& e2 = surf2.edges()[edge2I];
390 Pout<< pHit.hitPoint() <<
" is surf1:"
391 <<
" end point of edge " << e
392 <<
" surf2: edge " << e2
393 <<
" coords:" << surf2Pts[e2.start()]
394 << surf2Pts[e2.end()] <<
endl;
405 label edge2I = getEdge(surf2, surf2FaceI, nearLabel);
406 const edge& e2 = surf2.edges()[edge2I];
410 Pout<< pHit.hitPoint() <<
" is surf1:"
411 <<
" somewhere on edge " << e
412 <<
" surf2: edge " << e2
413 <<
" coords:" << surf2Pts[e2.start()]
414 << surf2Pts[e2.end()] <<
endl;
417 allCutPoints.append(pHit.hitPoint());
418 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
429 const labelList& facesB = surf2.edgeFaces()[edge2I];
453 Pout<< pHit.hitPoint() <<
" is surf1:"
454 <<
" end point of edge " << e
455 <<
" surf2: face " << surf2FaceI
469 nearVert = e.start();
476 const point& nearPt = surf1.localPoints()[nearVert];
479 label otherVert = e.otherVertex(nearVert);
481 const point& otherPt = surf1.localPoints()[otherVert];
487 << pHit.hitPoint() <<
" is surf1:"
488 <<
" end point of edge " << e <<
" coord:"
489 << surf1.localPoints()[nearVert]
490 <<
" surf2: face " << surf2FaceI <<
endl;
493 vector eVec = otherPt - nearPt;
495 if ((surf2.faceNormals()[surf2FaceI] & eVec) > 0)
501 point hitPt = nearPt;
505 Pout<<
"Shifted " << pHit.hitPoint()
507 <<
" along edge:" << e
508 <<
" coords:" << surf1.localPoints()[e.start()]
509 << surf1.localPoints()[e.end()] <<
endl;
514 allCutPoints.append(hitPt);
515 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
531 Pout<<
"Discarding " << pHit.hitPoint()
532 <<
" since edge " << e <<
" on inside of surf2."
533 <<
" surf2 normal:" << surf2.faceNormals()[surf2FaceI]
543 Pout<< pHit.hitPoint() <<
" is surf1:"
544 <<
" somewhere on edge " << e
545 <<
" surf2: face " << surf2FaceI
550 allCutPoints.append(pHit.hitPoint());
551 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
579 void Foam::surfaceIntersection::doCutEdges
581 const triSurface& surf1,
582 const triSurfaceSearch& querySurf2,
583 const bool isFirstSurf,
584 const bool isSelfIntersection,
586 DynamicList<edge>& allCutEdges,
587 DynamicList<point>& allCutPoints,
588 List<DynamicList<label> >& surfEdgeCuts
593 const pointField& surf1Pts = surf1.localPoints();
598 forAll(surf1PointTol, pointI)
600 surf1PointTol[pointI] =
602 * minEdgeLen(surf1, pointI);
605 const triSurface& surf2 = querySurf2.surface();
607 forAll(surf1.edges(), edgeI)
609 const edge& e = surf1.edges()[edgeI];
611 point pStart = surf1Pts[e.start()];
612 const point& pEnd = surf1Pts[e.end()];
615 const scalar tolDim =
mag(tolVec);
617 bool doTrack =
false;
620 pointIndexHit pHit = querySurf2.tree().findLine(pStart, pEnd);
624 if (isSelfIntersection)
636 label hitFaceI = pHit.index();
650 label edgeEnd = classify
652 surf1PointTol[e.start()],
653 surf1PointTol[e.end()],
663 Pout<<
"edge:" << edgeI <<
" vertices:" << e
664 <<
" start:" << surf1Pts[e.start()]
665 <<
" end:" << surf1Pts[e.end()]
666 <<
" hit:" << pHit.hitPoint()
667 <<
" tolDim:" << tolDim
672 allCutPoints.append(pHit.hitPoint());
673 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
695 if (
mag(pHit.hitPoint() - pEnd) < tolDim)
701 pStart = pHit.hitPoint() + tolVec;
724 facePairToVertex_(0),
753 Pout<<
"Cutting surf1 edges" <<
endl;
777 transfer(edgeCuts1, surf1EdgeCuts_);
785 Pout<<
"Cutting surf2 edges" <<
endl;
804 transfer(edgeCuts2, surf2EdgeCuts_);
805 cutEdges_.transfer(allCutEdges);
806 cutPoints_.transfer(allCutPoints);
811 Pout<<
"surfaceIntersection : Intersection generated:"
813 <<
" points:" << cutPoints_.size() <<
endl
814 <<
" edges :" << cutEdges_.size() <<
endl;
816 Pout<<
"surfaceIntersection : Writing intersection to intEdges.obj"
820 writeOBJ(cutPoints_, cutEdges_, intStream);
823 Pout<<
"Dumping cut edges of surface1 to surf1EdgeCuts.obj" <<
endl;
824 OFstream edge1Stream(
"surf1EdgeCuts.obj");
825 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
827 Pout<<
"Dumping cut edges of surface2 to surf2EdgeCuts.obj" <<
endl;
828 OFstream edge2Stream(
"surf2EdgeCuts.obj");
829 writeIntersectedEdges(surf2, surf2EdgeCuts_, edge2Stream);
845 facePairToVertex_(2*
max(surf1.
size(), surf2.
size())),
846 facePairToEdge_(2*
max(surf1.
size(), surf2.
size())),
861 Pout<<
"Storing surf1 intersections" <<
endl;
868 forAll(intersections1, edgeI)
878 edgeCuts1[edgeI].append(allCutPoints.
size()-1);
892 transfer(edgeCuts1, surf1EdgeCuts_);
902 Pout<<
"Storing surf2 intersections" <<
endl;
909 forAll(intersections2, edgeI)
919 edgeCuts2[edgeI].append(allCutPoints.
size()-1);
933 transfer(edgeCuts2, surf2EdgeCuts_);
938 cutEdges_.transfer(allCutEdges);
939 cutPoints_.transfer(allCutPoints);
944 Pout<<
"surfaceIntersection : Intersection generated:"
946 <<
" points:" << cutPoints_.size() <<
endl
947 <<
" edges :" << cutEdges_.size() <<
endl;
949 Pout<<
"surfaceIntersection : Writing intersection to intEdges.obj"
953 writeOBJ(cutPoints_, cutEdges_, intStream);
956 Pout<<
"Dumping cut edges of surface1 to surf1EdgeCuts.obj" <<
endl;
957 OFstream edge1Stream(
"surf1EdgeCuts.obj");
958 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
960 Pout<<
"Dumping cut edges of surface2 to surf2EdgeCuts.obj" <<
endl;
961 OFstream edge2Stream(
"surf2EdgeCuts.obj");
962 writeIntersectedEdges(surf2, surf2EdgeCuts_, edge2Stream);
973 label edgeI = iter();
975 const edge& e = cutEdges_[edgeI];
983 label pointI = iter();
985 if (!usedPoints.
found(pointI))
987 FatalErrorIn(
"surfaceIntersection::surfaceIntersection")
988 <<
"Problem: cut point:" << pointI
989 <<
" coord:" << cutPoints_[pointI]
1017 Pout<<
"Cutting surf1 edges" <<
endl;
1041 transfer(edgeCuts1, surf1EdgeCuts_);
1042 cutEdges_.transfer(allCutEdges);
1043 cutPoints_.transfer(allCutPoints);
1046 if (cutPoints_.empty() && cutEdges_.empty())
1050 Pout<<
"Empty intersection" <<
endl;
1060 scalar minEdgeLen = GREAT;
1087 Pout<<
"Merged:" << hasMerged
1089 <<
" cutPoints:" << cutPoints_.size()
1090 <<
" newPoints:" << newPoints.
size()
1095 cutPoints_.transfer(newPoints);
1100 edge& e = cutEdges_[edgeI];
1103 e.
end() = pointMap[e.
end()];
1109 Pout<<
"Degenerate cut:" << edgeI <<
" vertices:" << e
1110 <<
" coords:" << cutPoints_[e.
start()] <<
' '
1111 << cutPoints_[e.
end()] <<
endl;
1117 forAll(surf1EdgeCuts_, edgeI)
1120 labelList& cutVerts = surf1EdgeCuts_[edgeI];
1122 removeDuplicates(pointMap, cutVerts);
1128 Pout<<
"surfaceIntersection : Intersection generated and compressed:"
1130 <<
" points:" << cutPoints_.size() <<
endl
1131 <<
" edges :" << cutEdges_.size() <<
endl;
1134 Pout<<
"surfaceIntersection : Writing intersection to intEdges.obj"
1137 OFstream intStream(
"intEdges.obj");
1138 writeOBJ(cutPoints_, cutEdges_, intStream);
1144 Pout<<
"Dumping cut edges of surface1 to surf1EdgeCuts.obj" <<
endl;
1145 OFstream edge1Stream(
"surf1EdgeCuts.obj");
1146 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
1167 return facePairToEdge_;
1173 const bool isFirstSurf
1178 return surf1EdgeCuts_;
1182 return surf2EdgeCuts_;
1189 return surf1EdgeCuts_;
1195 return surf2EdgeCuts_;