6db5254a6b7a850f570c484588192b966c78c7c8
[occt.git] / src / ChFi3d / ChFi3d_Builder.cxx
1 // Created on: 1993-11-18
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1993-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 #include <ChFi3d_Builder.ixx>
18
19 #include <Standard_Failure.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_NotImplemented.hxx>
22 #include <Standard_ErrorHandler.hxx>
23 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
24 #include <TColStd_MapOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26
27 #include <TopoDS.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Vertex.hxx>
32
33 #include <TopAbs.hxx>
34 #include <TopAbs_ShapeEnum.hxx>
35 #include <TopAbs_Orientation.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRep_Tool.hxx>
38 #include <TopExp.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42
43 #include <TopOpeBRepDS_CurveExplorer.hxx>
44 #include <TopOpeBRepDS_CurvePointInterference.hxx>
45 #include <TopOpeBRepDS_DataStructure.hxx>
46 #include <TopOpeBRepDS_BuildTool.hxx>
47 #include <TopOpeBRepDS_Curve.hxx>
48 #include <TopOpeBRepDS_PointIterator.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50
51 #include <BRep_Tool.hxx>
52 #include <ChFiDS_Stripe.hxx>
53 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
54 #include <ChFiDS_SequenceOfSurfData.hxx>
55 #include <ChFiDS_HData.hxx>
56
57 #include <ChFi3d.hxx>
58
59 #include <ChFi3d_Builder_0.hxx>
60 #include <TopOpeBRepDS_ListOfInterference.hxx>
61 #include <BRepLib.hxx>
62 #include <ShapeFix.hxx>
63 #include <Precision.hxx>
64
65 #ifdef DRAW
66 #include <TestTopOpeTools.hxx>
67 #include <TestTopOpe.hxx>
68 #endif
69 #ifdef DEB
70 #include <OSD_Chronometer.hxx>
71
72
73
74 // variables for performances 
75
76
77 OSD_Chronometer cl_total,cl_extent,cl_perfsetofsurf,cl_perffilletonvertex,
78 cl_filds,cl_reconstruction,cl_setregul,cl_perform1corner,cl_perform2corner,
79 cl_performatend,cl_perform3corner,cl_performmore3corner;
80
81 Standard_EXPORT Standard_Real t_total, t_extent,t_perfsetofsurf,
82 t_perffilletonvertex, t_filds,t_reconstruction,t_setregul, t_perfsetofkgen,
83 t_perfsetofkpart,t_makextremities,t_performatend,t_startsol,t_performsurf,
84 t_perform1corner,t_perform2corner,t_perform3corner,t_performmore3corner,
85 t_batten,t_inter,t_sameinter,t_same,t_plate,t_approxplate,t_t2cornerinit,
86 t_perf2cornerbyinter,t_chfikpartcompdata,t_cheminement,t_remplissage,
87 t_t3cornerinit ,t_spherique,t_torique, t_notfilling,t_filling,t_sameparam,
88 t_computedata,t_completedata,t_t2cornerDS,t_t3cornerDS;
89                
90 extern void ChFi3d_InitChron(OSD_Chronometer& ch);
91 extern void ChFi3d_ResultChron(OSD_Chronometer & ch, Standard_Real& time);
92 extern Standard_Boolean ChFi3d_GettraceCHRON();
93 #endif
94
95
96 //=======================================================================
97 //function : CompleteDS
98 //purpose  : 
99 //=======================================================================
100
101 static void CompleteDS(TopOpeBRepDS_DataStructure& DStr,
102                        const TopoDS_Shape& S)
103 {
104   ChFiDS_Map MapEW,MapFS;
105   MapEW.Fill(S,TopAbs_EDGE,TopAbs_WIRE);
106   MapFS.Fill(S,TopAbs_FACE,TopAbs_SHELL);
107   
108   TopExp_Explorer ExpE;
109   for (ExpE.Init(S,TopAbs_EDGE); ExpE.More(); ExpE.Next()) {
110     const TopoDS_Edge& E = TopoDS::Edge(ExpE.Current());
111     Standard_Boolean hasgeom = DStr.HasGeometry(E);
112     if (hasgeom) {
113       const TopTools_ListOfShape& WireListAnc = MapEW(E);
114       TopTools_ListIteratorOfListOfShape itaW(WireListAnc);
115       while (itaW.More()) {
116         const TopoDS_Shape& WireAnc = itaW.Value();
117         DStr.AddShape(WireAnc);
118         itaW.Next();
119       }
120     }
121   }
122   
123   TopExp_Explorer ExpF;
124   for (ExpF.Init(S,TopAbs_FACE); ExpF.More(); ExpF.Next()) {
125     const TopoDS_Face& F = TopoDS::Face(ExpF.Current());
126     Standard_Boolean hasgeom = DStr.HasGeometry(F);
127     if (hasgeom) {
128       const TopTools_ListOfShape& ShellListAnc = MapFS(F);
129       TopTools_ListIteratorOfListOfShape itaS(ShellListAnc);
130       while (itaS.More()) {
131         const TopoDS_Shape& ShellAnc = itaS.Value();
132         DStr.AddShape(ShellAnc);
133         itaS.Next();
134       }
135     }
136   }
137   
138   // set the range on the DS Curves
139   for (Standard_Integer ic = 1; ic <= DStr.NbCurves(); ic++) {
140     Standard_Real parmin = RealLast(), parmax = RealFirst();
141     const TopOpeBRepDS_ListOfInterference& LI = DStr.CurveInterferences(ic);
142     for (TopOpeBRepDS_PointIterator it(LI);
143          it.More();
144          it.Next() ) {
145       Standard_Real par = it.Parameter();
146       parmin = Min (parmin,par); parmax = Max (parmax,par);
147     }
148     DStr.ChangeCurve(ic).SetRange(parmin,parmax);
149   }
150 }
151
152 void ChFi3d_Builder::Delete()
153 {}
154
155 //=======================================================================
156 //function : ExtentAnalyse
157 //purpose  : 
158 //=======================================================================
159
160 void ChFi3d_Builder::ExtentAnalyse ()
161 {
162   Standard_Integer nbedges, nbs;
163   for (Standard_Integer iv = 1; iv <= myVDataMap.Extent(); iv++) {
164     nbs = myVDataMap(iv).Extent();
165     const TopoDS_Vertex& Vtx = myVDataMap.FindKey(iv);
166     nbedges = ChFi3d_NumberOfEdges(Vtx, myVEMap); 
167     switch (nbs) {
168     case 1 :
169       ExtentOneCorner(Vtx, myVDataMap.FindFromIndex(iv).First());
170       break;
171     case 2 :
172       if (nbedges <= 3)
173         ExtentTwoCorner(Vtx, myVDataMap.FindFromIndex(iv));
174       break;
175     case 3 :
176       if (nbedges <= 3)
177         ExtentThreeCorner(Vtx, myVDataMap.FindFromIndex(iv));
178       break;
179     default : 
180       break;
181     }
182   }
183 }
184
185 //=======================================================================
186 //function : Compute
187 //purpose  : 
188 //=======================================================================
189
190 void  ChFi3d_Builder::Compute()
191 {
192   
193 #ifdef DEB   //perf 
194   t_total=0;t_extent=0; t_perfsetofsurf=0;t_perffilletonvertex=0;
195   t_filds=0;t_reconstruction=0;t_setregul=0;
196   t_perfsetofkpart=0; t_perfsetofkgen=0;t_makextremities=0;
197   t_performsurf=0;t_startsol=0; t_perform1corner=0;t_perform2corner=0;
198   t_perform3corner=0;t_performmore3corner=0;t_inter=0;t_same=0;t_sameinter=0;
199   t_plate=0;t_approxplate=0; t_batten=0;t_remplissage=0;t_t3cornerinit=0;
200   t_spherique=0;t_torique=0;t_notfilling=0;t_filling=0;t_performatend=0;
201   t_t2cornerinit=0; t_perf2cornerbyinter=0;t_chfikpartcompdata=0;
202   t_cheminement=0; t_sameparam=0; t_computedata=0;t_completedata=0;
203   t_t2cornerDS=0;t_t3cornerDS=0;
204   ChFi3d_InitChron(cl_total);
205   ChFi3d_InitChron(cl_extent);
206 #endif 
207   
208   if (myListStripe.IsEmpty())
209     Standard_Failure::Raise("There are no suitable edges for chamfer or fillet");
210   
211   Reset();
212   myDS = new TopOpeBRepDS_HDataStructure();
213   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
214   done = Standard_True;
215   hasresult=Standard_False;
216 #ifdef DRAW
217   TestTopOpe::CurrentDS(myDS);
218   TopoDS_Shape bids;
219   TestTopOpe::Shapes(myShape,bids);
220 #endif
221   
222   // filling of myVDatatMap
223   ChFiDS_ListIteratorOfListOfStripe itel;
224   
225   for (itel.Initialize(myListStripe);itel.More(); itel.Next()) {
226     if ((itel.Value()->Spine()->FirstStatus() <= ChFiDS_BreakPoint))
227       myVDataMap.Add(itel.Value()->Spine()->FirstVertex(),itel.Value());
228     else if (itel.Value()->Spine()->FirstStatus() == ChFiDS_FreeBoundary)
229       ExtentOneCorner(itel.Value()->Spine()->FirstVertex(),itel.Value());
230     if ((itel.Value()->Spine()->LastStatus() <= ChFiDS_BreakPoint))
231       myVDataMap.Add(itel.Value()->Spine()->LastVertex() ,itel.Value());
232     else if (itel.Value()->Spine()->LastStatus() == ChFiDS_FreeBoundary)
233       ExtentOneCorner(itel.Value()->Spine()->LastVertex(),itel.Value());
234   }
235   // preanalysis to evaluate the extensions.
236   ExtentAnalyse();
237   
238   
239 #ifdef DEB //perf 
240   ChFi3d_ResultChron(cl_extent,t_extent);
241   ChFi3d_InitChron(cl_perfsetofsurf);
242 #endif
243   
244   // Construction of the stripe of fillet on each stripe.
245   for (itel.Initialize(myListStripe);itel.More(); itel.Next()) {
246     itel.Value()->Spine()->SetErrorStatus(ChFiDS_Ok);
247     try {
248       OCC_CATCH_SIGNALS
249       PerformSetOfSurf(itel.Value());
250     }
251     catch(Standard_Failure) {
252       Handle(Standard_Failure) exc = Standard_Failure::Caught();
253 #ifdef DEB
254       cout <<"EXCEPTION Stripe compute " << exc << endl;
255 #endif
256       badstripes.Append(itel.Value());
257       done = Standard_True;
258       if (itel.Value()->Spine()->ErrorStatus()==ChFiDS_Ok) 
259       itel.Value()->Spine()->SetErrorStatus(ChFiDS_Error);
260     }
261     if (!done) badstripes.Append(itel.Value());
262     done = Standard_True;
263   }
264   done = (badstripes.IsEmpty());
265   
266 #ifdef DEB //perf 
267   ChFi3d_ResultChron(cl_perfsetofsurf,t_perfsetofsurf);
268   ChFi3d_InitChron(cl_perffilletonvertex);
269 #endif 
270   
271   //construct fillets on each vertex + feed the Ds
272   if (done) {
273     Standard_Integer j;
274     for (j=1;j<=myVDataMap.Extent();j++)
275     {
276       try
277       {
278         OCC_CATCH_SIGNALS
279         PerformFilletOnVertex(j);
280       }
281       catch(Standard_Failure)
282       {
283         Handle(Standard_Failure) exc = Standard_Failure::Caught();
284 #ifdef DEB
285         cout <<"EXCEPTION Corner compute " << exc << endl;
286 #endif
287         badvertices.Append(myVDataMap.FindKey(j));
288         hasresult=Standard_False;
289         done = Standard_True;
290       }
291       if (!done) badvertices.Append(myVDataMap.FindKey(j));
292       done = Standard_True;
293     }
294     if (!hasresult) done = badvertices.IsEmpty();
295   }
296   
297
298 #ifdef DEB //perf 
299   ChFi3d_ResultChron(cl_perffilletonvertex,t_perffilletonvertex);
300   ChFi3d_InitChron(cl_filds);
301 #endif
302   
303   TColStd_MapOfInteger MapIndSo;
304   TopExp_Explorer expso(myShape,TopAbs_SOLID);
305   for(; expso.More(); expso.Next()){
306     const TopoDS_Shape& cursol = expso.Current();
307     Standard_Integer indcursol = DStr.AddShape(cursol);
308     MapIndSo.Add(indcursol);
309   }
310   TopExp_Explorer expsh(myShape,TopAbs_SHELL,TopAbs_SOLID);
311   for(; expsh.More(); expsh.Next()){
312     const TopoDS_Shape& cursh = expsh.Current();
313     Standard_Integer indcursh = DStr.AddShape(cursh);
314     MapIndSo.Add(indcursh);
315   }
316   if (done) {
317     Standard_Integer i1;
318     for (itel.Initialize(myListStripe), i1=0;
319          itel.More(); 
320          itel.Next(), i1++) {
321       const Handle(ChFiDS_Stripe)& st = itel.Value();
322       // 05/02/02 akm vvv : (OCC119) First we'll check ain't there 
323       //                    intersections between fillets
324       ChFiDS_ListIteratorOfListOfStripe itel1;
325       Standard_Integer i2;
326       for (itel1.Initialize(myListStripe), i2=0;
327            itel1.More(); 
328            itel1.Next(), i2++) {
329         if (i2 <= i1)
330           // Do not twice intersect the stripes
331           continue;
332         Handle(ChFiDS_Stripe) aCheckStripe = itel1.Value();
333         try {
334           OCC_CATCH_SIGNALS
335           ChFi3d_StripeEdgeInter (st, aCheckStripe, DStr, tol2d);
336         }
337         catch(Standard_Failure) {
338           Handle(Standard_Failure) exc = Standard_Failure::Caught();
339 #ifdef DEB
340           cout <<"EXCEPTION Fillets compute " << exc << endl;
341 #endif
342           badstripes.Append(itel.Value());
343           hasresult=Standard_False;
344           done = Standard_False;
345           break;
346         }
347       }
348       // 05/02/02 akm ^^^
349       Standard_Integer solidindex = st->SolidIndex();
350       ChFi3d_FilDS(solidindex,st,DStr,myRegul,tolesp,tol2d);
351       if (!done) break;
352     }
353     
354 #ifdef DEB //perf 
355     ChFi3d_ResultChron(cl_filds,t_filds);
356     ChFi3d_InitChron(cl_reconstruction);
357 #endif
358     
359     
360     if (done) {
361       BRep_Builder B1;
362       CompleteDS(DStr,myShape);
363       //Update tolerances on vertex to max adjacent edges or
364       //Update tolerances on degenerated edge to max of adjacent vertexes.
365       TopOpeBRepDS_CurveExplorer cex(DStr);
366       for(;cex.More();cex.Next()){
367         TopOpeBRepDS_Curve& c = *((TopOpeBRepDS_Curve*)(void*)&(cex.Curve()));
368         Standard_Real tolc = 0.;
369         Standard_Boolean degen = c.Curve().IsNull();
370         if(!degen) tolc = c.Tolerance();
371         Standard_Integer ic = cex.Index();
372         TopOpeBRepDS_PointIterator It(myDS->CurvePoints(ic));
373         for(;It.More();It.Next()){
374           Handle(TopOpeBRepDS_CurvePointInterference) II;
375           II = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(It.Value());
376           if (II.IsNull()) continue;
377           TopOpeBRepDS_Kind gk = II->GeometryType();
378           Standard_Integer gi = II->Geometry();
379           if(gk == TopOpeBRepDS_VERTEX){
380             const TopoDS_Vertex& v = TopoDS::Vertex(myDS->Shape(gi));
381             Standard_Real tolv = BRep_Tool::Tolerance(v);
382             if( tolv > 0.0001 ) {
383               tolv += 0.0003;
384               if( tolc < tolv ) tolc = tolv + 0.00001;
385             }
386             if(degen && tolc < tolv) tolc = tolv;
387             else if(tolc>tolv) B1.UpdateVertex(v,tolc);
388           }
389           else if(gk == TopOpeBRepDS_POINT){
390             TopOpeBRepDS_Point& p = DStr.ChangePoint(gi);
391             Standard_Real tolp = p.Tolerance();
392             if(degen && tolc < tolp) tolc = tolp;
393             else if(tolc>tolp) p.Tolerance(tolc);
394           }
395         }
396         if(degen) c.Tolerance(tolc);
397       }
398       myCoup->Perform(myDS);
399       TColStd_MapIteratorOfMapOfInteger It(MapIndSo);
400       for(; It.More(); It.Next()){
401         Standard_Integer indsol = It.Key();
402         const TopoDS_Shape& curshape = DStr.Shape(indsol);
403         myCoup->MergeSolid(curshape,TopAbs_IN);
404       }
405       
406       Standard_Integer i=1,n=DStr.NbShapes();
407       for (;i<=n;i++) {
408         const TopoDS_Shape S = DStr.Shape(i);
409         if (S.ShapeType() != TopAbs_EDGE) continue;
410         Standard_Boolean issplitIN = myCoup->IsSplit(S,TopAbs_IN);
411         if ( !issplitIN ) continue;
412         TopTools_ListIteratorOfListOfShape it(myCoup->Splits(S,TopAbs_IN));
413         for (; it.More(); it.Next() ) {
414           const TopoDS_Edge& newE = TopoDS::Edge(it.Value());
415           Standard_Real tole = BRep_Tool::Tolerance(newE);
416           TopExp_Explorer exv(newE,TopAbs_VERTEX);
417           for (; exv.More(); exv.Next() ) {
418             const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());
419             Standard_Real tolv = BRep_Tool::Tolerance(v);
420             if (tole>tolv) B1.UpdateVertex(v,tole);
421           }
422         }
423       }
424       if (!hasresult) {
425       B1.MakeCompound(TopoDS::Compound(myShapeResult));
426       for(It.Reset(); It.More(); It.Next()){
427         Standard_Integer indsol = It.Key();
428         const TopoDS_Shape& curshape = DStr.Shape(indsol);
429         TopTools_ListIteratorOfListOfShape 
430           its = myCoup->Merged(curshape,TopAbs_IN);
431         if(!its.More()) B1.Add(myShapeResult,curshape);
432         else {
433           //If the old type of Shape is Shell, Shell is placed instead of Solid, 
434           //However there is a problem for compound of open Shell.
435           while (its.More()) {
436             const TopAbs_ShapeEnum letype = curshape.ShapeType();
437             if (letype == TopAbs_SHELL){
438               TopExp_Explorer expsh2(its.Value(),TopAbs_SHELL);
439               const TopoDS_Shape& cursh = expsh2.Current();
440               TopoDS_Shape tt = cursh;
441               B1.Add(myShapeResult,cursh);
442               its.Next();
443             }
444             else {
445               B1.Add(myShapeResult,its.Value());
446               its.Next();
447             }
448           }
449         }
450       }
451       }
452       else {
453        done=Standard_False;
454        B1.MakeCompound(TopoDS::Compound(badShape));
455       for(It.Reset(); It.More(); It.Next()){
456         Standard_Integer indsol = It.Key();
457         const TopoDS_Shape& curshape = DStr.Shape(indsol);
458         TopTools_ListIteratorOfListOfShape 
459           its = myCoup->Merged(curshape,TopAbs_IN);
460         if(!its.More()) B1.Add(badShape,curshape);
461         else {
462           while (its.More()) { 
463             B1.Add(badShape,its.Value());
464             its.Next();
465           }
466         }
467       }
468       }
469 #ifdef DEB //perf 
470       ChFi3d_ResultChron(cl_reconstruction ,t_reconstruction);
471       ChFi3d_InitChron(cl_setregul);
472 #endif
473       
474       // Regularities are coded after cutting.
475       SetRegul();
476       
477       
478 #ifdef DEB //perf 
479  ChFi3d_ResultChron(cl_setregul ,t_setregul);
480 #endif
481     }
482   }
483 #ifdef DEB //perf 
484   ChFi3d_ResultChron(cl_total,t_total);
485 #endif
486       
487   
488   // display of time for perfs 
489   
490 #ifdef DEB  
491   cout<<endl; 
492   cout<<"COMPUTE: temps total "<<t_total<<"s  dont :"<<endl;
493   cout<<"- Init + ExtentAnalyse "<<t_extent<<"s"<<endl;  
494   cout<<"- PerformSetOfSurf "<<t_perfsetofsurf<<"s"<<endl;
495   cout<<"- PerformFilletOnVertex "<<t_perffilletonvertex<<"s"<<endl; 
496   cout<<"- FilDS "<<t_filds<<"s"<<endl; 
497   cout<<"- Reconstruction "<<t_reconstruction<<"s"<<endl;
498   cout<<"- SetRegul "<<t_setregul<<"s"<<endl<<endl;
499   
500   if(ChFi3d_GettraceCHRON()){
501     cout<<endl;
502     cout <<"temps PERFORMSETOFSURF "<<t_perfsetofsurf <<"s  dont : "<<endl;
503     cout <<"- SetofKPart "<<t_perfsetofkpart<<"s"<<endl;
504     cout <<"- SetofKGen "<< t_perfsetofkgen <<"s"<<endl;
505     cout <<"- MakeExtremities "<<t_makextremities<<"s"<<endl<<endl;
506     
507     
508     cout <<"temps SETOFKGEN "<< t_perfsetofkgen<<"s dont : "<<endl;
509     cout<<"- PerformSurf "<<t_performsurf<<"s"<<endl;
510     cout<<"- starsol "<< t_startsol <<"s"<<endl<<endl;
511     
512     cout<<"temps PERFORMSURF "<<t_performsurf<<"s  dont : "  << endl;
513     cout<<"- computedata "<<t_computedata<<"s"<<endl;
514     cout<<"- completedata "<<t_completedata<<"s"<<endl<<endl;
515     
516     
517     cout<<"temps PERFORMFILLETVERTEX "<<t_perffilletonvertex <<"s dont : "  << endl;
518     cout<<"- PerformOneCorner "<<t_perform1corner<<"s"<<endl;
519     cout<<"- PerformIntersectionAtEnd "<<t_performatend<<"s"<<endl;
520     cout<<"- PerformTwoCorner "<<t_perform2corner<<"s"<<endl;
521     cout<<"- PerformThreeCorner "<<t_perform3corner<<"s"<<endl;
522     cout<<"- PerformMoreThreeCorner "<<t_performmore3corner<<"s"<<endl<<endl;
523     
524     
525     cout<<"temps PerformOneCorner "<<t_perform1corner<<"s dont:"<<endl;
526     cout<<"- temps condition if (same) "<<t_same << "s "<<endl; 
527     cout<<"- temps condition if (inter) "<<t_inter<<"s " <<endl;
528     cout<<"- temps condition if (same inter) "<<t_sameinter<<"s " <<endl<<endl;
529     
530     cout<<"temps PerformTwocorner "<<t_perform2corner<<"s  dont:"<<endl;
531     cout<<"- temps initialisation "<< t_t2cornerinit<<"s"<<endl;
532     cout<<"- temps PerformTwoCornerbyInter "<<t_perf2cornerbyinter<<"s"<<endl;
533     cout<<"- temps ChFiKPart_ComputeData "<<t_chfikpartcompdata <<"s"<<endl;
534     cout<<"- temps cheminement "<<t_cheminement<<"s"<<endl;
535     cout<<"- temps remplissage "<<t_remplissage<<"s"<<endl;
536     cout<<"- temps mise a jour stripes  "<<t_t2cornerDS<<"s"<<endl<<endl;
537     
538     cout<<" temps PerformThreecorner "<<t_perform3corner<<"s  dont:"<<endl;
539     cout<<"- temps initialisation "<< t_t3cornerinit<<"s"<<endl;
540     cout<<"- temps cas spherique  "<<t_spherique<<"s"<<endl;
541     cout<<"- temps cas torique  "<<t_torique<<"s"<<endl;
542     cout<<"- temps notfilling "<<t_notfilling<<"s"<<endl;
543     cout<<"- temps filling "<<t_filling<<"s"<<endl;
544     cout<<"- temps mise a jour stripes  "<<t_t3cornerDS<<"s"<<endl<<endl;
545     
546     cout<<"temps PerformMore3Corner "<<t_performmore3corner<<"s dont:"<<endl;
547     cout<<"-temps plate "<<t_plate << "s "<<endl; 
548     cout<<"-temps approxplate "<<t_approxplate<<"s " <<endl;
549     cout<<"-temps batten "<< t_batten<<"s " <<endl<<endl;
550     
551     cout <<"TEMPS DIVERS "<<endl;
552     cout<<"-temps ChFi3d_sameparameter "<<t_sameparam<<"s"<<endl<<endl;
553   }
554 #endif
555   //
556   // Inspect the new faces to provide sameparameter 
557   // if it is necessary
558   if (IsDone())
559   {
560     Standard_Real SameParTol = Precision::Confusion();
561     Standard_Integer aNbSurfaces, iF;
562     TopTools_ListIteratorOfListOfShape aIt;
563     //
564     aNbSurfaces=myDS->NbSurfaces();
565     
566     for (iF=1; iF<=aNbSurfaces; ++iF) {
567       const TopTools_ListOfShape& aLF=myCoup->NewFaces(iF);
568       aIt.Initialize(aLF);
569       for (; aIt.More(); aIt.Next()) {
570         const TopoDS_Shape& aF=aIt.Value();
571         BRepLib::SameParameter(aF, SameParTol, Standard_True);
572         ShapeFix::SameParameter(aF, Standard_False, SameParTol);
573       }
574     }
575   }
576 }
577
578 //=======================================================================
579 //function : PerformSingularCorner
580 //purpose  : Load vertex and degenerated edges.
581 //=======================================================================
582
583 void ChFi3d_Builder::PerformSingularCorner
584 (const Standard_Integer Index){
585   ChFiDS_ListIteratorOfListOfStripe It;
586   Handle(ChFiDS_Stripe) stripe;
587   TopOpeBRepDS_DataStructure&  DStr = myDS->ChangeDS();
588   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
589   
590   Handle(ChFiDS_SurfData) Fd;
591   Standard_Integer i, Icurv;
592   Standard_Integer Ivtx = 0;
593   for (It.Initialize(myVDataMap(Index)), i=0; It.More(); It.Next(),i++){
594     stripe = It.Value(); 
595     // SurfData concerned and its CommonPoints,
596     Standard_Integer sens = 0;
597     Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
598     Standard_Boolean isfirst = (sens == 1);
599     Fd =  stripe->SetOfSurfData()->Sequence().Value(num);
600     const ChFiDS_CommonPoint& CV1 = Fd->Vertex(isfirst,1);
601     const ChFiDS_CommonPoint& CV2 = Fd->Vertex(isfirst,2);
602     // Is it always degenerated ?
603     if ( CV1.Point().IsEqual( CV2.Point(), 0) ) { 
604       // if yes the vertex is stored in the stripe
605       // and the edge at end is created
606       if (i==0) Ivtx = ChFi3d_IndexPointInDS(CV1, DStr);
607       Standard_Real tolreached;
608       Standard_Real Pardeb, Parfin; 
609       gp_Pnt2d VOnS1, VOnS2;
610       Handle(Geom_Curve) C3d;
611       Handle(Geom2d_Curve) PCurv;
612       TopOpeBRepDS_Curve Crv;
613       if (isfirst) {
614         VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
615                     Value(Fd->InterferenceOnS1().FirstParameter());
616         VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
617                      Value(Fd->InterferenceOnS2().FirstParameter());
618       }
619       else {
620         VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
621                     Value(Fd->InterferenceOnS1().LastParameter());
622         VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
623                      Value(Fd->InterferenceOnS2().LastParameter());
624       }
625       
626       ChFi3d_ComputeArete(CV1, VOnS1,
627                           CV2, VOnS2,
628                           DStr.Surface(Fd->Surf()).Surface(),
629                           C3d, PCurv,
630                           Pardeb,Parfin,tolapp3d,tolapp2d,tolreached,0);
631       Crv = TopOpeBRepDS_Curve(C3d,tolreached);
632       Icurv = DStr.AddCurve(Crv);
633
634       stripe->SetCurve(Icurv, isfirst);
635       stripe->SetParameters(isfirst, Pardeb,Parfin);
636       stripe->ChangePCurve(isfirst) = PCurv;
637       stripe->SetIndexPoint(Ivtx, isfirst, 1);
638       stripe->SetIndexPoint(Ivtx, isfirst, 2);    
639     }
640   }  
641 }
642
643 //=======================================================================
644 //function : PerformFilletOnVertex
645 //purpose  : 
646 //=======================================================================
647
648 void ChFi3d_Builder::PerformFilletOnVertex
649 (const Standard_Integer Index){
650   
651   ChFiDS_ListIteratorOfListOfStripe It;
652   Handle(ChFiDS_Stripe) stripe;
653   Handle(ChFiDS_Spine) sp;
654   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
655   
656   Handle(ChFiDS_SurfData) Fd;
657   Standard_Integer i;
658   Standard_Boolean nondegenere = Standard_True;
659   Standard_Boolean toujoursdegenere = Standard_True; 
660   Standard_Boolean isfirst = Standard_False;
661   for (It.Initialize(myVDataMap(Index)), i=0; It.More(); It.Next(),i++){
662     stripe = It.Value(); 
663     sp = stripe->Spine();
664     // SurfData and its CommonPoints,
665     Standard_Integer sens = 0;
666     Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
667     isfirst = (sens == 1);
668     Fd =  stripe->SetOfSurfData()->Sequence().Value(num);
669     const ChFiDS_CommonPoint& CV1 = Fd->Vertex(isfirst,1);
670     const ChFiDS_CommonPoint& CV2 = Fd->Vertex(isfirst,2);
671     // Is it always degenerated ?
672     if ( CV1.Point().IsEqual( CV2.Point(), 0) )  
673       nondegenere = Standard_False;
674     else  toujoursdegenere = Standard_False;
675   }
676   
677   // calcul du nombre de faces = nombre d'aretes
678 /*  TopTools_ListIteratorOfListOfShape ItF,JtF,ItE;
679   Standard_Integer nbf = 0, jf = 0;
680   for (ItF.Initialize(myVFMap(Vtx)); ItF.More(); ItF.Next()){
681     jf++;
682     Standard_Integer kf = 1;
683     const TopoDS_Shape& cur = ItF.Value();
684     for (JtF.Initialize(myVFMap(Vtx)); JtF.More() && (kf < jf); JtF.Next(), kf++){
685       if(cur.IsSame(JtF.Value())) break;
686     }
687     if(kf == jf) nbf++;
688   }
689   Standard_Integer nba=myVEMap(Vtx).Extent();
690   for (ItE.Initialize(myVEMap(Vtx)); ItE.More(); ItE.Next()){
691     const TopoDS_Edge& cur = TopoDS::Edge(ItE.Value());
692     if (BRep_Tool::Degenerated(cur)) nba--;
693   }
694   nba=nba/2;*/
695   Standard_Integer nba = ChFi3d_NumberOfEdges(Vtx, myVEMap);
696
697   if (nondegenere) { // Normal processing
698     switch (i) {
699     case 1 : 
700       {
701         if(sp->Status(isfirst) == ChFiDS_FreeBoundary) return; 
702         if(nba>3) {
703 #ifdef DEB //perf    
704           ChFi3d_InitChron(cl_performatend);
705 #endif
706           PerformIntersectionAtEnd(Index);
707 #ifdef DEB    
708           ChFi3d_ResultChron(cl_performatend,t_performatend);
709 #endif 
710         }
711         else { 
712 #ifdef DEB //perf    
713           ChFi3d_InitChron(cl_perform1corner);
714 #endif
715           if (MoreSurfdata(Index))
716              PerformMoreSurfdata(Index);
717           else PerformOneCorner(Index);
718 #ifdef DEB //perf 
719           ChFi3d_ResultChron(cl_perform1corner,t_perform1corner);
720 #endif  
721         }
722       }
723       break;
724     case 2 : 
725       {
726         if(nba>3){
727 #ifdef DEB //perf 
728           ChFi3d_InitChron(cl_performmore3corner);
729 #endif
730           PerformMoreThreeCorner(Index, i);
731 #ifdef DEB //perf 
732           ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
733 #endif
734         }
735         else { 
736 #ifdef DEB //perf 
737           ChFi3d_InitChron(cl_perform2corner);
738 #endif
739           PerformTwoCorner(Index);
740 #ifdef DEB //perf 
741           ChFi3d_ResultChron(cl_perform2corner,t_perform2corner);
742 #endif
743         }
744       }
745       break;
746     case 3 : 
747       {
748         if(nba>3){
749 #ifdef DEB //perf 
750           ChFi3d_InitChron(cl_performmore3corner);
751 #endif
752           PerformMoreThreeCorner(Index, i);
753 #ifdef DEB //perf 
754           ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
755 #endif
756         }
757         else {
758 #ifdef DEB //perf 
759           ChFi3d_InitChron(cl_perform3corner);
760 #endif
761           PerformThreeCorner(Index);
762 #ifdef DEB //perf 
763           ChFi3d_ResultChron(cl_perform3corner,t_perform3corner);
764 #endif
765         }
766       }
767       break;
768       default : {
769 #ifdef DEB //perf 
770         ChFi3d_InitChron(cl_performmore3corner);
771 #endif
772         PerformMoreThreeCorner(Index, i);
773 #ifdef DEB //perf 
774         ChFi3d_ResultChron(cl_performmore3corner,t_performmore3corner);
775 #endif
776       }
777     }
778   }
779   else { // Single case processing
780     if (toujoursdegenere) PerformSingularCorner(Index);
781     else                  PerformMoreThreeCorner(Index, i);//Last chance...
782   }              
783 }
784
785
786 //=======================================================================
787 //function : Reset
788 //purpose  : 
789 //=======================================================================
790
791 void  ChFi3d_Builder::Reset()
792 {
793   done = Standard_False;
794   myVDataMap.Clear();
795   myRegul.Clear();
796   myEVIMap.Clear();
797   badstripes.Clear();
798   badvertices.Clear();
799
800   ChFiDS_ListIteratorOfListOfStripe itel;
801   for (itel.Initialize(myListStripe); itel.More(); ){
802     if(!itel.Value()->Spine().IsNull()){
803       itel.Value()->Reset();
804       itel.Next();
805     }
806     else myListStripe.Remove(itel);
807   }
808 }
809
810 //=======================================================================
811 //function : Generated
812 //purpose  : 
813 //=======================================================================
814
815 const TopTools_ListOfShape& ChFi3d_Builder::Generated(const TopoDS_Shape& EouV)
816 {
817   myGenerated.Clear();
818   if(EouV.IsNull()) return myGenerated;
819   if(EouV.ShapeType() != TopAbs_EDGE &&
820      EouV.ShapeType() != TopAbs_VERTEX) return myGenerated;
821   if(myEVIMap.IsBound(EouV)) {
822     const TColStd_ListOfInteger& L = myEVIMap.Find(EouV);
823     TColStd_ListIteratorOfListOfInteger IL;
824     for(IL.Initialize(L); IL.More(); IL.Next()){
825       Standard_Integer I = IL.Value();
826       const TopTools_ListOfShape& LS =  myCoup->NewFaces(I);
827       TopTools_ListIteratorOfListOfShape ILS;
828       for(ILS.Initialize(LS); ILS.More(); ILS.Next()){
829         myGenerated.Append(ILS.Value());
830       }
831     }
832   }
833   return myGenerated;
834 }
835
836