973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | //szv#4 S4163 |
7fd59977 |
15 | |
16 | #include <BRep_Tool.hxx> |
17 | #include <Geom_Curve.hxx> |
42cf5bc1 |
18 | #include <gp_Pnt.hxx> |
19 | #include <gp_XYZ.hxx> |
7fd59977 |
20 | #include <Precision.hxx> |
7fd59977 |
21 | #include <ShapeAnalysis_Curve.hxx> |
22 | #include <ShapeAnalysis_Edge.hxx> |
42cf5bc1 |
23 | #include <ShapeAnalysis_WireVertex.hxx> |
24 | #include <ShapeExtend_WireData.hxx> |
25 | #include <TopoDS_Edge.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
27 | #include <TopoDS_Wire.hxx> |
7fd59977 |
28 | |
42cf5bc1 |
29 | //ied_modif_for_compil_Nov-19-1998 |
7fd59977 |
30 | //======================================================================= |
31 | //function : ShapeAnalysis_WireVertex |
32 | //purpose : |
33 | //======================================================================= |
7fd59977 |
34 | ShapeAnalysis_WireVertex::ShapeAnalysis_WireVertex() |
35 | { |
36 | myDone = Standard_False; |
37 | myPreci = Precision::Confusion(); |
38 | } |
39 | |
40 | //======================================================================= |
41 | //function : Init |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | void ShapeAnalysis_WireVertex::Init(const TopoDS_Wire& wire, const Standard_Real preci) |
46 | { |
47 | Init (new ShapeExtend_WireData (wire), preci); |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : Init |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | void ShapeAnalysis_WireVertex::Init(const Handle(ShapeExtend_WireData)& sbwd, const Standard_Real /*preci*/) |
56 | { |
57 | Standard_Integer nb = sbwd->NbEdges(); |
58 | if (nb == 0) return; |
59 | myDone = Standard_False; |
60 | myWire = sbwd; |
61 | myStat = new TColStd_HArray1OfInteger (1,nb); myStat->Init(0); |
62 | myPos = new TColgp_HArray1OfXYZ (1,nb); |
63 | myUPre = new TColStd_HArray1OfReal (1,nb); myUPre->Init(0.0); |
64 | myUFol = new TColStd_HArray1OfReal (1,nb); myUFol->Init(0.0); |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : Load |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | void ShapeAnalysis_WireVertex::Load(const TopoDS_Wire& wire) |
73 | { |
74 | Init (wire, myPreci); |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : Load |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | void ShapeAnalysis_WireVertex::Load(const Handle(ShapeExtend_WireData)& sbwd) |
83 | { |
84 | Init (sbwd, myPreci); |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : SetPrecision |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | void ShapeAnalysis_WireVertex::SetPrecision(const Standard_Real preci) |
93 | { |
94 | myPreci = preci; |
95 | myDone = Standard_False; |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Analyze |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | void ShapeAnalysis_WireVertex::Analyze() |
104 | { |
105 | if (myStat.IsNull()) return; |
106 | myDone = Standard_True; |
107 | // Analyse des vertex qui se suivent |
108 | Handle(Geom_Curve) c1, c2; |
109 | Standard_Real cf, cl, upre, ufol; |
110 | Standard_Integer i, j, nb = myStat->Length(), stat; |
111 | ShapeAnalysis_Edge EA; |
112 | for (i = 1; i <= nb; i ++) { |
113 | stat = -1; // au depart |
114 | |
115 | j = (i == nb ? 1 : i+1); |
116 | TopoDS_Edge E1 = myWire->Edge (i); |
117 | TopoDS_Edge E2 = myWire->Edge (j); |
118 | TopoDS_Vertex V1 = EA.LastVertex (myWire->Edge (i)); |
119 | TopoDS_Vertex V2 = EA.FirstVertex (myWire->Edge (j)); |
120 | gp_Pnt PV1 = BRep_Tool::Pnt (V1); |
121 | gp_Pnt PV2 = BRep_Tool::Pnt (V2); |
122 | Standard_Real tol1 = BRep_Tool::Tolerance (V1); |
123 | Standard_Real tol2 = BRep_Tool::Tolerance (V2); |
124 | EA.Curve3d (myWire->Edge (i),c1,cf,upre); |
125 | EA.Curve3d (myWire->Edge (j),c2,ufol,cl); |
126 | if (c1.IsNull() || c2.IsNull()) continue; // on ne peut rien faire ... |
127 | gp_Pnt P1 = c1->Value (upre); |
128 | gp_Pnt P2 = c2->Value (ufol); |
129 | |
130 | // Est-ce que le jeu de vertex convient ? (meme si V1 == V2, on verifie) |
131 | Standard_Real d1 = PV1.Distance (P1); |
132 | Standard_Real d2 = PV2.Distance (P2); |
133 | Standard_Real dd = PV1.Distance (PV2); |
134 | if (d1 <= tol1 && d2 <= tol2 && dd <= (tol1+tol2)) stat = 1; |
135 | else if (d1 <= myPreci && d2 <= myPreci && dd <= myPreci) stat = 2; |
136 | myStat->SetValue (i,-1); // par defaut |
137 | if (stat > 0) { if (V1 == V2) stat = 0; } |
138 | if (stat >= 0) { myStat->SetValue (i,stat); continue; } |
139 | // Restent les autres cas ! |
140 | |
141 | // Une edge se termine sur l autre : il faudra simplement relimiter |
142 | // Projection calculee sur une demi-edge (pour eviter les pbs de couture) |
143 | gp_Pnt PJ1,PJ2; |
144 | Standard_Real U1,U2; |
145 | Standard_Real dj1 = ShapeAnalysis_Curve().Project (c1,P2,myPreci,PJ1,U1,(cf+upre)/2,upre); |
146 | Standard_Real dj2 = ShapeAnalysis_Curve().Project (c2,P1,myPreci,PJ2,U2,ufol,(ufol+cl)/2); |
147 | if (dj1 <= myPreci) { SetStart (i,PJ1.XYZ(),U1); continue; } |
148 | else if (dj2 <= myPreci) { SetEnd (i,PJ2.XYZ(),U2); continue; } |
149 | |
150 | // Restent a verifier les intersections et prolongations ! |
151 | } |
152 | } |
153 | |
154 | //======================================================================= |
155 | //function : SetSameVertex |
156 | //purpose : |
157 | //======================================================================= |
158 | |
159 | void ShapeAnalysis_WireVertex::SetSameVertex(const Standard_Integer num) |
160 | { |
161 | myStat->SetValue (num,0); |
162 | } |
163 | |
164 | //======================================================================= |
165 | //function : SetSameCoords |
166 | //purpose : |
167 | //======================================================================= |
168 | |
169 | void ShapeAnalysis_WireVertex::SetSameCoords(const Standard_Integer num) |
170 | { |
171 | myStat->SetValue (num,1); |
172 | } |
173 | |
174 | //======================================================================= |
175 | //function : SetClose |
176 | //purpose : |
177 | //======================================================================= |
178 | |
179 | void ShapeAnalysis_WireVertex::SetClose(const Standard_Integer num) |
180 | { |
181 | myStat->SetValue (num,2); |
182 | } |
183 | |
184 | //======================================================================= |
185 | //function : SetEnd |
186 | //purpose : |
187 | //======================================================================= |
188 | |
189 | void ShapeAnalysis_WireVertex::SetEnd(const Standard_Integer num,const gp_XYZ& pos,const Standard_Real ufol) |
190 | { |
191 | myStat->SetValue (num,3); |
192 | myPos->SetValue (num,pos); |
193 | myUFol->SetValue (num,ufol); |
194 | } |
195 | |
196 | //======================================================================= |
197 | //function : SetStart |
198 | //purpose : |
199 | //======================================================================= |
200 | |
201 | void ShapeAnalysis_WireVertex::SetStart(const Standard_Integer num,const gp_XYZ& pos,const Standard_Real upre) |
202 | { |
203 | myStat->SetValue (num,4); |
204 | myPos->SetValue (num,pos); |
205 | myUFol->SetValue (num,upre); |
206 | } |
207 | |
208 | //======================================================================= |
209 | //function : SetInters |
210 | //purpose : |
211 | //======================================================================= |
212 | |
213 | void ShapeAnalysis_WireVertex::SetInters(const Standard_Integer num, const gp_XYZ& pos, |
214 | const Standard_Real upre, const Standard_Real ufol) |
215 | { |
216 | myStat->SetValue (num,5); |
217 | myPos->SetValue (num,pos); |
218 | myUPre->SetValue (num,upre); |
219 | myUFol->SetValue (num,ufol); |
220 | } |
221 | |
222 | //======================================================================= |
223 | //function : SetDisjoined |
224 | //purpose : |
225 | //======================================================================= |
226 | |
227 | void ShapeAnalysis_WireVertex::SetDisjoined(const Standard_Integer num) |
228 | { |
229 | myStat->SetValue (num,-1); |
230 | } |
231 | |
232 | //======================================================================= |
233 | //function : IsDone |
234 | //purpose : |
235 | //======================================================================= |
236 | |
237 | Standard_Boolean ShapeAnalysis_WireVertex::IsDone() const |
238 | { |
239 | return myDone; |
240 | } |
241 | |
242 | //======================================================================= |
243 | //function : Precision |
244 | //purpose : |
245 | //======================================================================= |
246 | |
247 | Standard_Real ShapeAnalysis_WireVertex::Precision() const |
248 | { |
249 | return myPreci; |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : NbEdges |
254 | //purpose : |
255 | //======================================================================= |
256 | |
257 | Standard_Integer ShapeAnalysis_WireVertex::NbEdges() const |
258 | { |
259 | return myWire->NbEdges(); |
260 | } |
261 | |
262 | //======================================================================= |
263 | //function : WireData |
264 | //purpose : |
265 | //======================================================================= |
266 | |
267 | const Handle(ShapeExtend_WireData)& ShapeAnalysis_WireVertex::WireData() const |
268 | { |
269 | return myWire; |
270 | } |
271 | |
272 | //======================================================================= |
273 | //function : Status |
274 | //purpose : |
275 | //======================================================================= |
276 | |
277 | Standard_Integer ShapeAnalysis_WireVertex::Status(const Standard_Integer num) const |
278 | { |
279 | return myStat->Value(num); |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : Position |
284 | //purpose : |
285 | //======================================================================= |
286 | |
287 | gp_XYZ ShapeAnalysis_WireVertex::Position(const Standard_Integer num) const |
288 | { |
289 | return myPos->Value(num); |
290 | } |
291 | |
292 | //======================================================================= |
293 | //function : UPrevious |
294 | //purpose : |
295 | //======================================================================= |
296 | |
297 | //szv#4:S4163:12Mar99 was bug: returned Integer |
298 | Standard_Real ShapeAnalysis_WireVertex::UPrevious(const Standard_Integer num) const |
299 | { |
300 | return myUPre->Value(num); |
301 | } |
302 | |
303 | //======================================================================= |
304 | //function : UFollowing |
305 | //purpose : |
306 | //======================================================================= |
307 | |
308 | //szv#4:S4163:12Mar99 was bug: returned Integer |
309 | Standard_Real ShapeAnalysis_WireVertex::UFollowing(const Standard_Integer num) const |
310 | { |
311 | return myUFol->Value(num); |
312 | } |
313 | |
314 | //======================================================================= |
315 | //function : Data |
316 | //purpose : |
317 | //======================================================================= |
318 | |
319 | Standard_Integer ShapeAnalysis_WireVertex::Data(const Standard_Integer num, gp_XYZ& pos, |
320 | Standard_Real& upre, Standard_Real& ufol) const |
321 | { |
322 | pos = myPos->Value(num); |
323 | upre = myUPre->Value(num); |
324 | ufol = myUFol->Value(num); |
325 | return myStat->Value(num); |
326 | } |
327 | |
328 | //======================================================================= |
329 | //function : NextStatus |
330 | //purpose : |
331 | //======================================================================= |
332 | |
333 | Standard_Integer ShapeAnalysis_WireVertex::NextStatus(const Standard_Integer stat, |
334 | const Standard_Integer num) const |
335 | { |
336 | //szv#4:S4163:12Mar99 optimized |
337 | if (!myStat.IsNull()) { |
338 | Standard_Integer i,nb = myStat->Length(); |
339 | for (i = num+1; i <= nb; i ++) if (myStat->Value(i) == stat) return i; |
340 | } |
341 | return 0; |
342 | } |
343 | |
344 | //======================================================================= |
345 | //function : NextCriter |
346 | //purpose : |
347 | //======================================================================= |
348 | |
349 | Standard_Integer ShapeAnalysis_WireVertex::NextCriter(const Standard_Integer crit, |
350 | const Standard_Integer num) const |
351 | { |
352 | //szv#4:S4163:12Mar99 optimized |
353 | if (!myStat.IsNull()) { |
354 | Standard_Integer i,nb = myStat->Length(); |
355 | for (i = num+1; i <= nb; i ++) { |
356 | Standard_Integer stat = myStat->Value(i); |
357 | if ((crit == -1 && stat < 0) || |
358 | (crit == 0 && stat == 0) || |
359 | (crit == 1 && stat > 0) || |
360 | (crit == 2 && (stat >= 0 && stat <= 2)) || |
361 | (crit == 3 && (stat == 1 || stat == 2)) || |
362 | (crit == 4 && stat > 2)) return i; |
363 | } |
364 | } |
365 | return 0; |
366 | } |