summaryrefslogtreecommitdiff
path: root/src/ChFi3d/ChFi3d_Builder.cxx
blob: 39892b33cf65db199e35583a537eb8b698df4fc5 (plain)
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
// File:	ChFi3d_Builder.cxx
// Created:	Thu Nov 18 15:59:35 1993
// Author:	Isabelle GRIGNON
//		<isg@zerox>


#include <ChFi3d_Builder.ixx>

#include <Standard_Failure.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_ErrorHandler.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>

#include <TopAbs.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopAbs_Orientation.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <TopOpeBRepDS_CurveExplorer.hxx>
#include <TopOpeBRepDS_CurvePointInterference.hxx>
#include <TopOpeBRepDS_DataStructure.hxx>
#include <TopOpeBRepDS_BuildTool.hxx>
#include <TopOpeBRepDS_Curve.hxx>
#include <TopOpeBRepDS_PointIterator.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <BRep_Tool.hxx>
#include <ChFiDS_Stripe.hxx>
#include <ChFiDS_ListIteratorOfListOfStripe.hxx>
#include <ChFiDS_SequenceOfSurfData.hxx>
#include <ChFiDS_HData.hxx>

#include <ChFi3d.hxx>

#include <ChFi3d_Builder_0.hxx>
#include <TopOpeBRepDS_ListOfInterference.hxx>


#ifdef DRAW
#include <TestTopOpeTools.hxx>
#include <TestTopOpe.hxx>
#endif
#ifdef DEB
#include <OSD_Chronometer.hxx>

// variables for performances 


OSD_Chronometer cl_total,cl_extent,cl_perfsetofsurf,cl_perffilletonvertex,
cl_filds,cl_reconstruction,cl_setregul,cl_perform1corner,cl_perform2corner,
cl_performatend,cl_perform3corner,cl_performmore3corner;

Standard_EXPORT Standard_Real t_total, t_extent,t_perfsetofsurf,
t_perffilletonvertex, t_filds,t_reconstruction,t_setregul, t_perfsetofkgen,
t_perfsetofkpart,t_makextremities,t_performatend,t_startsol,t_performsurf,
t_perform1corner,t_perform2corner,t_perform3corner,t_performmore3corner,
t_batten,t_inter,t_sameinter,t_same,t_plate,t_approxplate,t_t2cornerinit,
t_perf2cornerbyinter,t_chfikpartcompdata,t_cheminement,t_remplissage,
t_t3cornerinit ,t_spherique,t_torique, t_notfilling,t_filling,t_sameparam,
t_computedata,t_completedata,t_t2cornerDS,t_t3cornerDS;
               
//Standard_IMPORT extern void ChFi3d_InitChron(OSD_Chronometer& ch);
Standard_IMPORT void ChFi3d_InitChron(OSD_Chronometer& ch);
//Standard_IMPORT extern void ChFi3d_ResultChron(OSD_Chronometer & ch,
Standard_IMPORT void ChFi3d_ResultChron(OSD_Chronometer & ch,
					       Standard_Real& time);
extern Standard_Boolean ChFi3d_GettraceCHRON();
#endif


//=======================================================================
//function : CompleteDS
//purpose  : 
//=======================================================================

