00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "surfaceIntersection.H"
00030 #include "triSurfaceSearch.H"
00031 #include "labelPairLookup.H"
00032 #include "OFstream.H"
00033 #include "HashSet.H"
00034 #include "triSurface.H"
00035 #include "pointIndexHit.H"
00036 #include "octreeDataTriSurface.H"
00037 #include "octree.H"
00038 #include "mergePoints.H"
00039 #include "plane.H"
00040 #include "edgeIntersections.H"
00041
00042
00043
00044 defineTypeNameAndDebug(Foam::surfaceIntersection, 0);
00045
00046
00047
00048
00049
00050
00051
00052
00053 bool Foam::surfaceIntersection::excludeEdgeHit
00054 (
00055 const triSurface& surf,
00056 const label edgeI,
00057 const label faceI,
00058 const scalar
00059 )
00060 {
00061 const labelledTri& f = surf.localFaces()[faceI];
00062
00063 const edge& e = surf.edges()[edgeI];
00064
00065 if
00066 (
00067 (f[0] == e.start())
00068 || (f[0] == e.end())
00069 || (f[1] == e.start())
00070 || (f[1] == e.end())
00071 || (f[2] == e.start())
00072 || (f[2] == e.end())
00073 )
00074 {
00075 return true;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 }
00121 else
00122 {
00123 return false;
00124 }
00125 }
00126
00127
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 void Foam::surfaceIntersection::storeIntersection
00206 (
00207 const bool isFirstSurf,
00208 const labelList& facesA,
00209 const label faceB,
00210 DynamicList<edge>& allCutEdges,
00211 DynamicList<point>& allCutPoints
00212 )
00213 {
00214
00215 forAll(facesA, facesAI)
00216 {
00217 label faceA = facesA[facesAI];
00218
00219
00220
00221 FixedList<label, 2> twoFaces;
00222 if (isFirstSurf)
00223 {
00224 twoFaces[0] = faceA;
00225 twoFaces[1] = faceB;
00226 }
00227 else
00228 {
00229 twoFaces[0] = faceB;
00230 twoFaces[1] = faceA;
00231 }
00232
00233 labelPairLookup::const_iterator iter = facePairToVertex_.find(twoFaces);
00234
00235 if (iter == facePairToVertex_.end())
00236 {
00237
00238 facePairToVertex_.insert(twoFaces, allCutPoints.size()-1);
00239 }
00240 else
00241 {
00242
00243
00244
00245
00246
00247 const point& prevHit = allCutPoints[*iter];
00248
00249 const point& thisHit = allCutPoints[allCutPoints.size()-1];
00250
00251 if (mag(prevHit - thisHit) < SMALL)
00252 {
00253 WarningIn
00254 (
00255 "Foam::surfaceIntersection::storeIntersection"
00256 "(const bool isFirstSurf, const labelList& facesA,"
00257 "const label faceB, DynamicList<edge>& allCutEdges,"
00258 "DynamicList<point>& allCutPoints)"
00259 ) << "Encountered degenerate edge between face "
00260 << twoFaces[0] << " on first surface"
00261 << " and face " << twoFaces[1] << " on second surface"
00262 << endl
00263 << "Point on first surface:" << prevHit << endl
00264 << "Point on second surface:" << thisHit << endl
00265 << endl;
00266 }
00267 else
00268 {
00269 allCutEdges.append(edge(*iter, allCutPoints.size()-1));
00270
00271
00272 facePairToEdge_.insert(twoFaces, allCutEdges.size()-1);
00273 }
00274 }
00275 }
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 void Foam::surfaceIntersection::classifyHit
00290 (
00291 const triSurface& surf1,
00292 const scalarField& surf1PointTol,
00293 const triSurface& surf2,
00294 const bool isFirstSurf,
00295 const label edgeI,
00296 const scalar tolDim,
00297 const pointIndexHit& pHit,
00298
00299 DynamicList<edge>& allCutEdges,
00300 DynamicList<point>& allCutPoints,
00301 List<DynamicList<label> >& surfEdgeCuts
00302 )
00303 {
00304 const edge& e = surf1.edges()[edgeI];
00305
00306 const labelList& facesA = surf1.edgeFaces()[edgeI];
00307
00308
00309 label surf2FaceI = pHit.index();
00310
00311
00312
00313 const labelledTri& f2 = surf2.localFaces()[surf2FaceI];
00314
00315 const pointField& surf2Pts = surf2.localPoints();
00316
00317 label nearType;
00318 label nearLabel;
00319
00320 (void)triPointRef
00321 (
00322 surf2Pts[f2[0]],
00323 surf2Pts[f2[1]],
00324 surf2Pts[f2[2]]
00325 ).classify(pHit.hitPoint(), tolDim, nearType, nearLabel);
00326
00327
00328 label edgeEnd =
00329 classify
00330 (
00331 surf1PointTol[e.start()],
00332 surf1PointTol[e.end()],
00333 pHit.hitPoint(),
00334 e,
00335 surf1.localPoints()
00336 );
00337
00338 if (nearType == triPointRef::POINT)
00339 {
00340 if (edgeEnd >= 0)
00341 {
00342
00343 if (debug&2)
00344 {
00345 Pout<< pHit.hitPoint() << " is surf1:"
00346 << " end point of edge " << e
00347 << " surf2: vertex " << f2[nearLabel]
00348 << " coord:" << surf2Pts[f2[nearLabel]] << endl;
00349 }
00350 }
00351 else
00352 {
00353
00354 if (debug&2)
00355 {
00356 Pout<< pHit.hitPoint() << " is surf1:"
00357 << " somewhere on edge " << e
00358 << " surf2: vertex " << f2[nearLabel]
00359 << " coord:" << surf2Pts[f2[nearLabel]] << endl;
00360 }
00361
00362 allCutPoints.append(pHit.hitPoint());
00363 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
00364
00365 const labelList& facesB = surf2.pointFaces()[f2[nearLabel]];
00366
00367 forAll(facesB, faceBI)
00368 {
00369 storeIntersection
00370 (
00371 isFirstSurf,
00372 facesA,
00373 facesB[faceBI],
00374 allCutEdges,
00375 allCutPoints
00376 );
00377 }
00378 }
00379 }
00380 else if (nearType == triPointRef::EDGE)
00381 {
00382 if (edgeEnd >= 0)
00383 {
00384
00385
00386 label edge2I = getEdge(surf2, surf2FaceI, nearLabel);
00387 const edge& e2 = surf2.edges()[edge2I];
00388
00389 if (debug&2)
00390 {
00391 Pout<< pHit.hitPoint() << " is surf1:"
00392 << " end point of edge " << e
00393 << " surf2: edge " << e2
00394 << " coords:" << surf2Pts[e2.start()]
00395 << surf2Pts[e2.end()] << endl;
00396 }
00397 }
00398 else
00399 {
00400
00401
00402
00403
00404
00405
00406 label edge2I = getEdge(surf2, surf2FaceI, nearLabel);
00407 const edge& e2 = surf2.edges()[edge2I];
00408
00409 if (debug&2)
00410 {
00411 Pout<< pHit.hitPoint() << " is surf1:"
00412 << " somewhere on edge " << e
00413 << " surf2: edge " << e2
00414 << " coords:" << surf2Pts[e2.start()]
00415 << surf2Pts[e2.end()] << endl;
00416 }
00417
00418 allCutPoints.append(pHit.hitPoint());
00419 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
00420
00421
00422
00423 if (isFirstSurf)
00424 {
00425
00426
00427
00428
00429
00430 const labelList& facesB = surf2.edgeFaces()[edge2I];
00431
00432 forAll(facesB, faceBI)
00433 {
00434 storeIntersection
00435 (
00436 isFirstSurf,
00437 facesA,
00438 facesB[faceBI],
00439 allCutEdges,
00440 allCutPoints
00441 );
00442 }
00443 }
00444 }
00445 }
00446 else
00447 {
00448 if (edgeEnd >= 0)
00449 {
00450
00451
00452 if (debug&2)
00453 {
00454 Pout<< pHit.hitPoint() << " is surf1:"
00455 << " end point of edge " << e
00456 << " surf2: face " << surf2FaceI
00457 << endl;
00458 }
00459
00460
00461
00462
00463
00464
00465
00466 label nearVert = -1;
00467
00468 if (edgeEnd == 0)
00469 {
00470 nearVert = e.start();
00471 }
00472 else
00473 {
00474 nearVert = e.end();
00475 }
00476
00477 const point& nearPt = surf1.localPoints()[nearVert];
00478
00479
00480 label otherVert = e.otherVertex(nearVert);
00481
00482 const point& otherPt = surf1.localPoints()[otherVert];
00483
00484
00485 if (debug)
00486 {
00487 Pout
00488 << pHit.hitPoint() << " is surf1:"
00489 << " end point of edge " << e << " coord:"
00490 << surf1.localPoints()[nearVert]
00491 << " surf2: face " << surf2FaceI << endl;
00492 }
00493
00494 vector eVec = otherPt - nearPt;
00495
00496 if ((surf2.faceNormals()[surf2FaceI] & eVec) > 0)
00497 {
00498
00499
00500
00501
00502 point hitPt = nearPt;
00503
00504 if (debug&2)
00505 {
00506 Pout<< "Shifted " << pHit.hitPoint()
00507 << " to " << hitPt
00508 << " along edge:" << e
00509 << " coords:" << surf1.localPoints()[e.start()]
00510 << surf1.localPoints()[e.end()] << endl;
00511 }
00512
00513
00514
00515 allCutPoints.append(hitPt);
00516 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
00517
00518
00519 storeIntersection
00520 (
00521 isFirstSurf,
00522 facesA,
00523 surf2FaceI,
00524 allCutEdges,
00525 allCutPoints
00526 );
00527 }
00528 else
00529 {
00530 if (debug&2)
00531 {
00532 Pout<< "Discarding " << pHit.hitPoint()
00533 << " since edge " << e << " on inside of surf2."
00534 << " surf2 normal:" << surf2.faceNormals()[surf2FaceI]
00535 << endl;
00536 }
00537 }
00538 }
00539 else
00540 {
00541
00542 if (debug&2)
00543 {
00544 Pout<< pHit.hitPoint() << " is surf1:"
00545 << " somewhere on edge " << e
00546 << " surf2: face " << surf2FaceI
00547 << endl;
00548 }
00549
00550
00551 allCutPoints.append(pHit.hitPoint());
00552 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
00553
00554
00555 storeIntersection
00556 (
00557 isFirstSurf,
00558 facesA,
00559 surf2FaceI,
00560 allCutEdges,
00561 allCutPoints
00562 );
00563 }
00564 }
00565 if (debug&2)
00566 {
00567 Pout<< endl;
00568 }
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 void Foam::surfaceIntersection::doCutEdges
00581 (
00582 const triSurface& surf1,
00583 const triSurfaceSearch& querySurf2,
00584 const bool isFirstSurf,
00585 const bool isSelfIntersection,
00586
00587 DynamicList<edge>& allCutEdges,
00588 DynamicList<point>& allCutPoints,
00589 List<DynamicList<label> >& surfEdgeCuts
00590 )
00591 {
00592 scalar oldTol = intersection::setPlanarTol(1E-3);
00593
00594 const pointField& surf1Pts = surf1.localPoints();
00595
00596
00597 scalarField surf1PointTol(surf1Pts.size());
00598
00599 forAll(surf1PointTol, pointI)
00600 {
00601 surf1PointTol[pointI] =
00602 intersection::planarTol()
00603 * minEdgeLen(surf1, pointI);
00604 }
00605
00606 const triSurface& surf2 = querySurf2.surface();
00607
00608 forAll(surf1.edges(), edgeI)
00609 {
00610 const edge& e = surf1.edges()[edgeI];
00611
00612 point pStart = surf1Pts[e.start()];
00613 const point& pEnd = surf1Pts[e.end()];
00614
00615 const point tolVec = intersection::planarTol()*(pEnd-pStart);
00616 const scalar tolDim = mag(tolVec);
00617
00618 bool doTrack = false;
00619 do
00620 {
00621 pointIndexHit pHit = querySurf2.tree().findLine(pStart, pEnd);
00622
00623 if (pHit.hit())
00624 {
00625 if (isSelfIntersection)
00626 {
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 label hitFaceI = pHit.index();
00638
00639 if
00640 (
00641 !excludeEdgeHit
00642 (
00643 surf1,
00644 edgeI,
00645 hitFaceI,
00646 0.1
00647 )
00648 )
00649 {
00650
00651 label edgeEnd = classify
00652 (
00653 surf1PointTol[e.start()],
00654 surf1PointTol[e.end()],
00655 pHit.hitPoint(),
00656 e,
00657 surf1Pts
00658 );
00659
00660 if (edgeEnd < 0)
00661 {
00662 if (debug)
00663 {
00664 Pout<< "edge:" << edgeI << " vertices:" << e
00665 << " start:" << surf1Pts[e.start()]
00666 << " end:" << surf1Pts[e.end()]
00667 << " hit:" << pHit.hitPoint()
00668 << " tolDim:" << tolDim
00669 << " planarTol:"
00670 << intersection::planarTol()
00671 << endl;
00672 }
00673 allCutPoints.append(pHit.hitPoint());
00674 surfEdgeCuts[edgeI].append(allCutPoints.size()-1);
00675 }
00676 }
00677 }
00678 else
00679 {
00680 classifyHit
00681 (
00682 surf1,
00683 surf1PointTol,
00684 surf2,
00685 isFirstSurf,
00686 edgeI,
00687 tolDim,
00688 pHit,
00689
00690 allCutEdges,
00691 allCutPoints,
00692 surfEdgeCuts
00693 );
00694 }
00695
00696 if (mag(pHit.hitPoint() - pEnd) < tolDim)
00697 {
00698 doTrack = false;
00699 }
00700 else
00701 {
00702 pStart = pHit.hitPoint() + tolVec;
00703
00704 doTrack = true;
00705 }
00706 }
00707 else
00708 {
00709 doTrack = false;
00710 }
00711 }
00712 while(doTrack);
00713 }
00714 intersection::setPlanarTol(oldTol);
00715 }
00716
00717
00718
00719
00720
00721 Foam::surfaceIntersection::surfaceIntersection()
00722 :
00723 cutPoints_(0),
00724 cutEdges_(0),
00725 facePairToVertex_(0),
00726 facePairToEdge_(0),
00727 surf1EdgeCuts_(0),
00728 surf2EdgeCuts_(0)
00729 {}
00730
00731
00732
00733 Foam::surfaceIntersection::surfaceIntersection
00734 (
00735 const triSurfaceSearch& query1,
00736 const triSurfaceSearch& query2
00737 )
00738 :
00739 cutPoints_(0),
00740 cutEdges_(0),
00741 facePairToVertex_(2*max(query1.surface().size(), query2.surface().size())),
00742 facePairToEdge_(2*max(query1.surface().size(), query2.surface().size())),
00743 surf1EdgeCuts_(0),
00744 surf2EdgeCuts_(0)
00745 {
00746 const triSurface& surf1 = query1.surface();
00747 const triSurface& surf2 = query2.surface();
00748
00749
00750
00751
00752 if (debug)
00753 {
00754 Pout<< "Cutting surf1 edges" << endl;
00755 }
00756
00757
00758 DynamicList<edge> allCutEdges(surf1.nEdges()/20);
00759 DynamicList<point> allCutPoints(surf1.nPoints()/20);
00760
00761
00762
00763 List<DynamicList<label> > edgeCuts1(query1.surface().nEdges());
00764
00765 doCutEdges
00766 (
00767 surf1,
00768 query2,
00769 true,
00770
00771 false,
00772
00773 allCutEdges,
00774 allCutPoints,
00775 edgeCuts1
00776 );
00777
00778 transfer(edgeCuts1, surf1EdgeCuts_);
00779
00780
00781
00782
00783
00784 if (debug)
00785 {
00786 Pout<< "Cutting surf2 edges" << endl;
00787 }
00788
00789
00790 List<DynamicList<label> > edgeCuts2(query2.surface().nEdges());
00791
00792 doCutEdges
00793 (
00794 surf2,
00795 query1,
00796 false,
00797 false,
00798
00799 allCutEdges,
00800 allCutPoints,
00801 edgeCuts2
00802 );
00803
00804
00805 transfer(edgeCuts2, surf2EdgeCuts_);
00806 cutEdges_.transfer(allCutEdges);
00807 cutPoints_.transfer(allCutPoints);
00808
00809
00810 if (debug)
00811 {
00812 Pout<< "surfaceIntersection : Intersection generated:"
00813 << endl
00814 << " points:" << cutPoints_.size() << endl
00815 << " edges :" << cutEdges_.size() << endl;
00816
00817 Pout<< "surfaceIntersection : Writing intersection to intEdges.obj"
00818 << endl;
00819
00820 OFstream intStream("intEdges.obj");
00821 writeOBJ(cutPoints_, cutEdges_, intStream);
00822
00823
00824 Pout<< "Dumping cut edges of surface1 to surf1EdgeCuts.obj" << endl;
00825 OFstream edge1Stream("surf1EdgeCuts.obj");
00826 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
00827
00828 Pout<< "Dumping cut edges of surface2 to surf2EdgeCuts.obj" << endl;
00829 OFstream edge2Stream("surf2EdgeCuts.obj");
00830 writeIntersectedEdges(surf2, surf2EdgeCuts_, edge2Stream);
00831 }
00832 }
00833
00834
00835
00836 Foam::surfaceIntersection::surfaceIntersection
00837 (
00838 const triSurface& surf1,
00839 const edgeIntersections& intersections1,
00840 const triSurface& surf2,
00841 const edgeIntersections& intersections2
00842 )
00843 :
00844 cutPoints_(0),
00845 cutEdges_(0),
00846 facePairToVertex_(2*max(surf1.size(), surf2.size())),
00847 facePairToEdge_(2*max(surf1.size(), surf2.size())),
00848 surf1EdgeCuts_(0),
00849 surf2EdgeCuts_(0)
00850 {
00851
00852
00853 DynamicList<edge> allCutEdges((surf1.nEdges() + surf2.nEdges())/20);
00854 DynamicList<point> allCutPoints((surf1.nPoints() + surf2.nPoints())/20);
00855
00856
00857
00858
00859
00860 if (debug)
00861 {
00862 Pout<< "Storing surf1 intersections" << endl;
00863 }
00864
00865 {
00866
00867 List<DynamicList<label> > edgeCuts1(surf1.nEdges());
00868
00869 forAll(intersections1, edgeI)
00870 {
00871 const List<pointIndexHit>& intersections = intersections1[edgeI];
00872
00873 forAll(intersections, i)
00874 {
00875 const pointIndexHit& pHit = intersections[i];
00876
00877
00878 allCutPoints.append(pHit.hitPoint());
00879 edgeCuts1[edgeI].append(allCutPoints.size()-1);
00880
00881 storeIntersection
00882 (
00883 true,
00884 surf1.edgeFaces()[edgeI],
00885 pHit.index(),
00886 allCutEdges,
00887 allCutPoints
00888 );
00889 }
00890 }
00891
00892
00893 transfer(edgeCuts1, surf1EdgeCuts_);
00894 }
00895
00896
00897
00898
00899
00900
00901 if (debug)
00902 {
00903 Pout<< "Storing surf2 intersections" << endl;
00904 }
00905
00906 {
00907
00908 List<DynamicList<label> > edgeCuts2(surf2.nEdges());
00909
00910 forAll(intersections2, edgeI)
00911 {
00912 const List<pointIndexHit>& intersections = intersections2[edgeI];
00913
00914 forAll(intersections, i)
00915 {
00916 const pointIndexHit& pHit = intersections[i];
00917
00918
00919 allCutPoints.append(pHit.hitPoint());
00920 edgeCuts2[edgeI].append(allCutPoints.size()-1);
00921
00922 storeIntersection
00923 (
00924 false,
00925 surf2.edgeFaces()[edgeI],
00926 pHit.index(),
00927 allCutEdges,
00928 allCutPoints
00929 );
00930 }
00931 }
00932
00933
00934 transfer(edgeCuts2, surf2EdgeCuts_);
00935 }
00936
00937
00938
00939 cutEdges_.transfer(allCutEdges);
00940 cutPoints_.transfer(allCutPoints);
00941
00942
00943 if (debug)
00944 {
00945 Pout<< "surfaceIntersection : Intersection generated:"
00946 << endl
00947 << " points:" << cutPoints_.size() << endl
00948 << " edges :" << cutEdges_.size() << endl;
00949
00950 Pout<< "surfaceIntersection : Writing intersection to intEdges.obj"
00951 << endl;
00952
00953 OFstream intStream("intEdges.obj");
00954 writeOBJ(cutPoints_, cutEdges_, intStream);
00955
00956
00957 Pout<< "Dumping cut edges of surface1 to surf1EdgeCuts.obj" << endl;
00958 OFstream edge1Stream("surf1EdgeCuts.obj");
00959 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
00960
00961 Pout<< "Dumping cut edges of surface2 to surf2EdgeCuts.obj" << endl;
00962 OFstream edge2Stream("surf2EdgeCuts.obj");
00963 writeIntersectedEdges(surf2, surf2EdgeCuts_, edge2Stream);
00964 }
00965
00966
00967
00968 {
00969
00970 labelHashSet usedPoints;
00971
00972 forAllConstIter(labelPairLookup, facePairToEdge_, iter)
00973 {
00974 label edgeI = iter();
00975
00976 const edge& e = cutEdges_[edgeI];
00977
00978 usedPoints.insert(e[0]);
00979 usedPoints.insert(e[1]);
00980 }
00981
00982 forAllConstIter(labelPairLookup, facePairToVertex_, iter)
00983 {
00984 label pointI = iter();
00985
00986 if (!usedPoints.found(pointI))
00987 {
00988 FatalErrorIn("surfaceIntersection::surfaceIntersection")
00989 << "Problem: cut point:" << pointI
00990 << " coord:" << cutPoints_[pointI]
00991 << " not used by any edge" << abort(FatalError);
00992 }
00993 }
00994 }
00995 }
00996
00997
00998
00999 Foam::surfaceIntersection::surfaceIntersection
01000 (
01001 const triSurfaceSearch& query1
01002 )
01003 :
01004 cutPoints_(0),
01005 cutEdges_(0),
01006 facePairToVertex_(2*query1.surface().size()),
01007 facePairToEdge_(2*query1.surface().size()),
01008 surf1EdgeCuts_(0),
01009 surf2EdgeCuts_(0)
01010 {
01011 const triSurface& surf1 = query1.surface();
01012
01013
01014
01015
01016 if (debug)
01017 {
01018 Pout<< "Cutting surf1 edges" << endl;
01019 }
01020
01021 DynamicList<edge> allCutEdges;
01022 DynamicList<point> allCutPoints;
01023
01024
01025 List<DynamicList<label> > edgeCuts1(query1.surface().nEdges());
01026
01027 doCutEdges
01028 (
01029 surf1,
01030 query1,
01031 true,
01032
01033 true,
01034
01035
01036 allCutEdges,
01037 allCutPoints,
01038 edgeCuts1
01039 );
01040
01041
01042 transfer(edgeCuts1, surf1EdgeCuts_);
01043 cutEdges_.transfer(allCutEdges);
01044 cutPoints_.transfer(allCutPoints);
01045
01046
01047 if (cutPoints_.empty() && cutEdges_.empty())
01048 {
01049 if (debug)
01050 {
01051 Pout<< "Empty intersection" << endl;
01052 }
01053 return;
01054 }
01055
01056
01057
01058
01059
01060
01061 scalar minEdgeLen = GREAT;
01062 forAll(surf1.edges(), edgeI)
01063 {
01064 minEdgeLen = min
01065 (
01066 minEdgeLen,
01067 surf1.edges()[edgeI].mag(surf1.localPoints())
01068 );
01069 }
01070
01071
01072 labelList pointMap;
01073 pointField newPoints;
01074
01075 bool hasMerged = mergePoints
01076 (
01077 cutPoints_,
01078 minEdgeLen*intersection::planarTol(),
01079 false,
01080 pointMap,
01081 newPoints
01082 );
01083
01084 if (hasMerged)
01085 {
01086 if (debug)
01087 {
01088 Pout<< "Merged:" << hasMerged
01089 << " mergeDist:" << minEdgeLen*intersection::planarTol()
01090 << " cutPoints:" << cutPoints_.size()
01091 << " newPoints:" << newPoints.size()
01092 << endl;
01093 }
01094
01095
01096 cutPoints_.transfer(newPoints);
01097
01098
01099 forAll(cutEdges_, edgeI)
01100 {
01101 edge& e = cutEdges_[edgeI];
01102
01103 e.start() = pointMap[e.start()];
01104 e.end() = pointMap[e.end()];
01105
01106 if (e.mag(cutPoints_) < minEdgeLen*intersection::planarTol())
01107 {
01108 if (debug)
01109 {
01110 Pout<< "Degenerate cut:" << edgeI << " vertices:" << e
01111 << " coords:" << cutPoints_[e.start()] << ' '
01112 << cutPoints_[e.end()] << endl;
01113 }
01114 }
01115 }
01116
01117
01118 forAll(surf1EdgeCuts_, edgeI)
01119 {
01120
01121 labelList& cutVerts = surf1EdgeCuts_[edgeI];
01122
01123 removeDuplicates(pointMap, cutVerts);
01124 }
01125 }
01126
01127 if (debug)
01128 {
01129 Pout<< "surfaceIntersection : Intersection generated and compressed:"
01130 << endl
01131 << " points:" << cutPoints_.size() << endl
01132 << " edges :" << cutEdges_.size() << endl;
01133
01134
01135 Pout<< "surfaceIntersection : Writing intersection to intEdges.obj"
01136 << endl;
01137
01138 OFstream intStream("intEdges.obj");
01139 writeOBJ(cutPoints_, cutEdges_, intStream);
01140 }
01141
01142 if (debug)
01143 {
01144
01145 Pout<< "Dumping cut edges of surface1 to surf1EdgeCuts.obj" << endl;
01146 OFstream edge1Stream("surf1EdgeCuts.obj");
01147 writeIntersectedEdges(surf1, surf1EdgeCuts_, edge1Stream);
01148 }
01149 }
01150
01151
01152
01153
01154 const Foam::pointField& Foam::surfaceIntersection::cutPoints() const
01155 {
01156 return cutPoints_;
01157 }
01158
01159
01160 const Foam::edgeList& Foam::surfaceIntersection::cutEdges() const
01161 {
01162 return cutEdges_;
01163 }
01164
01165
01166 const Foam::labelPairLookup& Foam::surfaceIntersection::facePairToEdge() const
01167 {
01168 return facePairToEdge_;
01169 }
01170
01171
01172 const Foam::labelListList& Foam::surfaceIntersection::edgeCuts
01173 (
01174 const bool isFirstSurf
01175 ) const
01176 {
01177 if (isFirstSurf)
01178 {
01179 return surf1EdgeCuts_;
01180 }
01181 else
01182 {
01183 return surf2EdgeCuts_;
01184 }
01185 }
01186
01187
01188 const Foam::labelListList& Foam::surfaceIntersection::surf1EdgeCuts() const
01189 {
01190 return surf1EdgeCuts_;
01191 }
01192
01193
01194 const Foam::labelListList& Foam::surfaceIntersection::surf2EdgeCuts() const
01195 {
01196 return surf2EdgeCuts_;
01197 }
01198
01199
01200