1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
// File: HLRBRep_Hider.cxx
// Created: Thu Apr 17 19:33:55 1997
// Author: Christophe MARION
// <cma@partox.paris1.matra-dtv.fr>
#define No_Standard_OutOfRange
#include <HLRBRep_Hider.ixx>
#include <HLRAlgo_Coincidence.hxx>
#include <HLRAlgo_Interference.hxx>
#include <HLRAlgo_InterferenceList.hxx>
#include <HLRAlgo_ListIteratorOfInterferenceList.hxx>
#include <HLRAlgo_Intersection.hxx>
#include <HLRBRep_EdgeIList.hxx>
#include <HLRBRep_EdgeBuilder.hxx>
#include <HLRBRep_VertexList.hxx>
#include <HLRBRep_EdgeInterferenceTool.hxx>
#include <Standard_ErrorHandler.hxx>
//=======================================================================
//function : HLRBRep_Hider
//purpose :
//=======================================================================
HLRBRep_Hider::
HLRBRep_Hider (const Handle(HLRBRep_Data)& DS) :
myDS(DS)
{}
//=======================================================================
//function : OwnHiding
//purpose :
//=======================================================================
void HLRBRep_Hider::OwnHiding(const Standard_Integer)
{
}
//=======================================================================
//function : Hide
//purpose :
//=======================================================================
void HLRBRep_Hider::Hide(const Standard_Integer FI,
BRepTopAdaptor_MapOfShapeTool& MST)
{
// *****************************************************************
//
// This algorithm hides a set of edges stored in the data structure <myDS>
// with the hiding face number FI in <myDS>.
//
// Outline of the algorithm
//
// 1. Loop on the Edges (not hidden and not rejected by the face minmax)
//
// The rejections depending of the face are
// - Edge above the face
// - Edge belonging to the face
// - Edge rejected by a wire minmax
//
// Compute interferences with the not rejected edges of the face.
// Store IN and ON interferences in two sorted lists
// ILHidden and ILOn
// If ILOn is not empty
// Resolve ComplexTransitions in ILOn
// Resolve ON Intersections in ILOn
// An On interference may become
// IN : Move it from ILOn to ILHidden
// OUT : Remove it from ILOn
// If ILHidden and ILOn are empty
// intersect the edge with the face and classify the Edge.
// - if inside and under the face hide it.
// Else
// If ILHidden is not empty
// Resolve ComplexTransitions in ILHidden
// Build Hidden parts of the edge
// - Hide them
// Build visible parts of the edge
// Build Parts of the edge under the boundary of the face
// - Hide them as Boundary
// If ILOn is not empty
// Build ON parts of the edge
// - Hide them as ON parts
// Build Parts of the edge on the boundary of the face
// - Hide them as ON parts on Boundary
//
//
// *****************************************************************
myDS->InitEdge(FI,MST);
if (!myDS->MoreEdge()) // there is nothing to do
return; // **********************
HLRBRep_EdgeInterferenceTool EIT(myDS); // List of Intersections
HLRBRep_Array1OfEData& myEData = myDS->EDataArray();
#ifdef DEB
Standard_Integer EToBeChecked = -1;
#endif
for (; myDS->MoreEdge(); myDS->NextEdge()) { // loop on the Edges
Standard_Integer E = myDS->Edge(); // *****************
#ifdef DEB
if(E == EToBeChecked) {
cout << E << endl;
}
#endif
try {
OCC_CATCH_SIGNALS
Standard_Boolean hasOut = Standard_False;
HLRAlgo_InterferenceList ILHidden;
HLRAlgo_InterferenceList ILOn;
EIT.LoadEdge();
for (myDS->InitInterference(); // intersections with face-edges
myDS->MoreInterference(); // *****************************
myDS->NextInterference()) {
if (myDS->RejectedInterference()) {
if (myDS->AboveInterference() &&
myDS->SimpleHidingFace ()) {
hasOut = Standard_True;
}
}
else {
HLRAlgo_Interference& Int = myDS->Interference();
switch (Int.Intersection().State()) {
case TopAbs_IN :
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT); break;
case TopAbs_ON :
HLRBRep_EdgeIList::AddInterference(ILOn ,Int,EIT); break;
case TopAbs_OUT :
case TopAbs_UNKNOWN : break;
}
}
}
//-- ============================================================
Standard_Boolean Modif;
do {
Modif = Standard_False;
HLRAlgo_ListIteratorOfInterferenceList ItSegHidden1(ILHidden);
while(ItSegHidden1.More() && Modif==Standard_False) {
HLRAlgo_Interference& Int1 = ItSegHidden1.Value();
Standard_Integer numseg1=Int1.Intersection().SegIndex();
if(numseg1!=0) {
HLRAlgo_ListIteratorOfInterferenceList ItSegHidden2(ILHidden);
while(ItSegHidden2.More() && Modif==Standard_False) {
HLRAlgo_Interference& Int2 = ItSegHidden2.Value();
Standard_Integer numseg2=Int2.Intersection().SegIndex();
if(numseg1+numseg2 == 0) {
//--printf("\nHidden Traitement du segment %d %d\n",numseg1,numseg2); fflush(stdout);
TopAbs_State stbef1,staft1,stbef2,staft2;
Int1.Boundary().State3D(stbef1,staft1);
Int2.Boundary().State3D(stbef2,staft2);
if(Int1.Orientation() == Int2.Orientation()) {
if(Int1.Transition() == Int2.Transition()) {
if(stbef1==stbef2 && staft1==staft2 && stbef1!=TopAbs_ON && staft1!=TopAbs_ON ) {
//-- printf("\n Index1 = %d Index2 = %d\n",Int1.Intersection().Index(),Int2.Intersection().Index());
Standard_Integer nind=-1;
if(Int1.Intersection().Index()!=0) {
nind=Int1.Intersection().Index();
}
if(Int2.Intersection().Index()!=0) {
if(nind!=-1) {
if(Int1.Intersection().Index() != Int2.Intersection().Index()) {
nind=-1;
}
}
else {
nind=Int2.Intersection().Index();
}
}
if(Int1.Intersection().Index()==0 && Int2.Intersection().Index()==0) nind=0;
if(nind!=-1) {
//-- printf("\n Segment Supprime\n"); fflush(stdout);
HLRAlgo_Intersection& inter = Int1.ChangeIntersection();
inter.SegIndex(nind);
Standard_Real p1 = Int1.Intersection().Parameter();
Standard_Real p2 = Int2.Intersection().Parameter();
inter.Parameter((p1+p2)*0.5);
Int1.BoundaryTransition(TopAbs_EXTERNAL);
ILHidden.Remove(ItSegHidden2);
Modif=Standard_True;
}
}
}
}
}
if(Modif==Standard_False) {
ItSegHidden2.Next();
}
}
}
if(Modif==Standard_False) {
ItSegHidden1.Next();
}
}
}
while(Modif);
//-- ============================================================
if (!ILOn.IsEmpty()) { // process the interferences on ILOn
// *********************************
HLRBRep_EdgeIList::ProcessComplex // complex transition on ILOn
(ILOn,EIT); // **************************
HLRAlgo_ListIteratorOfInterferenceList It(ILOn);
while(It.More()) { // process Intersections on the Face
// *********************************
HLRAlgo_Interference& Int = It.Value();
TopAbs_State stbef, staft; // read the 3d states
Int.Boundary().State3D(stbef,staft); // ******************
switch (Int.Transition()) {
case TopAbs_FORWARD :
switch (staft) {
case TopAbs_OUT :
ILOn.Remove(It); break;
case TopAbs_IN :
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT);
ILOn.Remove(It); break;
case TopAbs_UNKNOWN : cout << "UNKNOWN state staft" << endl;
case TopAbs_ON :
It.Next(); break;
} break;
case TopAbs_REVERSED :
switch (stbef) {
case TopAbs_OUT :
ILOn.Remove(It); break;
case TopAbs_IN :
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT);
ILOn.Remove(It); break;
case TopAbs_UNKNOWN : cout << "UNKNOWN state stbef" << endl;
case TopAbs_ON :
It.Next(); break;
} break;
case TopAbs_EXTERNAL :
ILOn.Remove(It); break;
case TopAbs_INTERNAL :
switch (stbef) {
case TopAbs_IN :
switch (staft) {
case TopAbs_IN :
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT);
ILOn.Remove(It); break;
case TopAbs_ON :
Int.Transition(TopAbs_FORWARD ); // FORWARD in ILOn,
HLRBRep_EdgeIList::AddInterference // REVERSED in ILHidden
(ILHidden,HLRAlgo_Interference
(Int.Intersection(),
Int.Boundary(),
Int.Orientation(),
TopAbs_REVERSED,
Int.BoundaryTransition()),EIT);
It.Next(); break;
case TopAbs_OUT :
Int.Transition(TopAbs_REVERSED); // set REVERSED
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT);
ILOn.Remove(It); break;
case TopAbs_UNKNOWN :
cout << "UNKNOWN state after" << endl;
It.Next(); break;
} break;
case TopAbs_ON :
switch (staft) {
case TopAbs_IN :
Int.Transition(TopAbs_REVERSED); // REVERSED in ILOn,
HLRBRep_EdgeIList::AddInterference // REVERSED in ILHidden
(ILHidden,HLRAlgo_Interference
(Int.Intersection(),
Int.Boundary(),
Int.Orientation(),
TopAbs_FORWARD,
Int.BoundaryTransition()),EIT); break;
case TopAbs_ON : break;
case TopAbs_OUT :
Int.Transition(TopAbs_REVERSED); break;
case TopAbs_UNKNOWN :
cout << "UNKNOWN state after" << endl; break;
}
It.Next(); break;
case TopAbs_OUT :
switch (staft) {
case TopAbs_IN :
Int.Transition(TopAbs_FORWARD); // set FORWARD
HLRBRep_EdgeIList::AddInterference(ILHidden,Int,EIT);
ILOn.Remove(It); break;
case TopAbs_ON :
Int.Transition(TopAbs_FORWARD ); // FORWARD in ILOn
It.Next(); break;
case TopAbs_OUT :
ILOn.Remove(It); break;
case TopAbs_UNKNOWN :
cout << "UNKNOWN state after" << endl;
It.Next(); break;
} break;
case TopAbs_UNKNOWN :
cout << "UNKNOWN state stbef" << endl; break;
}
}
}
}
if (ILHidden.IsEmpty() && ILOn.IsEmpty() && !hasOut) {
HLRBRep_EdgeData& ed = myEData(E);
TopAbs_State st = myDS->Compare(E,ed); // Classification
if (st == TopAbs_IN || st == TopAbs_ON) // **************
ed.Status().HideAll();
}
else {
Standard_Real p1 = 0.,p2 = 0.;
Standard_ShortReal tol1 = 0., tol2 = 0.;
HLRBRep_EdgeData& ed = myEData(E);
HLRAlgo_EdgeStatus& ES = ed.Status();
Standard_Boolean foundHidden = Standard_False;
if (!ILHidden.IsEmpty()) {
HLRBRep_EdgeIList::ProcessComplex // complex transition on ILHidden
(ILHidden,EIT); // ******************************
Standard_Integer level = 0;
if (!myDS->SimpleHidingFace()) // Level at Start
level = myDS->HidingStartLevel(E,ed,ILHidden); // **************
HLRAlgo_ListIteratorOfInterferenceList It(ILHidden);
while(It.More()) { // suppress multi-inside Intersections
// ***********************************
HLRAlgo_Interference& Int = It.Value();
switch (Int.Transition()) {
case TopAbs_FORWARD :
{
Standard_Integer decal = Int.Intersection().Level();
if (level > 0) ILHidden.Remove(It);
else It.Next();
level = level + decal;
}
break;
case TopAbs_REVERSED :
{
level = level - Int.Intersection().Level();
if (level > 0) ILHidden.Remove(It);
else It.Next();
}
break;
case TopAbs_EXTERNAL :
It.Next();
break;
case TopAbs_INTERNAL :
It.Next();
break;
default :
It.Next();
break;
}
}
if (ILHidden.IsEmpty()) // Edge hidden
ES.HideAll(); // ***********
else
foundHidden = Standard_True;
}
if (!ILHidden.IsEmpty()) {
//IFV
TopAbs_State aBuildIN = TopAbs_IN;
Standard_Boolean IsSuspision = Standard_True;
Standard_Real pmax, pmin;
Standard_Boolean allInt = Standard_False;
Standard_Boolean allFor = Standard_False;
Standard_Boolean allRev = Standard_False;
pmin = RealLast();
pmax = -pmin;
if(ILHidden.Extent() > 1 ) {
allInt = Standard_True;
allFor = Standard_True;
allRev = Standard_True;
HLRAlgo_ListIteratorOfInterferenceList It(ILHidden);
for(;It.More(); It.Next()) {
Standard_Real p = It.Value().Intersection().Parameter();
allFor = allFor && ( It.Value().Transition() == TopAbs_FORWARD);
allRev = allRev && ( It.Value().Transition() == TopAbs_REVERSED);
allInt = allInt && ( It.Value().Transition() == TopAbs_INTERNAL);
if(p < pmin) pmin = p;
if(p > pmax) pmax = p;
}
}
HLRAlgo_ListIteratorOfInterferenceList Itl(ILHidden);
HLRBRep_VertexList IL(EIT,Itl);
HLRBRep_EdgeBuilder EB(IL);
EB.Builds(aBuildIN); // build hidden parts
// ******************
while (EB.MoreEdges()) {
while (EB.MoreVertices()) {
switch (EB.Orientation()) {
case TopAbs_FORWARD :
p1 = EB.Current().Parameter();
tol1 = EB.Current().Tolerance();
break;
case TopAbs_REVERSED :
p2 = EB.Current().Parameter();
tol2 = EB.Current().Tolerance();
break;
case TopAbs_INTERNAL :
case TopAbs_EXTERNAL :
break;
}
EB.NextVertex();
}
if(Abs(p1 - p2) <= 1.e-7) {
EB.NextEdge();
continue;
}
if(allInt) {
if(p1 < pmin) p1 = pmin;
if(p2 > pmax) p2 = pmax;
//HLRBRep_EdgeData& ed = myEData(E);
//TopAbs_State st = myDS->Compare(E,ed); // Classification
}
TopAbs_State aTestState = TopAbs_IN;
if(IsSuspision) {
Standard_Integer aNbp = 1;
aTestState = myDS->SimplClassify(E, ed, aNbp, p1, p2);
}
if(aTestState != TopAbs_OUT) {
ES.Hide(p1,tol1,p2,tol2,
Standard_False, // under the Face
Standard_False); // inside the Face
}
EB.NextEdge();
}
EB.Builds(TopAbs_ON); // build parts under the boundary
// ******************************
while (EB.MoreEdges()) {
while (EB.MoreVertices()) {
switch (EB.Orientation()) {
case TopAbs_FORWARD :
p1 = EB.Current().Parameter();
tol1 = EB.Current().Tolerance();
break;
case TopAbs_REVERSED :
p2 = EB.Current().Parameter();
tol2 = EB.Current().Tolerance();
break;
case TopAbs_INTERNAL :
case TopAbs_EXTERNAL :
break;
}
EB.NextVertex();
}
ES.Hide(p1,tol1,p2,tol2,
Standard_False, // under the Face
Standard_True); // on the boundary
EB.NextEdge();
}
}
if (!ILOn.IsEmpty()) {
Standard_Integer level = 0;
if (!myDS->SimpleHidingFace()) // Level at Start
level = myDS->HidingStartLevel(E,ed,ILOn); // **************
if (level > 0) {
HLRAlgo_ListIteratorOfInterferenceList It(ILOn);
while(It.More()) { // suppress multi-inside Intersections
// ***********************************
HLRAlgo_Interference& Int = It.Value();
switch (Int.Transition()) {
case TopAbs_FORWARD :
{
Standard_Integer decal = Int.Intersection().Level();
if (level > 0) ILOn.Remove(It);
else It.Next();
level = level + decal;
}
break;
case TopAbs_REVERSED :
level = level - Int.Intersection().Level();
if (level > 0) ILOn.Remove(It);
else It.Next();
break;
case TopAbs_EXTERNAL :
case TopAbs_INTERNAL :
default :
It.Next();
break;
}
}
if (ILOn.IsEmpty() && !foundHidden) // Edge hidden
ES.HideAll(); // ***********
}
}
if (!ILOn.IsEmpty()) {
HLRBRep_VertexList IL(EIT,ILOn);
HLRBRep_EdgeBuilder EB(IL);
EB.Builds (TopAbs_IN); // build parts on the Face
// ***********************
while (EB.MoreEdges()) {
while (EB.MoreVertices()) {
switch (EB.Orientation()) {
case TopAbs_FORWARD :
p1 = EB.Current().Parameter();
tol1 = EB.Current().Tolerance();
break;
case TopAbs_REVERSED :
p2 = EB.Current().Parameter();
tol2 = EB.Current().Tolerance();
break;
case TopAbs_INTERNAL :
case TopAbs_EXTERNAL :
break;
}
EB.NextVertex();
}
ES.Hide(p1,tol1,p2,tol2,
Standard_True, // on the Face
Standard_False); // inside the Face
EB.NextEdge();
}
EB.Builds(TopAbs_ON); // build hidden parts under the boundary
// *************************************
while (EB.MoreEdges()) {
while (EB.MoreVertices()) {
switch (EB.Orientation()) {
case TopAbs_FORWARD :
p1 = EB.Current().Parameter();
tol1 = EB.Current().Tolerance();
break;
case TopAbs_REVERSED :
p2 = EB.Current().Parameter();
tol2 = EB.Current().Tolerance();
break;
case TopAbs_INTERNAL :
case TopAbs_EXTERNAL :
break;
}
EB.NextVertex();
}
ES.Hide(p1,tol1,p2,tol2,
Standard_True, // on the Face
Standard_True); // on the boundary
EB.NextEdge();
}
}
}
}
catch(Standard_Failure) {
#ifdef DEB
cout << "An exception was catched when hiding edge " << E;
cout << " by the face " << FI << endl;
Handle(Standard_Failure) fail = Standard_Failure::Caught();
cout << fail << endl;
#endif
}
}
}
|