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