1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: NMTTools_Tools.cxx
23 // Created: Mon Dec 8 10:35:15 2003
24 // Author: Peter KURNEV
27 #include <NMTTools_Tools.ixx>
29 #include <TColStd_IndexedMapOfInteger.hxx>
33 #include <gp_Pnt2d.hxx>
35 #include <Geom_Surface.hxx>
36 #include <GeomAPI_ProjectPointOnSurf.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
45 #include <TopTools_ListIteratorOfListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRep_Builder.hxx>
50 #include <BRepTools.hxx>
52 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
53 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
55 #include <BOPTools_VVInterference.hxx>
56 #include <BOPTools_SSInterference.hxx>
58 #include <BOPTools_Tools2D.hxx>
59 #include <BOPTools_Tools.hxx>
60 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
61 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
62 #include <NMTTools_CoupleOfShape.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <Geom2d_Curve.hxx>
65 #include <Geom_Curve.hxx>
66 #include <Geom_TrimmedCurve.hxx>
67 #include <BOPTools_Tools2D.hxx>
68 #include <BRepLib.hxx>
69 #include <BOPTools_Tools3D.hxx>
70 #include <TopExp_Explorer.hxx>
72 #include <TopTools_MapOfShape.hxx>
73 #include <TopTools_MapIteratorOfMapOfShape.hxx>
74 #include <TopoDS_Iterator.hxx>
77 void ProcessBlock(const Standard_Integer iV,
78 const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
79 TColStd_IndexedMapOfInteger& aProcessed,
80 TColStd_IndexedMapOfInteger& aChain);
82 void ProcessBlock(const TopoDS_Shape& aF,
83 const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
84 TopTools_IndexedMapOfShape& aProcessed,
85 TopTools_IndexedMapOfShape& aChain);
87 //modified by NIZNHY-PKV Thu Nov 16 10:46:53 2006f SKL/PartC5
88 //=======================================================================
89 // function: UpdateEdge
91 //=======================================================================
92 void NMTTools_Tools::UpdateEdge(const TopoDS_Edge& aE,
93 const Standard_Real aTolR)
95 Standard_Real aTolE, aTolES, aTolV;
99 aTolE=BRep_Tool::Tolerance(aE);
100 aTolES=Max(aTolR, aTolE);
101 aBB.UpdateEdge(aE, aTolES);
104 for (; aIt.More(); aIt.Next()) {
105 const TopoDS_Vertex& aV=TopoDS::Vertex(aIt.Value());
106 aTolV=BRep_Tool::Tolerance(aV);
108 aBB.UpdateVertex(aV, aTolES);
112 //=======================================================================
113 // function: MakePCurve
115 //=======================================================================
116 void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
117 const TopoDS_Face& aF,
118 const Handle(Geom2d_Curve)& aC2Dx1)
121 Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
122 Handle(Geom2d_Curve) aC2D, aC2DA;
127 aFFWD.Orientation(TopAbs_FORWARD);
129 aTolE=BRep_Tool::Tolerance(aE);
131 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2);
132 Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aT1, aT2);
135 if (aC2D.IsNull()) { // ?
136 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
137 BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
140 if (aC3DE->IsPeriodic()) {
141 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D, aC2DA);
144 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
147 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
148 BRepLib::SameParameter(aE);
151 //=======================================================================
152 // function: MakePCurve
154 //=======================================================================
155 void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
156 const TopoDS_Face& aF,
157 const Handle(Geom2d_Curve)& aC2Dx,
158 const Standard_Real aTolR2D)
160 Standard_Integer k, aNbV;
161 Standard_Real aTolEdge, aTolFact, aTolV, aTolVmax;
162 Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
164 TopTools_IndexedMapOfShape aVMap;
168 aFFWD.Orientation(TopAbs_FORWARD);
170 aTolEdge=BRep_Tool::Tolerance(aE);
171 aTolFact=Max(aTolEdge, aTolR2D);
173 TopExp::MapShapes(aE, TopAbs_VERTEX, aVMap);
177 for (k=1; k<=aNbV; ++k) {
178 const TopoDS_Vertex& aV=TopoDS::Vertex(aVMap(k));
179 aTolV=BRep_Tool::Tolerance(aV);
180 if (aTolV>aTolVmax) {
185 if (aTolFact>aTolVmax) {
189 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aTFirst, aTLast);
190 Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aTFirst, aTLast);
192 Handle(Geom2d_Curve) aC2D, aC2DA;
196 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
197 BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
199 if (aC3DE->IsPeriodic()) {
200 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aTFirst, aTLast, aC2D, aC2DA);
203 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
206 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolFact);
207 BRepLib::SameParameter(aE);
210 //modified by NIZNHY-PKV Thu Nov 16 10:46:55 2006t
211 //=======================================================================
212 // function: IsSplitInOnFace
214 //=======================================================================
215 Standard_Boolean NMTTools_Tools::IsSplitInOnFace(const TopoDS_Edge& aE,
216 const TopoDS_Face& aF,
217 IntTools_Context& aContext)
219 Standard_Boolean bFlag;
220 Standard_Real aT, aTolE, aTolF, aTol, aDist, aU, aV;
224 aTolE=BRep_Tool::Tolerance(aE);
225 aTolF=BRep_Tool::Tolerance(aF);
228 GeomAPI_ProjectPointOnSurf& aProjector=aContext.ProjPS(aF);
230 aT=BOPTools_Tools2D::IntermediatePoint(aE);
231 BOPTools_Tools::PointOnEdge(aE, aT, aP);
233 aProjector.Perform(aP);
234 bFlag=aProjector.IsDone();
239 aDist=aProjector.LowerDistance();
240 bFlag=(aDist <= aTol);
245 aProjector.LowerDistanceParameters(aU, aV);
246 aP2D.SetCoord(aU, aV);
247 bFlag=aContext.IsPointInOnFace (aF, aP2D);
250 //=======================================================================
251 // function: NMTTools_Tools::MakeNewVertex
253 //=======================================================================
254 void NMTTools_Tools::MakeNewVertex(const TopTools_ListOfShape& aLVs,
255 TopoDS_Vertex& aNewVertex)
257 Standard_Integer aNb;
258 Standard_Real aTi, aDi, aDmax=-1.e5;
260 gp_XYZ aXYZ(0.,0.,0.), aXYZi;
261 TopTools_ListIteratorOfListOfShape anIt;
268 anIt.Initialize(aLVs);
269 for (; anIt.More(); anIt.Next()) {
270 TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
271 aPi=BRep_Tool::Pnt(aVi);
276 aXYZ.Divide((Standard_Real)aNb);
279 anIt.Initialize(aLVs);
280 for (; anIt.More(); anIt.Next()) {
281 TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
282 aPi=BRep_Tool::Pnt(aVi);
283 aTi=BRep_Tool::Tolerance(aVi);
284 aDi=aP.Distance(aPi);
291 aBB.MakeVertex (aNewVertex, aP, aDmax);
293 //=======================================================================
294 // function: FindChains
296 //=======================================================================
297 void NMTTools_Tools::FindChains(const BOPTools_CArray1OfSSInterference& FFs,
298 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
300 Standard_Boolean bIsTangentFaces;
301 Standard_Integer j, aNb, anIndex1, anIndex2;
302 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
305 for (j=1; j<=aNb; ++j) {
306 const BOPTools_SSInterference& aFF=FFs(j);
308 bIsTangentFaces=aFF.IsTangentFaces();
309 if (!bIsTangentFaces) {
313 aFF.Indices(anIndex1, anIndex2);
315 if (aMCV.Contains(anIndex1)) {
316 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
321 TColStd_IndexedMapOfInteger aMV;
324 aMCV.Add(anIndex1, aMV);
327 if (aMCV.Contains(anIndex2)) {
328 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
333 TColStd_IndexedMapOfInteger aMV;
336 aMCV.Add(anIndex2, aMV);
339 NMTTools_Tools::FindChains(aMCV, aMapChains);
341 //=======================================================================
342 // function: FindChains
344 //=======================================================================
345 void NMTTools_Tools::FindChains(const BOPTools_CArray1OfVVInterference& VVs,
346 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
348 Standard_Integer j, aNb, anIndex1, anIndex2;
349 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
352 for (j=1; j<=aNb; ++j) {
353 const BOPTools_VVInterference& VV=VVs(j);
354 VV.Indices(anIndex1, anIndex2);
356 if (aMCV.Contains(anIndex1)) {
357 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
362 TColStd_IndexedMapOfInteger aMV;
365 aMCV.Add(anIndex1, aMV);
368 if (aMCV.Contains(anIndex2)) {
369 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
374 TColStd_IndexedMapOfInteger aMV;
377 aMCV.Add(anIndex2, aMV);
380 NMTTools_Tools::FindChains(aMCV, aMapChains);
383 //=======================================================================
384 // function: FindChains
386 //=======================================================================
387 void NMTTools_Tools::FindChains(const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
388 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
390 Standard_Integer i, j, aNbCV, aNbV, iV, iVx;
391 TColStd_IndexedMapOfInteger aProcessed, aChain;
394 for (i=1; i<=aNbCV; ++i) {
396 if (aProcessed.Contains(iV)) {
403 const TColStd_IndexedMapOfInteger& aMV=aMCV(i);
405 for (j=1; j<=aNbV; ++j) {
407 ProcessBlock(iVx, aMCV, aProcessed, aChain);
409 aMapChains.Add(i, aChain);
413 //=======================================================================
414 // function: ProcessBlock
416 //=======================================================================
417 void ProcessBlock(const Standard_Integer iV,
418 const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
419 TColStd_IndexedMapOfInteger& aProcessed,
420 TColStd_IndexedMapOfInteger& aChain)
422 Standard_Integer j, aNbV, iVx;
424 if (aProcessed.Contains(iV)) {
430 const TColStd_IndexedMapOfInteger& aMV=aMCV.FindFromKey(iV);
432 for (j=1; j<=aNbV; ++j) {
434 ProcessBlock(iVx, aMCV, aProcessed, aChain);
437 //=======================================================================
438 // function: AreFacesSameDomain
440 //=======================================================================
441 Standard_Boolean NMTTools_Tools::AreFacesSameDomain(const TopoDS_Face& aF1x,
442 const TopoDS_Face& aF2y,
443 IntTools_Context& aCtx)
445 Standard_Boolean bFlag;
446 // Modified Thu Sep 14 14:35:18 2006
447 // Contribution of Samtech www.samcef.com BEGIN
448 Standard_Integer aNbE1, aNbE2;
449 Standard_Real aTolF1, aTolF2, aTol;
452 TopoDS_Face aF1, aF2;
453 TopExp_Explorer aExp;
454 TopTools_MapOfShape aME1, aME2;
455 TopTools_MapIteratorOfMapOfShape aIt;
457 bFlag=Standard_False;
458 // Contribution of Samtech www.samcef.com END
461 aF1.Orientation(TopAbs_FORWARD);
463 aF2.Orientation(TopAbs_FORWARD);
465 // Modified Thu Sep 14 14:35:18 2006
466 // Contribution of Samtech www.samcef.com BEGIN
469 aExp.Init(aF1, TopAbs_EDGE);
470 for (; aExp.More(); aExp.Next()) {
471 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
472 if (!BRep_Tool::Degenerated(aE)) {
477 aExp.Init(aF2, TopAbs_EDGE);
478 for (; aExp.More(); aExp.Next()) {
479 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
480 if (!BRep_Tool::Degenerated(aE)) {
481 if (!aME1.Contains(aE)) {
488 // Contribution of Samtech www.samcef.com END
493 if(!aNbE1 || !aNbE2){
502 aTolF1=BRep_Tool::Tolerance(aF1);
503 aTolF2=BRep_Tool::Tolerance(aF2);
506 aIt.Initialize(aME1);
507 for (; aIt.More(); aIt.Next()) {
508 const TopoDS_Edge& aE=TopoDS::Edge(aIt.Key());
509 BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP);
510 bFlag=aCtx.IsValidPointForFace(aP, aF2, aTol);
516 //=======================================================================
517 // function: FindChains
519 //=======================================================================
520 void NMTTools_Tools::FindChains(const NMTTools_ListOfCoupleOfShape& aLCS,
521 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
523 NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
524 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCV;
526 aItCS.Initialize(aLCS);
527 for (; aItCS.More(); aItCS.Next()) {
528 const NMTTools_CoupleOfShape& aCS=aItCS.Value();
530 const TopoDS_Shape& aF1=aCS.Shape1();
531 const TopoDS_Shape& aF2=aCS.Shape2();
534 if (aMCV.Contains(aF1)) {
535 TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF1);
540 TopTools_IndexedMapOfShape aMV;
546 if (aMCV.Contains(aF2)) {
547 TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF2);
552 TopTools_IndexedMapOfShape aMV;
558 NMTTools_Tools::FindChains(aMCV, aMapChains);
560 //=======================================================================
561 // function: FindChains
563 //=======================================================================
564 void NMTTools_Tools::FindChains(const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
565 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
567 Standard_Integer i, j, aNbCV, aNbV;
568 TopTools_IndexedMapOfShape aProcessed, aChain;
571 for (i=1; i<=aNbCV; ++i) {
572 const TopoDS_Shape& aF=aMCV.FindKey(i);
573 if (aProcessed.Contains(aF)) {
580 const TopTools_IndexedMapOfShape& aMV=aMCV(i);
582 for (j=1; j<=aNbV; ++j) {
583 const TopoDS_Shape& aFx=aMV(j);
584 ProcessBlock(aFx, aMCV, aProcessed, aChain);
586 aMapChains.Add(aF, aChain);
590 //=======================================================================
591 // function: ProcessBlock
593 //=======================================================================
594 void ProcessBlock(const TopoDS_Shape& aF,
595 const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
596 TopTools_IndexedMapOfShape& aProcessed,
597 TopTools_IndexedMapOfShape& aChain)
599 Standard_Integer j, aNbV;
601 if (aProcessed.Contains(aF)) {
607 const TopTools_IndexedMapOfShape& aMV=aMCV.FindFromKey(aF);
609 for (j=1; j<=aNbV; ++j) {
610 const TopoDS_Shape& aFx=aMV(j);
611 ProcessBlock(aFx, aMCV, aProcessed, aChain);