4b66ae76 |
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 | // |
2f0109b7 |
64 | // if solid has one shell, it will return, without checking orientation |
65 | Standard_Integer aShellCounter = 0; |
66 | for (aIt.Initialize(aSolid); aIt.More(); aIt.Next()) { |
67 | const TopoDS_Shape& aSx=aIt.Value(); |
68 | if (aSx.ShapeType()==TopAbs_SHELL) { |
69 | aShell=*((TopoDS_Shell*)&aSx); |
70 | aShellCounter++; |
71 | if (aShellCounter >= 2) |
72 | break; |
73 | } |
74 | } |
75 | if (aShellCounter == 0) { |
76 | return aDummy; |
77 | } |
78 | else if (aShellCounter == 1) { |
79 | return aShell; |
80 | } |
81 | // |
82 | for (aIt.Initialize(aSolid); aIt.More(); aIt.Next()) { |
4b66ae76 |
83 | const TopoDS_Shape& aSx=aIt.Value(); |
84 | if (aSx.ShapeType()==TopAbs_SHELL) { |
85 | aShell=*((TopoDS_Shell*)&aSx); |
86 | if (!IsInternal(aShell)) { |
87 | aSDx=aSolid; |
88 | aSDx.EmptyCopy(); |
89 | aBB.Add(aSDx, aShell); |
90 | // |
91 | aSC.Load(aSDx); |
92 | aSC.PerformInfinitePoint(aTol); |
93 | if(aSC.State()==TopAbs_OUT) { |
94 | bFound=Standard_True; |
95 | break; |
96 | } |
97 | } |
98 | } |
99 | } |
100 | // |
101 | if (!bFound) { |
102 | return aDummy; |
103 | } |
104 | // |
105 | return aShell; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : IsInternal |
110 | //purpose : |
111 | //======================================================================= |
112 | Standard_Boolean IsInternal(const TopoDS_Shell& aSx) |
113 | { |
114 | Standard_Boolean bInternal; |
115 | TopAbs_Orientation aOr; |
116 | TopoDS_Iterator aIt; |
117 | // |
118 | bInternal=Standard_False; |
119 | // |
120 | aIt.Initialize(aSx); |
3ed30348 |
121 | if (aIt.More()) { |
4b66ae76 |
122 | const TopoDS_Shape& aSy=aIt.Value(); |
123 | aOr=aSy.Orientation(); |
124 | bInternal=(aOr==TopAbs_INTERNAL); |
4b66ae76 |
125 | } |
126 | // |
127 | return bInternal; |
128 | } |