1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTTools_DEProcessor.cxx
21 // Created: Wed Sep 12 12:10:52 2001
22 // Author: Peter KURNEV
25 #include <NMTTools_DEProcessor.ixx>
27 #include <Precision.hxx>
29 #include <TColStd_ListIteratorOfListOfInteger.hxx>
30 #include <TColStd_ListOfInteger.hxx>
32 #include <gp_Pnt2d.hxx>
34 #include <gp_Sphere.hxx>
36 #include <Geom2d_Curve.hxx>
37 #include <Geom2d_Line.hxx>
38 #include <Geom2dAdaptor_Curve.hxx>
39 #include <Geom2dInt_GInter.hxx>
41 #include <IntRes2d_IntersectionPoint.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Vertex.hxx>
48 #include <TopoDS_Solid.hxx>
51 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include <BRep_Tool.hxx>
56 #include <BRep_Builder.hxx>
58 #include <BRepAdaptor_Surface.hxx>
60 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
62 #include <IntTools_Tools.hxx>
63 #include <IntTools_Context.hxx>
65 #include <BOPTools_DEInfo.hxx>
66 #include <BOPTools_Pave.hxx>
67 #include <BOPTools_ListOfPave.hxx>
68 #include <BOPTools_ListIteratorOfListOfPave.hxx>
69 #include <BOPTools_PaveBlock.hxx>
70 #include <BOPTools_ListOfPaveBlock.hxx>
71 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
72 #include <BOPTools_PaveBlockIterator.hxx>
73 #include <BOPTools_SSInterference.hxx>
74 #include <BOPTools_PavePool.hxx>
75 #include <BOPTools_PaveSet.hxx>
76 #include <BOPTools_Tools3D.hxx>
77 #include <BOPTools_InterferencePool.hxx>
78 #include <BOPTools_CArray1OfSSInterference.hxx>
79 #include <BOPTools_SplitShapesPool.hxx>
81 #include <NMTDS_ShapesDataStructure.hxx>
83 #include <NMTTools_PaveFiller.hxx>
85 #include <BOPTools_SequenceOfCurves.hxx>
86 #include <BOPTools_Curve.hxx>
88 #include <Geom2d_TrimmedCurve.hxx>
91 #include <gp_Lin2d.hxx>
95 //=======================================================================
96 // function: NMTTools_DEProcessor::NMTTools_DEProcessor
98 //=======================================================================
99 NMTTools_DEProcessor::NMTTools_DEProcessor(NMTTools_PaveFiller& aPaveFiller)
101 myIsDone(Standard_False)
103 myFiller=(NMTTools_PaveFiller*) &aPaveFiller;
106 //=======================================================================
109 //=======================================================================
110 Standard_Boolean NMTTools_DEProcessor::IsDone() const
114 //=======================================================================
117 //=======================================================================
118 void NMTTools_DEProcessor::Do()
120 Standard_Integer aNbE;
121 myIsDone=Standard_False;
123 FindDegeneratedEdges();
124 aNbE=myDEMap.Extent();
127 myIsDone=Standard_True;
132 //=======================================================================
133 // function: FindDegeneratedEdges
135 //=======================================================================
136 void NMTTools_DEProcessor::FindDegeneratedEdges()
138 Standard_Integer i, aNb, nV, nF, nVx, ip, iRankE;
139 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
141 aNb=myDS->NumberOfShapesOfTheObject();
143 for (i=1; i<=aNb; i++) {
144 const TopoDS_Shape aF=myDS->Shape(i);//mpv
145 if (aF.ShapeType()==TopAbs_FACE) {
146 TopExp::MapShapesAndAncestors (aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
150 for (i=1; i<=aNb; i++) {
151 const TopoDS_Shape aS=myDS->Shape(i);//mpv
152 if (aS.ShapeType()==TopAbs_EDGE) {
153 const TopoDS_Edge& aE=TopoDS::Edge(aS);
155 if (BRep_Tool::Degenerated(aE)) {
156 iRankE=myDS->Rank(i);
158 TopoDS_Vertex aV=TopExp::FirstVertex(aE);
160 nVx=myDS->ShapeIndex(aV, iRankE);
163 ip=myFiller->FindSDVertex(nV);
168 TColStd_ListOfInteger aLFn;
169 const TopTools_ListOfShape& aLF=aMEF.FindFromKey(aE);
170 TopTools_ListIteratorOfListOfShape anIt(aLF);
171 for (; anIt.More(); anIt.Next()) {
172 const TopoDS_Shape& aF=anIt.Value();
173 nF=myDS->ShapeIndex(aF, iRankE);
176 BOPTools_DEInfo aDEInfo;
177 aDEInfo.SetVertex(nV);
178 aDEInfo.SetFaces(aLFn);
180 myDEMap.Add (i, aDEInfo);
185 //=======================================================================
188 //=======================================================================
189 void NMTTools_DEProcessor::DoPaves()
192 Standard_Integer i, aNbE, nED, nVD, nFD, aNbLPB;
195 aNbE=myDEMap.Extent();
196 for (i=1; i<=aNbE; i++) {
197 nED=myDEMap.FindKey(i);
199 const BOPTools_DEInfo& aDEInfo=myDEMap(i);
200 nVD=aDEInfo.Vertex();
201 // Fill PaveSet for the edge nED
202 const TColStd_ListOfInteger& nLF=aDEInfo.Faces();
203 TColStd_ListIteratorOfListOfInteger anIt(nLF);
204 for (; anIt.More(); anIt.Next()) {
207 BOPTools_ListOfPaveBlock aLPB;
208 FindPaveBlocks(nED, nVD, nFD, aLPB);
209 //modified by NIZNHY-PKV Fri Mar 23 10:35:27 2007f
211 aNbLPB=aLPB.Extent();
215 //modified by NIZNHY-PKV Fri Mar 23 10:35:33 2007t
216 FillPaveSet (nED, nVD, nFD, aLPB);
219 // Fill aSplitEdges for the edge nED
220 FillSplitEdgesPool(nED);
223 MakeSplitEdges(nED, nFD);
227 //=======================================================================
228 // function: FindPaveBlocks
230 //=======================================================================
231 void NMTTools_DEProcessor::FindPaveBlocks(const Standard_Integer ,
232 const Standard_Integer nVD,
233 const Standard_Integer nFD,
234 BOPTools_ListOfPaveBlock& aLPBOut)
236 BOPTools_ListIteratorOfListOfPaveBlock anIt;
237 Standard_Integer i, aNb, nF2, nV;
239 BOPTools_CArray1OfSSInterference& aFFs=(myFiller->InterfPool())->SSInterferences();
242 for (i=1; i<=aNb; ++i) {
243 BOPTools_SSInterference& aFF=aFFs(i);
245 nF2=aFF.OppositeIndex(nFD);
251 const BOPTools_ListOfPaveBlock& aLPBSplits=aFF.PaveBlocks();
252 anIt.Initialize(aLPBSplits);
253 for (; anIt.More(); anIt.Next()) {
254 const BOPTools_PaveBlock& aPBSp=anIt.Value();
256 const BOPTools_Pave& aPave1=aPBSp.Pave1();
259 aLPBOut.Append(aPBSp);
263 const BOPTools_Pave& aPave2=aPBSp.Pave2();
266 aLPBOut.Append(aPBSp);
272 Standard_Integer j, aNbCurves;
273 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
274 aNbCurves=aSC.Length();
276 for (j=1; j<=aNbCurves; j++) {
277 const BOPTools_Curve& aBC=aSC(j);
278 const BOPTools_ListOfPaveBlock& aLPBSe=aBC.NewPaveBlocks();
280 anIt.Initialize(aLPBSe);
281 for (; anIt.More(); anIt.Next()) {
282 const BOPTools_PaveBlock& aPBSe=anIt.Value();
284 const BOPTools_Pave& aPv1=aPBSe.Pave1();
287 aLPBOut.Append(aPBSe);
291 const BOPTools_Pave& aPv2=aPBSe.Pave2();
294 aLPBOut.Append(aPBSe);
301 //=======================================================================
302 // function: FillPaveSet
304 //=======================================================================
305 void NMTTools_DEProcessor::FillPaveSet (const Standard_Integer nED,
306 const Standard_Integer nVD,
307 const Standard_Integer nFD,
308 const BOPTools_ListOfPaveBlock& aLPB)
310 Standard_Boolean bIsDone, bXDir, bRejectFlag;
311 Standard_Integer nE, aNbPoints, j;
312 Standard_Real aTD1, aTD2, aT1, aT2, aTolInter, aX, aDT;
314 aDT=Precision::PConfusion();
316 BOPTools_PaveSet& aPaveSet= (myFiller->ChangePavePool()).ChangeValue(myDS->RefEdge(nED));
318 // Clear aPaveSet, aSplitEdges
319 aPaveSet.ChangeSet().Clear();
321 const TopoDS_Edge aDE=TopoDS::Edge(myDS->Shape(nED));//mpv
322 const TopoDS_Face aDF=TopoDS::Face(myDS->Shape(nFD));//mpv
324 // 2D Curve of degenerated edge on the face aDF
325 // Modified Thu Sep 14 14:35:18 2006
326 // Contribution of Samtech www.samcef.com BEGIN
327 //Handle(Geom2d_Curve) aC2DDE=BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
328 Handle(Geom2d_Curve) aC2DDE1=BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
329 Handle(Geom2d_TrimmedCurve)aC2DDE=new Geom2d_TrimmedCurve(aC2DDE1, aTD1, aTD2);
330 // Contribution of Samtech www.samcef.com END
332 // Choose direction for Degenerated Edge
333 gp_Pnt2d aP2d1, aP2d2;
334 aC2DDE->D0(aTD1, aP2d1);
335 aC2DDE->D0(aTD2, aP2d2);
337 bXDir=Standard_False;
338 if (fabs(aP2d1.Y()-aP2d2.Y()) < aDT){
342 // Prepare bounding Paves
343 BOPTools_Pave aPave1 (nVD, aTD1, BooleanOperations_UnknownInterference);
344 aPaveSet.Append(aPave1);
345 BOPTools_Pave aPave2 (nVD, aTD2, BooleanOperations_UnknownInterference);
346 aPaveSet.Append(aPave2);
349 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
350 for (; anIt.More(); anIt.Next()) {
351 const BOPTools_PaveBlock& aPB=anIt.Value();
353 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
355 Handle(Geom2d_Curve) aC2D=BRep_Tool::CurveOnSurface(aE, aDF, aT1, aT2);
360 Geom2dAdaptor_Curve aGAC1, aGAC2;
362 aGAC1.Load(aC2DDE, aTD1, aTD2);
363 Handle(Geom2d_Line) aL2D= Handle(Geom2d_Line)::DownCast(aC2D);
364 if (!aL2D.IsNull()) {
368 aGAC2.Load(aC2D, aT1, aT2);
371 Geom2dInt_GInter aGInter(aGAC1, aGAC2, aTolInter, aTolInter);
373 bIsDone=aGInter.IsDone();
375 aNbPoints=aGInter.NbPoints();
377 for (j=1; j<=aNbPoints; ++j) {
378 gp_Pnt2d aP2D=aGInter.Point(j).Value();
380 // Modified to obtain exact parameter Thu Sep 14 14:35:18 2006
381 // Contribution of Samtech www.samcef.com BEGIN
382 Handle(Geom2d_Line) aCLDE=Handle(Geom2d_Line)::DownCast(aC2DDE1);
383 if (aCLDE.IsNull()) {
386 gp_Lin2d aLDE=aCLDE->Lin2d();
387 aX=ElCLib::Parameter(aLDE, aP2D);
389 //aX=(bXDir) ? aP2D.X(): aP2D.Y();
390 // Contribution of Samtech www.samcef.com END
392 if (fabs (aX-aTD1) < aDT || fabs (aX-aTD2) < aDT) {
395 if (aX < aTD1 || aX > aTD2) {
399 bRejectFlag=Standard_False;
400 const BOPTools_ListOfPave& aListOfPave=aPaveSet.Set();
401 BOPTools_ListIteratorOfListOfPave aPaveIt(aListOfPave);
402 for (; aPaveIt.More(); aPaveIt.Next()) {
403 const BOPTools_Pave& aPavex=aPaveIt.Value();
404 Standard_Real aXx=aPavex.Param();
405 if (fabs (aX-aXx) < aDT) {
406 bRejectFlag=Standard_True;
414 BOPTools_Pave aPave(nVD, aX, BooleanOperations_UnknownInterference);
415 aPaveSet.Append(aPave);
421 //=======================================================================
422 // function: FillSplitEdgesPool
424 //=======================================================================
425 void NMTTools_DEProcessor::FillSplitEdgesPool (const Standard_Integer nED)
427 BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->ChangeSplitShapesPool();
428 BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool.ChangeValue(myDS->RefEdge(nED));
432 const BOPTools_PavePool& aPavePool=myFiller->PavePool();
433 BOPTools_PavePool* pPavePool=(BOPTools_PavePool*) &aPavePool;
434 BOPTools_PaveSet& aPaveSet= pPavePool->ChangeValue(myDS->RefEdge(nED));
436 BOPTools_PaveBlockIterator aPBIt(nED, aPaveSet);
437 for (; aPBIt.More(); aPBIt.Next()) {
438 BOPTools_PaveBlock& aPB=aPBIt.Value();
439 aSplitEdges.Append(aPB);
442 //=======================================================================
443 // function: MakeSplitEdges
445 //=======================================================================
446 void NMTTools_DEProcessor::MakeSplitEdges (const Standard_Integer nED,
447 const Standard_Integer nFD)
449 const BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->SplitShapesPool();
450 const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(myDS->RefEdge(nED));
452 Standard_Integer nV1, nV2, aNewShapeIndex;
453 Standard_Real t1, t2;
454 TopoDS_Edge aE, aESplit;
455 TopoDS_Vertex aV1, aV2;
457 const TopoDS_Edge aDE=TopoDS::Edge(myDS->Shape(nED));//mpv
458 const TopoDS_Face aDF=TopoDS::Face(myDS->Shape(nFD));//mpv
460 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
462 for (; aPBIt.More(); aPBIt.Next()) {
463 BOPTools_PaveBlock& aPB=aPBIt.Value();
465 const BOPTools_Pave& aPave1=aPB.Pave1();
468 aV1=TopoDS::Vertex(myDS->GetShape(nV1));
469 aV1.Orientation(TopAbs_FORWARD);
471 const BOPTools_Pave& aPave2=aPB.Pave2();
474 aV2=TopoDS::Vertex(myDS->GetShape(nV2));
475 aV2.Orientation(TopAbs_REVERSED);
477 MakeSplitEdge(aDE, aDF, aV1, t1, aV2, t2, aESplit);
479 // Add Split Part of the Original Edge to the DS
480 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
482 anASSeq.SetNewSuccessor(nV1);
483 anASSeq.SetNewOrientation(aV1.Orientation());
485 anASSeq.SetNewSuccessor(nV2);
486 anASSeq.SetNewOrientation(aV2.Orientation());
488 myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
489 aNewShapeIndex=myDS->NumberOfInsertedShapes();
490 myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
492 // Fill Split Set for the Original Edge
493 aPB.SetEdge(aNewShapeIndex);
497 //=======================================================================
498 // function: MakeSplitEdge
500 //=======================================================================
501 void NMTTools_DEProcessor::MakeSplitEdge (const TopoDS_Edge& aE,
502 const TopoDS_Face& aF,
503 const TopoDS_Vertex& aV1,
504 const Standard_Real aP1,
505 const TopoDS_Vertex& aV2,
506 const Standard_Real aP2,
507 TopoDS_Edge& aNewEdge)
509 Standard_Real aTol=1.e-7;
518 BB.Range(E, aF, aP1, aP2);
520 BB.Degenerated(E, Standard_True);
522 BB.UpdateEdge(E, aTol);
526 //=======================================================================
527 // function: NMTTools_DEProcessor::NMTTools_DEProcessor
529 //=======================================================================
530 NMTTools_DEProcessor::NMTTools_DEProcessor(NMTTools_PDSFiller& pDSFiller)
532 myIsDone(Standard_False)
534 myDSFiller=pDSFiller;
535 myFiller=(NMTTools_PaveFiller*) &(myDSFiller->PaveFiller());