static void CompleteDS(TopOpeBRepDS_DataStructure& DStr,
		       const TopoDS_Shape& S)
{
  ChFiDS_Map MapEW,MapFS;
  MapEW.Fill(S,TopAbs_EDGE,TopAbs_WIRE);
  MapFS.Fill(S,TopAbs_FACE,TopAbs_SHELL);
  
  TopExp_Explorer ExpE;
  for (ExpE.Init(S,TopAbs_EDGE); ExpE.More(); ExpE.Next()) {
    const TopoDS_Edge& E = TopoDS::Edge(ExpE.Current());
    Standard_Boolean hasgeom = DStr.HasGeometry(E);
    if (hasgeom) {
      const TopTools_ListOfShape& WireListAnc = MapEW(E);
      TopTools_ListIteratorOfListOfShape itaW(WireListAnc);
      while (itaW.More()) {
	const TopoDS_Shape& WireAnc = itaW.Value();
	DStr.AddShape(WireAnc);
	itaW.Next();
      }
    }
  }
  
  TopExp_Explorer ExpF;
  for (ExpF.Init(S,TopAbs_FACE); ExpF.More(); ExpF.Next()) {
    const TopoDS_Face& F = TopoDS::Face(ExpF.Current());
    Standard_Boolean hasgeom = DStr.HasGeometry(F);
    if (hasgeom) {
      const TopTools_ListOfShape& ShellListAnc = MapFS(F);
      TopTools_ListIteratorOfListOfShape itaS(ShellListAnc);
      while (itaS.More()) {
	const TopoDS_Shape& ShellAnc = itaS.Value();
	DStr.AddShape(ShellAnc);
	itaS.Next();
      }
    }
  }
  
  // set the range on the DS Curves
  for (Standard_Integer ic = 1; ic <= DStr.NbCurves(); ic++) {
    Standard_Real parmin = RealLast(), parmax = RealFirst();
    const TopOpeBRepDS_ListOfInterference& LI = DStr.CurveInterferences(ic);
    for (TopOpeBRepDS_PointIterator it(LI);
	 it.More();
	 it.Next() ) {
      Standard_Real par = it.Parameter();
      parmin = Min (parmin,par); parmax = Max (parmax,par);
    }
    DStr.ChangeCurve(ic).SetRange(parmin,parmax);
  }
}

void ChFi3d_Builder::Delete()
{}

//=======================================================================
//function : ExtentAnalyse
//purpose  : 
//=======================================================================

