1 // Created by: Peter KURNEV
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BRepCheck_Solid.ixx>
17 #include <Standard_DefineHandle.hxx>
18 #include <MMgt_TShared.hxx>
20 #include <NCollection_Vector.hxx>
21 #include <NCollection_Map.hxx>
25 #include <Geom_Curve.hxx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TopoDS_Solid.hxx>
29 #include <TopoDS_Shell.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Builder.hxx>
32 #include <BRep_Tool.hxx>
34 #include <TopExp_Explorer.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopTools_ShapeMapHasher.hxx>
39 #include <BRepClass3d_SolidClassifier.hxx>
41 #include <BRepCheck.hxx>
42 #include <BRepCheck_ListOfStatus.hxx>
45 DEFINE_STANDARD_HANDLE(BRepCheck_HSC, MMgt_TShared);
46 //=======================================================================
47 //class : BRepCheck_HSC
49 //=======================================================================
50 class BRepCheck_HSC : public MMgt_TShared {
58 virtual ~BRepCheck_HSC(){
62 BRepClass3d_SolidClassifier& SolidClassifier(){
66 DEFINE_STANDARD_RTTI(BRepCheck_HSC);
69 BRepClass3d_SolidClassifier mySC;
71 IMPLEMENT_STANDARD_HANDLE(BRepCheck_HSC, MMgt_TShared);
72 IMPLEMENT_STANDARD_RTTIEXT(BRepCheck_HSC, MMgt_TShared);
74 //=======================================================================
75 //class : BRepCheck_ToolSolid
77 //=======================================================================
78 class BRepCheck_ToolSolid {
83 BRepCheck_ToolSolid() {
84 myIsHole=Standard_False;
85 myPnt.SetCoord(-1.,-1.,-1.);
88 virtual ~BRepCheck_ToolSolid() {
91 void SetSolid(const TopoDS_Solid& aZ) {
95 const TopoDS_Solid& Solid()const {
99 Standard_Boolean IsHole() const {
103 const gp_Pnt& InnerPoint() {
108 Standard_Boolean IsOut(BRepCheck_ToolSolid& aOther) {
109 Standard_Boolean bFlag;
112 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
114 aSC.Perform(aOther.myPnt, ::RealSmall());
116 bFlag=(aState==TopAbs_OUT);
123 Standard_Real aT, aT1, aT2, aPAR_T;
124 TopExp_Explorer aExp;
127 myHSC=new BRepCheck_HSC();
129 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
134 aSC.PerformInfinitePoint(::RealSmall());
135 myIsHole=(aSC.State()==TopAbs_IN);
138 aPAR_T=0.43213918; // 10*e^(-PI)
139 aExp.Init(mySolid, TopAbs_EDGE);
140 for (; aExp.More(); aExp.Next()) {
141 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
142 if (!BRep_Tool::Degenerated(aE)) {
143 Handle(Geom_Curve) aC3D=BRep_Tool::Curve(aE, aT1, aT2);
144 aT=(1.-aPAR_T)*aT1 + aPAR_T*aT2;
145 myPnt=aC3D->Value(aT);
152 Standard_Boolean myIsHole;
154 TopoDS_Solid mySolid;
155 Handle(BRepCheck_HSC) myHSC;
158 typedef NCollection_Vector<BRepCheck_ToolSolid>
159 BRepCheck_VectorOfToolSolid;
162 //=======================================================================
163 //function : BRepCheck_Solid
165 //=======================================================================
166 BRepCheck_Solid::BRepCheck_Solid (const TopoDS_Solid& S)
170 //=======================================================================
173 //=======================================================================
174 void BRepCheck_Solid::Blind()
177 // nothing more than in the minimum
178 myBlind = Standard_True;
181 //=======================================================================
182 //function : InContext
184 //=======================================================================
185 void BRepCheck_Solid::InContext(const TopoDS_Shape& )
188 //=======================================================================
191 //=======================================================================
192 void BRepCheck_Solid::Minimum()
197 myMin = Standard_True;
199 Standard_Boolean bFound, bIsHole, bFlag;
200 Standard_Integer i, j, aNbVTS, aNbVTS1, iCntSh, iCntShInt;
202 TopoDS_Iterator aIt, aItF;
204 TopExp_Explorer aExp;
205 TopTools_MapOfShape aMSS;
206 TopAbs_Orientation aOr;
207 BRepCheck_VectorOfToolSolid aVTS;
208 BRepCheck_ListOfStatus thelist;
210 myMap.Bind(myShape, thelist);
211 BRepCheck_ListOfStatus& aLST = myMap(myShape);
212 aLST.Append(BRepCheck_NoError);
214 //-------------------------------------------------
215 // 1. InvalidImbricationOfShells
216 bFound=Standard_False;
217 aExp.Init(myShape, TopAbs_FACE);
218 for (; !bFound && aExp.More(); aExp.Next()) {
219 const TopoDS_Shape& aF=aExp.Current();
221 BRepCheck::Add(myMap(myShape),
222 BRepCheck_InvalidImbricationOfShells);
227 //-------------------------------------------------
229 // - Too many growths,
230 // - There is smt of the solid that is out of solid
233 aIt.Initialize(myShape);
234 for (; aIt.More(); aIt.Next()) {
235 const TopoDS_Shape& aSx=aIt.Value();
237 if (aSx.ShapeType()!=TopAbs_SHELL) {
238 aOr=aSx.Orientation();
239 if (aOr!=TopAbs_INTERNAL) {
240 BRepCheck::Add(myMap(myShape),
241 BRepCheck_BadOrientationOfSubshape);
246 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSx);
248 // Skip internal shells
249 bFound=Standard_False;
250 aItF.Initialize(aSh);
251 for (; !bFound && aItF.More(); aItF.Next()) {
252 const TopoDS_Shape& aF=aItF.Value();
253 aOr=aF.Orientation();
254 if (aOr==TopAbs_INTERNAL) {
265 // Skip not closed shells
266 if (!BRep_Tool::IsClosed(aSh)) {
273 BRepCheck_ToolSolid aTS;
277 }//for (; aIt.More(); aIt.Next()) {
279 if (!iCntSh && iCntShInt) {
280 // all shells in the solid are internal
281 BRepCheck::Add(myMap(myShape),
282 BRepCheck_BadOrientationOfSubshape);
291 for (i=0; i<aNbVTS; ++i) {
292 BRepCheck_ToolSolid& aTS=aVTS(i);
295 bIsHole=aTS.IsHole();
300 BRepCheck::Add(myMap(myShape),
301 BRepCheck_EnclosedRegion);
307 bFound=Standard_False;
309 for (i=0; !bFound && i<aNbVTS1; ++i) {
310 BRepCheck_ToolSolid& aTSi=aVTS(i);
312 for (j=i+1; !bFound && j<aNbVTS; ++j) {
313 BRepCheck_ToolSolid& aTSj=aVTS(j);
315 bFlag=aTSi.IsOut(aTSj);
317 // smt of solid is out of solid
318 BRepCheck::Add(myMap(myShape),
319 BRepCheck_SubshapeNotInShape);
325 //myMin = Standard_True;