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