1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
20 #include <BOPAlgo_CheckerSI.hxx>
21 #include <BOPAlgo_Alerts.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPDS_Interf.hxx>
24 #include <BOPDS_IteratorSI.hxx>
25 #include <BOPDS_MapOfPair.hxx>
26 #include <BOPDS_Pair.hxx>
27 #include <BOPDS_PIteratorSI.hxx>
28 #include <BOPDS_VectorOfInterfEF.hxx>
29 #include <BOPDS_VectorOfInterfFF.hxx>
30 #include <BOPDS_VectorOfInterfVE.hxx>
31 #include <BOPDS_VectorOfInterfVF.hxx>
32 #include <BOPDS_VectorOfInterfVV.hxx>
33 #include <BRep_Tool.hxx>
34 #include <gp_Torus.hxx>
36 #include <BOPTools_AlgoTools.hxx>
37 #include <BOPTools_Parallel.hxx>
38 #include <BRepBuilderAPI_Copy.hxx>
39 #include <IntTools_Context.hxx>
40 #include <IntTools_Tools.hxx>
41 #include <IntTools_FaceFace.hxx>
42 #include <Standard_ErrorHandler.hxx>
43 #include <Standard_Failure.hxx>
44 #include <TopTools_ListOfShape.hxx>
45 #include <TopTools_MapOfShape.hxx>
47 //=======================================================================
48 //class : BOPAlgo_FaceSelfIntersect
50 //=======================================================================
51 class BOPAlgo_FaceSelfIntersect :
52 public IntTools_FaceFace,
58 BOPAlgo_FaceSelfIntersect() :
61 myIF(-1), myTolF(1.e-7) {
64 virtual ~BOPAlgo_FaceSelfIntersect() {
67 void SetIndex(const Standard_Integer nF) {
71 Standard_Integer IndexOfFace() const {
75 void SetFace(const TopoDS_Face& aF) {
79 const TopoDS_Face& Face()const {
83 void SetTolF(const Standard_Real aTolF) {
87 Standard_Real TolF() const{
91 virtual void Perform() {
92 BOPAlgo_Algo::UserBreak();
93 IntTools_FaceFace::Perform(myF, myF);
97 Standard_Integer myIF;
101 //end of definition of class BOPAlgo_FaceSelfIntersect
103 //=======================================================================
105 typedef NCollection_Vector<BOPAlgo_FaceSelfIntersect> BOPAlgo_VectorOfFaceSelfIntersect;
107 //=======================================================================
110 //=======================================================================
111 BOPAlgo_CheckerSI::BOPAlgo_CheckerSI()
115 myLevelOfCheck=BOPDS_DS::NbInterfTypes()-1;
116 myNonDestructive=Standard_True;
117 SetAvoidBuildPCurve(Standard_True);
119 //=======================================================================
122 //=======================================================================
123 BOPAlgo_CheckerSI::~BOPAlgo_CheckerSI()
126 //=======================================================================
127 //function : SetLevelOfCheck
129 //=======================================================================
130 void BOPAlgo_CheckerSI::SetLevelOfCheck(const Standard_Integer theLevel)
132 Standard_Integer aNbLists;
134 aNbLists=BOPDS_DS::NbInterfTypes();
135 if (theLevel >= 0 && theLevel < aNbLists) {
136 myLevelOfCheck = theLevel;
139 //=======================================================================
142 //=======================================================================
143 void BOPAlgo_CheckerSI::Init()
148 myDS=new BOPDS_DS(myAllocator);
149 myDS->SetArguments(myArguments);
150 myDS->Init(myFuzzyValue);
153 myContext=new IntTools_Context;
156 BOPDS_PIteratorSI theIterSI=new BOPDS_IteratorSI(myAllocator);
157 theIterSI->SetDS(myDS);
158 theIterSI->Prepare(myContext, myUseOBB, myFuzzyValue);
159 theIterSI->UpdateByLevelOfCheck(myLevelOfCheck);
161 myIterator=theIterSI;
163 //=======================================================================
166 //=======================================================================
167 void BOPAlgo_CheckerSI::Perform()
172 if (myArguments.Extent() != 1) {
173 AddError (new BOPAlgo_AlertMultipleArguments);
177 // Perform intersection of sub shapes
178 BOPAlgo_PaveFiller::Perform();
180 CheckFaceSelfIntersection();
182 // Perform intersection with solids
195 // Treat the intersection results
199 catch (Standard_Failure const&) {
200 AddError (new BOPAlgo_AlertIntersectionFailed);
203 //=======================================================================
204 //function : PostTreat
206 //=======================================================================
207 void BOPAlgo_CheckerSI::PostTreat()
209 Standard_Integer i, aNb, n1, n2;
212 BOPDS_MapOfPair& aMPK=
213 *((BOPDS_MapOfPair*)&myDS->Interferences());
216 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
218 for (i=0; i!=aNb; ++i) {
219 const BOPDS_InterfVV& aVV=aVVs(i);
221 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
224 aPK.SetIndices(n1, n2);
229 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
231 for (i=0; i!=aNb; ++i) {
232 const BOPDS_InterfVE& aVE=aVEs(i);
234 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
237 aPK.SetIndices(n1, n2);
242 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
244 for (i=0; i!=aNb; ++i) {
245 const BOPDS_InterfEE& aEE=aEEs(i);
247 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
250 aPK.SetIndices(n1, n2);
255 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
257 for (i=0; i!=aNb; ++i) {
258 const BOPDS_InterfVF& aVF=aVFs(i);
260 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
263 aPK.SetIndices(n1, n2);
268 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
270 for (i=0; i!=aNb; ++i) {
271 const BOPDS_InterfEF& aEF=aEFs(i);
272 if (aEF.CommonPart().Type()==TopAbs_SHAPE) {
276 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
279 aPK.SetIndices(n1, n2);
284 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
286 for (i=0; i!=aNb; ++i) {
287 Standard_Boolean bTangentFaces, bFlag;
288 Standard_Integer aNbC, aNbP, j, iFound;
290 const BOPDS_InterfFF& aFF=aFFs(i);
293 bTangentFaces=aFF.TangentFaces();
294 aNbP=aFF.Points().Length();
295 const BOPDS_VectorOfCurve& aVC=aFF.Curves();
297 if (!aNbP && !aNbC && !bTangentFaces) {
301 iFound = (n1 == n2) ? 1 : 0;
302 //case of self-intersection inside one face
306 const TopoDS_Face& aF1=*((TopoDS_Face*)&myDS->Shape(n1));
307 const TopoDS_Face& aF2=*((TopoDS_Face*)&myDS->Shape(n2));
308 bFlag=BOPTools_AlgoTools::AreFacesSameDomain
309 (aF1, aF2, myContext, myFuzzyValue);
315 for (j=0; j!=aNbC; ++j) {
316 const BOPDS_Curve& aNC=aVC(j);
317 const BOPDS_ListOfPaveBlock& aLPBC=aNC.PaveBlocks();
318 if (aLPBC.Extent()) {
330 aPK.SetIndices(n1, n2);
336 BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ();
338 for (i=0; i!=aNb; ++i) {
340 const BOPDS_InterfVZ& aVZ=aVZs(i);
342 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
345 aPK.SetIndices(n1, n2);
350 BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ();
352 for (i=0; i!=aNb; ++i) {
354 const BOPDS_InterfEZ& aEZ=aEZs(i);
356 aPK.SetIndices(n1, n2);
361 BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ();
363 for (i=0; i!=aNb; ++i) {
365 const BOPDS_InterfFZ& aFZ=aFZs(i);
367 aPK.SetIndices(n1, n2);
372 BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ();
374 for (i=0; i!=aNb; ++i) {
376 const BOPDS_InterfZZ& aZZ=aZZs(i);
378 aPK.SetIndices(n1, n2);
383 //=======================================================================
384 //function : CheckFaceSelfIntersection
386 //=======================================================================
387 void BOPAlgo_CheckerSI::CheckFaceSelfIntersection()
389 if (myLevelOfCheck < 5)
394 BOPDS_MapOfPair& aMPK=
395 *((BOPDS_MapOfPair*)&myDS->Interferences());
398 BOPAlgo_VectorOfFaceSelfIntersect aVFace;
400 Standard_Integer aNbS=myDS->NbSourceShapes();
403 for (Standard_Integer i = 0; i < aNbS; i++)
405 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
406 if (aSI.ShapeType() != TopAbs_FACE)
409 const TopoDS_Face& aF = (*(TopoDS_Face*)(&aSI.Shape()));
410 BRepAdaptor_Surface BAsurf(aF, Standard_False);
411 GeomAbs_SurfaceType aSurfType = BAsurf.GetType();
412 if (aSurfType == GeomAbs_Plane ||
413 aSurfType == GeomAbs_Cylinder ||
414 aSurfType == GeomAbs_Cone ||
415 aSurfType == GeomAbs_Sphere)
418 if (aSurfType == GeomAbs_Torus)
420 gp_Torus aTorus = BAsurf.Torus();
421 Standard_Real aMajorRadius = aTorus.MajorRadius();
422 Standard_Real aMinorRadius = aTorus.MinorRadius();
423 if (aMajorRadius > aMinorRadius + Precision::Confusion())
427 Standard_Real aTolF = BRep_Tool::Tolerance(aF);
429 BOPAlgo_FaceSelfIntersect& aFaceSelfIntersect = aVFace.Appended();
431 aFaceSelfIntersect.SetIndex(i);
432 aFaceSelfIntersect.SetFace(aF);
433 aFaceSelfIntersect.SetTolF(aTolF);
435 aFaceSelfIntersect.SetProgressIndicator(myProgressIndicator);
438 Standard_Integer aNbFace = aVFace.Length();
439 //======================================================
440 BOPTools_Parallel::Perform (myRunParallel, aVFace);
441 //======================================================
443 for (Standard_Integer k = 0; k < aNbFace; k++)
445 BOPAlgo_FaceSelfIntersect& aFaceSelfIntersect = aVFace(k);
447 Standard_Integer nF = aFaceSelfIntersect.IndexOfFace();
449 Standard_Boolean bIsDone = aFaceSelfIntersect.IsDone();
452 const IntTools_SequenceOfCurves& aCvsX = aFaceSelfIntersect.Lines();
453 const IntTools_SequenceOfPntOn2Faces& aPntsX = aFaceSelfIntersect.Points();
455 Standard_Integer aNbCurves = aCvsX.Length();
456 Standard_Integer aNbPoints = aPntsX.Length();
458 if (aNbCurves || aNbPoints)
460 aPK.SetIndices(nF, nF);