void ChFi3d_Builder::ExtentAnalyse ()
{
  Standard_Integer nbedges, nbs;
  for (Standard_Integer iv = 1; iv <= myVDataMap.Extent(); iv++) {
    nbs = myVDataMap(iv).Extent();
    const TopoDS_Vertex& Vtx = myVDataMap.FindKey(iv);
    nbedges = ChFi3d_NumberOfEdges(Vtx, myVEMap); 
    switch (nbs) {
    case 1 :
      ExtentOneCorner(Vtx, myVDataMap.FindFromIndex(iv).First());
      break;
    case 2 :
      if (nbedges <= 3)
	ExtentTwoCorner(Vtx, myVDataMap.FindFromIndex(iv));
      break;
    case 3 :
      if (nbedges <= 3)
	ExtentThreeCorner(Vtx, myVDataMap.FindFromIndex(iv));
      break;
    default : 
      break;
    }
  }
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void  ChFi3d_Builder::Compute()
{
  
#ifdef DEB   //perf 
  t_total=0;t_extent=0; t_perfsetofsurf=0;t_perffilletonvertex=0;
  t_filds=0;t_reconstruction=0;t_setregul=0;
  t_perfsetofkpart=0; t_perfsetofkgen=0;t_makextremities=0;
  t_performsurf=0;t_startsol=0; t_perform1corner=0;t_perform2corner=0;
  t_perform3corner=0;t_performmore3corner=0;t_inter=0;t_same=0;t_sameinter=0;
  t_plate=0;t_approxplate=0; t_batten=0;t_remplissage=0;t_t3cornerinit=0;
  t_spherique=0;t_torique=0;t_notfilling=0;t_filling=0;t_performatend=0;
  t_t2cornerinit=0; t_perf2cornerbyinter=0;t_chfikpartcompdata=0;
  t_cheminement=0; t_sameparam=0; t_computedata=0;t_completedata=0;
  t_t2cornerDS=0;t_t3cornerDS=0;
  ChFi3d_InitChron(cl_total);
  ChFi3d_InitChron(cl_extent);
#endif 
  
  if (myListStripe.IsEmpty())
    Standard_Failure::Raise("There are no suitable edges for chamfer or fillet");
  
  Reset();
  myDS = new TopOpeBRepDS_HDataStructure();
  TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
  done = Standard_True;
  hasresult=Standard_False;
#ifdef DRAW
  TestTopOpe::CurrentDS(myDS);
  TopoDS_Shape bids;
  TestTopOpe::Shapes(myShape,bids);
#endif
  
  // filling of myVDatatMap
  ChFiDS_ListIteratorOfListOfStripe itel;
  
  for (itel.Initialize(myListStripe);itel.More(); itel.Next()) {
    if ((itel.Value()->Spine()->FirstStatus() <= ChFiDS_BreakPoint))
      myVDataMap.Add(itel.Value()->Spine()->FirstVertex(),itel.Value());
    else if (itel.Value()->Spine()->FirstStatus() == ChFiDS_FreeBoundary)
      ExtentOneCorner(itel.Value()->Spine()->FirstVertex(),itel.Value());
    if ((itel.Value()->Spine()->LastStatus() <= ChFiDS_BreakPoint))
      myVDataMap.Add(itel.Value()->Spine()->LastVertex() ,itel.Value());
    else if (itel.Value()->Spine()->LastStatus() == ChFiDS_FreeBoundary)
      ExtentOneCorner(itel.Value()->Spine()->LastVertex(),itel.Value());
  }
  // preanalysis to evaluate the extensions.
  ExtentAnalyse();
  
  
#ifdef DEB //perf 
  ChFi3d_ResultChron(cl_extent,t_extent);
  ChFi3d_InitChron(cl_perfsetofsurf);
#endif
  
  // Construction of the stripe of fillet on each stripe.
  for (itel.Initialize(myListStripe);itel.More(); itel.Next()) {
    itel.Value()->Spine()->SetErrorStatus(ChFiDS_Ok);
    try {
      OCC_CATCH_SIGNALS
      PerformSetOfSurf(itel.Value());
    }
    catch(Standard_Failure) {
      Handle(Standard_Failure) exc = Standard_Failure::Caught();
#ifdef DEB
      cout <<"EXCEPTION Stripe compute " << exc << endl;
#endif
      badstripes.Append(itel.Value());
      done = Standard_True;
      if (itel.Value()->Spine()->ErrorStatus()==ChFiDS_Ok) 
      itel.Value()->Spine()->SetErrorStatus(ChFiDS_Error);
    }
    if (!done) badstripes.Append(itel.Value());
    done = Standard_True;
  }
  done = (badstripes.IsEmpty());
  
#ifdef DEB //perf 
  ChFi3d_ResultChron(cl_perfsetofsurf,t_perfsetofsurf);
  ChFi3d_InitChron(cl_perffilletonvertex);
#endif 
  
  //construct fillets on each vertex + feed the Ds
  if (done) {
   //Standard_Integer nbresult=0;
//    for (Standard_Integer j=1;j<=myVDataMap.Extent();j++) {
#ifndef DEB
    static 
#endif  //to avoid Linux warning:<< variable `j' might be clobbered by `longjmp' or `vfork' >>
    Standard_Integer j;
    for (j=1;j<=myVDataMap.Extent();j++) {
      try {
        OCC_CATCH_SIGNALS
	PerformFilletOnVertex(j);
      }
      catch(Standard_Failure) {
	Handle(Standard_Failure) exc = Standard_Failure::Caught();
#ifdef DEB
	cout <<"EXCEPTION Corner compute " << exc << endl;
#endif
	badvertices.Append(myVDataMap.FindKey(j));
        hasresult=Standard_False;
	done = Standard_True;
      }
      if (!done) badvertices.Append(myVDataMap.FindKey(j));
      done = Standard_True;
    }
   if (!hasresult) done = badvertices.IsEmpty();
  }
  

#ifdef DEB //perf 
  ChFi3d_ResultChron(cl_perffilletonvertex,t_perffilletonvertex);
  ChFi3d_InitChron(cl_filds);
#endif
  
  TColStd_MapOfInteger MapIndSo;
  TopExp_Explorer expso(myShape,TopAbs_SOLID);
  for(; expso.More(); expso.Next()){
    const TopoDS_Shape& cursol = expso.Current();
    Standard_Integer indcursol = DStr.AddShape(cursol);
    MapIndSo.Add(indcursol);
  }
  TopExp_Explorer expsh(myShape,TopAbs_SHELL,TopAbs_SOLID);
  for(; expsh.More(); expsh.Next()){
    const TopoDS_Shape& cursh = expsh.Current();
    Standard_Integer indcursh = DStr.AddShape(cursh);
    MapIndSo.Add(indcursh);
  }
  if (done) {
    Standard_Integer i1;
    for (itel.Initialize(myListStripe), i1=0;
	 itel.More(); 
	 itel.Next(), i1++) {
      const Handle(ChFiDS_Stripe)& st = itel.Value();
      // 05/02/02 akm vvv : (OCC119) First we'll check ain't there 
      //                    intersections between fillets
      ChFiDS_ListIteratorOfListOfStripe itel1;
      Standard_Integer i2;
      for (itel1.Initialize(myListStripe), i2=0;
	   itel1.More(); 
	   itel1.Next(), i2++) {
	if (i2 <= i1)
	  // Do not twice intersect the stripes
	  continue;
	Handle(ChFiDS_Stripe) aCheckStripe = itel1.Value();
	try {
	  OCC_CATCH_SIGNALS
	  ChFi3d_StripeEdgeInter (st, aCheckStripe, DStr, tol2d);
	}
	catch(Standard_Failure) {
	  Handle(Standard_Failure) exc = Standard_Failure::Caught();
#ifdef DEB
	  cout <<"EXCEPTION Fillets compute " << exc << endl;
#endif
	  badstripes.Append(itel.Value());
	  hasresult=Standard_False;
	  done = Standard_False;
	  break;
	}
      }
      // 05/02/02 akm ^^^
      Standard_Integer solidindex = st->SolidIndex();
      ChFi3d_FilDS(solidindex,st,DStr,myRegul,tolesp,tol2d);
      if (!done) break;
    }
    
#ifdef DEB //perf 
    ChFi3d_ResultChron(cl_filds,t_filds);
    ChFi3d_InitChron(cl_reconstruction);
#endif
    
    
    if (done) {
      BRep_Builder B1;
      CompleteDS(DStr,myShape);
      //Update tolerances on vertex to max adjacent edges or
      //Update tolerances on degenerated edge to max of adjacent vertexes.
      TopOpeBRepDS_CurveExplorer cex(DStr);
      for(;cex.More();cex.Next()){
	TopOpeBRepDS_Curve& c = *((TopOpeBRepDS_Curve*)(void*)&(cex.Curve()));
	Standard_Real tolc = 0.;
	Standard_Boolean degen = c.Curve().IsNull();
	if(!degen) tolc = c.Tolerance();
	Standard_Integer ic = cex.Index();
	TopOpeBRepDS_PointIterator It(myDS->CurvePoints(ic));
	for(;It.More();It.Next()){
	  Handle(TopOpeBRepDS_CurvePointInterference) II;
	  II = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(It.Value());
	  if (II.IsNull()) continue;
	  TopOpeBRepDS_Kind gk = II->GeometryType();
	  Standard_Integer gi = II->Geometry();
	  if(gk == TopOpeBRepDS_VERTEX){
	    const TopoDS_Vertex& v = TopoDS::Vertex(myDS->Shape(gi));
	    Standard_Real tolv = BRep_Tool::Tolerance(v);
	    if( tolv > 0.0001 ) {
	      tolv += 0.0003;
	      if( tolc < tolv ) tolc = tolv + 0.00001;
	    }
	    if(degen && tolc < tolv) tolc = tolv;
	    else if(tolc>tolv) B1.UpdateVertex(v,tolc);
	  }
	  else if(gk == TopOpeBRepDS_POINT){
	    TopOpeBRepDS_Point& p = DStr.ChangePoint(gi);
	    Standard_Real tolp = p.Tolerance();
	    if(degen && tolc < tolp) tolc = tolp;
	    else if(tolc>tolp) p.Tolerance(tolc);
	  }
	}
	if(degen) c.Tolerance(tolc);
      }
      myCoup->Perform(myDS);
      TColStd_MapIteratorOfMapOfInteger It(MapIndSo);
      for(; It.More(); It.Next()){
	Standard_Integer indsol = It.Key();
	const TopoDS_Shape& curshape = DStr.Shape(indsol);
	myCoup->MergeSolid(curshape,TopAbs_IN);
      }
      
      Standard_Integer i=1,n=DStr.NbShapes();
      for (;i<=n;i++) {
	const TopoDS_Shape S = DStr.Shape(i);
	if (S.ShapeType() != TopAbs_EDGE) continue;
	Standard_Boolean issplitIN = myCoup->IsSplit(S,TopAbs_IN);
	if ( !issplitIN ) continue;
	TopTools_ListIteratorOfListOfShape it(myCoup->Splits(S,TopAbs_IN));
	for (; it.More(); it.Next() ) {
	  const TopoDS_Edge& newE = TopoDS::Edge(it.Value());
	  Standard_Real tole = BRep_Tool::Tolerance(newE);
	  TopExp_Explorer exv(newE,TopAbs_VERTEX);
	  for (; exv.More(); exv.Next() ) {
	    const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());
	    Standard_Real tolv = BRep_Tool::Tolerance(v);
	    if (tole>tolv) B1.UpdateVertex(v,tole);
	  }
	}
      }
      if (!hasresult) {
      B1.MakeCompound(TopoDS::Compound(myShapeResult));
      for(It.Reset(); It.More(); It.Next()){
	Standard_Integer indsol = It.Key();
	const TopoDS_Shape& curshape = DStr.Shape(indsol);
	TopTools_ListIteratorOfListOfShape 
	  its = myCoup->Merged(curshape,TopAbs_IN);
	if(!its.More()) B1.Add(myShapeResult,curshape);
	else {
	  //If the old type of Shape is Shell, Shell is placed instead of Solid, 
          //However there is a problem for compound of open Shell.
	  while (its.More()) {
	    const TopAbs_ShapeEnum letype = curshape.ShapeType();
	    if (letype == TopAbs_SHELL){
	      TopExp_Explorer expsh2(its.Value(),TopAbs_SHELL);
	      const TopoDS_Shape& cursh = expsh2.Current();
	      TopoDS_Shape tt = cursh;
	      B1.Add(myShapeResult,cursh);
	      its.Next();
	    }
	    else {
	      B1.Add(myShapeResult,its.Value());
	      its.Next();
	    }
	  }
	}
      }
      }
      else {
       done=Standard_False;
       B1.MakeCompound(TopoDS::Compound(badShape));
      for(It.Reset(); It.More(); It.Next()){
	Standard_Integer indsol = It.Key();
	const TopoDS_Shape& curshape = DStr.Shape(indsol);
	TopTools_ListIteratorOfListOfShape 
	  its = myCoup->Merged(curshape,TopAbs_IN);
	if(!its.More()) B1.Add(badShape,curshape);
	else {
	  while (its.More()) { 
	    B1.Add(badShape,its.Value());
	    its.Next();
	  }
	}
      }
      }
#ifdef DEB //perf 
      ChFi3d_ResultChron(cl_reconstruction ,t_reconstruction);
      ChFi3d_InitChron(cl_setregul);
#endif
      
      // Regularities are coded after cutting.
      SetRegul();
      
      
#ifdef DEB //perf 
 ChFi3d_ResultChron(cl_setregul ,t_setregul);
#endif
    }
  }
#ifdef DEB //perf 
  ChFi3d_ResultChron(cl_total,t_total);
#endif
      
  
  // display of time for perfs 
  
#ifdef DEB  
  cout<<endl; 
  cout<<"COMPUTE: temps total "<<t_total<<"s  dont :"<<endl;
  cout<<"- Init + ExtentAnalyse "<<t_extent<<"s"<<endl;  
  cout<<"- PerformSetOfSurf "<<t_perfsetofsurf<<"s"<<endl;
  cout<<"- PerformFilletOnVertex "<<t_perffilletonvertex<<"s"<<endl; 
  cout<<"- FilDS "<<t_filds<<"s"<<endl; 
  cout<<"- Reconstruction "<<t_reconstruction<<"s"<<endl;
  cout<<"- SetRegul "<<t_setregul<<"s"<<endl<<endl;
  
  if(ChFi3d_GettraceCHRON()){
    cout<<endl;
    cout <<"temps PERFORMSETOFSURF "<<t_perfsetofsurf <<"s  dont : "<<endl;
    cout <<"- SetofKPart "<<t_perfsetofkpart<<"s"<<endl;
    cout <<"- SetofKGen "<< t_perfsetofkgen <<"s"<<endl;
    cout <<"- MakeExtremities "<<t_makextremities<<"s"<<endl<<endl;
    
    
    cout <<"temps SETOFKGEN "<< t_perfsetofkgen<<"s dont : "<<endl;
    cout<<"- PerformSurf "<<t_performsurf<<"s"<<endl;
    cout<<"- starsol "<< t_startsol <<"s"<<endl<<endl;
    
    cout<<"temps PERFORMSURF "<<t_performsurf<<"s  dont : "  << endl;
    cout<<"- computedata "<<t_computedata<<"s"<<endl;
    cout<<"- completedata "<<t_completedata<<"s"<<endl<<endl;
    
    
    cout<<"temps PERFORMFILLETVERTEX "<<t_perffilletonvertex <<"s dont : "  << endl;
    cout<<"- PerformOneCorner "<<t_perform1corner<<"s"<<endl;
    cout<<"- PerformIntersectionAtEnd "<<t_performatend<<"s"<<endl;
    cout<<"- PerformTwoCorner "<<t_perform2corner<<"s"<<endl;
    cout<<"- PerformThreeCorner "<<t_perform3corner<<"s"<<endl;
    cout<<"- PerformMoreThreeCorner "<<t_performmore3corner<<"s"<<endl<<endl;
    
    
    cout<<"temps PerformOneCorner "<<t_perform1corner<<"s dont:"<<endl;
    cout<<"- temps condition if (same) "<<t_same << "s "<<endl; 
    cout<<"- temps condition if (inter) "<<t_inter<<"s " <<endl;
    cout<<"- temps condition if (same inter) "<<t_sameinter<<"s " <<endl<<endl;
    
    cout<<"temps PerformTwocorner "<<t_perform2corner<<"s  dont:"<<endl;
    cout<<"- temps initialisation "<< t_t2cornerinit<<"s"<<endl;
    cout<<"- temps PerformTwoCornerbyInter "<<t_perf2cornerbyinter<<"s"<<endl;
    cout<<"- temps ChFiKPart_ComputeData "<<t_chfikpartcompdata <<"s"<<endl;
    cout<<"- temps cheminement "<<t_cheminement<<"s"<<endl;
    cout<<"- temps remplissage "<<t_remplissage<<"s"<<endl;
    cout<<"- temps mise a jour stripes  "<<t_t2cornerDS<<"s"<<endl<<endl;
    
    cout<<" temps PerformThreecorner "<<t_perform3corner<<"s  dont:"<<endl;
    cout<<"- temps initialisation "<< t_t3cornerinit<<"s"<<endl;
    cout<<"- temps cas spherique  "<<t_spherique<<"s"<<endl;
    cout<<"- temps cas torique  "<<t_torique<<"s"<<endl;
    cout<<"- temps notfilling "<<t_notfilling<<"s"<<endl;
    cout<<"- temps filling "<<t_filling<<"s"<<endl;
    cout<<"- temps mise a jour stripes  "<<t_t3cornerDS<<"s"<<endl<<endl;
    
    cout<<"temps PerformMore3Corner "<<t_performmore3corner<<"s dont:"<<endl;
    cout<<"-temps plate "<<t_plate << "s "<<endl; 
    cout<<"-temps approxplate "<<t_approxplate<<"s " <<endl;
    cout<<"-temps batten "<< t_batten<<"s " <<endl<<endl;
    
    cout <<"TEMPS DIVERS "<<endl;
    cout<<"-temps ChFi3d_sameparameter "<<t_sameparam<<"s"<<endl<<endl;
  }
#endif
}

