/src/contrib/geom-5.1.2.7/src/NMTTools/NMTTools_Tools.cpp

http://pythonocc.googlecode.com/ · C++ · 613 lines · 401 code · 14 blank · 198 comment · 46 complexity · 50d5230ff7c120f849a8991ae7ad52fc MD5 · raw file

  1. // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
  2. //
  3. // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  4. // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  5. //
  6. // This library is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU Lesser General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2.1 of the License.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. // Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public
  17. // License along with this library; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. //
  20. // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
  21. //
  22. // File: NMTTools_Tools.cxx
  23. // Created: Mon Dec 8 10:35:15 2003
  24. // Author: Peter KURNEV
  25. // <pkv@irinox>
  26. //
  27. #include <NMTTools_Tools.ixx>
  28. #include <TColStd_IndexedMapOfInteger.hxx>
  29. #include <gp_Pnt.hxx>
  30. #include <gp_XYZ.hxx>
  31. #include <gp_Pnt2d.hxx>
  32. #include <Geom_Surface.hxx>
  33. #include <GeomAPI_ProjectPointOnSurf.hxx>
  34. #include <TopoDS.hxx>
  35. #include <TopoDS_Vertex.hxx>
  36. #include <TopoDS_Shape.hxx>
  37. #include <TopoDS_Edge.hxx>
  38. #include <TopExp.hxx>
  39. #include <TopTools_ListIteratorOfListOfShape.hxx>
  40. #include <TopTools_IndexedMapOfShape.hxx>
  41. #include <BRep_Tool.hxx>
  42. #include <BRep_Builder.hxx>
  43. #include <BRepTools.hxx>
  44. #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
  45. #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
  46. #include <BOPTools_VVInterference.hxx>
  47. #include <BOPTools_SSInterference.hxx>
  48. #include <BOPTools_Tools2D.hxx>
  49. #include <BOPTools_Tools.hxx>
  50. #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
  51. #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
  52. #include <NMTTools_CoupleOfShape.hxx>
  53. #include <TopTools_IndexedMapOfShape.hxx>
  54. #include <Geom2d_Curve.hxx>
  55. #include <Geom_Curve.hxx>
  56. #include <Geom_TrimmedCurve.hxx>
  57. #include <BOPTools_Tools2D.hxx>
  58. #include <BRepLib.hxx>
  59. #include <BOPTools_Tools3D.hxx>
  60. #include <TopExp_Explorer.hxx>
  61. //
  62. #include <TopTools_MapOfShape.hxx>
  63. #include <TopTools_MapIteratorOfMapOfShape.hxx>
  64. #include <TopoDS_Iterator.hxx>
  65. static
  66. void ProcessBlock(const Standard_Integer iV,
  67. const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
  68. TColStd_IndexedMapOfInteger& aProcessed,
  69. TColStd_IndexedMapOfInteger& aChain);
  70. static
  71. void ProcessBlock(const TopoDS_Shape& aF,
  72. const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
  73. TopTools_IndexedMapOfShape& aProcessed,
  74. TopTools_IndexedMapOfShape& aChain);
  75. //modified by NIZNHY-PKV Thu Nov 16 10:46:53 2006f SKL/PartC5
  76. //=======================================================================
  77. // function: UpdateEdge
  78. // purpose:
  79. //=======================================================================
  80. void NMTTools_Tools::UpdateEdge(const TopoDS_Edge& aE,
  81. const Standard_Real aTolR)
  82. {
  83. Standard_Real aTolE, aTolES, aTolV;
  84. TopoDS_Iterator aIt;
  85. BRep_Builder aBB;
  86. //
  87. aTolE=BRep_Tool::Tolerance(aE);
  88. aTolES=Max(aTolR, aTolE);
  89. aBB.UpdateEdge(aE, aTolES);
  90. //
  91. aIt.Initialize(aE);
  92. for (; aIt.More(); aIt.Next()) {
  93. const TopoDS_Vertex& aV=TopoDS::Vertex(aIt.Value());
  94. aTolV=BRep_Tool::Tolerance(aV);
  95. if (aTolV<aTolES) {
  96. aBB.UpdateVertex(aV, aTolES);
  97. }
  98. }
  99. }
  100. //=======================================================================
  101. // function: MakePCurve
  102. // purpose:
  103. //=======================================================================
  104. void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
  105. const TopoDS_Face& aF,
  106. const Handle(Geom2d_Curve)& aC2Dx1)
  107. {
  108. Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
  109. Handle(Geom2d_Curve) aC2D, aC2DA;
  110. TopoDS_Face aFFWD;
  111. BRep_Builder aBB;
  112. //
  113. aFFWD=aF;
  114. aFFWD.Orientation(TopAbs_FORWARD);
  115. //
  116. aTolE=BRep_Tool::Tolerance(aE);
  117. //
  118. const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2);
  119. Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aT1, aT2);
  120. //
  121. aC2D=aC2Dx1;
  122. if (aC2D.IsNull()) { // ?
  123. BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
  124. BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
  125. }
  126. //
  127. if (aC3DE->IsPeriodic()) {
  128. BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D, aC2DA);
  129. }
  130. else {
  131. BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
  132. }
  133. //
  134. aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
  135. BRepLib::SameParameter(aE);
  136. }
  137. /*
  138. //=======================================================================
  139. // function: MakePCurve
  140. // purpose:
  141. //=======================================================================
  142. void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
  143. const TopoDS_Face& aF,
  144. const Handle(Geom2d_Curve)& aC2Dx,
  145. const Standard_Real aTolR2D)
  146. {
  147. Standard_Integer k, aNbV;
  148. Standard_Real aTolEdge, aTolFact, aTolV, aTolVmax;
  149. Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
  150. TopoDS_Face aFFWD;
  151. TopTools_IndexedMapOfShape aVMap;
  152. BRep_Builder aBB;
  153. //
  154. aFFWD=aF;
  155. aFFWD.Orientation(TopAbs_FORWARD);
  156. //
  157. aTolEdge=BRep_Tool::Tolerance(aE);
  158. aTolFact=Max(aTolEdge, aTolR2D);
  159. //
  160. TopExp::MapShapes(aE, TopAbs_VERTEX, aVMap);
  161. //
  162. aTolVmax=-1.;
  163. aNbV=aVMap.Extent();
  164. for (k=1; k<=aNbV; ++k) {
  165. const TopoDS_Vertex& aV=TopoDS::Vertex(aVMap(k));
  166. aTolV=BRep_Tool::Tolerance(aV);
  167. if (aTolV>aTolVmax) {
  168. aTolVmax=aTolV;
  169. }
  170. }
  171. //
  172. if (aTolFact>aTolVmax) {
  173. aTolFact=aTolVmax;
  174. }
  175. //
  176. const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aTFirst, aTLast);
  177. Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aTFirst, aTLast);
  178. //
  179. Handle(Geom2d_Curve) aC2D, aC2DA;
  180. //
  181. aC2D=aC2Dx;
  182. if (aC2D.IsNull()) {
  183. BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
  184. BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
  185. }
  186. if (aC3DE->IsPeriodic()) {
  187. BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aTFirst, aTLast, aC2D, aC2DA);
  188. }
  189. else {
  190. BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
  191. }
  192. //
  193. aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolFact);
  194. BRepLib::SameParameter(aE);
  195. }
  196. */
  197. //modified by NIZNHY-PKV Thu Nov 16 10:46:55 2006t
  198. //=======================================================================
  199. // function: IsSplitInOnFace
  200. // purpose:
  201. //=======================================================================
  202. Standard_Boolean NMTTools_Tools::IsSplitInOnFace(const TopoDS_Edge& aE,
  203. const TopoDS_Face& aF,
  204. IntTools_Context& aContext)
  205. {
  206. Standard_Boolean bFlag;
  207. Standard_Real aT, aTolE, aTolF, aTol, aDist, aU, aV;
  208. gp_Pnt aP;
  209. gp_Pnt2d aP2D;
  210. //
  211. aTolE=BRep_Tool::Tolerance(aE);
  212. aTolF=BRep_Tool::Tolerance(aF);
  213. aTol=aTolE+aTolF;
  214. //
  215. GeomAPI_ProjectPointOnSurf& aProjector=aContext.ProjPS(aF);
  216. //
  217. aT=BOPTools_Tools2D::IntermediatePoint(aE);
  218. BOPTools_Tools::PointOnEdge(aE, aT, aP);
  219. //
  220. aProjector.Perform(aP);
  221. bFlag=aProjector.IsDone();
  222. if (!bFlag) {
  223. return bFlag;
  224. }
  225. //
  226. aDist=aProjector.LowerDistance();
  227. bFlag=(aDist <= aTol);
  228. if (!bFlag) {
  229. return bFlag;
  230. }
  231. //
  232. aProjector.LowerDistanceParameters(aU, aV);
  233. aP2D.SetCoord(aU, aV);
  234. bFlag=aContext.IsPointInOnFace (aF, aP2D);
  235. return bFlag;
  236. }
  237. //=======================================================================
  238. // function: NMTTools_Tools::MakeNewVertex
  239. // purpose :
  240. //=======================================================================
  241. void NMTTools_Tools::MakeNewVertex(const TopTools_ListOfShape& aLVs,
  242. TopoDS_Vertex& aNewVertex)
  243. {
  244. Standard_Integer aNb;
  245. Standard_Real aTi, aDi, aDmax=-1.e5;
  246. gp_Pnt aPi, aP;
  247. gp_XYZ aXYZ(0.,0.,0.), aXYZi;
  248. TopTools_ListIteratorOfListOfShape anIt;
  249. //
  250. aNb=aLVs.Extent();
  251. if (!aNb) {
  252. return;
  253. }
  254. //
  255. anIt.Initialize(aLVs);
  256. for (; anIt.More(); anIt.Next()) {
  257. TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
  258. aPi=BRep_Tool::Pnt(aVi);
  259. aXYZi=aPi.XYZ();
  260. aXYZ=aXYZ+aXYZi;
  261. }
  262. //
  263. aXYZ.Divide((Standard_Real)aNb);
  264. aP.SetXYZ(aXYZ);
  265. //
  266. anIt.Initialize(aLVs);
  267. for (; anIt.More(); anIt.Next()) {
  268. TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
  269. aPi=BRep_Tool::Pnt(aVi);
  270. aTi=BRep_Tool::Tolerance(aVi);
  271. aDi=aP.Distance(aPi);
  272. aDi=aDi+aTi;
  273. if (aDi > aDmax) {
  274. aDmax=aDi;
  275. }
  276. }
  277. BRep_Builder aBB;
  278. aBB.MakeVertex (aNewVertex, aP, aDmax);
  279. }
  280. //=======================================================================
  281. // function: FindChains
  282. // purpose :
  283. //=======================================================================
  284. void NMTTools_Tools::FindChains(const BOPTools_CArray1OfSSInterference& FFs,
  285. BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
  286. {
  287. Standard_Boolean bIsTangentFaces;
  288. Standard_Integer j, aNb, anIndex1, anIndex2;
  289. BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
  290. //
  291. aNb=FFs.Extent();
  292. for (j=1; j<=aNb; ++j) {
  293. const BOPTools_SSInterference& aFF=FFs(j);
  294. //
  295. bIsTangentFaces=aFF.IsTangentFaces();
  296. if (!bIsTangentFaces) {
  297. continue;
  298. }
  299. //
  300. aFF.Indices(anIndex1, anIndex2);
  301. //
  302. if (aMCV.Contains(anIndex1)) {
  303. TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
  304. aMV.Add(anIndex1);
  305. aMV.Add(anIndex2);
  306. }
  307. else {
  308. TColStd_IndexedMapOfInteger aMV;
  309. aMV.Add(anIndex1);
  310. aMV.Add(anIndex2);
  311. aMCV.Add(anIndex1, aMV);
  312. }
  313. //
  314. if (aMCV.Contains(anIndex2)) {
  315. TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
  316. aMV.Add(anIndex1);
  317. aMV.Add(anIndex2);
  318. }
  319. else {
  320. TColStd_IndexedMapOfInteger aMV;
  321. aMV.Add(anIndex1);
  322. aMV.Add(anIndex2);
  323. aMCV.Add(anIndex2, aMV);
  324. }
  325. }
  326. NMTTools_Tools::FindChains(aMCV, aMapChains);
  327. }
  328. //=======================================================================
  329. // function: FindChains
  330. // purpose :
  331. //=======================================================================
  332. void NMTTools_Tools::FindChains(const BOPTools_CArray1OfVVInterference& VVs,
  333. BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
  334. {
  335. Standard_Integer j, aNb, anIndex1, anIndex2;
  336. BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
  337. //
  338. aNb=VVs.Extent();
  339. for (j=1; j<=aNb; ++j) {
  340. const BOPTools_VVInterference& VV=VVs(j);
  341. VV.Indices(anIndex1, anIndex2);
  342. //
  343. if (aMCV.Contains(anIndex1)) {
  344. TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
  345. aMV.Add(anIndex1);
  346. aMV.Add(anIndex2);
  347. }
  348. else {
  349. TColStd_IndexedMapOfInteger aMV;
  350. aMV.Add(anIndex1);
  351. aMV.Add(anIndex2);
  352. aMCV.Add(anIndex1, aMV);
  353. }
  354. //
  355. if (aMCV.Contains(anIndex2)) {
  356. TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
  357. aMV.Add(anIndex1);
  358. aMV.Add(anIndex2);
  359. }
  360. else {
  361. TColStd_IndexedMapOfInteger aMV;
  362. aMV.Add(anIndex1);
  363. aMV.Add(anIndex2);
  364. aMCV.Add(anIndex2, aMV);
  365. }
  366. }
  367. NMTTools_Tools::FindChains(aMCV, aMapChains);
  368. }
  369. //=======================================================================
  370. // function: FindChains
  371. // purpose :
  372. //=======================================================================
  373. void NMTTools_Tools::FindChains(const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
  374. BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
  375. {
  376. Standard_Integer i, j, aNbCV, aNbV, iV, iVx;
  377. TColStd_IndexedMapOfInteger aProcessed, aChain;
  378. //
  379. aNbCV=aMCV.Extent();
  380. for (i=1; i<=aNbCV; ++i) {
  381. iV=aMCV.FindKey(i);
  382. if (aProcessed.Contains(iV)) {
  383. continue;
  384. }
  385. //
  386. aProcessed.Add(iV);
  387. aChain.Add(iV);
  388. //
  389. const TColStd_IndexedMapOfInteger& aMV=aMCV(i);
  390. aNbV=aMV.Extent();
  391. for (j=1; j<=aNbV; ++j) {
  392. iVx=aMV(j);
  393. ProcessBlock(iVx, aMCV, aProcessed, aChain);
  394. }
  395. aMapChains.Add(i, aChain);
  396. aChain.Clear();
  397. }
  398. }
  399. //=======================================================================
  400. // function: ProcessBlock
  401. // purpose:
  402. //=======================================================================
  403. void ProcessBlock(const Standard_Integer iV,
  404. const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
  405. TColStd_IndexedMapOfInteger& aProcessed,
  406. TColStd_IndexedMapOfInteger& aChain)
  407. {
  408. Standard_Integer j, aNbV, iVx;
  409. //
  410. if (aProcessed.Contains(iV)) {
  411. return;
  412. }
  413. aProcessed.Add(iV);
  414. aChain.Add(iV);
  415. //
  416. const TColStd_IndexedMapOfInteger& aMV=aMCV.FindFromKey(iV);
  417. aNbV=aMV.Extent();
  418. for (j=1; j<=aNbV; ++j) {
  419. iVx=aMV(j);
  420. ProcessBlock(iVx, aMCV, aProcessed, aChain);
  421. }
  422. }
  423. //=======================================================================
  424. // function: AreFacesSameDomain
  425. // purpose :
  426. //=======================================================================
  427. Standard_Boolean NMTTools_Tools::AreFacesSameDomain(const TopoDS_Face& aF1x,
  428. const TopoDS_Face& aF2y,
  429. IntTools_Context& aCtx)
  430. {
  431. Standard_Boolean bFlag;
  432. // Modified Thu Sep 14 14:35:18 2006
  433. // Contribution of Samtech www.samcef.com BEGIN
  434. Standard_Integer aNbE1, aNbE2;
  435. Standard_Real aTolF1, aTolF2, aTol;
  436. gp_Pnt2d aP2D;
  437. gp_Pnt aP;
  438. TopoDS_Face aF1, aF2;
  439. TopExp_Explorer aExp;
  440. TopTools_MapOfShape aME1, aME2;
  441. TopTools_MapIteratorOfMapOfShape aIt;
  442. //
  443. bFlag=Standard_False;
  444. // Contribution of Samtech www.samcef.com END
  445. //
  446. aF1=aF1x;
  447. aF1.Orientation(TopAbs_FORWARD);
  448. aF2=aF2y;
  449. aF2.Orientation(TopAbs_FORWARD);
  450. //
  451. // Modified Thu Sep 14 14:35:18 2006
  452. // Contribution of Samtech www.samcef.com BEGIN
  453. //
  454. // 1
  455. aExp.Init(aF1, TopAbs_EDGE);
  456. for (; aExp.More(); aExp.Next()) {
  457. const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
  458. if (!BRep_Tool::Degenerated(aE)) {
  459. aME1.Add(aE);
  460. }
  461. }
  462. //
  463. aExp.Init(aF2, TopAbs_EDGE);
  464. for (; aExp.More(); aExp.Next()) {
  465. const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
  466. if (!BRep_Tool::Degenerated(aE)) {
  467. if (!aME1.Contains(aE)) {
  468. return bFlag;
  469. }
  470. aME2.Add(aE);
  471. }
  472. }
  473. //
  474. // Contribution of Samtech www.samcef.com END
  475. //
  476. aNbE1=aME1.Extent();
  477. aNbE2=aME2.Extent();
  478. //
  479. if(!aNbE1 || !aNbE2){
  480. return bFlag;
  481. }
  482. //
  483. if(aNbE1!=aNbE2) {
  484. return bFlag;
  485. }
  486. //
  487. // 2
  488. aTolF1=BRep_Tool::Tolerance(aF1);
  489. aTolF2=BRep_Tool::Tolerance(aF2);
  490. aTol=aTolF1+aTolF2;
  491. //
  492. aIt.Initialize(aME1);
  493. for (; aIt.More(); aIt.Next()) {
  494. const TopoDS_Edge& aE=TopoDS::Edge(aIt.Key());
  495. BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP);
  496. bFlag=aCtx.IsValidPointForFace(aP, aF2, aTol);
  497. break;
  498. }
  499. //
  500. return bFlag;
  501. }
  502. //=======================================================================
  503. // function: FindChains
  504. // purpose :
  505. //=======================================================================
  506. void NMTTools_Tools::FindChains(const NMTTools_ListOfCoupleOfShape& aLCS,
  507. NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
  508. {
  509. NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
  510. NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCV;
  511. //
  512. aItCS.Initialize(aLCS);
  513. for (; aItCS.More(); aItCS.Next()) {
  514. const NMTTools_CoupleOfShape& aCS=aItCS.Value();
  515. //
  516. const TopoDS_Shape& aF1=aCS.Shape1();
  517. const TopoDS_Shape& aF2=aCS.Shape2();
  518. //
  519. //
  520. if (aMCV.Contains(aF1)) {
  521. TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF1);
  522. aMV.Add(aF1);
  523. aMV.Add(aF2);
  524. }
  525. else {
  526. TopTools_IndexedMapOfShape aMV;
  527. aMV.Add(aF1);
  528. aMV.Add(aF2);
  529. aMCV.Add(aF1, aMV);
  530. }
  531. //
  532. if (aMCV.Contains(aF2)) {
  533. TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF2);
  534. aMV.Add(aF1);
  535. aMV.Add(aF2);
  536. }
  537. else {
  538. TopTools_IndexedMapOfShape aMV;
  539. aMV.Add(aF1);
  540. aMV.Add(aF2);
  541. aMCV.Add(aF2, aMV);
  542. }
  543. }
  544. NMTTools_Tools::FindChains(aMCV, aMapChains);
  545. }
  546. //=======================================================================
  547. // function: FindChains
  548. // purpose :
  549. //=======================================================================
  550. void NMTTools_Tools::FindChains(const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
  551. NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
  552. {
  553. Standard_Integer i, j, aNbCV, aNbV;
  554. TopTools_IndexedMapOfShape aProcessed, aChain;
  555. //
  556. aNbCV=aMCV.Extent();
  557. for (i=1; i<=aNbCV; ++i) {
  558. const TopoDS_Shape& aF=aMCV.FindKey(i);
  559. if (aProcessed.Contains(aF)) {
  560. continue;
  561. }
  562. //
  563. aProcessed.Add(aF);
  564. aChain.Add(aF);
  565. //
  566. const TopTools_IndexedMapOfShape& aMV=aMCV(i);
  567. aNbV=aMV.Extent();
  568. for (j=1; j<=aNbV; ++j) {
  569. const TopoDS_Shape& aFx=aMV(j);
  570. ProcessBlock(aFx, aMCV, aProcessed, aChain);
  571. }
  572. aMapChains.Add(aF, aChain);
  573. aChain.Clear();
  574. }
  575. }
  576. //=======================================================================
  577. // function: ProcessBlock
  578. // purpose:
  579. //=======================================================================
  580. void ProcessBlock(const TopoDS_Shape& aF,
  581. const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
  582. TopTools_IndexedMapOfShape& aProcessed,
  583. TopTools_IndexedMapOfShape& aChain)
  584. {
  585. Standard_Integer j, aNbV;
  586. //
  587. if (aProcessed.Contains(aF)) {
  588. return;
  589. }
  590. aProcessed.Add(aF);
  591. aChain.Add(aF);
  592. //
  593. const TopTools_IndexedMapOfShape& aMV=aMCV.FindFromKey(aF);
  594. aNbV=aMV.Extent();
  595. for (j=1; j<=aNbV; ++j) {
  596. const TopoDS_Shape& aFx=aMV(j);
  597. ProcessBlock(aFx, aMCV, aProcessed, aChain);
  598. }
  599. }