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