//=======================================================================
//function : PerformSingularCorner
//purpose  : Load vertex and degenerated edges.
//=======================================================================

void ChFi3d_Builder::PerformSingularCorner
(const Standard_Integer Index){
  ChFiDS_ListIteratorOfListOfStripe It;
  Handle(ChFiDS_Stripe) stripe;
  TopOpeBRepDS_DataStructure&  DStr = myDS->ChangeDS();
  const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
  
  Handle(ChFiDS_SurfData) Fd;
  Standard_Integer i, Icurv;
#ifndef DEB
  Standard_Integer Ivtx = 0;
#else
  Standard_Integer Ivtx;
#endif
  for (It.Initialize(myVDataMap(Index)), i=0; It.More(); It.Next(),i++){
    stripe = It.Value(); 
    // SurfData concerned and its CommonPoints,
    Standard_Integer sens = 0;
    Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
    Standard_Boolean isfirst = (sens == 1);
    Fd =  stripe->SetOfSurfData()->Sequence().Value(num);
    const ChFiDS_CommonPoint& CV1 = Fd->Vertex(isfirst,1);
    const ChFiDS_CommonPoint& CV2 = Fd->Vertex(isfirst,2);
    // Is it always degenerated ?
    if ( CV1.Point().IsEqual( CV2.Point(), 0) ) { 
      // if yes the vertex is stored in the stripe
      // and the edge at end is created
      if (i==0) Ivtx = ChFi3d_IndexPointInDS(CV1, DStr);
      Standard_Real tolreached;
      Standard_Real Pardeb, Parfin; 
      gp_Pnt2d VOnS1, VOnS2;
      Handle(Geom_Curve) C3d;
      Handle(Geom2d_Curve) PCurv;
      TopOpeBRepDS_Curve Crv;
      if (isfirst) {
	VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
		    Value(Fd->InterferenceOnS1().FirstParameter());
	VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
		     Value(Fd->InterferenceOnS2().FirstParameter());
      }
      else {
	VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
		    Value(Fd->InterferenceOnS1().LastParameter());
	VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
		     Value(Fd->InterferenceOnS2().LastParameter());
      }
      
      ChFi3d_ComputeArete(CV1, VOnS1,
			  CV2, VOnS2,
			  DStr.Surface(Fd->Surf()).Surface(),
			  C3d, PCurv,
			  Pardeb,Parfin,tolapp3d,tolapp2d,tolreached,0);
      Crv = TopOpeBRepDS_Curve(C3d,tolreached);
      Icurv = DStr.AddCurve(Crv);

      stripe->SetCurve(Icurv, isfirst);
      stripe->SetParameters(isfirst, Pardeb,Parfin);
      stripe->ChangePCurve(isfirst) = PCurv;
      stripe->SetIndexPoint(Ivtx, isfirst, 1);
      stripe->SetIndexPoint(Ivtx, isfirst, 2);	  
    }
  }  
}

