Commit | Line | Data |
---|---|---|
733a0e55 S |
1 | // File: HLRBRep_InternalAlgo.cxx |
2 | // Created: Thu Apr 17 21:49:17 1997 | |
3 | // Author: Christophe MARION | |
4 | // Copyright: OPEN CASCADE 2000 | |
7fd59977 | 5 | |
6 | #include <Standard_Stream.hxx> | |
7 | #include <HLRBRep_InternalAlgo.ixx> | |
8 | ||
9 | #include <Standard_ErrorHandler.hxx> | |
b8f2022a | 10 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 11 | #include <HLRAlgo.hxx> |
12 | #include <HLRBRep_ShapeToHLR.hxx> | |
13 | #include <HLRBRep_Hider.hxx> | |
14 | #include <stdio.h> | |
15 | ||
16 | extern Standard_Integer nbPtIntersection; // total P.I. | |
17 | extern Standard_Integer nbSegIntersection; // total S.I | |
18 | extern Standard_Integer nbClassification; // total classification | |
19 | extern Standard_Integer nbOkIntersection; // pairs of intersecting edges | |
20 | extern Standard_Integer nbCal1Intersection; // pairs of unrejected edges | |
21 | extern Standard_Integer nbCal2Intersection; // true intersections (not vertex) | |
22 | extern Standard_Integer nbCal3Intersection; // curve-surface intersections | |
23 | ||
24 | static Standard_Integer TRACE = Standard_True; | |
25 | static Standard_Integer TRACE10 = Standard_True; | |
26 | ||
27 | #define MinShBI1 MinMaxShBI[ 0] | |
28 | #define MinShBI2 MinMaxShBI[ 1] | |
29 | #define MinShBI3 MinMaxShBI[ 2] | |
30 | #define MinShBI4 MinMaxShBI[ 3] | |
31 | #define MinShBI5 MinMaxShBI[ 4] | |
32 | #define MinShBI6 MinMaxShBI[ 5] | |
33 | #define MinShBI7 MinMaxShBI[ 6] | |
34 | #define MinShBI8 MinMaxShBI[ 7] | |
35 | #define MaxShBI1 MinMaxShBI[ 8] | |
36 | #define MaxShBI2 MinMaxShBI[ 9] | |
37 | #define MaxShBI3 MinMaxShBI[10] | |
38 | #define MaxShBI4 MinMaxShBI[11] | |
39 | #define MaxShBI5 MinMaxShBI[12] | |
40 | #define MaxShBI6 MinMaxShBI[13] | |
41 | #define MaxShBI7 MinMaxShBI[14] | |
42 | #define MaxShBI8 MinMaxShBI[15] | |
43 | ||
44 | #define MinShBJ1 MinMaxShBJ[ 0] | |
45 | #define MinShBJ2 MinMaxShBJ[ 1] | |
46 | #define MinShBJ3 MinMaxShBJ[ 2] | |
47 | #define MinShBJ4 MinMaxShBJ[ 3] | |
48 | #define MinShBJ5 MinMaxShBJ[ 4] | |
49 | #define MinShBJ6 MinMaxShBJ[ 5] | |
50 | #define MinShBJ7 MinMaxShBJ[ 6] | |
51 | #define MinShBJ8 MinMaxShBJ[ 7] | |
52 | #define MaxShBJ1 MinMaxShBJ[ 8] | |
53 | #define MaxShBJ2 MinMaxShBJ[ 9] | |
54 | #define MaxShBJ3 MinMaxShBJ[10] | |
55 | #define MaxShBJ4 MinMaxShBJ[11] | |
56 | #define MaxShBJ5 MinMaxShBJ[12] | |
57 | #define MaxShBJ6 MinMaxShBJ[13] | |
58 | #define MaxShBJ7 MinMaxShBJ[14] | |
59 | #define MaxShBJ8 MinMaxShBJ[15] | |
60 | ||
61 | //======================================================================= | |
62 | //function : HLRBRep_InternalAlgo | |
63 | //purpose : | |
64 | //======================================================================= | |
65 | ||
66 | HLRBRep_InternalAlgo::HLRBRep_InternalAlgo () : | |
67 | myDebug (Standard_False) | |
68 | { | |
69 | } | |
70 | ||
71 | //======================================================================= | |
72 | //function : HLRBRep_InternalAlgo | |
73 | //purpose : | |
74 | //======================================================================= | |
75 | ||
76 | HLRBRep_InternalAlgo:: | |
77 | HLRBRep_InternalAlgo (const Handle(HLRBRep_InternalAlgo)& A) | |
78 | { | |
79 | myDS = A->DataStructure(); | |
80 | myProj = A->Projector(); | |
81 | myShapes = A->SeqOfShapeBounds(); | |
82 | myDebug = A->Debug(); | |
83 | } | |
84 | ||
85 | //======================================================================= | |
86 | //function : Projector | |
87 | //purpose : | |
88 | //======================================================================= | |
89 | ||
90 | void HLRBRep_InternalAlgo::Projector (const HLRAlgo_Projector& P) | |
91 | { | |
92 | myProj = P; | |
93 | } | |
94 | ||
95 | //======================================================================= | |
96 | //function : Projector | |
97 | //purpose : | |
98 | //======================================================================= | |
99 | ||
100 | HLRAlgo_Projector & HLRBRep_InternalAlgo::Projector () | |
101 | { return myProj; } | |
102 | ||
103 | //======================================================================= | |
104 | //function : Update | |
105 | //purpose : | |
106 | //======================================================================= | |
107 | ||
108 | void HLRBRep_InternalAlgo::Update () | |
109 | { | |
110 | if (!myShapes.IsEmpty()) { | |
111 | Standard_Integer n = myShapes.Length(); | |
112 | Handle(HLRBRep_Data) *DS = new Handle(HLRBRep_Data) [n]; | |
733a0e55 S |
113 | |
114 | Standard_Integer i,dv,de,df,nv=0,ne=0,nf=0; | |
7fd59977 | 115 | |
116 | for (i = 1; i <= n; i++) { | |
117 | HLRBRep_ShapeBounds& SB = myShapes(i); | |
118 | try { | |
119 | OCC_CATCH_SIGNALS | |
120 | DS[i-1] = HLRBRep_ShapeToHLR::Load(SB.Shape(), | |
121 | myProj, | |
122 | myMapOfShapeTool, | |
123 | SB.NbOfIso()); | |
124 | dv = DS[i-1]->NbVertices(); | |
125 | de = DS[i-1]->NbEdges (); | |
126 | df = DS[i-1]->NbFaces (); | |
127 | } | |
128 | catch(Standard_Failure) { | |
129 | cout << "An exception was catched when preparing the Shape " << i; | |
130 | cout << " and computing its OutLines " << endl; | |
131 | Handle(Standard_Failure) fail = Standard_Failure::Caught(); | |
132 | cout << fail << endl; | |
133 | DS[i-1] = new HLRBRep_Data(0,0,0); | |
134 | dv = 0; | |
135 | de = 0; | |
136 | df = 0; | |
137 | } | |
138 | ||
139 | SB = HLRBRep_ShapeBounds | |
140 | (SB.Shape(),SB.ShapeData(),SB.NbOfIso(),1,dv,1,de,1,df); | |
141 | nv += dv; | |
142 | ne += de; | |
143 | nf += df; | |
144 | } | |
145 | ||
146 | if (n == 1) myDS = DS[0]; | |
147 | else { | |
148 | myDS = new HLRBRep_Data(nv,ne,nf); | |
149 | nv = 0; | |
150 | ne = 0; | |
151 | nf = 0; | |
152 | ||
153 | for (i = 1; i <= n; i++) { | |
154 | HLRBRep_ShapeBounds& SB = myShapes(i); | |
155 | SB.Sizes(dv,de,df); | |
156 | SB.Translate(nv,ne,nf); | |
157 | myDS->Write(DS[i-1],nv,ne,nf); | |
158 | nv += dv; | |
159 | ne += de; | |
160 | nf += df; | |
161 | } | |
162 | } | |
163 | ||
164 | delete [] DS; | |
165 | ||
166 | myDS->Update(myProj); | |
167 | ||
168 | Standard_Integer ShapMin[16],ShapMax[16],MinMaxShap[16]; | |
169 | Standard_Integer TheMin[16],TheMax[16]; | |
170 | ||
171 | for (i = 1; i <= n; i++) { | |
172 | Standard_Boolean FirstTime = Standard_True; | |
173 | HLRBRep_ShapeBounds& SB = myShapes(i); | |
174 | Standard_Integer v1,v2,e1,e2,f1,f2; | |
175 | SB.Bounds(v1,v2,e1,e2,f1,f2); | |
176 | ||
177 | HLRBRep_EdgeData* ed = &(myDS->EDataArray (). ChangeValue(e1 - 1)); | |
178 | HLRBRep_FaceData* fd = &(myDS->FDataArray (). ChangeValue(f1 - 1)); | |
179 | ed++; | |
180 | fd++; | |
181 | ||
182 | for (Standard_Integer e = e1; e <= e2; e++) { | |
183 | HLRAlgo::DecodeMinMax(ed->MinMax(), | |
184 | (Standard_Address)TheMin, | |
185 | (Standard_Address)TheMax); | |
186 | if (FirstTime) { | |
187 | FirstTime = Standard_False; | |
188 | HLRAlgo::CopyMinMax((Standard_Address)TheMin, | |
189 | (Standard_Address)TheMax, | |
190 | (Standard_Address)ShapMin, | |
191 | (Standard_Address)ShapMax); | |
192 | } | |
193 | else | |
194 | HLRAlgo::AddMinMax((Standard_Address)TheMin, | |
195 | (Standard_Address)TheMax, | |
196 | (Standard_Address)ShapMin, | |
197 | (Standard_Address)ShapMax); | |
198 | ed++; | |
199 | } | |
200 | ||
201 | for (Standard_Integer f = f1; f <= f2; f++) { | |
202 | HLRAlgo::DecodeMinMax(fd->Wires()->MinMax(), | |
203 | (Standard_Address)TheMin, | |
204 | (Standard_Address)TheMax); | |
205 | HLRAlgo::AddMinMax((Standard_Address)TheMin, | |
206 | (Standard_Address)TheMax, | |
207 | (Standard_Address)ShapMin, | |
208 | (Standard_Address)ShapMax); | |
209 | fd++; | |
210 | } | |
211 | HLRAlgo::EncodeMinMax((Standard_Address)ShapMin, | |
212 | (Standard_Address)ShapMax, | |
213 | (Standard_Address)MinMaxShap); | |
214 | SB.UpdateMinMax((Standard_Address)MinMaxShap); | |
215 | } | |
216 | } | |
217 | } | |
218 | ||
219 | //======================================================================= | |
220 | //function : Load | |
221 | //purpose : | |
222 | //======================================================================= | |
223 | ||
224 | void HLRBRep_InternalAlgo::Load (const Handle(HLRTopoBRep_OutLiner)& S, | |
225 | const Handle(MMgt_TShared)& SData, | |
226 | const Standard_Integer nbIso) | |
227 | { | |
228 | myShapes.Append(HLRBRep_ShapeBounds(S,SData,nbIso,0,0,0,0,0,0)); | |
229 | myDS.Nullify(); | |
230 | } | |
231 | ||
232 | //======================================================================= | |
233 | //function : Load | |
234 | //purpose : | |
235 | //======================================================================= | |
236 | ||
237 | void HLRBRep_InternalAlgo::Load (const Handle(HLRTopoBRep_OutLiner)& S, | |
238 | const Standard_Integer nbIso) | |
239 | { | |
240 | myShapes.Append(HLRBRep_ShapeBounds(S,nbIso,0,0,0,0,0,0)); | |
241 | myDS.Nullify(); | |
242 | } | |
243 | ||
244 | //======================================================================= | |
245 | //function : Index | |
246 | //purpose : | |
247 | //======================================================================= | |
248 | ||
249 | Standard_Integer HLRBRep_InternalAlgo:: | |
250 | Index (const Handle(HLRTopoBRep_OutLiner)& S) const | |
251 | { | |
252 | Standard_Integer n = myShapes.Length(); | |
253 | ||
254 | for (Standard_Integer i = 1; i <= n; i++) | |
255 | if (myShapes(i).Shape() == S) return i; | |
256 | ||
257 | return 0; | |
258 | } | |
259 | ||
260 | //======================================================================= | |
261 | //function : Remove | |
262 | //purpose : | |
263 | //======================================================================= | |
264 | ||
265 | void HLRBRep_InternalAlgo::Remove (const Standard_Integer I) | |
266 | { | |
267 | Standard_OutOfRange_Raise_if | |
268 | (I == 0 || I > myShapes.Length(), | |
269 | "HLRBRep_InternalAlgo::Remove : unknown Shape"); | |
270 | myShapes.Remove(I); | |
271 | ||
272 | myMapOfShapeTool.Clear(); | |
273 | myDS.Nullify(); | |
274 | } | |
275 | ||
276 | //======================================================================= | |
277 | //function : ShapeData | |
278 | //purpose : | |
279 | //======================================================================= | |
280 | ||
281 | void HLRBRep_InternalAlgo::ShapeData (const Standard_Integer I, | |
282 | const Handle(MMgt_TShared)& SData) | |
283 | { | |
284 | Standard_OutOfRange_Raise_if | |
285 | (I == 0 || I > myShapes.Length(), | |
286 | "HLRBRep_InternalAlgo::ShapeData : unknown Shape"); | |
287 | ||
288 | myShapes(I).ShapeData(SData); | |
289 | } | |
290 | ||
291 | //======================================================================= | |
292 | //function : SeqOfShapeBounds | |
293 | //purpose : | |
294 | //======================================================================= | |
295 | ||
296 | HLRBRep_SeqOfShapeBounds & HLRBRep_InternalAlgo::SeqOfShapeBounds () | |
297 | { | |
298 | return myShapes; | |
299 | } | |
300 | ||
301 | //======================================================================= | |
302 | //function : NbShapes | |
303 | //purpose : | |
304 | //======================================================================= | |
305 | ||
306 | Standard_Integer HLRBRep_InternalAlgo::NbShapes () const | |
307 | { return myShapes.Length(); } | |
308 | ||
309 | //======================================================================= | |
310 | //function : ShapeBounds | |
311 | //purpose : | |
312 | //======================================================================= | |
313 | ||
314 | HLRBRep_ShapeBounds & HLRBRep_InternalAlgo:: | |
315 | ShapeBounds (const Standard_Integer I) | |
316 | { | |
317 | Standard_OutOfRange_Raise_if | |
318 | (I == 0 || I > myShapes.Length(), | |
319 | "HLRBRep_InternalAlgo::ShapeBounds : unknown Shape"); | |
320 | ||
321 | return myShapes(I); | |
322 | } | |
323 | ||
324 | //======================================================================= | |
325 | //function : InitEdgeStatus | |
326 | //purpose : | |
327 | //======================================================================= | |
328 | ||
329 | void HLRBRep_InternalAlgo::InitEdgeStatus () | |
330 | { | |
331 | Standard_Boolean visible; | |
332 | HLRBRep_FaceIterator faceIt; | |
333 | ||
334 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
335 | HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1)); | |
336 | Standard_Integer ne = myDS->NbEdges(); | |
337 | Standard_Integer nf = myDS->NbFaces(); | |
338 | ||
339 | for (Standard_Integer e = 1; e <= ne; e++) { | |
340 | if (ed->Selected()) ed->Status().ShowAll(); | |
341 | ed++; | |
342 | } | |
343 | // for (Standard_Integer f = 1; f <= nf; f++) { | |
344 | Standard_Integer f; | |
345 | for ( f = 1; f <= nf; f++) { | |
346 | if (fd->Selected()) { | |
347 | ||
348 | for (faceIt.InitEdge(*fd); | |
349 | faceIt.MoreEdge(); | |
350 | faceIt.NextEdge()) { | |
351 | HLRBRep_EdgeData* edf = &(myDS->EDataArray().ChangeValue(faceIt.Edge())); | |
352 | if (edf->Selected()) edf->Status().HideAll(); | |
353 | } | |
354 | } | |
355 | fd++; | |
356 | } | |
357 | ||
358 | fd = &(myDS->FDataArray().ChangeValue(1)); | |
359 | ||
360 | for (f = 1; f <= nf; f++) { | |
361 | visible = Standard_True; | |
362 | if (fd->Selected() && fd->Closed()) { | |
363 | if ( fd->Side()) visible = Standard_False; | |
364 | else if ( !fd->WithOutL()) { | |
365 | switch (fd->Orientation()) { | |
366 | case TopAbs_REVERSED : visible = fd->Back() ; break; | |
367 | case TopAbs_FORWARD : visible = !fd->Back() ; break; | |
368 | case TopAbs_EXTERNAL : | |
369 | case TopAbs_INTERNAL : visible = Standard_True; break; | |
370 | } | |
371 | } | |
372 | } | |
373 | if (visible) { | |
374 | ||
375 | for (faceIt.InitEdge(*fd); | |
376 | faceIt.MoreEdge(); | |
377 | faceIt.NextEdge()) { | |
378 | Standard_Integer E = faceIt.Edge(); | |
379 | HLRBRep_EdgeData* edf = &(myDS->EDataArray().ChangeValue(E)); | |
380 | if ( edf->Selected() && | |
381 | !edf->Vertical()) | |
382 | edf->Status().ShowAll(); | |
383 | } | |
384 | } | |
385 | fd++; | |
386 | } | |
387 | } | |
388 | ||
389 | //======================================================================= | |
390 | //function : Select | |
391 | //purpose : | |
392 | //======================================================================= | |
393 | ||
394 | void HLRBRep_InternalAlgo::Select () | |
395 | { | |
396 | if (!myDS.IsNull()) { | |
397 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
398 | HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1)); | |
399 | Standard_Integer ne = myDS->NbEdges(); | |
400 | Standard_Integer nf = myDS->NbFaces(); | |
401 | ||
402 | for (Standard_Integer e = 1; e <= ne; e++) { | |
403 | ed->Selected(Standard_True); | |
404 | ed++; | |
405 | } | |
406 | ||
407 | for (Standard_Integer f = 1; f <= nf; f++) { | |
408 | fd->Selected(Standard_True); | |
409 | fd++; | |
410 | } | |
411 | } | |
412 | } | |
413 | ||
414 | //======================================================================= | |
415 | //function : Select | |
416 | //purpose : | |
417 | //======================================================================= | |
418 | ||
419 | void HLRBRep_InternalAlgo::Select (const Standard_Integer I) | |
420 | { | |
421 | if (!myDS.IsNull()) { | |
422 | Standard_OutOfRange_Raise_if | |
423 | (I == 0 || I > myShapes.Length(), | |
424 | "HLRBRep_InternalAlgo::Select : unknown Shape"); | |
425 | ||
426 | Standard_Integer v1,v2,e1,e2,f1,f2; | |
427 | myShapes(I).Bounds(v1,v2,e1,e2,f1,f2); | |
428 | ||
429 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
430 | HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1)); | |
431 | Standard_Integer ne = myDS->NbEdges(); | |
432 | Standard_Integer nf = myDS->NbFaces(); | |
433 | ||
434 | for (Standard_Integer e = 1; e <= ne; e++) { | |
435 | ed->Selected(e >= e1 && e <= e2); | |
436 | ed++; | |
437 | } | |
438 | ||
439 | for (Standard_Integer f = 1; f <= nf; f++) { | |
440 | fd->Selected(f >= f1 && f <= f2); | |
441 | fd++; | |
442 | } | |
443 | } | |
444 | } | |
445 | ||
446 | //======================================================================= | |
447 | //function : SelectEdge | |
448 | //purpose : | |
449 | //======================================================================= | |
450 | ||
451 | void HLRBRep_InternalAlgo::SelectEdge (const Standard_Integer I) | |
452 | { | |
453 | if (!myDS.IsNull()) { | |
454 | Standard_OutOfRange_Raise_if | |
455 | (I == 0 || I > myShapes.Length(), | |
456 | "HLRBRep_InternalAlgo::SelectEdge : unknown Shape"); | |
457 | ||
458 | Standard_Integer v1,v2,e1,e2,f1,f2; | |
459 | myShapes(I).Bounds(v1,v2,e1,e2,f1,f2); | |
460 | ||
461 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
462 | Standard_Integer ne = myDS->NbEdges(); | |
463 | ||
464 | for (Standard_Integer e = 1; e <= ne; e++) { | |
465 | ed->Selected(e >= e1 && e <= e2); | |
466 | ed++; | |
467 | } | |
468 | } | |
469 | } | |
470 | ||
471 | //======================================================================= | |
472 | //function : SelectFace | |
473 | //purpose : | |
474 | //======================================================================= | |
475 | ||
476 | void HLRBRep_InternalAlgo::SelectFace (const Standard_Integer I) | |
477 | { | |
478 | if (!myDS.IsNull()) { | |
479 | Standard_OutOfRange_Raise_if | |
480 | (I == 0 || I > myShapes.Length(), | |
481 | "HLRBRep_InternalAlgo::SelectFace : unknown Shape"); | |
482 | ||
483 | Standard_Integer v1,v2,e1,e2,f1,f2; | |
484 | myShapes(I).Bounds(v1,v2,e1,e2,f1,f2); | |
485 | ||
486 | HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1)); | |
487 | Standard_Integer nf = myDS->NbFaces(); | |
488 | ||
489 | for (Standard_Integer f = 1; f <= nf; f++) { | |
490 | fd->Selected(f >= f1 && f <= f2); | |
491 | fd++; | |
492 | } | |
493 | } | |
494 | } | |
495 | ||
496 | //======================================================================= | |
497 | //function : ShowAll | |
498 | //purpose : | |
499 | //======================================================================= | |
500 | ||
501 | void HLRBRep_InternalAlgo::ShowAll () | |
502 | { | |
503 | if (!myDS.IsNull()) { | |
504 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
505 | Standard_Integer ne = myDS->NbEdges(); | |
506 | ||
507 | for (Standard_Integer ie = 1; ie <= ne; ie++) { | |
508 | ed->Status().ShowAll(); | |
509 | ed++; | |
510 | } | |
511 | } | |
512 | } | |
513 | ||
514 | //======================================================================= | |
515 | //function : ShowAll | |
516 | //purpose : | |
517 | //======================================================================= | |
518 | ||
519 | void HLRBRep_InternalAlgo::ShowAll (const Standard_Integer I) | |
520 | { | |
521 | if (!myDS.IsNull()) { | |
522 | Standard_OutOfRange_Raise_if | |
523 | (I == 0 || I > myShapes.Length(), | |
524 | "HLRBRep_InternalAlgo::ShowAll : unknown Shape"); | |
525 | ||
526 | Select(I); | |
527 | ||
528 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
529 | Standard_Integer ne = myDS->NbEdges(); | |
530 | ||
531 | for (Standard_Integer e = 1; e <= ne; e++) { | |
532 | if (ed->Selected()) ed->Status().ShowAll(); | |
533 | ed++; | |
534 | } | |
535 | } | |
536 | } | |
537 | ||
538 | //======================================================================= | |
539 | //function : HideAll | |
540 | //purpose : | |
541 | //======================================================================= | |
542 | ||
543 | void HLRBRep_InternalAlgo::HideAll () | |
544 | { | |
545 | if (!myDS.IsNull()) { | |
546 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
547 | Standard_Integer ne = myDS->NbEdges(); | |
548 | ||
549 | for (Standard_Integer ie = 1; ie <= ne; ie++) { | |
550 | ed->Status().HideAll(); | |
551 | ed++; | |
552 | } | |
553 | } | |
554 | } | |
555 | ||
556 | //======================================================================= | |
557 | //function : HideAll | |
558 | //purpose : | |
559 | //======================================================================= | |
560 | ||
561 | void HLRBRep_InternalAlgo::HideAll (const Standard_Integer I) | |
562 | { | |
563 | if (!myDS.IsNull()) { | |
564 | Standard_OutOfRange_Raise_if | |
565 | (I == 0 || I > myShapes.Length(), | |
566 | "HLRBRep_InternalAlgo::HideAll : unknown Shape"); | |
567 | ||
568 | Select(I); | |
569 | ||
570 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
571 | Standard_Integer ne = myDS->NbEdges(); | |
572 | ||
573 | for (Standard_Integer e = 1; e <= ne; e++) { | |
574 | if (ed->Selected()) ed->Status().HideAll(); | |
575 | ed++; | |
576 | } | |
577 | } | |
578 | } | |
579 | ||
580 | //======================================================================= | |
581 | //function : PartialHide | |
582 | //purpose : | |
583 | //======================================================================= | |
584 | ||
585 | void HLRBRep_InternalAlgo::PartialHide () | |
586 | { | |
587 | if (!myDS.IsNull()) { | |
588 | Standard_Integer i,n = myShapes.Length(); | |
589 | ||
590 | if (myDebug) | |
591 | cout << " Partial hiding" << endl << endl; | |
592 | ||
593 | for (i = 1; i <= n; i++) | |
594 | Hide(i); | |
595 | ||
596 | Select(); | |
597 | } | |
598 | } | |
599 | ||
600 | //======================================================================= | |
601 | //function : Hide | |
602 | //purpose : | |
603 | //======================================================================= | |
604 | ||
605 | void HLRBRep_InternalAlgo::Hide () | |
606 | { | |
607 | if (!myDS.IsNull()) { | |
608 | Standard_Integer i,j,n = myShapes.Length(); | |
609 | ||
610 | if (myDebug) | |
611 | cout << " Total hiding" << endl; | |
612 | ||
613 | for (i = 1; i <= n; i++) | |
614 | Hide(i); | |
615 | ||
616 | for (i = 1; i <= n; i++) | |
617 | for (j = 1; j <= n; j++) | |
618 | if (i != j) Hide(i,j); | |
619 | ||
620 | Select(); | |
621 | } | |
622 | } | |
623 | ||
624 | //======================================================================= | |
625 | //function : Hide | |
626 | //purpose : | |
627 | //======================================================================= | |
628 | ||
629 | void HLRBRep_InternalAlgo::Hide (const Standard_Integer I) | |
630 | { | |
631 | if (!myDS.IsNull()) { | |
632 | Standard_OutOfRange_Raise_if | |
633 | (I == 0 || I > myShapes.Length(), | |
634 | "HLRBRep_InternalAlgo::Hide : unknown Shape"); | |
635 | ||
636 | if (myDebug) | |
637 | cout << " hiding the shape " << I << " by itself" << endl; | |
638 | ||
639 | Select(I); | |
640 | InitEdgeStatus(); | |
641 | HideSelected(I,Standard_True); | |
642 | } | |
643 | } | |
644 | ||
645 | //======================================================================= | |
646 | //function : Hide | |
647 | //purpose : | |
648 | //======================================================================= | |
649 | ||
650 | void HLRBRep_InternalAlgo::Hide (const Standard_Integer I, | |
651 | const Standard_Integer J) | |
652 | { | |
653 | if (!myDS.IsNull()) { | |
654 | Standard_OutOfRange_Raise_if | |
655 | (I == 0 || I > myShapes.Length() || | |
656 | J == 0 || J > myShapes.Length(), | |
657 | "HLRBRep_InternalAlgo::Hide : unknown Shapes"); | |
658 | ||
659 | if (I == J) Hide(I); | |
660 | else { | |
661 | Standard_Integer* MinMaxShBI = | |
662 | (Standard_Integer*)myShapes(I).MinMax(); | |
663 | Standard_Integer* MinMaxShBJ = | |
664 | (Standard_Integer*)myShapes(J).MinMax(); | |
665 | if (((MaxShBJ1 - MinShBI1) & 0x80008000) == 0 && | |
666 | ((MaxShBI1 - MinShBJ1) & 0x80008000) == 0 && | |
667 | ((MaxShBJ2 - MinShBI2) & 0x80008000) == 0 && | |
668 | ((MaxShBI2 - MinShBJ2) & 0x80008000) == 0 && | |
669 | ((MaxShBJ3 - MinShBI3) & 0x80008000) == 0 && | |
670 | ((MaxShBI3 - MinShBJ3) & 0x80008000) == 0 && | |
671 | ((MaxShBJ4 - MinShBI4) & 0x80008000) == 0 && | |
672 | ((MaxShBI4 - MinShBJ4) & 0x80008000) == 0 && | |
673 | ((MaxShBJ5 - MinShBI5) & 0x80008000) == 0 && | |
674 | ((MaxShBI5 - MinShBJ5) & 0x80008000) == 0 && | |
675 | ((MaxShBJ6 - MinShBI6) & 0x80008000) == 0 && | |
676 | ((MaxShBI6 - MinShBJ6) & 0x80008000) == 0 && | |
677 | ((MaxShBJ7 - MinShBI7) & 0x80008000) == 0 && | |
678 | ((MaxShBJ8 - MinShBI8) & 0x80008000) == 0) { | |
679 | if (myDebug) { | |
680 | cout << " hiding the shape " << I; | |
681 | cout << " by the shape : " << J << endl; | |
682 | } | |
683 | SelectEdge(I); | |
684 | SelectFace(J); | |
685 | HideSelected(I,Standard_False); | |
686 | } | |
687 | } | |
688 | } | |
689 | } | |
690 | ||
691 | //======================================================================= | |
692 | //function : HideSelected | |
693 | //purpose : | |
694 | //======================================================================= | |
695 | ||
696 | void HLRBRep_InternalAlgo::HideSelected (const Standard_Integer I, | |
697 | const Standard_Boolean SideFace) | |
698 | { | |
699 | Standard_Integer e,f,j,nbVisEdges,nbSelEdges,nbSelFaces,nbCache; | |
700 | Standard_Integer nbFSide,nbFSimp; | |
701 | ||
702 | #ifdef DEB | |
703 | if (myDebug) { | |
704 | nbPtIntersection = 0; | |
705 | nbSegIntersection = 0; | |
706 | nbOkIntersection = 0; | |
707 | nbClassification = 0; | |
708 | nbCal1Intersection = 0; | |
709 | nbCal2Intersection = 0; | |
710 | nbCal3Intersection = 0; | |
711 | } | |
712 | #endif | |
713 | ||
714 | HLRBRep_ShapeBounds& SB = myShapes(I); | |
715 | Standard_Integer v1,v2,e1,e2,f1,f2; | |
716 | SB.Bounds(v1,v2,e1,e2,f1,f2); | |
717 | ||
718 | if (e2 >= e1) { | |
719 | myDS->InitBoundSort(SB.MinMax(),e1,e2); | |
720 | HLRBRep_Hider Cache(myDS); | |
721 | HLRBRep_EdgeData* ed = &(myDS->EDataArray().ChangeValue(1)); | |
722 | HLRBRep_FaceData* fd = &(myDS->FDataArray().ChangeValue(1)); | |
723 | Standard_Integer ne = myDS->NbEdges(); | |
724 | Standard_Integer nf = myDS->NbFaces(); | |
725 | ||
726 | if (myDebug) { | |
727 | nbVisEdges = 0; | |
728 | nbSelEdges = 0; | |
729 | nbSelFaces = 0; | |
730 | nbCache = 0; | |
731 | nbFSide = 0; | |
732 | nbFSimp = 0; | |
733 | ||
734 | for (e = 1; e <= ne; e++) { | |
735 | if (ed->Selected()) { | |
736 | nbSelEdges++; | |
737 | if (!ed->Status().AllHidden()) nbVisEdges++; | |
738 | } | |
739 | ed++; | |
740 | } | |
741 | ||
742 | for (f = 1; f <= nf; f++) { | |
743 | if (fd->Selected()) { | |
744 | nbSelFaces++; | |
745 | if (fd->Hiding()) nbCache++; | |
746 | if (fd->Side ()) nbFSide++; | |
747 | if (fd->Simple()) nbFSimp++; | |
748 | } | |
749 | fd++; | |
750 | } | |
751 | ||
752 | cout << endl; | |
753 | cout << "Vertices : " << setw(5) << myDS->NbVertices() << endl; | |
754 | cout << "Edges : " << setw(5) << myDS->NbEdges() << " , "; | |
755 | cout << "Selected : " << setw(5) << nbSelEdges << " , "; | |
756 | cout << "Visibles : " << setw(5) << nbVisEdges << endl; | |
757 | cout << "Faces : " << setw(5) << myDS->NbFaces() << " , "; | |
758 | cout << "Selected : " << setw(5) << nbSelFaces << " , "; | |
759 | cout << "Simple : " << setw(5) << nbFSimp << endl; | |
760 | if (SideFace) | |
761 | cout << "Side : " << setw(5) << nbFSide << " , "; | |
762 | cout << "Cachantes : " << setw(5) << nbCache << endl << endl; | |
763 | } | |
764 | ||
765 | Standard_Integer QWE=0,QWEQWE; | |
766 | QWEQWE=nf/10; | |
767 | ||
768 | if (SideFace) { | |
769 | j = 0; | |
770 | fd = &(myDS->FDataArray().ChangeValue(1)); | |
771 | ||
772 | for (f = 1; f <= nf; f++) { | |
773 | if (fd->Selected()) { | |
774 | if (fd->Side()) { | |
775 | if(TRACE10) { | |
776 | if(++QWE>QWEQWE) { | |
777 | QWE=0; | |
778 | cout<<"*"; | |
779 | } | |
780 | } | |
781 | else { | |
782 | if (myDebug && TRACE) { | |
783 | j++; | |
784 | cout << " OwnHiding " << j << " of face : " << f << endl; | |
785 | } | |
786 | } | |
787 | Cache.OwnHiding(f); | |
788 | } | |
789 | } | |
790 | fd++; | |
791 | } | |
792 | } | |
793 | ||
794 | ||
795 | //-- | |
b8f2022a D |
796 | TColStd_Array1OfInteger Val(1, nf); |
797 | TColStd_Array1OfReal Size(1, nf); | |
798 | TColStd_Array1OfInteger Index(1, nf); | |
7fd59977 | 799 | |
800 | ||
801 | fd = &(myDS->FDataArray().ChangeValue(1)); | |
802 | for (f = 1; f <= nf; f++) { | |
b8f2022a D |
803 | if(fd->Plane()) Val(f)=10; |
804 | else if(fd->Cylinder()) Val(f)=9; | |
805 | else if(fd->Cone()) Val(f)=8; | |
806 | else if(fd->Sphere()) Val(f)=7; | |
807 | else if(fd->Torus()) Val(f)=6; | |
808 | else Val(f)=0; | |
809 | if(fd->Cut()) Val(f)-=10; | |
810 | if(fd->Side()) Val(f)-=100; | |
811 | if(fd->WithOutL()) Val(f)-=20; | |
7fd59977 | 812 | |
b8f2022a | 813 | Size(f)=fd->Size(); |
7fd59977 | 814 | fd++; |
815 | } | |
816 | ||
817 | for(Standard_Integer tt=1;tt<=nf;tt++) { | |
b8f2022a | 818 | Index(tt)=tt; |
7fd59977 | 819 | } |
820 | ||
821 | //-- ====================================================================== | |
822 | /* Standard_Boolean TriOk; //-- a refaire | |
823 | do { | |
824 | Standard_Integer t,tp1; | |
825 | TriOk=Standard_True; | |
826 | for(t=1,tp1=2;t<nf;t++,tp1++) { | |
b8f2022a D |
827 | if(Val(Index(t))<Val(Index(tp1))) { |
828 | Standard_Integer q=Index(t); Index(t)=Index(tp1); Index(tp1)=q; | |
7fd59977 | 829 | TriOk=Standard_False; |
830 | } | |
b8f2022a D |
831 | else if(Val(Index(t))==Val(Index(tp1))) { |
832 | if(Size(Index(t))<Size(Index(tp1))) { | |
833 | Standard_Integer q=Index(t); Index(t)=Index(tp1); Index(tp1)=q; | |
7fd59977 | 834 | TriOk=Standard_False; |
835 | } | |
836 | } | |
837 | } | |
838 | } | |
839 | while(TriOk==Standard_False); | |
840 | */ | |
841 | //-- ====================================================================== | |
842 | if(nf>2) { | |
843 | Standard_Integer i,ir,j,l; | |
844 | Standard_Integer rra; | |
845 | l=(nf>>1)+1; | |
846 | ir=nf; | |
847 | for(;;) { | |
848 | if(l>1) { | |
b8f2022a | 849 | rra=Index(--l); |
7fd59977 | 850 | } |
851 | else { | |
b8f2022a D |
852 | rra=Index(ir); |
853 | Index(ir)=Index(1); | |
7fd59977 | 854 | if(--ir == 1) { |
b8f2022a | 855 | Index(1)=rra; |
7fd59977 | 856 | break; |
857 | } | |
858 | } | |
859 | i=l; | |
860 | j=l+l; | |
861 | while(j<=ir) { | |
862 | if(j<ir) { | |
b8f2022a | 863 | if(Val(Index(j)) > Val(Index(j+1))) |
7fd59977 | 864 | j++; |
b8f2022a D |
865 | else if(Val(Index(j)) == Val(Index(j+1))) { |
866 | if(Size(Index(j)) > Size(Index(j+1))) | |
7fd59977 | 867 | j++; |
868 | } | |
869 | } | |
b8f2022a D |
870 | if(Val(rra) > Val(Index(j))) { |
871 | Index(i)=Index(j); | |
7fd59977 | 872 | i=j; |
873 | j<<=1; | |
874 | } | |
b8f2022a D |
875 | else if((Val(rra) == Val(Index(j))) && (Size(rra) > Size(Index(j)))) { |
876 | Index(i)=Index(j); | |
7fd59977 | 877 | i=j; |
878 | j<<=1; | |
879 | } | |
880 | else { | |
881 | j=ir+1; | |
882 | } | |
883 | } | |
b8f2022a | 884 | Index(i)=rra; |
7fd59977 | 885 | } |
886 | } | |
887 | ||
888 | j = 0; | |
889 | HLRBRep_Array1OfFData& FD = myDS->FDataArray(); | |
890 | ||
891 | QWE=0; | |
892 | for (f = 1; f <= nf; f++) { | |
b8f2022a | 893 | Standard_Integer fi = Index(f); |
7fd59977 | 894 | fd=&(FD.ChangeValue(fi)); |
895 | if (fd->Selected()) { | |
896 | if (fd->Hiding()) { | |
897 | if(TRACE10 && TRACE==Standard_False) { | |
898 | if(++QWE>QWEQWE) { | |
899 | cout<<"."; | |
900 | QWE=0; | |
901 | } | |
902 | } | |
903 | else if (myDebug && TRACE) { | |
904 | static int rty=0; | |
905 | j++; | |
906 | printf("%6d",fi); fflush(stdout); | |
907 | if(++rty>25) { rty=0; printf("\n"); } | |
908 | } | |
909 | Cache.Hide(fi,myMapOfShapeTool); | |
910 | } | |
911 | } | |
912 | } | |
913 | ||
7fd59977 | 914 | #ifdef DEB |
915 | if (myDebug) { | |
916 | fd = &(myDS->FDataArray().ChangeValue(1)); | |
917 | nbFSimp = 0; | |
918 | ||
919 | for (f = 1; f <= nf; f++) { | |
920 | if (fd->Selected() && fd->Simple()) | |
921 | nbFSimp++; | |
922 | fd++; | |
923 | } | |
924 | ||
925 | cout << "\n"; | |
926 | cout << "Simple Faces : "; | |
927 | cout << nbFSimp << "\n"; | |
928 | cout << "Intersections calculees : "; | |
929 | cout << nbCal2Intersection << "\n"; | |
930 | cout << "Intersections Ok : "; | |
931 | cout << nbOkIntersection << "\n"; | |
932 | cout << "Points : "; | |
933 | cout << nbPtIntersection << "\n"; | |
934 | cout << "Segments : "; | |
935 | cout << nbSegIntersection << "\n"; | |
936 | cout << "Classification : "; | |
937 | cout << nbClassification << "\n"; | |
938 | cout << "Intersections curve-surface : "; | |
939 | cout << nbCal3Intersection << "\n"; | |
940 | cout << endl << endl; | |
941 | } | |
942 | #endif | |
943 | } | |
944 | } | |
945 | ||
946 | //======================================================================= | |
947 | //function : Debug | |
948 | //purpose : | |
949 | //======================================================================= | |
950 | ||
951 | void HLRBRep_InternalAlgo::Debug (const Standard_Boolean deb) | |
952 | { myDebug = deb; } | |
953 | ||
954 | //======================================================================= | |
955 | //function : Debug | |
956 | //purpose : | |
957 | //======================================================================= | |
958 | ||
959 | Standard_Boolean HLRBRep_InternalAlgo::Debug () const | |
960 | { return myDebug; } | |
961 | ||
962 | //======================================================================= | |
963 | //function : DataStructure | |
964 | //purpose : | |
965 | //======================================================================= | |
966 | ||
967 | Handle(HLRBRep_Data) HLRBRep_InternalAlgo::DataStructure () const | |
968 | { return myDS; } |