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_Type.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, MMgt_TShared);
69 BRepClass3d_SolidClassifier mySC;
75 //=======================================================================
76 //class : BRepCheck_ToolSolid
78 //=======================================================================
79 class BRepCheck_ToolSolid {
84 BRepCheck_ToolSolid() {
85 myIsHole=Standard_False;
86 myPnt.SetCoord(-1.,-1.,-1.);
89 virtual ~BRepCheck_ToolSolid() {
92 void SetSolid(const TopoDS_Solid& aZ) {
96 const TopoDS_Solid& Solid()const {
100 Standard_Boolean IsHole() const {
104 const gp_Pnt& InnerPoint() {
109 Standard_Boolean IsOut(BRepCheck_ToolSolid& aOther) {
110 Standard_Boolean bFlag;
113 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
115 aSC.Perform(aOther.myPnt, ::RealSmall());
117 bFlag=(aState==TopAbs_OUT);
124 Standard_Real aT, aT1, aT2, aPAR_T;
125 TopExp_Explorer aExp;
128 myHSC=new BRepCheck_HSC();
130 BRepClass3d_SolidClassifier& aSC=myHSC->SolidClassifier();
135 aSC.PerformInfinitePoint(::RealSmall());
136 myIsHole=(aSC.State()==TopAbs_IN);
139 aPAR_T=0.43213918; // 10*e^(-PI)
140 aExp.Init(mySolid, TopAbs_EDGE);
141 for (; aExp.More(); aExp.Next()) {
142 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
143 if (!BRep_Tool::Degenerated(aE)) {
144 Handle(Geom_Curve) aC3D=BRep_Tool::Curve(aE, aT1, aT2);
145 aT=(1.-aPAR_T)*aT1 + aPAR_T*aT2;
146 myPnt=aC3D->Value(aT);
153 Standard_Boolean myIsHole;
155 TopoDS_Solid mySolid;
156 Handle(BRepCheck_HSC) myHSC;
159 typedef NCollection_Vector<BRepCheck_ToolSolid>
160 BRepCheck_VectorOfToolSolid;
163 //=======================================================================
164 //function : BRepCheck_Solid
166 //=======================================================================
167 BRepCheck_Solid::BRepCheck_Solid (const TopoDS_Solid& S)
171 //=======================================================================
174 //=======================================================================
175 void BRepCheck_Solid::Blind()
178 // nothing more than in the minimum
179 myBlind = Standard_True;
182 //=======================================================================
183 //function : InContext
185 //=======================================================================
186 void BRepCheck_Solid::InContext(const TopoDS_Shape& )
189 //=======================================================================
192 //=======================================================================
193 void BRepCheck_Solid::Minimum()
198 myMin = Standard_True;
200 Standard_Boolean bFound, bIsHole, bFlag;
201 Standard_Integer i, j, aNbVTS, aNbVTS1, iCntSh, iCntShInt;
203 TopoDS_Iterator aIt, aItF;
205 TopExp_Explorer aExp;
206 TopTools_MapOfShape aMSS;
207 TopAbs_Orientation aOr;
208 BRepCheck_VectorOfToolSolid aVTS;
209 BRepCheck_ListOfStatus thelist;
211 myMap.Bind(myShape, thelist);
212 BRepCheck_ListOfStatus& aLST = myMap(myShape);
213 aLST.Append(BRepCheck_NoError);
215 //-------------------------------------------------
216 // 1. InvalidImbricationOfShells
217 bFound=Standard_False;
218 aExp.Init(myShape, TopAbs_FACE);
219 for (; !bFound && aExp.More(); aExp.Next()) {
220 const TopoDS_Shape& aF=aExp.Current();
222 BRepCheck::Add(myMap(myShape),
223 BRepCheck_InvalidImbricationOfShells);
228 //-------------------------------------------------
230 // - Too many growths,
231 // - There is smt of the solid that is out of solid
234 aIt.Initialize(myShape);
235 for (; aIt.More(); aIt.Next()) {
236 const TopoDS_Shape& aSx=aIt.Value();
238 if (aSx.ShapeType()!=TopAbs_SHELL) {
239 aOr=aSx.Orientation();
240 if (aOr!=TopAbs_INTERNAL) {
241 BRepCheck::Add(myMap(myShape),
242 BRepCheck_BadOrientationOfSubshape);
247 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSx);
249 // Skip internal shells
250 bFound=Standard_False;
251 aItF.Initialize(aSh);
252 for (; !bFound && aItF.More(); aItF.Next()) {
253 const TopoDS_Shape& aF=aItF.Value();
254 aOr=aF.Orientation();
255 if (aOr==TopAbs_INTERNAL) {
266 // Skip not closed shells
267 if (!BRep_Tool::IsClosed(aSh)) {
274 BRepCheck_ToolSolid aTS;
278 }//for (; aIt.More(); aIt.Next()) {
280 if (!iCntSh && iCntShInt) {
281 // all shells in the solid are internal
282 BRepCheck::Add(myMap(myShape),
283 BRepCheck_BadOrientationOfSubshape);
292 for (i=0; i<aNbVTS; ++i) {
293 BRepCheck_ToolSolid& aTS=aVTS(i);
296 bIsHole=aTS.IsHole();
301 BRepCheck::Add(myMap(myShape),
302 BRepCheck_EnclosedRegion);
308 bFound=Standard_False;
310 for (i=0; !bFound && i<aNbVTS1; ++i) {
311 BRepCheck_ToolSolid& aTSi=aVTS(i);
313 for (j=i+1; !bFound && j<aNbVTS; ++j) {
314 BRepCheck_ToolSolid& aTSj=aVTS(j);
316 bFlag=aTSi.IsOut(aTSj);
318 // smt of solid is out of solid
319 BRepCheck::Add(myMap(myShape),
320 BRepCheck_SubshapeNotInShape);
326 //myMin = Standard_True;