//=======================================================================
//function : PerformFilletOnVertex
//purpose  : 
//=======================================================================

void ChFi3d_Builder::PerformFilletOnVertex
(const Standard_Integer Index){
  
  ChFiDS_ListIteratorOfListOfStripe It;
  Handle(ChFiDS_Stripe) stripe;
  Handle(ChFiDS_Spine) sp;
  const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
  
  Handle(ChFiDS_SurfData) Fd;
  Standard_Integer i;
  Standard_Boolean nondegenere = Standard_True;
  Standard_Boolean toujoursdegenere = Standard_True; 
#ifndef DEB
  Standard_Boolean isfirst = Standard_False;
#else
  Standard_Boolean isfirst;
#endif
  for (It.Initialize(myVDataMap(Index)), i=0; It.More(); It.Next(),i++){
    stripe = It.Value(); 
    sp = stripe->Spine();
    // SurfData and its CommonPoints,
    Standard_Integer sens = 0;
    Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
    isfirst = (sens == 1);
    Fd =  stripe->SetOfSurfData()->Sequence().Value(num);
    const ChFiDS_CommonPoint& CV1 = Fd->Vertex(isfirst,1);
    const ChFiDS_CommonPoint& CV2 = Fd->Vertex(isfirst,2);
    // Is it always degenerated ?
    if ( CV1.Point().IsEqual( CV2.Point(), 0) )  
      nondegenere = Standard_False;
    else  toujoursdegenere = Standard_False;
  }
  
  // calcul du nombre de faces = nombre d'aretes
/*  TopTools_ListIteratorOfListOfShape ItF,JtF,ItE;
  Standard_Integer nbf = 0, jf = 0;
  for (ItF.Initialize(myVFMap(Vtx)); ItF.More(); ItF.Next()){
    jf++;
    Standard_Integer kf = 1;
    const TopoDS_Shape& cur = ItF.Value();
    for (JtF.Initialize(myVFMap(Vtx)); JtF.More() && (kf < jf); JtF.Next(), kf++){
      if(cur.IsSame(JtF.Value())) break;
    }
    if(kf == jf) nbf++;
  }
  Standard_Integer nba=myVEMap(Vtx).Extent();
  for (ItE.Initialize(myVEMap(Vtx)); ItE.More(); ItE.Next()){
    const TopoDS_Edge& cur = TopoDS::Edge(ItE.Value());
    if (BRep_Tool::Degenerated(cur)) nba--;
  }
  nba=nba/2;*/
  Standard_Integer nba = ChFi3d_NumberOfEdges(Vtx, myVEMap);

  if (nondegenere) { // Normal processing
    switch (i) {
    case 1 : 
      {
	if(sp->Status(isfirst) == ChFiDS_FreeBoundary) return; 
	if(nba>3) {
#ifdef DEB //perf    
	  ChFi3d_InitChron(cl_performatend);
#endif
	  PerformIntersectionAtEnd(Index);
#ifdef DEB    
	  ChFi3d_ResultChron(cl_performatend,t_performatend);
#endif 
	}
	else { 
#ifdef DEB //perf    
	  ChFi3d_InitChron(cl_perform1corner);
#endif
          if (MoreSurfdata(Index))
             PerformMoreSurfdata(Index);
	  else PerformOneCorner(Index);
#ifdef DEB //perf 
	  ChFi3d_ResultChron(cl_perform1corner,t_perform1corner);
#endif  
	}
      }
      break;
    case 2 : 
      {
	if(nba>3){
#ifdef DEB //perf 
	  ChFi3d_InitChron(cl_performmore3corner);
#endif
	  PerformMoreThreeCorner(Index, i);
#ifdef DEB //perf 
	  ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
#endif
	}
	else { 
#ifdef DEB //perf 
	  ChFi3d_InitChron(cl_perform2corner);
#endif
	  PerformTwoCorner(Index);
#ifdef DEB //perf 
	  ChFi3d_ResultChron(cl_perform2corner,t_perform2corner);
#endif
	}
      }
      break;
    case 3 : 
      {
	if(nba>3){
#ifdef DEB //perf 
	  ChFi3d_InitChron(cl_performmore3corner);
#endif
	  PerformMoreThreeCorner(Index, i);
#ifdef DEB //perf 
	  ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
#endif
	}
	else {
#ifdef DEB //perf 
	  ChFi3d_InitChron(cl_perform3corner);
#endif
	  PerformThreeCorner(Index);
#ifdef DEB //perf 
	  ChFi3d_ResultChron(cl_perform3corner,t_perform3corner);
#endif
	}
      }
      break;
      default : {
#ifdef DEB //perf 
	ChFi3d_InitChron(cl_performmore3corner);
#endif
	PerformMoreThreeCorner(Index, i);
#ifdef DEB //perf 
	ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
#endif
      }
    }
  }
  else { // Single case processing
    if (toujoursdegenere) PerformSingularCorner(Index);
    else                  PerformMoreThreeCorner(Index, i);//Last chance...
  }              
}


