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