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=0;
194 aNbE=myDEMap.Extent();
195 for (i=1; i<=aNbE; i++) {
196 nED=myDEMap.FindKey(i);
198 const BOPTools_DEInfo& aDEInfo=myDEMap(i);
199 nVD=aDEInfo.Vertex();
200 // Fill PaveSet for the edge nED
201 const TColStd_ListOfInteger& nLF=aDEInfo.Faces();
202 TColStd_ListIteratorOfListOfInteger anIt(nLF);
203 for (; anIt.More(); anIt.Next()) {
206 BOPTools_ListOfPaveBlock aLPB;
207 FindPaveBlocks(nED, nVD, nFD, aLPB);
208 FillPaveSet (nED, nVD, nFD, aLPB);
211 // Fill aSplitEdges for the edge nED
212 FillSplitEdgesPool(nED);
215 MakeSplitEdges(nED, nFD);
219 //=======================================================================
220 // function: FindPaveBlocks
222 //=======================================================================
223 void NMTTools_DEProcessor::FindPaveBlocks(const Standard_Integer ,
224 const Standard_Integer nVD,
225 const Standard_Integer nFD,
226 BOPTools_ListOfPaveBlock& aLPBOut)
228 BOPTools_ListIteratorOfListOfPaveBlock anIt;
229 Standard_Integer i, aNb, nF2, nV;
231 BOPTools_CArray1OfSSInterference& aFFs=(myFiller->InterfPool())->SSInterferences();
234 for (i=1; i<=aNb; ++i) {
235 BOPTools_SSInterference& aFF=aFFs(i);
237 nF2=aFF.OppositeIndex(nFD);
243 const BOPTools_ListOfPaveBlock& aLPBSplits=aFF.PaveBlocks();
244 anIt.Initialize(aLPBSplits);
245 for (; anIt.More(); anIt.Next()) {
246 const BOPTools_PaveBlock& aPBSp=anIt.Value();
248 const BOPTools_Pave& aPave1=aPBSp.Pave1();
251 aLPBOut.Append(aPBSp);
255 const BOPTools_Pave& aPave2=aPBSp.Pave2();
258 aLPBOut.Append(aPBSp);
264 Standard_Integer j, aNbCurves;
265 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
266 aNbCurves=aSC.Length();
268 for (j=1; j<=aNbCurves; j++) {
269 const BOPTools_Curve& aBC=aSC(j);
270 const BOPTools_ListOfPaveBlock& aLPBSe=aBC.NewPaveBlocks();
272 anIt.Initialize(aLPBSe);
273 for (; anIt.More(); anIt.Next()) {
274 const BOPTools_PaveBlock& aPBSe=anIt.Value();
276 const BOPTools_Pave& aPv1=aPBSe.Pave1();
279 aLPBOut.Append(aPBSe);
283 const BOPTools_Pave& aPv2=aPBSe.Pave2();
286 aLPBOut.Append(aPBSe);
293 //=======================================================================
294 // function: FillPaveSet
296 //=======================================================================
297 void NMTTools_DEProcessor::FillPaveSet (const Standard_Integer nED,
298 const Standard_Integer nVD,
299 const Standard_Integer nFD,
300 const BOPTools_ListOfPaveBlock& aLPB)
302 Standard_Boolean bIsDone, bXDir, bRejectFlag;
303 Standard_Integer nE, aNbPoints, j;
304 Standard_Real aTD1, aTD2, aT1, aT2, aTolInter, aX, aDT;
306 aDT=Precision::PConfusion();
308 BOPTools_PaveSet& aPaveSet= (myFiller->ChangePavePool()).ChangeValue(myDS->RefEdge(nED));
310 // Clear aPaveSet, aSplitEdges
311 aPaveSet.ChangeSet().Clear();
313 const TopoDS_Edge aDE=TopoDS::Edge(myDS->Shape(nED));//mpv
314 const TopoDS_Face aDF=TopoDS::Face(myDS->Shape(nFD));//mpv
316 // 2D Curve of degenerated edge on the face aDF
317 // Modified Thu Sep 14 14:35:18 2006
318 // Contribution of Samtech www.samcef.com BEGIN
319 //Handle(Geom2d_Curve) aC2DDE=BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
320 Handle(Geom2d_Curve) aC2DDE1=BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
321 Handle(Geom2d_TrimmedCurve)aC2DDE=new Geom2d_TrimmedCurve(aC2DDE1, aTD1, aTD2);
322 // Contribution of Samtech www.samcef.com END
324 // Choose direction for Degenerated Edge
325 gp_Pnt2d aP2d1, aP2d2;
326 aC2DDE->D0(aTD1, aP2d1);
327 aC2DDE->D0(aTD2, aP2d2);
329 bXDir=Standard_False;
330 if (fabs(aP2d1.Y()-aP2d2.Y()) < aDT){
334 // Prepare bounding Paves
335 BOPTools_Pave aPave1 (nVD, aTD1, BooleanOperations_UnknownInterference);
336 aPaveSet.Append(aPave1);
337 BOPTools_Pave aPave2 (nVD, aTD2, BooleanOperations_UnknownInterference);
338 aPaveSet.Append(aPave2);
341 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
342 for (; anIt.More(); anIt.Next()) {
343 const BOPTools_PaveBlock& aPB=anIt.Value();
345 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
347 Handle(Geom2d_Curve) aC2D=BRep_Tool::CurveOnSurface(aE, aDF, aT1, aT2);
352 Geom2dAdaptor_Curve aGAC1, aGAC2;
354 aGAC1.Load(aC2DDE, aTD1, aTD2);
355 Handle(Geom2d_Line) aL2D= Handle(Geom2d_Line)::DownCast(aC2D);
356 if (!aL2D.IsNull()) {
360 aGAC2.Load(aC2D, aT1, aT2);
363 Geom2dInt_GInter aGInter(aGAC1, aGAC2, aTolInter, aTolInter);
365 bIsDone=aGInter.IsDone();
367 aNbPoints=aGInter.NbPoints();
369 for (j=1; j<=aNbPoints; ++j) {
370 gp_Pnt2d aP2D=aGInter.Point(j).Value();
372 // Modified to obtain exact parameter Thu Sep 14 14:35:18 2006
373 // Contribution of Samtech www.samcef.com BEGIN
374 Handle(Geom2d_Line) aCLDE=Handle(Geom2d_Line)::DownCast(aC2DDE1);
375 if (aCLDE.IsNull()) {
378 gp_Lin2d aLDE=aCLDE->Lin2d();
379 aX=ElCLib::Parameter(aLDE, aP2D);
381 //aX=(bXDir) ? aP2D.X(): aP2D.Y();
382 // Contribution of Samtech www.samcef.com END
384 if (fabs (aX-aTD1) < aDT || fabs (aX-aTD2) < aDT) {
387 if (aX < aTD1 || aX > aTD2) {
391 bRejectFlag=Standard_False;
392 const BOPTools_ListOfPave& aListOfPave=aPaveSet.Set();
393 BOPTools_ListIteratorOfListOfPave aPaveIt(aListOfPave);
394 for (; aPaveIt.More(); aPaveIt.Next()) {
395 const BOPTools_Pave& aPavex=aPaveIt.Value();
396 Standard_Real aXx=aPavex.Param();
397 if (fabs (aX-aXx) < aDT) {
398 bRejectFlag=Standard_True;
406 BOPTools_Pave aPave(nVD, aX, BooleanOperations_UnknownInterference);
407 aPaveSet.Append(aPave);
413 //=======================================================================
414 // function: FillSplitEdgesPool
416 //=======================================================================
417 void NMTTools_DEProcessor::FillSplitEdgesPool (const Standard_Integer nED)
419 BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->ChangeSplitShapesPool();
420 BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool.ChangeValue(myDS->RefEdge(nED));
424 const BOPTools_PavePool& aPavePool=myFiller->PavePool();
425 BOPTools_PavePool* pPavePool=(BOPTools_PavePool*) &aPavePool;
426 BOPTools_PaveSet& aPaveSet= pPavePool->ChangeValue(myDS->RefEdge(nED));
428 BOPTools_PaveBlockIterator aPBIt(nED, aPaveSet);
429 for (; aPBIt.More(); aPBIt.Next()) {
430 BOPTools_PaveBlock& aPB=aPBIt.Value();
431 aSplitEdges.Append(aPB);
434 //=======================================================================
435 // function: MakeSplitEdges
437 //=======================================================================
438 void NMTTools_DEProcessor::MakeSplitEdges (const Standard_Integer nED,
439 const Standard_Integer nFD)
441 const BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->SplitShapesPool();
442 const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(myDS->RefEdge(nED));
444 Standard_Integer nV1, nV2, aNewShapeIndex;
445 Standard_Real t1, t2;
446 TopoDS_Edge aE, aESplit;
447 TopoDS_Vertex aV1, aV2;
449 const TopoDS_Edge aDE=TopoDS::Edge(myDS->Shape(nED));//mpv
450 const TopoDS_Face aDF=TopoDS::Face(myDS->Shape(nFD));//mpv
452 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
454 for (; aPBIt.More(); aPBIt.Next()) {
455 BOPTools_PaveBlock& aPB=aPBIt.Value();
457 const BOPTools_Pave& aPave1=aPB.Pave1();
460 aV1=TopoDS::Vertex(myDS->GetShape(nV1));
461 aV1.Orientation(TopAbs_FORWARD);
463 const BOPTools_Pave& aPave2=aPB.Pave2();
466 aV2=TopoDS::Vertex(myDS->GetShape(nV2));
467 aV2.Orientation(TopAbs_REVERSED);
469 MakeSplitEdge(aDE, aDF, aV1, t1, aV2, t2, aESplit);
471 // Add Split Part of the Original Edge to the DS
472 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
474 anASSeq.SetNewSuccessor(nV1);
475 anASSeq.SetNewOrientation(aV1.Orientation());
477 anASSeq.SetNewSuccessor(nV2);
478 anASSeq.SetNewOrientation(aV2.Orientation());
480 myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
481 aNewShapeIndex=myDS->NumberOfInsertedShapes();
482 myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
484 // Fill Split Set for the Original Edge
485 aPB.SetEdge(aNewShapeIndex);
489 //=======================================================================
490 // function: MakeSplitEdge
492 //=======================================================================
493 void NMTTools_DEProcessor::MakeSplitEdge (const TopoDS_Edge& aE,
494 const TopoDS_Face& aF,
495 const TopoDS_Vertex& aV1,
496 const Standard_Real aP1,
497 const TopoDS_Vertex& aV2,
498 const Standard_Real aP2,
499 TopoDS_Edge& aNewEdge)
501 Standard_Real aTol=1.e-7;
510 BB.Range(E, aF, aP1, aP2);
512 BB.Degenerated(E, Standard_True);
514 BB.UpdateEdge(E, aTol);
518 //=======================================================================
519 // function: NMTTools_DEProcessor::NMTTools_DEProcessor
521 //=======================================================================
522 NMTTools_DEProcessor::NMTTools_DEProcessor(NMTTools_PDSFiller& pDSFiller)
524 myIsDone(Standard_False)
526 myDSFiller=pDSFiller;
527 myFiller=(NMTTools_PaveFiller*) &(myDSFiller->PaveFiller());