//=======================================================================
//function : Reset
//purpose  : 
//=======================================================================

void  ChFi3d_Builder::Reset()
{
  done = Standard_False;
  myVDataMap.Clear();
  myRegul.Clear();
  myEVIMap.Clear();
  badstripes.Clear();
  badvertices.Clear();

  ChFiDS_ListIteratorOfListOfStripe itel;
  for (itel.Initialize(myListStripe); itel.More(); ){
    if(!itel.Value()->Spine().IsNull()){
      itel.Value()->Reset();
      itel.Next();
    }
    else myListStripe.Remove(itel);
  }
}

//=======================================================================
//function : Generated
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& ChFi3d_Builder::Generated(const TopoDS_Shape& EouV)
{
  myGenerated.Clear();
  if(EouV.IsNull()) return myGenerated;
  if(EouV.ShapeType() != TopAbs_EDGE &&
     EouV.ShapeType() != TopAbs_VERTEX) return myGenerated;
  if(myEVIMap.IsBound(EouV)) {
    const TColStd_ListOfInteger& L = myEVIMap.Find(EouV);
    TColStd_ListIteratorOfListOfInteger IL;
    for(IL.Initialize(L); IL.More(); IL.Next()){
      Standard_Integer I = IL.Value();
      const TopTools_ListOfShape& LS =  myCoup->NewFaces(I);
      TopTools_ListIteratorOfListOfShape ILS;
      for(ILS.Initialize(LS); ILS.More(); ILS.Next()){
	myGenerated.Append(ILS.Value());
      }
    }
  }
  return myGenerated;
}