cffa3402d21396ac6571055539e390349d40074f
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 // File:        BRepClass3d.cxx
22 // Created:     Thu Sep 20 10:05:46 2012
23 // Author:      
24 //              <pkv@PETREX>
25
26 #include <BRepClass3d.ixx>
27
28
29 #include <TopAbs_State.hxx>
30 #include <TopAbs_Orientation.hxx>
31
32 #include <TopoDS_Solid.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Iterator.hxx>
35
36 #include <BRep_Builder.hxx>
37 #include <BRepClass3d_SolidClassifier.hxx>
38
39
40 static 
41   Standard_Boolean IsInternal(const TopoDS_Shell& aSx);
42
43 //=======================================================================
44 //function : OuterShell
45 //purpose  : 
46 //=======================================================================
47 TopoDS_Shell BRepClass3d::OuterShell(const TopoDS_Solid& aSolid)
48 {
49   Standard_Boolean bFound;
50   Standard_Real aTol;
51   TopoDS_Solid aSDx;
52   TopoDS_Shell aShell, aDummy;
53   TopoDS_Iterator aIt;
54   BRep_Builder aBB;
55   BRepClass3d_SolidClassifier aSC;
56   //
57   if (aSolid.IsNull()) {
58     return aDummy;
59   }
60   //
61   aTol=1.e-7;
62   bFound=Standard_False;
63   //
64   aIt.Initialize(aSolid);
65   for (; aIt.More(); aIt.Next()) { 
66     const TopoDS_Shape& aSx=aIt.Value();
67     if (aSx.ShapeType()==TopAbs_SHELL) {
68       aShell=*((TopoDS_Shell*)&aSx);
69       if (!IsInternal(aShell)) {
70         aSDx=aSolid;
71         aSDx.EmptyCopy();
72         aBB.Add(aSDx, aShell);
73         //
74         aSC.Load(aSDx);
75         aSC.PerformInfinitePoint(aTol);
76         if(aSC.State()==TopAbs_OUT) {
77           bFound=Standard_True;
78           break;
79         }
80       }
81     }
82   }
83   //
84   if (!bFound) {
85     return aDummy;
86   } 
87   //
88   return aShell;
89 }
90
91 //=======================================================================
92 //function : IsInternal
93 //purpose  : 
94 //=======================================================================
95 Standard_Boolean IsInternal(const TopoDS_Shell& aSx)
96 {
97   Standard_Boolean bInternal;
98   TopAbs_Orientation aOr;
99   TopoDS_Iterator aIt; 
100   //
101   bInternal=Standard_False;
102   //
103   aIt.Initialize(aSx);
104   for (; aIt.More(); aIt.Next()) {
105     const TopoDS_Shape& aSy=aIt.Value();
106     aOr=aSy.Orientation();
107     bInternal=(aOr==TopAbs_INTERNAL);
108     break;
109   }     
110   //
111   return bInternal;
112 }