29ab06ef0fe97a79459b2cbd00ca075af0fd54b3
[occt.git] / src / BRepClass3d / BRepClass3d.cxx
1 // Created on: 1993-01-21
2 // Created by: Peter KURNEV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // File:        BRepClass3d.cxx
18 // Created:     Thu Sep 20 10:05:46 2012
19 // Author:      
20 //              <pkv@PETREX>
21
22 #include <BRep_Builder.hxx>
23 #include <BRepClass3d.hxx>
24 #include <BRepClass3d_SolidClassifier.hxx>
25 #include <TopAbs_Orientation.hxx>
26 #include <TopAbs_State.hxx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <TopoDS_Solid.hxx>
30
31 static 
32   Standard_Boolean IsInternal(const TopoDS_Shell& aSx);
33
34 //=======================================================================
35 //function : OuterShell
36 //purpose  : 
37 //=======================================================================
38 TopoDS_Shell BRepClass3d::OuterShell(const TopoDS_Solid& aSolid)
39 {
40   Standard_Boolean bFound;
41   Standard_Real aTol;
42   TopoDS_Solid aSDx;
43   TopoDS_Shell aShell, aDummy;
44   TopoDS_Iterator aIt;
45   BRep_Builder aBB;
46   BRepClass3d_SolidClassifier aSC;
47   //
48   if (aSolid.IsNull()) {
49     return aDummy;
50   }
51   //
52   aTol=1.e-7;
53   bFound=Standard_False;
54   //
55   // if solid has one shell, it will return, without checking orientation 
56   Standard_Integer aShellCounter = 0;
57   for (aIt.Initialize(aSolid); aIt.More(); aIt.Next()) {
58     const TopoDS_Shape& aSx=aIt.Value();
59     if (aSx.ShapeType()==TopAbs_SHELL) {
60       aShell=*((TopoDS_Shell*)&aSx);
61       aShellCounter++;
62       if (aShellCounter >= 2)
63         break;
64     }
65   }
66   if (aShellCounter == 0) {
67     return aDummy;
68   }
69   else if (aShellCounter == 1) {
70     return aShell;
71   }
72   //
73   for (aIt.Initialize(aSolid); aIt.More(); aIt.Next()) { 
74     const TopoDS_Shape& aSx=aIt.Value();
75     if (aSx.ShapeType()==TopAbs_SHELL) {
76       aShell=*((TopoDS_Shell*)&aSx);
77       if (!IsInternal(aShell)) {
78         aSDx=aSolid;
79         aSDx.EmptyCopy();
80         aBB.Add(aSDx, aShell);
81         //
82         aSC.Load(aSDx);
83         aSC.PerformInfinitePoint(aTol);
84         if(aSC.State()==TopAbs_OUT) {
85           bFound=Standard_True;
86           break;
87         }
88       }
89     }
90   }
91   //
92   if (!bFound) {
93     return aDummy;
94   } 
95   //
96   return aShell;
97 }
98
99 //=======================================================================
100 //function : IsInternal
101 //purpose  : 
102 //=======================================================================
103 Standard_Boolean IsInternal(const TopoDS_Shell& aSx)
104 {
105   Standard_Boolean bInternal;
106   TopAbs_Orientation aOr;
107   TopoDS_Iterator aIt; 
108   //
109   bInternal=Standard_False;
110   //
111   aIt.Initialize(aSx);
112   if (aIt.More()) {
113     const TopoDS_Shape& aSy=aIt.Value();
114     aOr=aSy.Orientation();
115     bInternal=(aOr==TopAbs_INTERNAL);
116   }     
117   //
118   return bInternal;
119 }