b311480e |
1 | // Created on: 1996-08-27 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1996-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 | |
7fd59977 |
21 | |
22 | #include <TopOpeBRepTool_SolidClassifier.ixx> |
23 | #include <BRepClass3d_SolidClassifier.hxx> |
24 | |
25 | //======================================================================= |
26 | //function : TopOpeBRepTool_SolidClassifier |
27 | //purpose : |
28 | //======================================================================= |
29 | TopOpeBRepTool_SolidClassifier::TopOpeBRepTool_SolidClassifier() |
30 | { |
31 | Clear(); |
32 | } |
33 | |
34 | //modified by NIZNHY-PKV Mon Dec 16 10:39:00 2002 f |
35 | //======================================================================= |
36 | //function : Destroy |
37 | //purpose : alias ~TopOpeBRepTool_SolidClassifier |
38 | //======================================================================= |
39 | void TopOpeBRepTool_SolidClassifier::Destroy() |
40 | { |
41 | Standard_Integer i, aNb; |
42 | |
43 | aNb=myShapeClassifierMap.Extent(); |
44 | for (i=1; i<=aNb; ++i) { |
45 | Standard_Address anAddr=myShapeClassifierMap(i); |
46 | BRepClass3d_SolidClassifier* pClsf= |
47 | (BRepClass3d_SolidClassifier*) anAddr; |
48 | delete pClsf; |
49 | } |
50 | myShapeClassifierMap.Clear(); |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : LoadSolid |
55 | //purpose : |
56 | //======================================================================= |
57 | void TopOpeBRepTool_SolidClassifier::LoadSolid(const TopoDS_Solid& SOL) |
58 | { |
59 | Standard_Boolean found = myShapeClassifierMap.Contains(SOL); |
60 | |
61 | if ( !found ) { |
62 | myPClassifier = new BRepClass3d_SolidClassifier(SOL); |
63 | myShapeClassifierMap.Add(SOL, (Standard_Address)myPClassifier); |
64 | } |
65 | else { |
66 | myPClassifier = |
67 | (BRepClass3d_SolidClassifier*)myShapeClassifierMap.ChangeFromKey(SOL); |
68 | } |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : LoadShell |
73 | //purpose : |
74 | //======================================================================= |
75 | void TopOpeBRepTool_SolidClassifier::LoadShell(const TopoDS_Shell& SHE) |
76 | { |
77 | Standard_Boolean found = myShapeClassifierMap.Contains(SHE); |
78 | if ( !found ) { |
79 | myBuilder.MakeSolid(mySolid); |
80 | myBuilder.Add(mySolid, SHE); |
81 | |
82 | myPClassifier = new BRepClass3d_SolidClassifier(mySolid); |
83 | myShapeClassifierMap.Add(SHE, (Standard_Address)myPClassifier); |
84 | } |
85 | else { |
86 | myPClassifier = |
87 | (BRepClass3d_SolidClassifier*)myShapeClassifierMap.ChangeFromKey(SHE); |
88 | } |
89 | } |
90 | //modified by NIZNHY-PKV Mon Dec 16 10:53:41 2002 t |
91 | |
92 | //======================================================================= |
93 | //function : Clear |
94 | //purpose : |
95 | //======================================================================= |
96 | void TopOpeBRepTool_SolidClassifier::Clear() |
97 | { |
98 | myPClassifier = NULL; |
99 | //modified by NIZNHY-PKV Mon Dec 16 10:46:04 2002 f |
100 | //myClassifierMap.Clear(); |
101 | myShapeClassifierMap.Clear(); |
102 | //modified by NIZNHY-PKV Mon Dec 16 10:46:06 2002 t |
103 | myState = TopAbs_UNKNOWN; |
104 | myShell.Nullify(); |
105 | mySolid.Nullify(); |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : Classify |
110 | //purpose : |
111 | //======================================================================= |
112 | TopAbs_State TopOpeBRepTool_SolidClassifier::Classify (const TopoDS_Solid& SOL, |
113 | const gp_Pnt& P, |
114 | const Standard_Real Tol) |
115 | { |
116 | myPClassifier = NULL; |
117 | myState = TopAbs_UNKNOWN; |
118 | LoadSolid(SOL); |
119 | if (myPClassifier == NULL) return myState; |
120 | myPClassifier->Perform(P,Tol); |
121 | myState = myPClassifier->State(); |
122 | const TopoDS_Shape& fres = myPClassifier->Face(); |
123 | if (fres.IsNull()) { |
124 | // NYI : en cas d'elimination des faces EXTERNAL et INTERNAL par le |
125 | // classifier BRepClass3d_SolidClassifier, traiter quand meme ces faces |
126 | // pour generer l'etat ON/Solid quand le point est IN/face INTERNAL ou EXTERNAL |
127 | return myState; |
128 | } |
129 | TopAbs_Orientation ofres = fres.Orientation(); |
130 | if ( ofres == TopAbs_EXTERNAL ) { |
131 | if ( myState == TopAbs_IN ) myState = TopAbs_OUT; |
132 | else if ( myState == TopAbs_OUT ) myState = TopAbs_OUT; |
133 | else if ( myState == TopAbs_ON ) myState = TopAbs_ON; |
134 | else if ( myState == TopAbs_UNKNOWN ) myState = TopAbs_OUT; |
135 | } |
136 | else if ( ofres == TopAbs_INTERNAL ) { |
137 | if ( myState == TopAbs_IN ) myState = TopAbs_IN; |
138 | else if ( myState == TopAbs_OUT) myState = TopAbs_IN; |
139 | else if ( myState == TopAbs_ON ) myState = TopAbs_ON; |
140 | else if ( myState == TopAbs_UNKNOWN ) myState = TopAbs_IN; |
141 | } |
142 | return myState; |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : Classify |
147 | //purpose : |
148 | //======================================================================= |
149 | TopAbs_State TopOpeBRepTool_SolidClassifier::Classify(const TopoDS_Shell& SHE, |
150 | const gp_Pnt& P, |
151 | const Standard_Real Tol) |
152 | { |
153 | myPClassifier = NULL; |
154 | myState = TopAbs_UNKNOWN; |
155 | LoadShell(SHE); |
156 | if (myPClassifier == NULL) return myState; |
157 | myPClassifier->Perform(P,Tol); |
158 | myState = myPClassifier->State(); |
159 | return myState; |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : State |
164 | //purpose : |
165 | //======================================================================= |
166 | TopAbs_State TopOpeBRepTool_SolidClassifier::State() const |
167 | { |
168 | return myState; |
169 | } |
170 | //modified by NIZNHY-PKV Mon Dec 16 10:55:47 2002 f |
171 | /* |
172 | //======================================================================= |
173 | //function : LoadSolid |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | void TopOpeBRepTool_SolidClassifier::LoadSolid(const TopoDS_Solid& SOL) |
178 | { |
179 | Standard_Boolean found = myClassifierMap.Contains(SOL); |
180 | if ( !found ) { |
181 | myPClassifier = new BRepClass3d_SolidClassifier(SOL); |
182 | myClassifierMap.Add(SOL,*myPClassifier); |
183 | } |
184 | else { |
185 | myPClassifier = &myClassifierMap.ChangeFromKey(SOL); |
186 | } |
187 | #ifdef DEB |
188 | Standard_Integer i = |
189 | #endif |
190 | myClassifierMap.FindIndex(SOL); // DEB |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : LoadShell |
195 | //purpose : |
196 | //======================================================================= |
197 | void TopOpeBRepTool_SolidClassifier::LoadShell(const TopoDS_Shell& SHE) |
198 | { |
199 | Standard_Boolean found = myClassifierMap.Contains(SHE); |
200 | if ( !found ) { |
201 | myBuilder.MakeSolid(mySolid); |
202 | myBuilder.Add(mySolid,SHE); |
203 | TopoDS_Shell* pshe = (TopoDS_Shell*)&SHE; (*pshe).Free(Standard_True); |
204 | myPClassifier = new BRepClass3d_SolidClassifier(mySolid); |
205 | myClassifierMap.Add(SHE,*myPClassifier); |
206 | } |
207 | else { |
208 | myPClassifier = &myClassifierMap.ChangeFromKey(SHE); |
209 | } |
210 | #ifdef DEB |
211 | Standard_Integer i = |
212 | #endif |
213 | myClassifierMap.FindIndex(SHE); // DEB |
214 | } |
215 | */ |
216 | //modified by NIZNHY-PKV Mon Dec 16 10:55:56 2002 t |