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