0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / ChFi3d / ChFi3d_Builder_6.cxx
CommitLineData
b311480e 1// Created on: 1994-10-25
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// modif : jlr branchement F(t) pour Edge/Face
7fd59977 18// Modified by skv - Wed Jun 9 17:16:26 2004 OCC5898
19// modified by Edward AGAPOV (eap) Fri Feb 8 2002 (bug occ67 == BUC61052)
20// ComputeData(), case where BRepBlend_Walking::Continu() can't get up to Target
21
42cf5bc1 22#include <Adaptor2d_HCurve2d.hxx>
7fd59977 23#include <Adaptor3d_HSurface.hxx>
24#include <Adaptor3d_TopolTool.hxx>
42cf5bc1 25#include <AppBlend_Approx.hxx>
7fd59977 26#include <Approx_SweepFunction.hxx>
42cf5bc1 27#include <Blend_CurvPointFuncInv.hxx>
28#include <Blend_FuncInv.hxx>
29#include <Blend_Function.hxx>
7fd59977 30#include <Blend_Point.hxx>
42cf5bc1 31#include <Blend_RstRstFunction.hxx>
32#include <Blend_SurfCurvFuncInv.hxx>
33#include <Blend_SurfPointFuncInv.hxx>
34#include <Blend_SurfRstFunction.hxx>
35#include <BRep_Tool.hxx>
36#include <BRepAdaptor_Curve.hxx>
37#include <BRepAdaptor_Curve2d.hxx>
38#include <BRepAdaptor_HCurve2d.hxx>
39#include <BRepAdaptor_HSurface.hxx>
40#include <BRepAdaptor_Surface.hxx>
7fd59977 41#include <BRepBlend_AppFunc.hxx>
42#include <BRepBlend_AppFuncRst.hxx>
43#include <BRepBlend_AppFuncRstRst.hxx>
42cf5bc1 44#include <BRepBlend_AppSurf.hxx>
45#include <BRepBlend_AppSurface.hxx>
7fd59977 46#include <BRepBlend_ConstRad.hxx>
47#include <BRepBlend_ConstRadInv.hxx>
42cf5bc1 48#include <BRepBlend_CSWalking.hxx>
49#include <BRepBlend_Extremity.hxx>
50#include <BRepBlend_Line.hxx>
51#include <BRepBlend_PointOnRst.hxx>
52#include <BRepBlend_RstRstLineBuilder.hxx>
53#include <BRepBlend_SurfRstLineBuilder.hxx>
54#include <BRepBlend_Walking.hxx>
55#include <BRepTopAdaptor_HVertex.hxx>
56#include <BRepTopAdaptor_TopolTool.hxx>
57#include <BSplCLib.hxx>
58#include <ChFi3d_Builder.hxx>
59#include <ChFi3d_Builder_0.hxx>
7fd59977 60#include <ChFiDS_CommonPoint.hxx>
42cf5bc1 61#include <ChFiDS_FaceInterference.hxx>
62#include <ChFiDS_HElSpine.hxx>
63#include <ChFiDS_Spine.hxx>
64#include <ChFiDS_Stripe.hxx>
65#include <ChFiDS_SurfData.hxx>
66#include <Geom2d_BSplineCurve.hxx>
67#include <Geom2d_Curve.hxx>
68#include <Geom2d_Line.hxx>
69#include <Geom2d_TrimmedCurve.hxx>
70#include <Geom2dAPI_ProjectPointOnCurve.hxx>
71#include <Geom2dInt_GInter.hxx>
72#include <Geom_BSplineSurface.hxx>
73#include <Geom_Curve.hxx>
74#include <Geom_Surface.hxx>
75#include <GeomAdaptor_HCurve.hxx>
76#include <GeomAdaptor_HSurface.hxx>
77#include <GeomLib.hxx>
78#include <gp_Dir2d.hxx>
79#include <gp_Pnt.hxx>
80#include <gp_Pnt2d.hxx>
81#include <gp_Vec.hxx>
82#include <gp_Vec2d.hxx>
83#include <IntRes2d_IntersectionPoint.hxx>
84#include <math_Vector.hxx>
85#include <Precision.hxx>
86#include <Standard_ConstructionError.hxx>
87#include <Standard_NoSuchObject.hxx>
88#include <Standard_OutOfRange.hxx>
7fd59977 89#include <TopExp.hxx>
42cf5bc1 90#include <TopoDS_Edge.hxx>
91#include <TopoDS_Face.hxx>
92#include <TopoDS_Shape.hxx>
93#include <TopoDS_Vertex.hxx>
94#include <TopOpeBRepBuild_HBuilder.hxx>
95#include <TopOpeBRepDS_Curve.hxx>
96#include <TopOpeBRepDS_DataStructure.hxx>
97#include <TopOpeBRepDS_HDataStructure.hxx>
98#include <TopOpeBRepDS_Surface.hxx>
7fd59977 99#include <TopTools_ListIteratorOfListOfShape.hxx>
42cf5bc1 100#include <TopTools_ListOfShape.hxx>
7fd59977 101
42cf5bc1 102#include <stdio.h>
0797d9d3 103#ifdef OCCT_DEBUG
81bba717 104// For measurements.
7fd59977 105#include <OSD_Chronometer.hxx>
106//static OSD_Chronometer appclock;
107#endif
108
109//#define DRAW
110
111#ifdef DRAW
112#include <Draw_Appli.hxx>
113#include <Draw_Segment2D.hxx>
114#include <Draw_Marker2D.hxx>
115#include <Draw_Segment3D.hxx>
116#include <Draw_Marker3D.hxx>
117#include <Draw.hxx>
118#include <DrawTrSurf.hxx>
ec357c5c 119#include <BRepAdaptor_HSurface.hxx>
7fd59977 120static Standard_Integer IndexOfConge = 0;
121#endif
122
0797d9d3 123#ifdef OCCT_DEBUG
7fd59977 124extern Standard_Boolean ChFi3d_GettraceDRAWFIL();
125extern Standard_Boolean ChFi3d_GettraceDRAWWALK();
126extern Standard_Boolean ChFi3d_GetcontextNOOPT();
127extern void ChFi3d_SettraceDRAWFIL(const Standard_Boolean b);
128extern void ChFi3d_SettraceDRAWWALK(const Standard_Boolean b);
129extern void ChFi3d_SetcontextNOOPT(const Standard_Boolean b);
130#endif
131
132#ifdef DRAW
133static void drawline(const Handle(BRepBlend_Line)& lin,
134 const Standard_Boolean iscs)
135{
136 Handle(Draw_Marker3D) p3d;
137 Handle(Draw_Marker2D) p2d;
138 Handle(Draw_Segment3D) tg3d;
139 Handle(Draw_Segment2D) tg2d;
140
141 for(Standard_Integer i = 1; i <= lin->NbPoints(); i++){
142 const Blend_Point& pt = lin->Point(i);
143 gp_Pnt point = pt.PointOnS1();
144 gp_Pnt extr = point.Translated(pt.TangentOnS1());
145 p3d = new Draw_Marker3D(point,Draw_Square,Draw_rouge);
146 dout<<p3d;
147 tg3d = new Draw_Segment3D(point,extr,Draw_rouge);
148 dout<<tg3d;
149 point = pt.PointOnS2();
150 extr = point.Translated(pt.TangentOnS2());
151 p3d = new Draw_Marker3D(point,Draw_Plus,Draw_jaune);
152 dout<<p3d;
153 tg3d = new Draw_Segment3D(point,extr,Draw_jaune);
154 dout<<tg3d;
155
156 Standard_Real u,v;
157 pt.ParametersOnS1(u,v);
158 gp_Pnt2d point2d(u,v);
159 gp_Pnt2d extr2d = point2d.Translated(pt.Tangent2dOnS1());
160 p2d = new Draw_Marker2D(point2d,Draw_Square,Draw_rouge);
161 dout<<p2d;
162 tg2d = new Draw_Segment2D(point2d,extr2d,Draw_rouge);
163 dout<<tg2d;
164 pt.ParametersOnS2(u,v);
165 point2d.SetCoord(u,v);
166 extr2d = point2d.Translated(pt.Tangent2dOnS2());
167 p2d = new Draw_Marker2D(point2d,Draw_Plus,Draw_jaune);
168 dout<<p2d;
169 tg2d = new Draw_Segment2D(point2d,extr2d,Draw_jaune);
170 dout<<tg2d;
171 dout.Flush();
172 }
173}
174#endif
175//=======================================================================
176//function : SearchIndex
177//purpose :
178//
179//=======================================================================
180static Standard_Integer SearchIndex(const Standard_Real Value,
181 Handle(BRepBlend_Line)& Lin)
182{
183 Standard_Integer NbPnt = Lin->NbPoints(), Ind;
184
185 for (Ind = 1;
186 (Ind < NbPnt) && (Lin->Point(Ind).Parameter() < Value); )
187 Ind++;
188 return Ind;
189}
190
191
192//=======================================================================
193//function : IsObst
194//purpose :
195//
196//=======================================================================
197static Standard_Integer nbedconnex(const TopTools_ListOfShape& L)
198{
199 Standard_Integer nb = 0, i = 0;
200 TopTools_ListIteratorOfListOfShape It1(L);
201 for(;It1.More();It1.Next(),i++){
202 const TopoDS_Shape& curs = It1.Value();
203 Standard_Boolean dejavu = 0;
204 TopTools_ListIteratorOfListOfShape It2(L);
205 for(Standard_Integer j = 0; j < i && It2.More(); j++, It2.Next()){
206 if(curs.IsSame(It2.Value())){
207 dejavu = 1;
208 break;
209 }
210 }
211 if(!dejavu) nb++;
212 }
213 return nb;
214}
215
216static Standard_Boolean IsVois(const TopoDS_Edge& E,
217 const TopoDS_Vertex& Vref,
218 const ChFiDS_Map& VEMap,
219 TopTools_MapOfShape& DONE,
220 const Standard_Integer prof,
221 const Standard_Integer profmax)
222{
223 if(prof > profmax) return Standard_False;
224 if(DONE.Contains(E)) return Standard_False;
225 TopoDS_Vertex V1,V2;
226 TopExp::Vertices(E,V1,V2);
227 if(Vref.IsSame(V1) || Vref.IsSame(V2)) return Standard_True;
228 DONE.Add(E);
229 const TopTools_ListOfShape& L1 = VEMap(V1);
230 Standard_Integer i1 = nbedconnex(L1);
231 TopTools_ListIteratorOfListOfShape It1(L1);
232 for(;It1.More();It1.Next()){
233 const TopoDS_Edge& curE = TopoDS::Edge(It1.Value());
234 if(i1 <= 2){
235 if(IsVois(curE,Vref,VEMap,DONE,prof,profmax)) return Standard_True;
236 }
237 else if(IsVois(curE,Vref,VEMap,DONE,prof+1,profmax)) return Standard_True;
238 }
239 const TopTools_ListOfShape& L2 = VEMap(V2);
0797d9d3 240#ifdef OCCT_DEBUG
7fd59977 241// Standard_Integer i2 = nbedconnex(L2);
242#endif
243 TopTools_ListIteratorOfListOfShape It2(L2);
244 for(;It2.More();It2.Next()){
245 const TopoDS_Edge& curE = TopoDS::Edge(It2.Value());
246 if(i1 <= 2){
247 if(IsVois(curE,Vref,VEMap,DONE,prof,profmax)) return Standard_True;
248 }
249 else if(IsVois(curE,Vref,VEMap,DONE,prof+1,profmax)) return Standard_True;
250 }
251 return Standard_False;
252}
253
254static Standard_Boolean IsObst(const ChFiDS_CommonPoint& CP,
255 const TopoDS_Vertex& Vref,
256 const ChFiDS_Map& VEMap)
257{
258 if(!CP.IsOnArc()) return Standard_False;
259 const TopoDS_Edge& E = CP.Arc();
260 TopTools_MapOfShape DONE;
261 Standard_Integer prof = 4;
262 return !IsVois(E,Vref,VEMap,DONE,0,prof);
263}
264
265//=======================================================================
266//function : CompParam
267//purpose :
268//
269//=======================================================================
270
271static void CompParam(Geom2dAdaptor_Curve Carc,
272 Handle(Geom2d_Curve) Ctg,
273 Standard_Real& parc,
274 Standard_Real& ptg,
275 const Standard_Real prefarc,
276 const Standard_Real preftg)
277{
278 Standard_Boolean found = 0;
81bba717 279 //(1) It is checked if the provided parameters are good
280 // if pcurves have the same parameters as the spine.
7fd59977 281 gp_Pnt2d point = Carc.Value(prefarc);
282 Standard_Real distini = point.Distance(Ctg->Value(preftg));
283 if (distini <= Precision::PConfusion()) {
284 parc = prefarc;
285 ptg = preftg;
286 found = Standard_True;
287 }
288 else {
81bba717 289 //(2) Intersection
0797d9d3 290#ifdef OCCT_DEBUG
81bba717 291 cout<< "CompParam : bad intersection parameters"<<endl;
7fd59977 292#endif
293 IntRes2d_IntersectionPoint int2d;
294 Geom2dInt_GInter Intersection;
295 Standard_Integer nbpt,nbseg;
296 Intersection.Perform(Geom2dAdaptor_Curve(Ctg),Carc,
297 Precision::PIntersection(),
298 Precision::PIntersection());
299
300 Standard_Real dist = Precision::Infinite(), p1, p2;
301 if (Intersection.IsDone()){
302 if (!Intersection.IsEmpty()){
303 nbseg = Intersection.NbSegments();
304 if ( nbseg > 0 ){
0797d9d3 305#ifdef OCCT_DEBUG
81bba717 306 cout<< "segments of intersection on the restrictions"<<endl;
7fd59977 307#endif
308 }
309 nbpt = Intersection.NbPoints();
310 for (Standard_Integer i = 1; i <= nbpt; i++) {
311 int2d = Intersection.Point(i);
312 p1 = int2d.ParamOnFirst();
313 p2 = int2d.ParamOnSecond();
314 if(Abs(prefarc - p2) < dist){
315 ptg = p1;
316 parc = p2;
317 dist = Abs(prefarc - p2);
318 found = 1;
319 }
320 }
321 }
322 }
323 }
324
325 if(!found){
81bba717 326 // (3) Projection...
0797d9d3 327#ifdef OCCT_DEBUG
81bba717 328 cout<<"CompParam : failed intersection PC, projection is created."<<endl;
7fd59977 329#endif
330 parc = prefarc;
331 Geom2dAPI_ProjectPointOnCurve projector(point,Ctg);
332
333 if(projector.NbPoints() == 0){
81bba717 334 // This happens in some cases when there is a vertex
335 // at the end of spine...
7fd59977 336 ptg = preftg;
0797d9d3 337#ifdef OCCT_DEBUG
81bba717 338 cout<<"CompParam : failed proj p2d/c2d, the extremity is taken!" <<endl;
7fd59977 339#endif
340 }
341 else {
81bba717 342 // It is checked if everything was calculated correctly (EDC402 C2)
7fd59977 343 if (projector.LowerDistance() < distini)
344 ptg = projector.LowerDistanceParameter();
345 else ptg = preftg;
346 }
347 }
348}
349
350//=======================================================================
351//function : CompBlendPoint
81bba717 352//purpose : create BlendPoint corresponding to a tangency on Vertex
353// pmn : 15/10/1997 : returns false, if there is no pcurve
7fd59977 354//=======================================================================
355
356static Standard_Boolean CompBlendPoint(const TopoDS_Vertex& V,
357 const TopoDS_Edge& E,
358 const Standard_Real W,
359 const TopoDS_Face F1,
360 const TopoDS_Face F2,
361 Blend_Point& BP)
362{
363 gp_Pnt2d P1, P2;
364 gp_Pnt P3d;
365 Standard_Real param, f, l;
366 Handle(Geom2d_Curve) pc;
367
368 P3d = BRep_Tool::Pnt(V);
369 param = BRep_Tool::Parameter(V,E,F1);
370 pc = BRep_Tool::CurveOnSurface(E,F1,f,l);
371 if (pc.IsNull()) return Standard_False;
372 P1 = pc->Value(param);
373 param = BRep_Tool::Parameter(V,E,F2);
374 pc = BRep_Tool::CurveOnSurface(E,F2,f,l);
375 if (pc.IsNull()) return Standard_False;
376 P2 = pc->Value(param);
377 BP.SetValue(P3d, P3d, W, P1.X(), P1.Y(), P2.X(), P2.Y());
378 return Standard_True;
379}
380
381//=======================================================================
382//function : UpdateLine
81bba717 383//purpose : Updates extremities after a partial invalidation
7fd59977 384//=======================================================================
385
386static void UpdateLine(Handle(BRepBlend_Line)& Line,
387 const Standard_Boolean isfirst)
388{
389 Standard_Real tguide, U, V;
390 if (isfirst) {
391 const Blend_Point& BP = Line->Point(1);
392 tguide = BP.Parameter();
393 if (Line->StartPointOnFirst().ParameterOnGuide() < tguide) {
394 BRepBlend_Extremity BE;
395 BP.ParametersOnS1(U, V);
396 BE.SetValue(BP.PointOnS1(), U, V, Precision::Confusion());
397 Line->SetStartPoints(BE, Line->StartPointOnSecond());
398 }
399 if (Line->StartPointOnSecond().ParameterOnGuide() < tguide) {
400 BRepBlend_Extremity BE;
401 BP.ParametersOnS2(U, V);
402 BE.SetValue(BP.PointOnS2(), U, V, Precision::Confusion());
403 Line->SetStartPoints(Line->StartPointOnFirst(), BE);
404 }
405 }
406 else {
407 const Blend_Point& BP = Line->Point(Line->NbPoints());
408 tguide = BP.Parameter();
409 if (Line->EndPointOnFirst().ParameterOnGuide() > tguide) {
410 BRepBlend_Extremity BE;
411 BP.ParametersOnS1(U, V);
412 BE.SetValue(BP.PointOnS1(), U, V, Precision::Confusion());
413 Line->SetEndPoints(BE, Line->EndPointOnSecond());
414 }
415 if (Line->EndPointOnSecond().ParameterOnGuide() > tguide) {
416 BRepBlend_Extremity BE;
417 BP.ParametersOnS2(U, V);
418 BE.SetValue(BP.PointOnS2(), U, V, Precision::Confusion());
419 Line->SetEndPoints(Line->EndPointOnFirst(), BE);
420 }
421 }
422}
423
424//=======================================================================
425//function : CompleteData
81bba717 426//purpose : Calculates curves and CommonPoints from the data
427// calculated by filling.
7fd59977 428//=======================================================================
429
430Standard_Boolean ChFi3d_Builder::CompleteData
431(Handle(ChFiDS_SurfData)& Data,
432 const Handle(Geom_Surface)& Surfcoin,
433 const Handle(Adaptor3d_HSurface)& S1,
434 const Handle(Geom2d_Curve)& PC1,
435 const Handle(Adaptor3d_HSurface)& S2,
436 const Handle(Geom2d_Curve)& PC2,
437 const TopAbs_Orientation Or,
438 const Standard_Boolean On1,
439 const Standard_Boolean Gd1,
440 const Standard_Boolean Gd2,
441 const Standard_Boolean Gf1,
442 const Standard_Boolean Gf2)
443{
444 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
445 Data->ChangeSurf(DStr.AddSurface(TopOpeBRepDS_Surface(Surfcoin,tolesp)));
446#ifdef DRAW
447 ChFi3d_SettraceDRAWFIL(Standard_True);
448 if (ChFi3d_GettraceDRAWFIL()) {
449 IndexOfConge++;
450// char name[100];
451 char* name = new char[100];
452 sprintf(name,"%s_%d","Surf",IndexOfConge);
453 DrawTrSurf::Set(name,Surfcoin);
454 }
455#endif
456
457 Standard_Real UFirst,ULast,VFirst,VLast;
458 Surfcoin->Bounds(UFirst,ULast,VFirst,VLast);
459 if(!Gd1) Data->ChangeVertexFirstOnS1().SetPoint(Surfcoin->Value(UFirst,VFirst));
460 if(!Gd2) Data->ChangeVertexFirstOnS2().SetPoint(Surfcoin->Value(UFirst,VLast));
461 if(!Gf1) Data->ChangeVertexLastOnS1().SetPoint(Surfcoin->Value(ULast,VFirst));
462 if(!Gf2) Data->ChangeVertexLastOnS2().SetPoint(Surfcoin->Value(ULast,VLast));
463
81bba717 464 //calculate curves side S1
7fd59977 465 Handle(Geom_Curve) Crv3d1;
466 if(!PC1.IsNull()) Crv3d1= Surfcoin->VIso(VFirst);
467 gp_Pnt2d pd1(UFirst,VFirst), pf1(ULast,VFirst);
468 gp_Lin2d lfil1(pd1,gp_Dir2d(gp_Vec2d(pd1,pf1)));
469 Handle(Geom2d_Curve) PCurveOnSurf = new Geom2d_Line(lfil1);
470 TopAbs_Orientation tra1 = TopAbs_FORWARD, orsurf = Or;
471 Standard_Real x,y,w = 0.5*(UFirst+ULast);
472 gp_Pnt p;
473 gp_Vec du,dv;
474 Handle(Geom2d_Curve) c2dtrim;
a8195d65 475 Standard_Real tolreached = 1.e-5;
7fd59977 476 if(!PC1.IsNull()){
477 Handle(GeomAdaptor_HCurve) hcS1 = new GeomAdaptor_HCurve(Crv3d1);
478 c2dtrim = new Geom2d_TrimmedCurve(PC1,UFirst,ULast);
479 ChFi3d_SameParameter(hcS1,c2dtrim,S1,tolapp3d,tolreached);
480 c2dtrim->Value(w).Coord(x,y);
481 S1->D1(x,y,p,du,dv);
482 gp_Vec nf = du.Crossed(dv);
483 Surfcoin->D1(w,VFirst,p,du,dv);
484 gp_Vec ns = du.Crossed(dv);
485 if(nf.Dot(ns) > 0.) tra1 = TopAbs_REVERSED;
486 else if(On1) orsurf = TopAbs::Reverse(orsurf);
487 }
488 Standard_Integer Index1OfCurve =
489 DStr.AddCurve(TopOpeBRepDS_Curve(Crv3d1,tolreached));
490 ChFiDS_FaceInterference& Fint1 = Data->ChangeInterferenceOnS1();
491 Fint1.SetFirstParameter(UFirst);
492 Fint1.SetLastParameter(ULast);
493 Fint1.SetInterference(Index1OfCurve,tra1,c2dtrim,PCurveOnSurf);
81bba717 494 //calculate curves side S2
7fd59977 495 Handle(Geom_Curve) Crv3d2;
496 if(!PC2.IsNull()) Crv3d2 = Surfcoin->VIso(VLast);
497 gp_Pnt2d pd2(UFirst,VLast), pf2(ULast,VLast);
498 gp_Lin2d lfil2(pd2,gp_Dir2d(gp_Vec2d(pd2,pf2)));
499 PCurveOnSurf = new Geom2d_Line(lfil2);
500 TopAbs_Orientation tra2 = TopAbs_FORWARD;
501 if(!PC2.IsNull()){
502 Handle(GeomAdaptor_HCurve) hcS2 = new GeomAdaptor_HCurve(Crv3d2);
503 c2dtrim = new Geom2d_TrimmedCurve(PC2,UFirst,ULast);
504 ChFi3d_SameParameter(hcS2,c2dtrim,S2,tolapp3d,tolreached);
505 c2dtrim->Value(w).Coord(x,y);
506 S2->D1(x,y,p,du,dv);
507 gp_Vec np = du.Crossed(dv);
508 Surfcoin->D1(w,VLast,p,du,dv);
509 gp_Vec ns = du.Crossed(dv);
510 if(np.Dot(ns) < 0.) {
511 tra2 = TopAbs_REVERSED;
512 if(!On1) orsurf = TopAbs::Reverse(orsurf);
513 }
514 }
515 Standard_Integer Index2OfCurve =
516 DStr.AddCurve(TopOpeBRepDS_Curve(Crv3d2,tolreached));
517 ChFiDS_FaceInterference& Fint2 = Data->ChangeInterferenceOnS2();
518 Fint2.SetFirstParameter(UFirst);
519 Fint2.SetLastParameter(ULast);
520 Fint2.SetInterference(Index2OfCurve,tra2,c2dtrim,PCurveOnSurf);
521 Data->ChangeOrientation() = orsurf;
522 return Standard_True;
523}
524
525//=======================================================================
526//function : CompleteData
81bba717 527//purpose : Calculates the surface of curves and eventually
528// CommonPoints from the data calculated in ComputeData.
7fd59977 529//
81bba717 530// 11/08/1996 : Use of F(t)
7fd59977 531//
532//=======================================================================
533
534Standard_Boolean ChFi3d_Builder::CompleteData
535(Handle(ChFiDS_SurfData)& Data,
536 Blend_Function& Func,
537 Handle(BRepBlend_Line)& lin,
538 const Handle(Adaptor3d_HSurface)& S1,
539 const Handle(Adaptor3d_HSurface)& S2,
540 const TopAbs_Orientation Or1,
541 const Standard_Boolean Gd1,
542 const Standard_Boolean Gd2,
543 const Standard_Boolean Gf1,
544 const Standard_Boolean Gf2,
545 const Standard_Boolean Reversed)
546{
547 Handle(BRepBlend_AppFunc) TheFunc
548 = new (BRepBlend_AppFunc)(lin, Func, tolapp3d, 1.e-5);
822ffdff 549
ea9632bc 550 Standard_Integer Degmax = 20, Segmax = 5000;
7fd59977 551 BRepBlend_AppSurface approx (TheFunc,
552 lin->Point(1).Parameter(),
553 lin->Point(lin->NbPoints()).Parameter(),
554 tolapp3d, 1.e-5, //tolapp2d, tolerance max
555 tolappangle, // Contact G1
822ffdff 556 myConti, Degmax, Segmax);
7fd59977 557 if (!approx.IsDone()) {
0797d9d3 558#ifdef OCCT_DEBUG
7fd59977 559 cout << "Approximation non faite !!!" << endl;
560#endif
561 return Standard_False;
562 }
0797d9d3 563#ifdef OCCT_DEBUG
7fd59977 564 approx.Dump(cout);
565#endif
566 return StoreData( Data, approx, lin, S1, S2, Or1, Gd1, Gd2, Gf1, Gf2, Reversed);
567}
568
569
570//=======================================================================
571//function : CompleteData
81bba717 572//purpose : New overload for functions surf/rst
7fd59977 573// jlr le 28/07/97 branchement F(t)
574//=======================================================================
575
576Standard_Boolean ChFi3d_Builder::CompleteData
577(Handle(ChFiDS_SurfData)& Data,
578 Blend_SurfRstFunction& Func,
579 Handle(BRepBlend_Line)& lin,
580 const Handle(Adaptor3d_HSurface)& S1,
581 const Handle(Adaptor3d_HSurface)& S2,
582 const TopAbs_Orientation Or,
583 const Standard_Boolean Reversed)
584{
585 Handle(BRepBlend_AppFuncRst) TheFunc
586 = new (BRepBlend_AppFuncRst)(lin, Func, tolapp3d, 1.e-5);
587 BRepBlend_AppSurface approx (TheFunc,
588 lin->Point(1).Parameter(),
589 lin->Point(lin->NbPoints()).Parameter(),
590 tolapp3d, 1.e-5, //tolapp2d, tolerance max
591 tolappangle, // Contact G1
592 myConti);
593 if (!approx.IsDone()) {
0797d9d3 594#ifdef OCCT_DEBUG
81bba717 595 cout << "Approximation is not done!" << endl;
7fd59977 596#endif
597 return Standard_False;
598 }
0797d9d3 599#ifdef OCCT_DEBUG
7fd59977 600 approx.Dump(cout);
601#endif
602
603 return StoreData(Data,approx,lin,S1,S2,Or,0,0,0,0,Reversed);
604}
605
606
607
608//=======================================================================
609//function : CompleteData
81bba717 610//purpose : New overload for functions rst/rst
7fd59977 611// jlr le 28/07/97 branchement F(t)
612//=======================================================================
613
614Standard_Boolean ChFi3d_Builder::CompleteData
615(Handle(ChFiDS_SurfData)& Data,
616 Blend_RstRstFunction& Func,
617 Handle(BRepBlend_Line)& lin,
618 const Handle(Adaptor3d_HSurface)& S1,
619 const Handle(Adaptor3d_HSurface)& S2,
620 const TopAbs_Orientation Or)
621{
622 Handle(BRepBlend_AppFuncRstRst) TheFunc
623 = new (BRepBlend_AppFuncRstRst)(lin, Func, tolapp3d, 1.e-5);
624 BRepBlend_AppSurface approx (TheFunc,
625 lin->Point(1).Parameter(),
626 lin->Point(lin->NbPoints()).Parameter(),
627 tolapp3d, 1.e-5, //tolapp2d, tolerance max
628 tolappangle, // Contact G1
629 myConti);
630 if (!approx.IsDone()) {
0797d9d3 631#ifdef OCCT_DEBUG
7fd59977 632 cout << "Approximation non faite !!!" << endl;
633#endif
634 return Standard_False;
635 }
0797d9d3 636#ifdef OCCT_DEBUG
7fd59977 637 approx.Dump(cout);
638#endif
639
640 return StoreData(Data,approx,lin,S1,S2,Or,0,0,0,0);
641}
642
643
644
645
646//=======================================================================
647//function : StoreData
81bba717 648//purpose : Copy of an approximation result in SurfData.
7fd59977 649//=======================================================================
650
651Standard_Boolean ChFi3d_Builder::StoreData(Handle(ChFiDS_SurfData)& Data,
652 const AppBlend_Approx& approx,
653 const Handle(BRepBlend_Line)& lin,
654 const Handle(Adaptor3d_HSurface)& S1,
655 const Handle(Adaptor3d_HSurface)& S2,
656 const TopAbs_Orientation Or1,
657 const Standard_Boolean Gd1,
658 const Standard_Boolean Gd2,
659 const Standard_Boolean Gf1,
660 const Standard_Boolean Gf2,
661 const Standard_Boolean Reversed)
662{
81bba717 663 // Small control tools.
7fd59977 664 static Handle(GeomAdaptor_HCurve) checkcurve;
665 if(checkcurve.IsNull()) checkcurve = new GeomAdaptor_HCurve();
666 GeomAdaptor_Curve& chc = checkcurve->ChangeCurve();
667 Standard_Real tolget3d, tolget2d, tolaux, tolC1, tolcheck;
7fd59977 668 Standard_Real tolC2 = 0.;
7fd59977 669 approx.TolReached(tolget3d, tolget2d);
670 tolaux = approx.TolCurveOnSurf(1);
671 tolC1 = tolget3d + tolaux;
672 if(!S2.IsNull()) {
673 tolaux = approx.TolCurveOnSurf(2);
674 tolC2 = tolget3d + tolaux;
675 }
676
677 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
81bba717 678 // By default parametric space is created using a square surface
679 // to be able to parameterize in U by # R*teta // a revoir lbo 29/08/97
7fd59977 680 const TColStd_Array1OfReal& ku = approx.SurfUKnots();
681 const TColStd_Array1OfReal& kv = approx.SurfVKnots();
682 Standard_Real larg = (kv(kv.Upper())-kv(kv.Lower()));
683 TColStd_Array1OfReal& kku = *((TColStd_Array1OfReal*)((void*)&ku));
684 BSplCLib::Reparametrize(0.,larg,kku);
685 Handle(Geom_BSplineSurface) Surf =
686 new Geom_BSplineSurface(approx.SurfPoles(),approx.SurfWeights(),
687 kku,kv,
688 approx.SurfUMults(),approx.SurfVMults(),
689 approx.UDegree(),approx.VDegree());
81bba717 690// extension of the surface
7fd59977 691
692 Standard_Real length1,length2;
693 length1=Data->FirstExtensionValue();
694 length2=Data->LastExtensionValue();
695 if (length1 > Precision::Confusion())
696 GeomLib::ExtendSurfByLength(Surf,length1,1,Standard_False,Standard_False);
697 if (length2 > Precision::Confusion())
698 GeomLib::ExtendSurfByLength(Surf,length2,1,Standard_False,Standard_True);
699
af99433e 700 //Correction of surface on extremities
701 if (length1 <= Precision::Confusion())
702 {
703 gp_Pnt P11, P21;
704 P11 = lin->StartPointOnFirst().Value();
705 P21 = lin->StartPointOnSecond().Value();
706 Surf->SetPole(1, 1, P11);
707 Surf->SetPole(Surf->NbUPoles(), 1, P21);
708 }
709 if (length2 <= Precision::Confusion())
710 {
711 gp_Pnt P12, P22;
712 P12 = lin->EndPointOnFirst().Value();
713 P22 = lin->EndPointOnSecond().Value();
714 Surf->SetPole(1, Surf->NbVPoles(), P12);
715 Surf->SetPole(Surf->NbUPoles(), Surf->NbVPoles(), P22);
716 }
717
7fd59977 718 Data->ChangeSurf(DStr.AddSurface(TopOpeBRepDS_Surface(Surf,tolget3d)));
719
720#ifdef DRAW
721 ChFi3d_SettraceDRAWFIL(Standard_True);
722 if (ChFi3d_GettraceDRAWFIL()) {
723 IndexOfConge++;
724// char name[100];
725 char* name=new char[100];
726 sprintf(name,"%s_%d","Surf",IndexOfConge);
727 DrawTrSurf::Set(name,Surf);
728 }
729#endif
730 Standard_Real UFirst,ULast,VFirst,VLast,pppdeb,pppfin;
731 Surf->Bounds(UFirst,ULast,VFirst,VLast);
732 BRepAdaptor_Curve2d brc;
733 BRepAdaptor_Curve CArc;
734 Handle(BRepAdaptor_HSurface)
735 BS1 = Handle(BRepAdaptor_HSurface)::DownCast(S1);
736 Handle(BRepAdaptor_HSurface)
737 BS2 = Handle(BRepAdaptor_HSurface)::DownCast(S2);
738 Geom2dAPI_ProjectPointOnCurve projector;
739
740 Standard_Real Uon1 = UFirst, Uon2 = ULast;
741 Standard_Integer ion1 = 1, ion2 = 2;
742 if(Reversed) { Uon1 = ULast; Uon2 = UFirst; ion1 = 2; ion2 = 1; }
743
81bba717 744 // The SurfData is filled in what concerns S1,
7fd59977 745 Handle(Geom_Curve) Crv3d1 = Surf->UIso(Uon1);
746 gp_Pnt2d pori1(Uon1,0.);
747 gp_Lin2d lfil1(pori1,gp::DY2d());
748 Handle(Geom2d_Curve) PCurveOnSurf = new Geom2d_Line(lfil1);
749 Handle(Geom2d_Curve) PCurveOnFace;
750 PCurveOnFace = new
751 Geom2d_BSplineCurve(approx.Curve2dPoles(ion1),approx.Curves2dKnots(),
752 approx.Curves2dMults(),approx.Curves2dDegree());
753
754
755 Standard_Real par1=PCurveOnFace->FirstParameter();
756 Standard_Real par2= PCurveOnFace->LastParameter();
757 chc.Load(Crv3d1,par1,par2);
758
759 if(!ChFi3d_CheckSameParameter(checkcurve,PCurveOnFace,S1,tolC1,tolcheck)){
0797d9d3 760#ifdef OCCT_DEBUG
81bba717 761 cout<<"aaproximate tolerance under-valued : "<<tolC1<<" for "<<tolcheck<<endl;
7fd59977 762#endif
763 tolC1 = tolcheck;
764 }
765 Standard_Integer Index1OfCurve =
766 DStr.AddCurve(TopOpeBRepDS_Curve(Crv3d1,tolC1));
767
768 Standard_Real uarc,utg;
769 if(Gd1){
770 TopoDS_Face forwfac = BS1->ChangeSurface().Face();
771 forwfac.Orientation(TopAbs_FORWARD);
772 brc.Initialize(Data->VertexFirstOnS1().Arc(),forwfac);
773 ChFiDS_CommonPoint& V = Data->ChangeVertexFirstOnS1();
774 CArc.Initialize(V.Arc());
775 CompParam(brc,PCurveOnFace,uarc,utg, V.ParameterOnArc(), V.Parameter());
776 tolcheck = CArc.Value(uarc).Distance(V.Point());
777 V.SetArc(tolC1+tolcheck,V.Arc(),uarc,V.TransitionOnArc());
778 pppdeb = utg;
779 }
780 else pppdeb = VFirst;
781 if(Gf1){
782 TopoDS_Face forwfac = BS1->ChangeSurface().Face();
783 forwfac.Orientation(TopAbs_FORWARD);
784 ChFiDS_CommonPoint& V = Data->ChangeVertexLastOnS1();
785 brc.Initialize(V.Arc(),forwfac);
786 CArc.Initialize(V.Arc());
787 CompParam(brc,PCurveOnFace,uarc,utg, V.ParameterOnArc(), V.Parameter());
788 tolcheck = CArc.Value(uarc).Distance(V.Point());
789 V.SetArc(tolC1+tolcheck,V.Arc(),uarc,V.TransitionOnArc());
790 pppfin = utg;
791 }
792 else pppfin = VLast;
793 ChFiDS_FaceInterference& Fint1 = Data->ChangeInterferenceOnS1();
794 Fint1.SetFirstParameter(pppdeb);
795 Fint1.SetLastParameter(pppfin);
796 TopAbs_Orientation TraOn1;
797 if(Reversed) TraOn1 = ChFi3d_TrsfTrans(lin->TransitionOnS2());
798 else TraOn1 = ChFi3d_TrsfTrans(lin->TransitionOnS1());
799 Fint1.SetInterference(Index1OfCurve,TraOn1,PCurveOnFace,PCurveOnSurf);
800
81bba717 801 // SurfData is filled in what concerns S2,
7fd59977 802 Handle(Geom_Curve) Crv3d2 = Surf->UIso(Uon2);
803 gp_Pnt2d pori2(Uon2,0.);
804 gp_Lin2d lfil2(pori2,gp::DY2d());
805 PCurveOnSurf = new Geom2d_Line(lfil2);
806 if(!S2.IsNull()){
807 PCurveOnFace = new Geom2d_BSplineCurve(approx.Curve2dPoles(ion2),
808 approx.Curves2dKnots(),
809 approx.Curves2dMults(),
810 approx.Curves2dDegree());
811 chc.Load(Crv3d2,par1,par2);
812 if(!ChFi3d_CheckSameParameter(checkcurve,PCurveOnFace,S2,tolC2,tolcheck)){
0797d9d3 813#ifdef OCCT_DEBUG
81bba717 814 cout<<"approximate tolerance under-evaluated : "<<tolC2<<" for "<<tolcheck<<endl;
7fd59977 815#endif
816 tolC2 = tolcheck;
817 }
818 }
819 Standard_Integer Index2OfCurve =
820 DStr.AddCurve(TopOpeBRepDS_Curve(Crv3d2,tolC2));
821 if(Gd2){
822 TopoDS_Face forwfac = BS2->ChangeSurface().Face();
823 forwfac.Orientation(TopAbs_FORWARD);
824 brc.Initialize(Data->VertexFirstOnS2().Arc(),forwfac);
825 ChFiDS_CommonPoint& V = Data->ChangeVertexFirstOnS2();
826 CArc.Initialize(V.Arc());
827 CompParam(brc,PCurveOnFace,uarc,utg, V.ParameterOnArc(), V.Parameter());
828 tolcheck = CArc.Value(uarc).Distance(V.Point());
829 V.SetArc(tolC2+tolcheck,V.Arc(),uarc,V.TransitionOnArc());
830 pppdeb = utg;
831 }
832 else pppdeb = VFirst;
833 if(Gf2){
834 TopoDS_Face forwfac = BS2->ChangeSurface().Face();
835 forwfac.Orientation(TopAbs_FORWARD);
836 brc.Initialize(Data->VertexLastOnS2().Arc(),forwfac);
837 ChFiDS_CommonPoint& V = Data->ChangeVertexLastOnS2();
838 CArc.Initialize(V.Arc());
839 CompParam(brc,PCurveOnFace,uarc,utg, V.ParameterOnArc(), V.Parameter());
840 tolcheck = CArc.Value(uarc).Distance(V.Point());
841 V.SetArc(tolC2+tolcheck,V.Arc(),uarc,V.TransitionOnArc());
842 pppfin = utg;
843 }
844 else pppfin = VLast;
845 ChFiDS_FaceInterference& Fint2 = Data->ChangeInterferenceOnS2();
846 Fint2.SetFirstParameter(pppdeb);
847 Fint2.SetLastParameter(pppfin);
848 if(!S2.IsNull()){
849 TopAbs_Orientation TraOn2;
850 if(Reversed) TraOn2 = ChFi3d_TrsfTrans(lin->TransitionOnS1());
851 else TraOn2 = ChFi3d_TrsfTrans(lin->TransitionOnS2());
852 Fint2.SetInterference(Index2OfCurve,TraOn2,PCurveOnFace,PCurveOnSurf);
853 }
854 else {
855 Handle(Geom2d_Curve) bidpc;
856 Fint2.SetInterference
857 (Index2OfCurve,TopAbs_FORWARD,bidpc,PCurveOnSurf);
858 }
859
81bba717 860 // the orientation of the fillet in relation to the faces is evaluated,
7fd59977 861
862 Handle(Adaptor3d_HSurface) Sref = S1;
863 PCurveOnFace = Fint1.PCurveOnFace();
864 if(Reversed){ Sref = S2; PCurveOnFace = Fint2.PCurveOnFace(); }
865
866// Modified by skv - Wed Jun 9 17:16:26 2004 OCC5898 Begin
867// gp_Pnt2d PUV = PCurveOnFace->Value((VFirst+VLast)/2.);
868// gp_Pnt P;
869// gp_Vec Du1,Du2,Dv1,Dv2;
870// Sref->D1(PUV.X(),PUV.Y(),P,Du1,Dv1);
871// Du1.Cross(Dv1);
872// if (Or1 == TopAbs_REVERSED) Du1.Reverse();
873// Surf->D1(UFirst,(VFirst+VLast)/2.,P,Du2,Dv2);
874// Du2.Cross(Dv2);
875// if (Du1.Dot(Du2)>0) Data->ChangeOrientation() = TopAbs_FORWARD;
876// else Data->ChangeOrientation() = TopAbs_REVERSED;
877
878 Standard_Real aDelta = VLast - VFirst;
879 Standard_Integer aDenom = 2;
880
302f96fb 881 for(;;) {
7fd59977 882 Standard_Real aDeltav = aDelta/aDenom;
883 Standard_Real aParam = VFirst + aDeltav;
884 gp_Pnt2d PUV = PCurveOnFace->Value(aParam);
885 gp_Pnt P;
886 gp_Vec Du1,Du2,Dv1,Dv2;
887
888 Sref->D1(PUV.X(),PUV.Y(),P,Du1,Dv1);
889 Du1.Cross(Dv1);
890
891 if (Or1 == TopAbs_REVERSED)
892 Du1.Reverse();
893
894 Surf->D1(UFirst, aParam, P, Du2, Dv2);
895 Du2.Cross(Dv2);
896
897 if (Du1.Magnitude() <= tolget3d ||
898 Du2.Magnitude() <= tolget3d) {
899 aDenom++;
900
901 if (Abs(aDeltav) <= tolget2d)
902 return Standard_False;
903
904 continue;
905 }
906
907 if (Du1.Dot(Du2)>0)
908 Data->ChangeOrientation() = TopAbs_FORWARD;
909 else
910 Data->ChangeOrientation() = TopAbs_REVERSED;
911
912 break;
913 }
914// Modified by skv - Wed Jun 9 17:16:26 2004 OCC5898 End
915
916 if(!Gd1 && !S1.IsNull())
917 ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
918 Standard_True, Data->ChangeVertex(1,ion1),tolC1);
919 if(!Gf1 && !S1.IsNull())
920 ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
921 Standard_False,Data->ChangeVertex(0,ion1),tolC1);
922 if(!Gd2 && !S2.IsNull())
923 ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
924 Standard_True, Data->ChangeVertex(1,ion2),tolC2);
925 if(!Gf2 && !S2.IsNull())
926 ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
927 Standard_False, Data->ChangeVertex(0,ion2),tolC2);
81bba717 928 // Parameters on ElSpine
7fd59977 929 Standard_Integer nbp = lin->NbPoints();
930 Data->FirstSpineParam(lin->Point(1).Parameter());
931 Data->LastSpineParam(lin->Point(nbp).Parameter());
932 return Standard_True;
933}
934
935
936
937//=======================================================================
938//function : ComputeData
81bba717 939//purpose : Head of the path edge/face for the bypass of obstacle.
7fd59977 940//=======================================================================
941
942Standard_Boolean ChFi3d_Builder::ComputeData
943(Handle(ChFiDS_SurfData)& Data,
944 const Handle(ChFiDS_HElSpine)& HGuide,
945 Handle(BRepBlend_Line)& Lin,
946 const Handle(Adaptor3d_HSurface)& S1,
947 const Handle(Adaptor3d_TopolTool)& I1,
948 const Handle(Adaptor3d_HSurface)& S2,
949 const Handle(Adaptor2d_HCurve2d)& PC2,
950 const Handle(Adaptor3d_TopolTool)& I2,
951 Standard_Boolean& Decroch,
952 Blend_SurfRstFunction& Func,
953 Blend_FuncInv& FInv,
954 Blend_SurfPointFuncInv& FInvP,
955 Blend_SurfCurvFuncInv& FInvC,
956 const Standard_Real PFirst,
957 const Standard_Real MaxStep,
958 const Standard_Real Fleche,
959 const Standard_Real TolGuide,
960 Standard_Real& First,
961 Standard_Real& Last,
962 const math_Vector& Soldep,
963 const Standard_Boolean Inside,
964 const Standard_Boolean Appro,
965 const Standard_Boolean Forward,
966 const Standard_Boolean RecP,
967 const Standard_Boolean RecS,
968 const Standard_Boolean RecRst)
969{
970 BRepBlend_SurfRstLineBuilder TheWalk(S1,I1,S2,PC2,I2);
971
972 Data->FirstExtensionValue(0);
973 Data->LastExtensionValue(0);
974
975 Standard_Boolean reverse = (!Forward || Inside);
976 Standard_Real SpFirst = HGuide->FirstParameter();
977 Standard_Real SpLast = HGuide->LastParameter();
978 Standard_Real Target = SpLast;
979 if(reverse) Target = SpFirst;
980 Standard_Real Targetsov = Target;
981
982 Standard_Real MS = MaxStep;
983 Standard_Integer again = 0;
984 Standard_Integer nbptmin = 3; //jlr
1d47d8d0 985 Standard_Integer Nbpnt = 1;
81bba717 986 // the initial solution is reframed if necessary.
7fd59977 987 math_Vector ParSol(1,3);
988 Standard_Real NewFirst = PFirst;
989 if(RecP || RecS || RecRst){
990 if(!TheWalk.PerformFirstSection(Func,FInv,FInvP,FInvC,PFirst,Target,Soldep,
991 tolesp,TolGuide,RecRst,RecP,RecS,
992 NewFirst,ParSol)){
0797d9d3 993#ifdef OCCT_DEBUG
81bba717 994 cout<<"ChFi3d_Builder::ComputeData : calculation fail first section"<<endl;
7fd59977 995#endif
996 return Standard_False;
997 }
998 }
999 else {
1000 ParSol = Soldep;
1001 }
1002
1003 while (again < 2){
1004 TheWalk.Perform (Func,FInv,FInvP,FInvC,NewFirst,Last,
1005 MS,TolGuide,ParSol,tolesp,Fleche,Appro);
1006
1007 if (!TheWalk.IsDone()) {
0797d9d3 1008#ifdef OCCT_DEBUG
81bba717 1009 cout << "Path not created" << endl;
7fd59977 1010#endif
1011 return Standard_False;
1012 }
1013
1014 if (reverse) {
1015 if (!TheWalk.Complete(Func,FInv,FInvP,FInvC,SpLast)) {
0797d9d3 1016#ifdef OCCT_DEBUG
81bba717 1017 cout << "Not completed" << endl;
7fd59977 1018#endif
1019 }
1020 }
1021
1022
1023 Lin = TheWalk.Line();
1024 Nbpnt = Lin->NbPoints();
1025 if (Nbpnt <= 1 && again == 0) {
1026 again++;
0797d9d3 1027#ifdef OCCT_DEBUG
81bba717 1028 cout <<"one point of the path MS/50 is attempted."<<endl;
7fd59977 1029#endif
1030 MS = MS/50.; Target = Targetsov;
1031 }
1032 else if (Nbpnt<=nbptmin && again == 0) {
1033 again++;
0797d9d3 1034#ifdef OCCT_DEBUG
81bba717 1035 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 1036#endif
1037 Standard_Real u1 = Lin->Point(1).Parameter();
1038 Standard_Real u2 = Lin->Point(Nbpnt).Parameter();
1039 MS = (u2-u1)/(nbptmin+1.0);
1040// cout << " MS : " << MS << " u1 : " << u1 << " u2 : " << u2 << " nbptmin : " << nbptmin << endl;
1041 Target = Targetsov;
1042 }
1043 else if(Nbpnt<=nbptmin){
0797d9d3 1044#ifdef OCCT_DEBUG
81bba717 1045 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 1046#endif
1047 return Standard_False;
1048 }
1049 else {
1050 again = 2;
1051 }
1052 }
1053#ifdef DRAW
1054 ChFi3d_SettraceDRAWWALK(Standard_True);
1055 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_True);
1056#endif
1057 if(Forward) Decroch = TheWalk.DecrochEnd();
1058 else Decroch = TheWalk.DecrochStart();
1059 Last = Lin->Point(Nbpnt).Parameter();
1060 First = Lin->Point(1).Parameter();
1061 return Standard_True;
1062}
1063
1064
1065//=======================================================================
1066//function : ComputeData
81bba717 1067//purpose : Heading of the path edge/edge for the bypass of obstacle.
7fd59977 1068//=======================================================================
1069
1070Standard_Boolean ChFi3d_Builder::ComputeData
1071(Handle(ChFiDS_SurfData)& Data,
1072 const Handle(ChFiDS_HElSpine)& HGuide,
1073 Handle(BRepBlend_Line)& Lin,
1074 const Handle(Adaptor3d_HSurface)& S1,
1075 const Handle(Adaptor2d_HCurve2d)& PC1,
1076 const Handle(Adaptor3d_TopolTool)& I1,
1077 Standard_Boolean& Decroch1,
1078 const Handle(Adaptor3d_HSurface)& S2,
1079 const Handle(Adaptor2d_HCurve2d)& PC2,
1080 const Handle(Adaptor3d_TopolTool)& I2,
1081 Standard_Boolean& Decroch2,
1082 Blend_RstRstFunction& Func,
1083 Blend_SurfCurvFuncInv& FInv1,
1084 Blend_CurvPointFuncInv& FInvP1,
1085 Blend_SurfCurvFuncInv& FInv2,
1086 Blend_CurvPointFuncInv& FInvP2,
1087 const Standard_Real PFirst,
1088 const Standard_Real MaxStep,
1089 const Standard_Real Fleche,
1090 const Standard_Real TolGuide,
1091 Standard_Real& First,
1092 Standard_Real& Last,
1093 const math_Vector& Soldep,
1094 const Standard_Boolean Inside,
1095 const Standard_Boolean Appro,
1096 const Standard_Boolean Forward,
1097 const Standard_Boolean RecP1,
1098 const Standard_Boolean RecRst1,
1099 const Standard_Boolean RecP2,
1100 const Standard_Boolean RecRst2)
1101{
1102 BRepBlend_RstRstLineBuilder TheWalk(S1, PC1, I1, S2, PC2, I2);
1103
1104 Data->FirstExtensionValue(0);
1105 Data->LastExtensionValue(0);
1106
1107 Standard_Boolean reverse = (!Forward || Inside);
1108 Standard_Real SpFirst = HGuide->FirstParameter();
1109 Standard_Real SpLast = HGuide->LastParameter();
1110 Standard_Real Target = SpLast;
1111 if(reverse) Target = SpFirst;
1112 Standard_Real Targetsov = Target;
1113
1114 Standard_Real MS = MaxStep;
1115 Standard_Integer again = 0;
1116 Standard_Integer nbptmin = 3; //jlr
7fd59977 1117 Standard_Integer Nbpnt = 0;
81bba717 1118 // the initial solution is reframed if necessary.
7fd59977 1119 math_Vector ParSol(1,2);
1120 Standard_Real NewFirst = PFirst;
1121 if (RecP1 || RecRst1 || RecP2 || RecRst2) {
1122 if (!TheWalk.PerformFirstSection(Func, FInv1, FInvP1, FInv2, FInvP2, PFirst, Target, Soldep,
1123 tolesp, TolGuide, RecRst1, RecP1, RecRst2, RecP2,
1124 NewFirst, ParSol)){
0797d9d3 1125#ifdef OCCT_DEBUG
81bba717 1126 cout<<"ChFi3d_Builder::ComputeData : fail calculation first section"<<endl;
7fd59977 1127#endif
1128 return Standard_False;
1129 }
1130 }
1131 else {
1132 ParSol = Soldep;
1133 }
1134
1135 while (again < 2){
1136 TheWalk.Perform (Func, FInv1, FInvP1, FInv2, FInvP2, NewFirst, Last,
1137 MS, TolGuide, ParSol, tolesp, Fleche, Appro);
1138
1139 if (!TheWalk.IsDone()) {
0797d9d3 1140#ifdef OCCT_DEBUG
81bba717 1141 cout << "Path not done" << endl;
7fd59977 1142#endif
1143 return Standard_False;
1144 }
1145
1146 if (reverse) {
1147 if (!TheWalk.Complete(Func, FInv1, FInvP1, FInv2, FInvP2, SpLast)) {
0797d9d3 1148#ifdef OCCT_DEBUG
81bba717 1149 cout << "Not completed" << endl;
7fd59977 1150#endif
1151 }
1152 }
1153
1154
1155 Lin = TheWalk.Line();
1156 Nbpnt = Lin->NbPoints();
1157 if (Nbpnt <= 1 && again == 0) {
1158 again++;
0797d9d3 1159#ifdef OCCT_DEBUG
81bba717 1160 cout <<"one point of path MS/50 is attempted."<<endl;
7fd59977 1161#endif
1162 MS = MS/50.; Target = Targetsov;
1163 }
1164 else if (Nbpnt<=nbptmin && again == 0) {
1165 again++;
0797d9d3 1166#ifdef OCCT_DEBUG
81bba717 1167 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 1168#endif
1169 Standard_Real u1 = Lin->Point(1).Parameter();
1170 Standard_Real u2 = Lin->Point(Nbpnt).Parameter();
1171 MS = (u2-u1)/(nbptmin+1);
1172 Target = Targetsov;
1173 }
1174 else if(Nbpnt<=nbptmin){
0797d9d3 1175#ifdef OCCT_DEBUG
81bba717 1176 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 1177#endif
1178 return Standard_False;
1179 }
1180 else {
1181 again = 2;
1182 }
1183 }
1184#ifdef DRAW
1185 ChFi3d_SettraceDRAWWALK(Standard_True);
1186 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_True);
1187#endif
1188 if (Forward) {
1189 Decroch1 = TheWalk.Decroch1End();
1190 Decroch2 = TheWalk.Decroch2End();
1191 }
1192 else {
1193 Decroch1 = TheWalk.Decroch1Start();
1194 Decroch2 = TheWalk.Decroch2Start();
1195 }
1196 Last = Lin->Point(Nbpnt).Parameter();
1197 First = Lin->Point(1).Parameter();
1198 return Standard_True;
1199}
1200
1201
1202//=======================================================================
1203//function : SimulData
81bba717 1204//purpose : Heading of the path edge/face for the bypass of obstacle in simulation mode.
7fd59977 1205//=======================================================================
1206
1207Standard_Boolean ChFi3d_Builder::SimulData
1208(Handle(ChFiDS_SurfData)& /*Data*/,
1209 const Handle(ChFiDS_HElSpine)& HGuide,
1210 Handle(BRepBlend_Line)& Lin,
1211 const Handle(Adaptor3d_HSurface)& S1,
1212 const Handle(Adaptor3d_TopolTool)& I1,
1213 const Handle(Adaptor3d_HSurface)& S2,
1214 const Handle(Adaptor2d_HCurve2d)& PC2,
1215 const Handle(Adaptor3d_TopolTool)& I2,
1216 Standard_Boolean& Decroch,
1217 Blend_SurfRstFunction& Func,
1218 Blend_FuncInv& FInv,
1219 Blend_SurfPointFuncInv& FInvP,
1220 Blend_SurfCurvFuncInv& FInvC,
1221 const Standard_Real PFirst,
1222 const Standard_Real MaxStep,
1223 const Standard_Real Fleche,
1224 const Standard_Real TolGuide,
1225 Standard_Real& First,
1226 Standard_Real& Last,
1227 const math_Vector& Soldep,
1228 const Standard_Integer NbSecMin,
1229 const Standard_Boolean Inside,
1230 const Standard_Boolean Appro,
1231 const Standard_Boolean Forward,
1232 const Standard_Boolean RecP,
1233 const Standard_Boolean RecS,
1234 const Standard_Boolean RecRst)
1235{
1236 BRepBlend_SurfRstLineBuilder TheWalk(S1,I1,S2,PC2,I2);
1237
1238 Standard_Boolean reverse = (!Forward || Inside);
1239 Standard_Real SpFirst = HGuide->FirstParameter();
1240 Standard_Real SpLast = HGuide->LastParameter();
1241 Standard_Real Target = SpLast;
1242 if(reverse) Target = SpFirst;
1243 Standard_Real Targetsov = Target;
1244
1245 Standard_Real MS = MaxStep;
1246 Standard_Integer again = 0;
7fd59977 1247 Standard_Integer Nbpnt = 0;
81bba717 1248 // the starting solution is reframed if needed.
7fd59977 1249 math_Vector ParSol(1,3);
1250 Standard_Real NewFirst = PFirst;
1251 if(RecP || RecS || RecRst){
1252 if(!TheWalk.PerformFirstSection(Func,FInv,FInvP,FInvC,PFirst,Target,Soldep,
1253 tolesp,TolGuide,RecRst,RecP,RecS,
1254 NewFirst,ParSol)){
0797d9d3 1255#ifdef OCCT_DEBUG
7fd59977 1256
81bba717 1257 cout<<"ChFi3d_Builder::SimulData : fail calculate first section"<<endl;
7fd59977 1258#endif
1259 return Standard_False;
1260 }
1261 }
1262 else {
1263 ParSol = Soldep;
1264 }
1265
1266 while (again < 2){
1267 TheWalk.Perform (Func,FInv,FInvP,FInvC,NewFirst,Last,
1268 MS,TolGuide,ParSol,tolesp,Fleche,Appro);
1269 if (!TheWalk.IsDone()) {
0797d9d3 1270#ifdef OCCT_DEBUG
81bba717 1271 cout << "Path not done" << endl;
7fd59977 1272#endif
1273 return Standard_False;
1274 }
1275 if (reverse) {
1276 if (!TheWalk.Complete(Func,FInv,FInvP,FInvC,SpLast)) {
0797d9d3 1277#ifdef OCCT_DEBUG
81bba717 1278 cout << "Not completed" << endl;
7fd59977 1279#endif
1280 }
1281 }
1282 Lin = TheWalk.Line();
1283 Nbpnt = Lin->NbPoints();
1284 if (Nbpnt <= 1 && again == 0) {
1285 again++;
0797d9d3 1286#ifdef OCCT_DEBUG
81bba717 1287 cout <<"one point of path MS/50 is attempted."<<endl;
7fd59977 1288#endif
1289 MS = MS/50.; Target = Targetsov;
1290 }
1291 else if (Nbpnt <= NbSecMin && again == 0) {
1292 again++;
0797d9d3 1293#ifdef OCCT_DEBUG
81bba717 1294 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 1295#endif
1296 Standard_Real u1 = Lin->Point(1).Parameter();
1297 Standard_Real u2 = Lin->Point(Nbpnt).Parameter();
1298 MS = (u2-u1)/(NbSecMin+1);
1299 Target = Targetsov;
1300 }
1301 else if(Nbpnt<=NbSecMin){
0797d9d3 1302#ifdef OCCT_DEBUG
81bba717 1303 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 1304#endif
1305 return Standard_False;
1306 }
1307 else {
1308 again = 2;
1309 }
1310 }
1311#ifdef DRAW
1312 ChFi3d_SettraceDRAWWALK(Standard_True);
1313 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_True);
1314#endif
1315 if(Forward) Decroch = TheWalk.DecrochEnd();
1316 else Decroch = TheWalk.DecrochStart();
1317 Last = Lin->Point(Nbpnt).Parameter();
1318 First = Lin->Point(1).Parameter();
1319 return Standard_True;
1320}
1321
1322
1323//=======================================================================
1324//function : SimulData
81bba717 1325//purpose : Heading of path edge/edge for the bypass
1326// of obstacle in simulation mode.
7fd59977 1327//=======================================================================
1328
1329Standard_Boolean ChFi3d_Builder::SimulData
1330(Handle(ChFiDS_SurfData)& /*Data*/,
1331 const Handle(ChFiDS_HElSpine)& HGuide,
1332 Handle(BRepBlend_Line)& Lin,
1333 const Handle(Adaptor3d_HSurface)& S1,
1334 const Handle(Adaptor2d_HCurve2d)& PC1,
1335 const Handle(Adaptor3d_TopolTool)& I1,
1336 Standard_Boolean& Decroch1,
1337 const Handle(Adaptor3d_HSurface)& S2,
1338 const Handle(Adaptor2d_HCurve2d)& PC2,
1339 const Handle(Adaptor3d_TopolTool)& I2,
1340 Standard_Boolean& Decroch2,
1341 Blend_RstRstFunction& Func,
1342 Blend_SurfCurvFuncInv& FInv1,
1343 Blend_CurvPointFuncInv& FInvP1,
1344 Blend_SurfCurvFuncInv& FInv2,
1345 Blend_CurvPointFuncInv& FInvP2,
1346 const Standard_Real PFirst,
1347 const Standard_Real MaxStep,
1348 const Standard_Real Fleche,
1349 const Standard_Real TolGuide,
1350 Standard_Real& First,
1351 Standard_Real& Last,
1352 const math_Vector& Soldep,
1353 const Standard_Integer NbSecMin,
1354 const Standard_Boolean Inside,
1355 const Standard_Boolean Appro,
1356 const Standard_Boolean Forward,
1357 const Standard_Boolean RecP1,
1358 const Standard_Boolean RecRst1,
1359 const Standard_Boolean RecP2,
1360 const Standard_Boolean RecRst2)
1361{
1362 BRepBlend_RstRstLineBuilder TheWalk(S1, PC1, I1, S2, PC2, I2);
1363
1364 Standard_Boolean reverse = (!Forward || Inside);
1365 Standard_Real SpFirst = HGuide->FirstParameter();
1366 Standard_Real SpLast = HGuide->LastParameter();
1367 Standard_Real Target = SpLast;
1368 if(reverse) Target = SpFirst;
1369 Standard_Real Targetsov = Target;
1370
1371 Standard_Real MS = MaxStep;
1372 Standard_Integer again = 0;
7fd59977 1373 Standard_Integer Nbpnt = 0;
81bba717 1374 // The initial solution is reframed if necessary.
7fd59977 1375 math_Vector ParSol(1,2);
1376 Standard_Real NewFirst = PFirst;
1377 if (RecP1 || RecRst1 || RecP2 || RecRst2) {
1378 if(!TheWalk.PerformFirstSection(Func, FInv1, FInvP1, FInv2, FInvP2, PFirst, Target, Soldep,
1379 tolesp, TolGuide, RecRst1, RecP1, RecRst2, RecP2,
1380 NewFirst,ParSol)){
0797d9d3 1381#ifdef OCCT_DEBUG
7fd59977 1382
81bba717 1383 cout<<"ChFi3d_Builder::SimulData : calculation fail first section"<<endl;
7fd59977 1384#endif
1385 return Standard_False;
1386 }
1387 }
1388 else {
1389 ParSol = Soldep;
1390 }
1391
1392 while (again < 2){
1393 TheWalk.Perform (Func, FInv1, FInvP1, FInv2, FInvP2, NewFirst, Last,
1394 MS, TolGuide, ParSol, tolesp, Fleche, Appro);
1395 if (!TheWalk.IsDone()) {
0797d9d3 1396#ifdef OCCT_DEBUG
81bba717 1397 cout << "Path not created" << endl;
7fd59977 1398#endif
1399 return Standard_False;
1400 }
1401 if (reverse) {
1402 if (!TheWalk.Complete(Func, FInv1, FInvP1, FInv2, FInvP2, SpLast)) {
0797d9d3 1403#ifdef OCCT_DEBUG
81bba717 1404 cout << "Not completed" << endl;
7fd59977 1405#endif
1406 }
1407 }
1408 Lin = TheWalk.Line();
1409 Nbpnt = Lin->NbPoints();
1410 if (Nbpnt <= 1 && again == 0) {
1411 again++;
0797d9d3 1412#ifdef OCCT_DEBUG
81bba717 1413 cout <<"only one point of path MS/50 is attempted."<<endl;
7fd59977 1414#endif
1415 MS = MS/50.; Target = Targetsov;
1416 }
1417 else if (Nbpnt <= NbSecMin && again == 0) {
1418 again++;
0797d9d3 1419#ifdef OCCT_DEBUG
81bba717 1420 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 1421#endif
1422 Standard_Real u1 = Lin->Point(1).Parameter();
1423 Standard_Real u2 = Lin->Point(Nbpnt).Parameter();
1424 MS = (u2-u1)/(NbSecMin+1);
1425 Target = Targetsov;
1426 }
1427 else if(Nbpnt<=NbSecMin){
0797d9d3 1428#ifdef OCCT_DEBUG
81bba717 1429 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 1430#endif
1431 return Standard_False;
1432 }
1433 else {
1434 again = 2;
1435 }
1436 }
1437#ifdef DRAW
1438 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_True);
1439#endif
1440 if (Forward) {
1441 Decroch1 = TheWalk.Decroch1End();
1442 Decroch2 = TheWalk.Decroch2End();
1443 }
1444 else {
1445 Decroch1 = TheWalk.Decroch1Start();
1446 Decroch2 = TheWalk.Decroch2Start();
1447 }
1448
1449 Last = Lin->Point(Nbpnt).Parameter();
1450 First = Lin->Point(1).Parameter();
1451 return Standard_True;
1452}
1453
1454
1455
1456
1457//=======================================================================
1458//function : ComputeData
81bba717 1459//purpose : Construction of elementary fillet by path.
7fd59977 1460//
1461//=======================================================================
1462
1463Standard_Boolean ChFi3d_Builder::ComputeData
1464(Handle(ChFiDS_SurfData)& Data,
1465 const Handle(ChFiDS_HElSpine)& HGuide,
1466 const Handle(ChFiDS_Spine)& Spine,
1467 Handle(BRepBlend_Line)& Lin,
1468 const Handle(Adaptor3d_HSurface)& S1,
1469 const Handle(Adaptor3d_TopolTool)& I1,
1470 const Handle(Adaptor3d_HSurface)& S2,
1471 const Handle(Adaptor3d_TopolTool)& I2,
1472 Blend_Function& Func,
1473 Blend_FuncInv& FInv,
1474 const Standard_Real PFirst,
1475 const Standard_Real MaxStep,
1476 const Standard_Real Fleche,
1477 const Standard_Real tolguide,
1478 Standard_Real& First,
1479 Standard_Real& Last,
1480 const Standard_Boolean Inside,
1481 const Standard_Boolean Appro,
1482 const Standard_Boolean Forward,
1483 const math_Vector& Soldep,
1484 Standard_Boolean& intf,
1485 Standard_Boolean& intl,
1486 Standard_Boolean& Gd1,
1487 Standard_Boolean& Gd2,
1488 Standard_Boolean& Gf1,
1489 Standard_Boolean& Gf2,
1490 const Standard_Boolean RecOnS1,
1491 const Standard_Boolean RecOnS2)
1492{
81bba717 1493 //The extrensions are created in case of output of two domains
1494 //directly and not by path ( too hasardous ).
7fd59977 1495 Data->FirstExtensionValue(0);
1496 Data-> LastExtensionValue(0);
1497
81bba717 1498 //The eventual faces are restored to test the jump of edge.
7fd59977 1499 TopoDS_Face F1, F2;
1500 Handle(BRepAdaptor_HSurface) HS = Handle(BRepAdaptor_HSurface)::DownCast(S1);
1501 if(!HS.IsNull()) F1 = HS->ChangeSurface().Face();
1502 HS = Handle(BRepAdaptor_HSurface)::DownCast(S2);
1503 if(!HS.IsNull()) F2 = HS->ChangeSurface().Face();
1504
81bba717 1505 // Path framing variables
7fd59977 1506 Standard_Real TolGuide=tolguide, TolEsp = tolesp;
1507 Standard_Integer nbptmin = 4;
1508
af99433e 1509 BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
7fd59977 1510
81bba717 1511 //Start of removal, 2D path controls
1512 //that qui s'accomodent mal des surfaces a parametrages non homogenes
1513 //en u et en v are extinguished.
7fd59977 1514 TheWalk.Check2d(0);
1515
1516 Standard_Real MS = MaxStep;
1517 Standard_Integer Nbpnt;
1518 Standard_Real SpFirst = HGuide->FirstParameter();
1519 Standard_Real SpLast = HGuide->LastParameter();
1520
81bba717 1521 // When the start point is inside, the path goes first to the left
1522 // to determine the Last for the periodicals.
7fd59977 1523 Standard_Boolean reverse = (!Forward || Inside);
1524 Standard_Real Target;
1525 if(reverse){
1526 Target = SpFirst;
1527 if(!intf) Target = Last;
1528 }
1529 else{
1530 Target = SpLast + Abs(SpLast);
1531 if(!intl) Target = Last;
1532 }
1533
81bba717 1534 // In case if the singularity is pre-determined,
1535 // the path is indicated.
7fd59977 1536 if (!Spine.IsNull()){
1537 if (Spine->IsTangencyExtremity(Standard_True)) {
1538 TopoDS_Vertex V = Spine->FirstVertex();
1539 TopoDS_Edge E = Spine->Edges(1);
1540 Standard_Real param = Spine->FirstParameter();
1541 Blend_Point BP;
1542 if (CompBlendPoint(V, E, param, F1, F2, BP)) {
1543 math_Vector vec(1,4);
1544 BP.ParametersOnS1(vec(1),vec(2));
1545 BP.ParametersOnS2(vec(3),vec(4));
1546 Func.Set(param);
1547 if (Func.IsSolution(vec, tolesp)) {
1548 TheWalk.AddSingularPoint(BP);
1549 }
1550 }
1551 }
1552 if (Spine->IsTangencyExtremity(Standard_False)) {
1553 TopoDS_Vertex V = Spine->LastVertex();
1554 TopoDS_Edge E = Spine->Edges( Spine->NbEdges());
1555 Standard_Real param = Spine->LastParameter();
1556 Blend_Point BP;
1557 if (CompBlendPoint(V, E, param, F1, F2, BP)) {
1558 math_Vector vec(1,4);
1559 BP.ParametersOnS1(vec(1),vec(2));
1560 BP.ParametersOnS2(vec(3),vec(4));
1561 Func.Set(param);
1562 if (Func.IsSolution(vec, tolesp)) {
1563 TheWalk.AddSingularPoint(BP);
1564 }
1565 }
1566 }
1567 }
1568
81bba717 1569 //The starting solution is reframed if necessary.
7fd59977 1570 //**********************************************//
1571 math_Vector ParSol(1,4);
1572 Standard_Real NewFirst = PFirst;
1573 if(RecOnS1 || RecOnS2){
1574 if(!TheWalk.PerformFirstSection(Func,FInv,PFirst,Target,Soldep,
1575 tolesp,TolGuide,RecOnS1,RecOnS2,
1576 NewFirst,ParSol)){
0797d9d3 1577#ifdef OCCT_DEBUG
81bba717 1578 cout<<"ChFi3d_Builder::ComputeData : calculation fail first section"<<endl;
7fd59977 1579#endif
1580 return Standard_False;
1581 }
1582 }
1583 else {
1584 ParSol = Soldep;
1585 }
1586
81bba717 1587 //First the valid part is calculate, without caring for the extensions.
7fd59977 1588 //******************************************************************//
1589 Standard_Integer again = 0;
1590 Standard_Boolean tchernobyl = 0;
7fd59977 1591 Standard_Real u1sov = 0., u2sov = 0.;
7fd59977 1592 TopoDS_Face bif;
81bba717 1593 //Max step is relevant, but too great, the vector is required to detect
1594 //the twists.
7fd59977 1595 if( (Abs(Last-First) <= MS * 5.) &&
1596 (Abs(Last-First) >= 0.01*Abs(NewFirst-Target)) ){
1597 MS = Abs(Last-First)*0.2;
1598 }
1599
1600 while(again < 3){
81bba717 1601 //Path.
7fd59977 1602 if(!again && (MS < 5*TolGuide)) MS = 5*TolGuide;
1603 else {
1604 if (5*TolGuide > MS) TolGuide = MS/5;
1605 if (5*TolEsp > MS) TolEsp = MS/5;
1606 }
af99433e 1607 TheWalk.Perform(Func,FInv,NewFirst,Target,MS,TolGuide,
7fd59977 1608 ParSol,TolEsp,Fleche,Appro);
1609 if (!TheWalk.IsDone()) {
0797d9d3 1610#ifdef OCCT_DEBUG
81bba717 1611 cout << "Path is not created" << endl;
7fd59977 1612#endif
1613 return Standard_False;
1614 }
1615 Lin = TheWalk.Line();
1616 if(HGuide->IsPeriodic() && Inside) {
1617 SpFirst = Lin->Point(1).Parameter();
1618 SpLast = SpFirst + HGuide->Period();
1619 HGuide->ChangeCurve().FirstParameter(SpFirst);
1620 HGuide->ChangeCurve().LastParameter (SpLast );
1621 HGuide->ChangeCurve().SetOrigin(SpFirst);
1622 }
1623 Standard_Boolean complmnt = Standard_True;
1624 if (Inside) complmnt = TheWalk.Complete(Func,FInv,SpLast);
1625 if(!complmnt){
0797d9d3 1626#ifdef OCCT_DEBUG
81bba717 1627 cout << "Not completed" << endl;
7fd59977 1628#endif
1629 return Standard_False;
1630 }
1631
81bba717 1632 //The result is controlled using two criterions :
1633 //- if there is enough points,
1634 //- if one has gone far enough.
7fd59977 1635 Nbpnt = Lin->NbPoints();
1636 if (Nbpnt == 0){
0797d9d3 1637#ifdef OCCT_DEBUG
81bba717 1638 cout <<"0 point of path, quit."<<endl;
7fd59977 1639#endif
1640 return Standard_False;
1641 }
1642 Standard_Real fpointpar = Lin->Point(1).Parameter();
1643 Standard_Real lpointpar = Lin->Point(Nbpnt).Parameter();
1644
1645 Standard_Real factor = 1./(nbptmin + 1);
1646 Standard_Boolean okdeb = (Forward && !Inside);
1647 Standard_Boolean okfin = (!Forward && !Inside);
1648 if(!okdeb){
1649 Standard_Integer narc1 = Lin->StartPointOnFirst().NbPointOnRst();
1650 Standard_Integer narc2 = Lin->StartPointOnSecond().NbPointOnRst();
1651 okdeb = (narc1 > 0 || narc2 > 0 || (fpointpar-First) < 10*TolGuide);
1652 }
1653 if(!okfin){
1654 Standard_Integer narc1 = Lin->EndPointOnFirst().NbPointOnRst();
1655 Standard_Integer narc2 = Lin->EndPointOnSecond().NbPointOnRst();
1656 okfin = (narc1 > 0 || narc2 > 0 || (Last-lpointpar) < 10*TolGuide);
1657 }
1658 if(!okdeb || !okfin || Nbpnt == 1){
81bba717 1659 //It drags, the controls are extended, it is expected to evaluate a
1660 //satisfactory maximum step. If it already done, quit.
7fd59977 1661 if(tchernobyl){
0797d9d3 1662#ifdef OCCT_DEBUG
81bba717 1663 cout <<"If it drags without control, quit."<<endl;
7fd59977 1664#endif
1665 return Standard_False;
1666 }
1667 tchernobyl = Standard_True;
1668 TheWalk.Check(0);
1669 if (Nbpnt == 1){
0797d9d3 1670#ifdef OCCT_DEBUG
81bba717 1671 cout <<"only one point of path MS/100 is attempted"<<endl;
1672 cout <<"and the controls are extended."<<endl;
7fd59977 1673#endif
1674 MS *= 0.01;
1675 }
1676 else{
0797d9d3 1677#ifdef OCCT_DEBUG
81bba717 1678 cout <<"It drags, the controls are extended."<<endl;
7fd59977 1679#endif
1680 MS = (lpointpar-fpointpar)/Nbpnt; //EvalStep(Lin);
1681 }
1682 }
1683 else if (Nbpnt < nbptmin){
1684 if(again == 0){
0797d9d3 1685#ifdef OCCT_DEBUG
81bba717 1686 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 1687#endif
1688 u1sov = fpointpar;
1689 u2sov = lpointpar;
1690 MS = (lpointpar - fpointpar) * factor;
1691 }
1692 else if(again == 1){
1693 if(Abs(fpointpar-u1sov)>=TolGuide ||
1694 Abs(lpointpar-u2sov)>=TolGuide){
0797d9d3 1695#ifdef OCCT_DEBUG
81bba717 1696 cout <<"Number of points is still too small, the step is reduced"<<endl;
7fd59977 1697#endif
1698 MS = (lpointpar - fpointpar) * factor;
1699 }
1700 else{
0797d9d3 1701#ifdef OCCT_DEBUG
81bba717 1702 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 1703#endif
1704 return Standard_False;
1705 }
1706 }
1707 again++;
1708 }
1709 else {
1710 again = 3;
1711 }
1712 }
1713
1714 if(TheWalk.TwistOnS1()){
1715 Data->TwistOnS1(Standard_True);
0797d9d3 1716#ifdef OCCT_DEBUG
81bba717 1717 cout<<"Path completed, but TWIST on S1"<<endl;
7fd59977 1718#endif
1719 }
1720 if(TheWalk.TwistOnS2()){
1721 Data->TwistOnS2(Standard_True);
0797d9d3 1722#ifdef OCCT_DEBUG
81bba717 1723 cout<<"Parh completed, but TWIST on S2"<<endl;
7fd59977 1724#endif
1725 }
1726
1727
81bba717 1728 //Here there is a more or less presentable result
1729 //however it covers a the minimum zone.
1730 //The extensions are targeted.
7fd59977 1731 //*****************************//
1732
1733 Gd1 = Gd2 = Gf1 = Gf2 = Standard_False;
1734
1735 Standard_Boolean unseulsuffitdeb = (intf >= 2);
1736 Standard_Boolean unseulsuffitfin = (intl >= 2);
1737 Standard_Boolean noproldeb = (intf >= 3);
1738 Standard_Boolean noprolfin = (intl >= 3);
1739
1740 Standard_Real Rab = 0.03*(SpLast-SpFirst);
1741
1742 Standard_Boolean debarc1 = 0, debarc2 = 0;
1743 Standard_Boolean debcas1 = 0, debcas2 = 0;
1744 Standard_Boolean debobst1 = 0, debobst2 = 0;
1745
1746 Standard_Boolean finarc1 = 0, finarc2 = 0;
1747 Standard_Boolean fincas1 = 0, fincas2 = 0;
1748 Standard_Boolean finobst1 = 0, finobst2 = 0;
1749
1750 Standard_Integer narc1, narc2;
1751
1752 Standard_Boolean backwContinueFailed = Standard_False; // eap
1753 if(reverse && intf) {
1754 narc1 = Lin->StartPointOnFirst().NbPointOnRst();
1755 narc2 = Lin->StartPointOnSecond().NbPointOnRst();
1756 if(narc1 != 0) {
1757 ChFi3d_FilCommonPoint(Lin->StartPointOnFirst(),Lin->TransitionOnS1(),
1758 Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
1759 debarc1 = Standard_True;
1760 if(!SearchFace(Spine,Data->VertexFirstOnS1(),F1,bif)){
81bba717 1761 //It is checked if there is not an obstacle.
7fd59977 1762 debcas1 = Standard_True;
1763 if(!Spine.IsNull()){
1764 if(Spine->IsPeriodic()){
1765 debobst1 = 1;
1766 }
1767 else{
1768 debobst1 = IsObst(Data->VertexFirstOnS1(),
1769 Spine->FirstVertex(),myVEMap);
1770 }
1771 }
1772 }
1773 }
1774 if(narc2 != 0){
1775 ChFi3d_FilCommonPoint(Lin->StartPointOnSecond(),Lin->TransitionOnS2(),
1776 Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1777 debarc2 = Standard_True;
1778 if(!SearchFace(Spine,Data->VertexFirstOnS2(),F2,bif)){
81bba717 1779 //It is checked if it is not an obstacle.
7fd59977 1780 debcas2 = Standard_True;
1781 if(!Spine.IsNull()){
1782 if(Spine->IsPeriodic()){
1783 debobst2 = 1;
1784 }
1785 else{
1786 debobst2 = IsObst(Data->VertexFirstOnS2(),
1787 Spine->FirstVertex(),myVEMap);
1788 }
1789 }
1790 }
1791 }
1792 Standard_Boolean oncontinue = !noproldeb && (narc1 != 0 || narc2 != 0);
1793 if(debobst1 || debobst2) oncontinue = Standard_False;
1794 else if(debcas1 && debcas2) oncontinue = Standard_False;
1795 else if((!debcas1 && debarc1) || (!debcas2 && debarc2)) oncontinue = Standard_False;
1796
1797 if(oncontinue) {
1798 TheWalk.ClassificationOnS1(!debarc1);
1799 TheWalk.ClassificationOnS2(!debarc2);
81bba717 1800 TheWalk.Check2d(Standard_True); // It should be strict (PMN)
7fd59977 1801 TheWalk.Continu(Func,FInv,Target);
1802 TheWalk.ClassificationOnS1(Standard_True);
1803 TheWalk.ClassificationOnS2(Standard_True);
1804 TheWalk.Check2d(Standard_False);
1805 narc1 = Lin->StartPointOnFirst().NbPointOnRst();
1806 narc2 = Lin->StartPointOnSecond().NbPointOnRst();
1807// modified by eap Fri Feb 8 11:43:48 2002 ___BEGIN___
eafb234b 1808 if(!debarc1) {
7fd59977 1809 if (narc1 == 0)
1810 backwContinueFailed = Lin->StartPointOnFirst().ParameterOnGuide() > Target;
1811 else {
1812 ChFi3d_FilCommonPoint(Lin->StartPointOnFirst(),Lin->TransitionOnS1(),
1813 Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
1814 debarc1 = Standard_True;
1815 if(!SearchFace(Spine,Data->VertexFirstOnS1(),F1,bif)){
81bba717 1816 //It is checked if it is not an obstacle.
7fd59977 1817 debcas1 = Standard_True;
1818// if(!Spine.IsNull()) {
1819// if(Spine->IsPeriodic()){
1820// debobst1 = 1;
1821// }
1822// else{
1823// debobst1 = IsObst(Data->VertexFirstOnS1(),
1824// Spine->FirstVertex(),myVEMap);
1825// }
1826// }
1827 }
1828 }
eafb234b 1829 }
1830 if(!debarc2) {
7fd59977 1831 if (narc2 == 0)
1832 backwContinueFailed = Lin->StartPointOnSecond().ParameterOnGuide() > Target;
1833 else {
1834 ChFi3d_FilCommonPoint(Lin->StartPointOnSecond(),Lin->TransitionOnS2(),
1835 Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1836 debarc2 = Standard_True;
1837 if(!SearchFace(Spine,Data->VertexFirstOnS2(),F2,bif)){
81bba717 1838 //It is checked if it is not an obstacle.
7fd59977 1839 debcas2 = Standard_True;
1840// if(!Spine.IsNull()){
1841// if(Spine->IsPeriodic()){
1842// debobst2 = 1;
1843// }
1844// else{
1845// debobst2 = IsObst(Data->VertexFirstOnS2(),
1846// Spine->FirstVertex(),myVEMap);
1847// }
1848// }
1849 }
1850 }
eafb234b 1851 }
7fd59977 1852 if (backwContinueFailed) {
1853 // if we leave backwContinueFailed as is, we will stop in this direction
1854 // but we are to continue if there are no more faces on the side with arc
1855 // check this condition
1856 const ChFiDS_CommonPoint& aCP
1857 = debarc1 ? Data->VertexFirstOnS1() : Data->VertexFirstOnS2();
1858 if (aCP.IsOnArc() && bif.IsNull())
1859 backwContinueFailed = Standard_False;
1860 }
1861 }
1862 }
1863 Standard_Boolean forwContinueFailed = Standard_False;
1864// modified by eap Fri Feb 8 11:44:11 2002 ___END___
1865 if(Forward && intl) {
1866 Target = SpLast;
1867 narc1 = Lin->EndPointOnFirst().NbPointOnRst();
1868 narc2 = Lin->EndPointOnSecond().NbPointOnRst();
1869 if(narc1 != 0){
1870 ChFi3d_FilCommonPoint(Lin->EndPointOnFirst(),Lin->TransitionOnS1(),
1871 Standard_False, Data->ChangeVertexLastOnS1(),tolesp);
1872 finarc1 = Standard_True;
1873 if(!SearchFace(Spine,Data->VertexLastOnS1(),F1,bif)){
81bba717 1874 //It is checked if it is not an obstacle.
7fd59977 1875 fincas1 = Standard_True;
1876 if(!Spine.IsNull()){
1877 finobst1 = IsObst(Data->VertexLastOnS1(),
1878 Spine->LastVertex(),myVEMap);
1879 }
1880 }
1881 }
1882 if(narc2 != 0){
1883 ChFi3d_FilCommonPoint(Lin->EndPointOnSecond(),Lin->TransitionOnS2(),
1884 Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1885 finarc2 = Standard_True;
1886 if(!SearchFace(Spine,Data->VertexLastOnS2(),F2,bif)){
81bba717 1887 //It is checked if it is not an obstacle.
7fd59977 1888 fincas2 = Standard_True;
1889 if(!Spine.IsNull()){
1890 finobst2 = IsObst(Data->VertexLastOnS2(),
1891 Spine->LastVertex(),myVEMap);
1892 }
1893 }
1894 }
1895 Standard_Boolean oncontinue = !noprolfin && (narc1 != 0 || narc2 != 0);
1896 if(finobst1 || finobst2) oncontinue = Standard_False;
1897 else if(fincas1 && fincas2) oncontinue = Standard_False;
1898 else if((!fincas1 && finarc1) || (!fincas2 && finarc2)) oncontinue = Standard_False;
1899
1900 if(oncontinue){
1901 TheWalk.ClassificationOnS1(!finarc1);
1902 TheWalk.ClassificationOnS2(!finarc2);
81bba717 1903 TheWalk.Check2d(Standard_True); // It should be strict (PMN)
7fd59977 1904 TheWalk.Continu(Func,FInv,Target);
1905 TheWalk.ClassificationOnS1(Standard_True);
1906 TheWalk.ClassificationOnS2(Standard_True);
1907 TheWalk.Check2d(Standard_False);
1908 narc1 = Lin->EndPointOnFirst().NbPointOnRst();
1909 narc2 = Lin->EndPointOnSecond().NbPointOnRst();
1910// modified by eap Fri Feb 8 11:44:57 2002 ___BEGIN___
eafb234b 1911 if(!finarc1) {
7fd59977 1912 if (narc1 == 0)
1913 forwContinueFailed = Lin->EndPointOnFirst().ParameterOnGuide() < Target;
1914 else {
1915 ChFi3d_FilCommonPoint(Lin->EndPointOnFirst(),Lin->TransitionOnS1(),
1916 Standard_False, Data->ChangeVertexLastOnS1(),tolesp);
1917 finarc1 = Standard_True;
1918 if(!SearchFace(Spine,Data->VertexLastOnS1(),F1,bif)){
81bba717 1919 //It is checked if it is not an obstacle.
7fd59977 1920 fincas1 = Standard_True;
1921// if(!Spine.IsNull()){
1922// finobst1 = IsObst(Data->VertexLastOnS1(),
1923// Spine->LastVertex(),myVEMap);
1924// }
1925 }
1926 }
eafb234b 1927 }
1928 if(!finarc2) {
7fd59977 1929 if (narc2 == 0)
1930 forwContinueFailed = Lin->EndPointOnSecond().ParameterOnGuide() < Target;
1931 else {
1932 ChFi3d_FilCommonPoint(Lin->EndPointOnSecond(),Lin->TransitionOnS2(),
1933 Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1934 finarc2 = Standard_True;
1935 if(!SearchFace(Spine,Data->VertexLastOnS2(),F2,bif)){
1936 //On regarde si ce n'est pas un obstacle.
1937 fincas2 = Standard_True;
1938// if(!Spine.IsNull()){
1939// finobst2 = IsObst(Data->VertexLastOnS2(),
1940// Spine->LastVertex(),myVEMap);
1941// }
1942 }
1943 }
eafb234b 1944 }
7fd59977 1945 if (forwContinueFailed) {
1946 // if we leave forwContinueFailed as is, we will stop in this direction
1947 // but we are to continue if there are no more faces on the side with arc
1948 // check this condition
1949 const ChFiDS_CommonPoint& aCP
1950 = finarc1 ? Data->VertexLastOnS1() : Data->VertexLastOnS2();
1951 if (aCP.IsOnArc() && bif.IsNull())
1952 forwContinueFailed = Standard_False;
1953 }
1954// modified by eap Fri Feb 8 11:45:10 2002 ___END___
1955 }
1956 }
1957 Nbpnt = Lin->NbPoints();
1958#ifdef DRAW
1959 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_False);
1960#endif
1961 First = Lin->Point(1).Parameter();
1962 Last = Lin->Point(Nbpnt).Parameter();
1963
1964 // ============= INVALIDATION EVENTUELLE =============
1965 // ------ Preparation des prolongement par plan tangent -----
1966 if(reverse && intf){
1967 Gd1 = debcas1/* && !debobst1*/; // skv(occ67)
1968 Gd2 = debcas2/* && !debobst2*/; // skv(occ67)
1969 if ((debarc1^debarc2) && !unseulsuffitdeb && (First!=SpFirst)) {
81bba717 1970 // Case of incomplete path, of course this ends badly :
1971 // the result is truncated instead of exit.
7fd59977 1972 Standard_Real sortie;
1973 Standard_Integer ind;
1974 if (debarc1) sortie = Data->VertexFirstOnS1().Parameter();
1975 else sortie = Data->VertexFirstOnS2().Parameter();
1976 if (sortie - First > tolesp) {
1977 ind = SearchIndex(sortie, Lin);
1978 if (Lin->Point(ind).Parameter() == sortie) ind--;
1979 if (ind >= 1) {
1980 Lin->Remove(1, ind);
1981 UpdateLine(Lin, Standard_True);
1982 }
1983 Nbpnt = Lin->NbPoints();
1984 First = Lin->Point(1).Parameter();
1985 }
1986 }
1987 else if ((intf>=5) && !debarc1 && !debarc2 && (First!=SpFirst)) {
1988 Standard_Real sortie = (2*First+Last)/3;
1989 Standard_Integer ind;
1990 if (sortie - First > tolesp) {
1991 ind = SearchIndex(sortie, Lin);
1992 if (Lin->Point(ind).Parameter() == sortie) ind--;
1993 if (Nbpnt-ind < 3) ind = Nbpnt -3;
1994 if (ind >= 1) {
1995 Lin->Remove(1, ind);
1996 UpdateLine(Lin, Standard_True);
1997 }
1998 Nbpnt = Lin->NbPoints();
1999 First = Lin->Point(1).Parameter();
2000 }
2001 }
2002 if(Gd1 && Gd2){
2003 Target = Min((Lin->Point(1).Parameter() - Rab),First);
2004 Target = Max(Target,SpFirst);
2005 Data->FirstExtensionValue(Abs(Lin->Point(1).Parameter()-Target));
2006 }
2007 if (intf && !unseulsuffitdeb) intf = (Gd1 && Gd2)//;
2008 || backwContinueFailed; // eap
2009 else if (intf && unseulsuffitdeb && (intf<5)) {
2010 intf = (Gd1 || Gd2);
81bba717 2011 // It is checked if there is no new face.
7fd59977 2012 if (intf &&
2013 ((!debcas1 && debarc1) || (!debcas2 && debarc2)) ) intf = 0;
2014 }
2015 else if (intf < 5) intf = 0;
2016 }
2017
2018 if(Forward && intl){
2019 Gf1 = fincas1/* && !finobst1*/; // skv(occ67)
2020 Gf2 = fincas2/* && !finobst2*/; // skv(occ67)
2021 if ((finarc1 ^finarc2) && !unseulsuffitfin && (Last!=SpLast)) {
81bba717 2022 // Case of incomplete path, of course, this ends badly :
2023 // the result is truncated instead of exit.
7fd59977 2024 Standard_Real sortie;
2025 Standard_Integer ind;
2026 if (finarc1) sortie = Data->VertexLastOnS1().Parameter();
2027 else sortie = Data->VertexLastOnS2().Parameter();
2028 if (Last - sortie > tolesp) {
2029 ind = SearchIndex(sortie, Lin);
2030 if (Lin->Point(ind).Parameter() == sortie) ind++;
2031 if (ind<= Nbpnt) {
2032 Lin->Remove(ind, Nbpnt);
2033 UpdateLine(Lin, Standard_False);
2034 }
2035 Nbpnt = Lin->NbPoints();
2036 Last = Lin->Point(Nbpnt).Parameter();
2037 }
2038 }
2039 else if ((intl>=5) && !finarc1 && !finarc2 && (Last!=SpLast) ) {
81bba717 2040 // The same in case when the entire "Lin" is an extension
7fd59977 2041 Standard_Real sortie = (First+2*Last)/3;
2042 Standard_Integer ind;
2043 if (Last - sortie > tolesp) {
2044 ind = SearchIndex(sortie, Lin);
2045 if (Lin->Point(ind).Parameter() == sortie) ind++;
2046 if (ind < 3) ind = 3;
2047 if (ind <= Nbpnt) {
2048 Lin->Remove(ind, Nbpnt);
2049 UpdateLine(Lin, Standard_False);
2050 }
2051 Nbpnt = Lin->NbPoints();
2052 Last = Lin->Point(Nbpnt).Parameter();
2053 }
2054 }
2055 if(Gf1 && Gf2) {
2056 Target = Max((Lin->Point(Nbpnt).Parameter() + Rab),Last);
2057 Target = Min(Target,SpLast);
2058 Data->LastExtensionValue(Abs(Target-Lin->Point(Nbpnt).Parameter()));
2059 }
2060
2061 if (intl && !unseulsuffitfin) intl = (Gf1 && Gf2)//;
2062 || forwContinueFailed; // eap
2063 else if (intl && unseulsuffitfin && (intl<5)) {
81bba717 2064 intl = (Gf1 || Gf2);// It is checked if there is no new face.
7fd59977 2065 if (intl &&
2066 ((!fincas1 && finarc1) || (!fincas2 && finarc2)) ) intl = 0;
2067 }
2068 else if (intl <5) intl = 0;
2069 }
2070 return Standard_True;
2071}
2072
2073//=======================================================================
2074//function : SimulData
2075//purpose :
2076//=======================================================================
2077
2078Standard_Boolean ChFi3d_Builder::SimulData
2079(Handle(ChFiDS_SurfData)& /*Data*/,
2080 const Handle(ChFiDS_HElSpine)& HGuide,
2081 Handle(BRepBlend_Line)& Lin,
2082 const Handle(Adaptor3d_HSurface)& S1,
2083 const Handle(Adaptor3d_TopolTool)& I1,
2084 const Handle(Adaptor3d_HSurface)& S2,
2085 const Handle(Adaptor3d_TopolTool)& I2,
2086 Blend_Function& Func,
2087 Blend_FuncInv& FInv,
2088 const Standard_Real PFirst,
2089 const Standard_Real MaxStep,
2090 const Standard_Real Fleche,
2091 const Standard_Real tolguide,
2092 Standard_Real& First,
2093 Standard_Real& Last,
2094 const Standard_Boolean Inside,
2095 const Standard_Boolean Appro,
2096 const Standard_Boolean Forward,
2097 const math_Vector& Soldep,
2098 const Standard_Integer NbSecMin,
2099 const Standard_Boolean RecOnS1,
2100 const Standard_Boolean RecOnS2)
2101{
af99433e 2102 BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
7fd59977 2103 TheWalk.Check2d(Standard_False);
2104
2105 Standard_Real MS = MaxStep;
2106 Standard_Real TolGuide=tolguide, TolEsp = tolesp;
1d47d8d0 2107 Standard_Integer Nbpnt = 0;
7fd59977 2108 Standard_Real SpFirst = HGuide->FirstParameter();
2109 Standard_Real SpLast = HGuide->LastParameter();
2110 Standard_Boolean reverse = (!Forward || Inside);
2111 Standard_Real Target;
2112 if(reverse){
2113 Target = SpFirst;
2114 }
2115 else{
2116 Target = SpLast;
2117 }
2118
2119 Standard_Real Targetsov = Target;
7fd59977 2120 Standard_Real u1sov = 0., u2sov = 0.;
7fd59977 2121 // on recadre la solution de depart a la demande.
2122 math_Vector ParSol(1,4);
2123 Standard_Real NewFirst = PFirst;
2124 if(RecOnS1 || RecOnS2){
2125 if(!TheWalk.PerformFirstSection(Func,FInv,PFirst,Target,Soldep,
2126 tolesp,TolGuide,RecOnS1,RecOnS2,
2127 NewFirst,ParSol)){
0797d9d3 2128#ifdef OCCT_DEBUG
81bba717 2129 cout<<"ChFi3d_Builder::SimulData : calculation fail first section"<<endl;
7fd59977 2130#endif
2131 return Standard_False;
2132 }
2133 }
2134 else {
2135 ParSol = Soldep;
2136 }
2137 Standard_Integer again = 0;
2138 while(again < 3){
81bba717 2139 // When the start point is inside, the path goes first to the left
2140 // to determine the Last for the periodicals.
7fd59977 2141 if(!again && (MS < 5*TolGuide)) MS = 5*TolGuide;
2142 else {
2143 if (5*TolGuide > MS) TolGuide = MS/5;
2144 if (5*TolEsp > MS) TolEsp = MS/5;
2145 }
2146
af99433e 2147 TheWalk.Perform(Func,FInv,NewFirst,Target,MS,TolGuide,
7fd59977 2148 ParSol,TolEsp,Fleche,Appro);
2149
2150 if (!TheWalk.IsDone()) {
0797d9d3 2151#ifdef OCCT_DEBUG
81bba717 2152 cout << "Path not created" << endl;
7fd59977 2153#endif
2154 return Standard_False;
2155 }
2156 Lin = TheWalk.Line();
2157 if(reverse){
2158 if(HGuide->IsPeriodic()) {
2159 SpFirst = Lin->Point(1).Parameter();
2160 SpLast = SpFirst + HGuide->Period();
2161 HGuide->ChangeCurve().FirstParameter(SpFirst);
2162 HGuide->ChangeCurve().LastParameter (SpLast );
2163 }
2164 Standard_Boolean complmnt = Standard_True;
2165 if (Inside) complmnt = TheWalk.Complete(Func,FInv,SpLast);
2166 if(!complmnt){
0797d9d3 2167#ifdef OCCT_DEBUG
81bba717 2168 cout << "Not completed" << endl;
7fd59977 2169#endif
2170 return Standard_False;
2171 }
2172 }
2173 Nbpnt = Lin->NbPoints();
2174 Standard_Real factor = 1./(NbSecMin + 1);
2175 if (Nbpnt == 0){
0797d9d3 2176#ifdef OCCT_DEBUG
81bba717 2177 cout <<"0 point of path, quit."<<endl;
7fd59977 2178#endif
2179 return Standard_False;
2180 }
2181 else if (Nbpnt == 1 && again == 0) {
2182 again++;
0797d9d3 2183#ifdef OCCT_DEBUG
81bba717 2184 cout <<"only one point of path, MS/100 is attempted."<<endl;
7fd59977 2185#endif
2186 MS *= 0.01; Target = Targetsov;
2187 u1sov = u2sov = Lin->Point(1).Parameter();
2188 }
2189 else if (Nbpnt< NbSecMin && again == 0) {
2190 again++;
0797d9d3 2191#ifdef OCCT_DEBUG
81bba717 2192 cout <<"Number of points is too small, the step is reduced"<<endl;
7fd59977 2193#endif
2194 Standard_Real u1 = u1sov = Lin->Point(1).Parameter();
2195 Standard_Real u2 = u2sov = Lin->Point(Nbpnt).Parameter();
2196 MS = (u2-u1)*factor;
2197 Target = Targetsov;
2198 }
2199 else if (Nbpnt < NbSecMin && again == 1) {
2200 Standard_Real u1 = Lin->Point(1).Parameter();
2201 Standard_Real u2 = Lin->Point(Nbpnt).Parameter();
2202 if(Abs(u1-u1sov)>=TolGuide || Abs(u2-u2sov)>=TolGuide){
2203 again++;
0797d9d3 2204#ifdef OCCT_DEBUG
81bba717 2205 cout <<"Number of points is still too small, the step is reduced"<<endl;
7fd59977 2206#endif
2207 MS /= 100;
2208 Target = Targetsov;
2209 }
2210 else{
0797d9d3 2211#ifdef OCCT_DEBUG
81bba717 2212 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 2213#endif
2214 return Standard_False;
2215 }
2216 }
2217 else if(Nbpnt < NbSecMin){
0797d9d3 2218#ifdef OCCT_DEBUG
81bba717 2219 cout <<"Number of points is still too small, quit"<<endl;
7fd59977 2220#endif
2221 return Standard_False;
2222 }
2223 else {
2224 again = 3;
2225 }
2226 }
2227#ifdef DRAW
2228 if(ChFi3d_GettraceDRAWWALK()) drawline(Lin,Standard_False);
2229#endif
2230 First = Lin->Point(1).Parameter();
2231 Last = Lin->Point(Nbpnt).Parameter();
2232 return Standard_True;
2233}
2234