1 // Created on: 1997-01-24
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HSurface.hxx>
20 #include <Adaptor3d_HVertex.hxx>
21 #include <Adaptor3d_TopolTool.hxx>
22 #include <Blend_FuncInv.hxx>
23 #include <Blend_Point.hxx>
24 #include <Blend_SurfCurvFuncInv.hxx>
25 #include <Blend_SurfPointFuncInv.hxx>
26 #include <Blend_SurfRstFunction.hxx>
27 #include <BRepBlend_BlendTool.hxx>
28 #include <BRepBlend_Extremity.hxx>
29 #include <BRepBlend_Line.hxx>
30 #include <BRepBlend_SurfRstLineBuilder.hxx>
32 #include <gp_Pnt2d.hxx>
34 #include <gp_Vec2d.hxx>
35 #include <IntSurf.hxx>
36 #include <IntSurf_Transition.hxx>
37 #include <math_FunctionSetRoot.hxx>
42 #include <TColStd_Array1OfInteger.hxx>
43 #include <TColStd_Array1OfReal.hxx>
44 #include <TColgp_Array1OfPnt2d.hxx>
45 #include <TColgp_Array1OfVec.hxx>
46 #include <TColgp_Array1OfVec2d.hxx>
47 #include <TColgp_Array1OfPnt.hxx>
48 #include <Geom_BSplineCurve.hxx>
50 #include <DrawTrSurf.hxx>
52 static Standard_Integer IndexOfSection = 0;
53 extern Standard_Boolean Blend_GettraceDRAWSECT();
54 #ifdef OCCT_DEBUG_BBPP_N_TRDERIV
55 // for debug : visualisation of the section
56 static Standard_Boolean BBPP(const Standard_Real param,
57 Blend_SurfRstFunction& Func,
58 const math_Vector& sol,
59 const Standard_Real tol,
62 if(!Func.IsSolution(sol,tol)) return 0;
63 gp_Pnt pnts = Func.PointOnS();
64 gp_Pnt pntrst = Func.PointOnRst();
65 gp_Pnt2d p2ds = Func.Pnt2dOnS();
66 gp_Pnt2d p2drst = Func.Pnt2dOnRst();
67 Standard_Real w = Func.ParameterOnRst();
68 BP = Blend_Point(pnts,pntrst,param,
70 p2drst.X(),p2drst.Y(),w);
73 static void tracederiv(Blend_SurfRstFunction& Func,
74 const Blend_Point& BP1,
75 const Blend_Point& BP2)
77 Standard_Integer hp,hk,hd,hp2d,i;
78 Func.GetShape(hp,hk,hd,hp2d);
79 TColgp_Array1OfPnt TP1(1,hp);
80 TColgp_Array1OfVec TDP1(1,hp);
81 TColgp_Array1OfPnt2d TP2d1(1,hp2d);
82 TColgp_Array1OfVec2d TDP2d1(1,hp2d);
83 TColStd_Array1OfReal TW1(1,hp);
84 TColStd_Array1OfReal TDW1(1,hp);
85 Func.Section(BP1,TP1,TDP1,TP2d1,TDP2d1,TW1,TDW1);
87 TColgp_Array1OfPnt TP2(1,hp);
88 TColgp_Array1OfVec TDP2(1,hp);
89 TColgp_Array1OfPnt2d TP2d2(1,hp2d);
90 TColgp_Array1OfVec2d TDP2d2(1,hp2d);
91 TColStd_Array1OfReal TW2(1,hp);
92 TColStd_Array1OfReal TDW2(1,hp);
93 Func.Section(BP2,TP2,TDP2,TP2d2,TDP2d2,TW2,TDW2);
95 Standard_Real param1 = BP1.Parameter();
96 Standard_Real param2 = BP2.Parameter();
97 Standard_Real scal = 1./(param1-param2);
100 std::cout<<"control derivatives at point : "<<param1<<std::endl;
102 for(i = 1; i <= hp; i++){
103 std::cout<<std::endl;
104 std::cout<<"point : "<<i<<std::endl;
105 std::cout<<"dx calculated : "<<TDP1(i).X()<<std::endl;
106 std::cout<<"dx estimated : "<<scal*(TP1(i).X()-TP2(i).X())<<std::endl;
107 std::cout<<"dy calculated : "<<TDP1(i).Y()<<std::endl;
108 std::cout<<"dy estimated : "<<scal*(TP1(i).Y()-TP2(i).Y())<<std::endl;
109 std::cout<<"dz calculated : "<<TDP1(i).Z()<<std::endl;
110 std::cout<<"dz estimated : "<<scal*(TP1(i).Z()-TP2(i).Z())<<std::endl;
111 std::cout<<"dw calculated : "<<TDW1(i)<<std::endl;
112 std::cout<<"dw estimated : "<<scal*(TW1(i)-TW2(i))<<std::endl;
114 for(i = 1; i <= hp2d; i++){
115 std::cout<<std::endl;
116 std::cout<<"point 2d : "<<i<<std::endl;
117 std::cout<<"dx calculated : "<<TDP2d1(i).X()<<std::endl;
118 std::cout<<"dx estimated : "<<scal*(TP2d1(i).X()-TP2d2(i).X())<<std::endl;
119 std::cout<<"dy calculated : "<<TDP2d1(i).Y()<<std::endl;
120 std::cout<<"dy estimated : "<<scal*(TP2d1(i).Y()-TP2d2(i).Y())<<std::endl;
124 static void Drawsect(const Standard_Real param,
125 Blend_SurfRstFunction& Func)
127 gp_Pnt pnts = Func.PointOnS();
128 gp_Pnt pntrst = Func.PointOnRst();
129 gp_Pnt2d p2ds = Func.Pnt2dOnS();
130 gp_Pnt2d p2drst = Func.Pnt2dOnRst();
131 Standard_Real w = Func.ParameterOnRst();
132 Blend_Point BP(pnts,pntrst,param,
134 p2drst.X(),p2drst.Y(),w);
135 Standard_Integer hp,hk,hd,hp2d;
136 Func.GetShape(hp,hk,hd,hp2d);
137 TColStd_Array1OfReal TK(1,hk);
139 TColStd_Array1OfInteger TMul(1,hk);
141 TColgp_Array1OfPnt TP(1,hp);
142 TColgp_Array1OfPnt2d TP2d(1,hp2d);
143 TColStd_Array1OfReal TW(1,hp);
144 Func.Section(BP,TP,TP2d,TW);
145 Handle(Geom_BSplineCurve) sect = new Geom_BSplineCurve
150 Standard_CString name = tname ;
151 sprintf(name,"%s_%d","Section",IndexOfSection);
152 DrawTrSurf::Set(name,sect);
157 //=======================================================================
158 //function : ArcToRecadre
159 //purpose : Find a suitable arc
160 // PrevIndex is used to reject an already tested arc
161 //=======================================================================
163 Standard_Integer BRepBlend_SurfRstLineBuilder::
164 ArcToRecadre(const math_Vector& theSol,
165 const Standard_Integer PrevIndex,
168 Standard_Real& ponarc)
170 Standard_Integer IndexSol = 0, nbarc = 0;
171 Standard_Boolean ok = Standard_False;
172 Standard_Boolean byinter = (line->NbPoints() != 0), okinter = 0;
173 Standard_Real distmin = RealLast();
174 Standard_Real uprev = 0.,vprev = 0., prm = 0., dist = 0.;
176 if(byinter) previousP.ParametersOnS(uprev,vprev);
177 pt2d.SetCoord(theSol(1),theSol(2));
178 lastpt2d.SetCoord(uprev,vprev);
181 while (domain1->More()) {
184 ok = okinter = BRepBlend_BlendTool::Inters(pt2d,lastpt2d,
186 domain1->Value(),prm,dist);
188 if(!ok) ok = BRepBlend_BlendTool::Project(pt2d,surf1,
189 domain1->Value(),prm,dist);
191 if (ok && (nbarc != PrevIndex) ) {
192 if (dist<distmin || okinter) {
196 if(okinter && (PrevIndex==0) ) break;
204 //=======================================================================
205 //function : BRepBlend_SurfRstLineBuilder
207 //=======================================================================
209 BRepBlend_SurfRstLineBuilder::BRepBlend_SurfRstLineBuilder
210 (const Handle(Adaptor3d_HSurface)& Surf1,
211 const Handle(Adaptor3d_TopolTool)& Domain1,
212 const Handle(Adaptor3d_HSurface)& Surf2,
213 const Handle(Adaptor2d_HCurve2d)& Rst,
214 const Handle(Adaptor3d_TopolTool)& Domain2):
215 sol(1,3),surf1(Surf1), domain1(Domain1),
216 surf2(Surf2), rst(Rst), domain2(Domain2)
220 //=======================================================================
223 //=======================================================================
225 void BRepBlend_SurfRstLineBuilder::Perform(Blend_SurfRstFunction& Func,
227 Blend_SurfPointFuncInv& FinvP,
228 Blend_SurfCurvFuncInv& FinvC,
229 const Standard_Real Pdep,
230 const Standard_Real Pmax,
231 const Standard_Real MaxStep,
232 const Standard_Real TolGuide,
233 const math_Vector& ParDep,
234 const Standard_Real Tolesp,
235 const Standard_Real Fleche,
236 const Standard_Boolean Appro)
238 done = Standard_False;
239 iscomplete = Standard_False;
240 comptra = Standard_False;
241 line = new BRepBlend_Line();
242 tolesp = Abs(Tolesp);
243 tolgui = Abs(TolGuide);
244 fleche = Abs(Fleche);
245 rebrou = Standard_False;
246 pasmax = Abs(MaxStep);
248 if (Pmax-Pdep >= 0.) {
261 TopAbs_State siturst,situs;
262 Standard_Boolean decroch;
263 math_Vector tolerance(1,3),infbound(1,3),supbound(1,3);
264 Func.GetTolerance(tolerance,tolesp);
265 Func.GetBounds(infbound,supbound);
266 math_FunctionSetRoot rsnld(Func,tolerance,30);
268 rsnld.Perform(Func,ParDep,infbound,supbound);
270 if (!rsnld.IsDone()) {
274 if (!CheckInside(Func,siturst,situs,decroch)) {
282 State = TestArret(Func,Standard_False,Blend_OK);
283 if (State!=Blend_OK) {
287 if (Blend_GettraceDRAWSECT()){
288 Drawsect(param,Func);
292 line->Append(previousP);
294 previousP.ParametersOnS(U,V);
295 // W = previousP.ParameterOnC();
297 BRepBlend_Extremity ptf1(previousP.PointOnS(),
298 U,V,previousP.Parameter(),tolesp);
299 BRepBlend_Extremity ptf2(previousP.PointOnC(),
300 U,V,previousP.Parameter(),tolesp);
301 if (!previousP.IsTangencyPoint()) {
302 ptf1.SetTangent(previousP.TangentOnS());
303 ptf2.SetTangent(previousP.TangentOnC());
306 line->SetStartPoints(ptf1, ptf2);
309 line->SetEndPoints(ptf1, ptf2);
312 InternalPerform(Func,Finv,FinvP,FinvC,Pmax);
313 done = Standard_True;
316 //=======================================================================
317 //function : PerformFirstSection
319 //=======================================================================
321 Standard_Boolean BRepBlend_SurfRstLineBuilder::PerformFirstSection
322 (Blend_SurfRstFunction& Func,
324 Blend_SurfPointFuncInv& FinvP,
325 Blend_SurfCurvFuncInv& FinvC,
326 const Standard_Real Pdep,
327 const Standard_Real Pmax,
328 const math_Vector& ParDep,
329 const Standard_Real Tolesp,
330 const Standard_Real TolGuide,
331 const Standard_Boolean RecRst,
332 const Standard_Boolean RecP,
333 const Standard_Boolean RecS,
337 done = Standard_False;
338 iscomplete = Standard_False;
339 comptra = Standard_False;
340 line = new BRepBlend_Line();
341 tolesp = Abs(Tolesp);
342 tolgui = Abs(TolGuide);
343 rebrou = Standard_False;
345 if (Pmax-Pdep >= 0.) {
351 Blend_Status State = Blend_OnRst12;
352 Standard_Real trst = 0.;
353 Standard_Boolean recadp,recadrst,recads;
354 Standard_Real wp,wrst,ws;
355 Standard_Real U = 0.,V = 0.;
356 math_Vector infbound(1,3),supbound(1,3),tolerance(1,3);
357 math_Vector solinvp(1,3),solinvrst(1,4),solinvs(1,3);
358 Handle(Adaptor3d_HVertex) Vtxp,Vtxrst,Vtxs,Vtxc;
359 Standard_Boolean IsVtxp = 0,IsVtxrst = 0,IsVtxs = 0;
360 Handle(Adaptor2d_HCurve2d) Arc;
361 wp = wrst = ws = Pmax;
364 Func.GetTolerance(tolerance,tolesp);
365 Func.GetBounds(infbound,supbound);
367 math_FunctionSetRoot rsnld(Func,tolerance,30);
368 rsnld.Perform(Func,ParDep,infbound,supbound);
369 if (!rsnld.IsDone()) return Standard_False;
372 recads = RecS && Recadre(FinvC,solinvs,Arc,IsVtxs,Vtxs);
376 recadp = RecP && Recadre(FinvP,solinvp,IsVtxp,Vtxp);
380 recadrst = RecRst && Recadre(Func,Finv,solinvrst,IsVtxrst,Vtxrst);
384 if (!recads && !recadp && !recadrst) return Standard_False;
385 if (recadp && recadrst) {
386 if(sens*(wrst-wp) > tolgui){ //first one leaves the domain
390 trst = BRepBlend_BlendTool::Parameter(Vtxp,rst);
404 trst = BRepBlend_BlendTool::Parameter(Vtxp,rst);
407 recadrst = Standard_True;
414 if(recads && recadrst){
415 if(Abs(ws - wrst) < tolgui){
416 State = Blend_OnRst12;
417 param = 0.5*(ws+wrst);
422 else if(sens*(ws-wrst)<0){
424 State = Blend_OnRst1;
426 Arc->Value(solinvs(3)).Coord(U,V);
433 State = Blend_OnRst2;
443 State = Blend_OnRst1;
445 Arc->Value(solinvs(3)).Coord(U,V);
453 State = Blend_OnRst2;
460 State = TestArret(Func,Standard_False,State);
463 return Standard_True;
466 //=======================================================================
467 //function : Complete
469 //=======================================================================
471 Standard_Boolean BRepBlend_SurfRstLineBuilder::Complete(Blend_SurfRstFunction& Func,
473 Blend_SurfPointFuncInv& FinvP,
474 Blend_SurfCurvFuncInv& FinvC,
475 const Standard_Real Pmin)
477 if (!done) {throw StdFail_NotDone();}
478 if (iscomplete) {return Standard_True;}
480 previousP = line->Point(1);
483 previousP = line->Point(line->NbPoints());
486 param = previousP.Parameter();
487 previousP.ParametersOnS(sol(1),sol(2));
488 sol(3) = previousP.ParameterOnC();
490 InternalPerform(Func,Finv,FinvP,FinvC,Pmin);
491 iscomplete = Standard_True;
492 return Standard_True;
495 //=======================================================================
496 //function : InternalPerform
498 //=======================================================================
500 void BRepBlend_SurfRstLineBuilder::InternalPerform(Blend_SurfRstFunction& Func,
502 Blend_SurfPointFuncInv& FinvP,
503 Blend_SurfCurvFuncInv& FinvC,
504 const Standard_Real Bound)
506 Standard_Real stepw = pasmax;
507 Standard_Integer nbp = line->NbPoints();
508 if(nbp >= 2){ //The last step is reproduced if it is not too small.
510 stepw = (line->Point(2).Parameter() - line->Point(1).Parameter());
513 stepw = (line->Point(nbp).Parameter() - line->Point(nbp - 1).Parameter());
515 stepw = Max(stepw,100.*tolgui);
517 Standard_Real parprec = param;
518 if (sens*(parprec - Bound) >= -tolgui) {
521 Blend_Status State = Blend_OnRst12;
522 TopAbs_State situonc = TopAbs_UNKNOWN, situons = TopAbs_UNKNOWN;
523 Standard_Boolean decroch = Standard_False;
524 Standard_Boolean Arrive,recadp,recadrst,recads,echecrecad;
525 Standard_Real wp,wrst,ws;
526 Standard_Real U = 0.,V = 0.;
527 Standard_Real trst = 0.;
528 math_Vector infbound(1,3),supbound(1,3);
529 math_Vector parinit(1,3),tolerance(1,3);
530 math_Vector solinvp(1,3),solinvrst(1,4),solinvs(1,3);
531 Handle(Adaptor3d_HVertex) Vtxp,Vtxrst,Vtxs,Vtxc;
532 Standard_Boolean IsVtxp = 0,IsVtxrst = 0,IsVtxs = 0;
533 BRepBlend_Extremity Extrst,Exts;
534 Handle(Adaptor2d_HCurve2d) Arc;
536 //IntSurf_Transition Tline,Tarc;
538 Func.GetTolerance(tolerance,tolesp);
539 Func.GetBounds(infbound,supbound);
541 math_FunctionSetRoot rsnld(Func,tolerance,30);
544 Arrive = Standard_False;
545 param = parprec + sens*stepw;
546 if(sens *(param - Bound) > 0.) {
547 stepw = sens*(Bound - parprec)*0.5;
548 param = parprec + sens*stepw;
552 Standard_Boolean bonpoint = 1;
553 #ifdef OCCT_DEBUG_BBPP_N_TRDERIV
556 rsnld.Perform(Func,parinit,infbound,supbound);
557 if (rsnld.IsDone()) {
560 if(BBPP(param,Func,sol,tolesp,bp1)){
561 Standard_Real dw = 1.e-10;
563 rsnld.Perform(Func,parinit,infbound,supbound);
564 if (rsnld.IsDone()) {
567 if(BBPP(param+dw,Func,sol,tolesp,bp2)){
568 tracederiv(Func,bp1,bp2);
576 rsnld.Perform(Func,parinit,infbound,supbound);
578 if (rsnld.IsDone()) {
580 if(!CheckInside(Func,situonc,situons,decroch) && line->NbPoints() == 1){
581 State = Blend_StepTooLarge;
586 State = Blend_StepTooLarge;
590 wp = wrst = ws = Bound;
591 recadp = recadrst = recads = Standard_False;
592 echecrecad = Standard_False;
593 if (situons == TopAbs_OUT || situons == TopAbs_ON) {
594 // pb inverse rst/rst
595 recads = Recadre(FinvC,solinvs,Arc,IsVtxs,Vtxs);
598 // It is necessary to reevaluate the deviation (BUC60360)
601 Arc->Value(solinvs(3)).Coord(U,V);
605 decroch = Func.Decroch(sol, t, n);
608 echecrecad = Standard_True;
611 if (situonc == TopAbs_OUT || situonc == TopAbs_ON) {
612 // pb inverse point/surf
613 recadp = Recadre(FinvP,solinvp,IsVtxp,Vtxp);
618 echecrecad = Standard_True;
622 // pb inverse rst/surf
623 recadrst = Recadre(Func,Finv,solinvrst,IsVtxrst,Vtxrst);
628 echecrecad = Standard_True;
632 if(recadp || recads || recadrst) echecrecad = Standard_False;
634 if (recadp && recadrst) {
635 if(sens*(wrst-wp) > tolgui){ //first one leaves the domain
639 trst = BRepBlend_BlendTool::Parameter(Vtxp,rst);
654 trst = BRepBlend_BlendTool::Parameter(Vtxp,rst);
657 recadrst = Standard_True;
665 if(recads && recadrst){
666 if(Abs(ws - wrst) < tolgui){
667 State = Blend_OnRst12;
668 param = 0.5*(ws+wrst);
673 else if(sens*(ws-wrst)<0){
676 State = Blend_OnRst1;
678 Arc->Value(solinvs(3)).Coord(U,V);
685 State = Blend_OnRst2;
695 State = Blend_OnRst1;
697 Arc->Value(solinvs(3)).Coord(U,V);
705 State = Blend_OnRst2;
715 State = TestArret(Func,Standard_True,State);
718 // Failed reframing. Leave with PointsConfondus
720 std::cout<<"SurfRstLineBuilder : failed reframing"<<std::endl;
722 State = Blend_SamePoints;
730 if (Blend_GettraceDRAWSECT()){
731 Drawsect(param,Func);
736 line->Append(previousP);
739 line->Prepend(previousP);
744 if (param == Bound) {
745 Arrive = Standard_True;
746 Exts.SetValue(previousP.PointOnS(),
748 previousP.Parameter(),tolesp);
749 MakeExtremity(Extrst,Standard_False,rst,sol(3),IsVtxrst,Vtxrst);
750 // Indicate end on Bound.
753 param = param + sens*stepw;
754 if (sens*(param - Bound) > - tolgui) {
761 case Blend_StepTooLarge :
764 if (Abs(stepw) < tolgui) {
765 previousP.ParametersOnS(U,V);
766 Exts.SetValue(previousP.PointOnS(),U,V,
767 previousP.Parameter(),tolesp);
768 Extrst.SetValue(previousP.PointOnC(),
769 previousP.ParameterOnC(),
770 previousP.Parameter(),tolesp);
771 Arrive = Standard_True;
772 if (line->NbPoints()>=2) {
773 // Indicate that one stops during the processing
775 std::cout<<"SurfRstLineBuilder : No advancement in the processing"<<std::endl;
780 param = parprec + sens*stepw; // no risk to exceed Bound.
785 case Blend_StepTooSmall :
788 if (Blend_GettraceDRAWSECT()){
789 Drawsect(param,Func);
794 line->Append(previousP);
797 line->Prepend(previousP);
802 stepw = Min(1.5*stepw,pasmax);
803 if (param == Bound) {
804 Arrive = Standard_True;
805 Exts.SetValue(previousP.PointOnS(),sol(1),sol(2),
806 previousP.Parameter(),tolesp);
807 MakeExtremity(Extrst,Standard_False,rst,sol(3),IsVtxrst,Vtxrst);
808 // Indicate end on Bound.
811 param = param + sens*stepw;
812 if (sens*(param - Bound) > - tolgui) {
822 if (Blend_GettraceDRAWSECT()){
823 Drawsect(param,Func);
827 line->Append(previousP);
830 line->Prepend(previousP);
832 MakeExtremity(Exts,Standard_True,Arc,solinvs(3),IsVtxs,Vtxs);
833 MakeExtremity(Extrst,Standard_False,rst,sol(3),IsVtxrst,Vtxrst);
834 Arrive = Standard_True;
841 if (Blend_GettraceDRAWSECT()){
842 Drawsect(param,Func);
846 line->Append(previousP);
849 line->Prepend(previousP);
851 Exts.SetValue(previousP.PointOnS(),sol(1),sol(2),
852 previousP.Parameter(),tolesp);
853 MakeExtremity(Extrst,Standard_False,rst,sol(3),IsVtxrst,Vtxrst);
854 Arrive = Standard_True;
861 if (Blend_GettraceDRAWSECT()){
862 Drawsect(param,Func);
866 line->Append(previousP);
869 line->Prepend(previousP);
871 MakeExtremity(Exts,Standard_True,Arc,solinvs(1),IsVtxs,Vtxs);
872 MakeExtremity(Extrst,Standard_False,rst,sol(3),IsVtxrst,Vtxrst);
873 Arrive = Standard_True;
877 case Blend_SamePoints :
881 std::cout << "SurfRstLineBuilder Points mixed in the processing" << std::endl;
883 previousP.ParametersOnS(U,V);
884 Exts.SetValue(previousP.PointOnS(),U,V,
885 previousP.Parameter(),tolesp);
886 Extrst.SetValue(previousP.PointOnC(),
887 previousP.ParameterOnC(),
888 previousP.Parameter(),tolesp);
889 Arrive = Standard_True;
897 line->SetEndPoints(Exts,Extrst);
898 decrochfin = decroch;
901 line->SetStartPoints(Exts,Extrst);
902 decrochdeb = decroch;
908 //=======================================================================
910 //purpose : Reframe section Surface / Restriction
911 //=======================================================================
913 Standard_Boolean BRepBlend_SurfRstLineBuilder::Recadre(Blend_SurfCurvFuncInv& FinvC,
915 Handle(Adaptor2d_HCurve2d)& Arc,
916 Standard_Boolean& IsVtx,
917 Handle(Adaptor3d_HVertex)& Vtx)
919 Standard_Boolean recadre = Standard_False;
921 gp_Pnt2d pt2d, lastpt2d;
922 Standard_Integer IndexSol, nbarc;
925 IndexSol = ArcToRecadre(sol, 0, lastpt2d, pt2d, pmin);
927 IsVtx = Standard_False;
929 return Standard_False;
934 while (nbarc < IndexSol) {
938 Arc = domain1->Value();
942 math_Vector toler(1,3),infb(1,3),supb(1,3);
943 FinvC.GetTolerance(toler,tolesp);
944 FinvC.GetBounds(infb,supb);
949 math_FunctionSetRoot rsnld(FinvC,toler,30);
950 rsnld.Perform(FinvC,Solinv,infb,supb);
952 if (!rsnld.IsDone()) {
954 std::cout << "SurfRstLineBuilder : RSNLD not done "<< std::endl << std::endl;
958 // It is necessary to check the value of the function
960 recadre = FinvC.IsSolution(Solinv,tolesp);
963 // In case of fail, it is checked if another arc
964 // can be useful (case of output at the proximity of a vertex)
967 IndexSol = ArcToRecadre(sol, IndexSol,
968 lastpt2d, pt2d, pmin);
970 return Standard_False; // No other solution
975 while (nbarc < IndexSol) {
980 Arc = domain1->Value();
983 FinvC.GetTolerance(toler,tolesp);
984 FinvC.GetBounds(infb,supb);
988 math_FunctionSetRoot aRsnld(FinvC,toler,30);
989 aRsnld.Perform(FinvC,Solinv,infb,supb);
991 if (!aRsnld.IsDone()) {
993 std::cout << "SurfRstLineBuilder : RSNLD not done "<< std::endl << std::endl;
997 // It is necessary to check the value of the function
999 recadre = FinvC.IsSolution(Solinv,tolesp);
1004 Standard_Real w = Solinv(2);
1005 if(w < rst->FirstParameter() - toler(2)||
1006 w > rst->LastParameter() + toler(2)){
1007 return Standard_False;
1009 domain1->Initialize(Arc);
1010 domain1->InitVertexIterator();
1011 IsVtx = !domain1->MoreVertex();
1013 Vtx = domain1->Vertex();
1014 if (Abs(BRepBlend_BlendTool::Parameter(Vtx,Arc)-Solinv(3)) <=
1015 BRepBlend_BlendTool::Tolerance(Vtx,Arc)) {
1016 IsVtx = Standard_True;
1019 domain1->NextVertex();
1020 IsVtx = !domain1->MoreVertex();
1023 if (!domain1->MoreVertex()) {
1024 IsVtx = Standard_False;
1026 return Standard_True;
1028 return Standard_False;
1031 //=======================================================================
1032 //function : Recadre
1034 //=======================================================================
1036 Standard_Boolean BRepBlend_SurfRstLineBuilder::Recadre(Blend_SurfRstFunction& Func,
1037 Blend_FuncInv& Finv,
1038 math_Vector& Solinv,
1039 Standard_Boolean& IsVtx,
1040 Handle(Adaptor3d_HVertex)& Vtx)
1042 math_Vector toler(1,4),infb(1,4),supb(1,4);
1043 Finv.GetTolerance(toler,tolesp);
1044 Finv.GetBounds(infb,supb);
1050 math_FunctionSetRoot rsnld(Finv,toler,30);
1051 rsnld.Perform(Finv,Solinv,infb,supb);
1052 if (!rsnld.IsDone()) {
1054 std::cout << "SurfRstLineBuilder :RSNLD not done "<< std::endl;
1056 return Standard_False;
1060 if(Finv.IsSolution(Solinv,tolesp)){
1061 gp_Pnt2d p2d(Solinv(3),Solinv(4));
1062 TopAbs_State situ = domain1->Classify(p2d,Min(toler(3),toler(4)),0);
1063 if ((situ != TopAbs_IN) && (situ != TopAbs_ON)) {
1064 return Standard_False;
1066 domain2->Initialize(rst);
1067 domain2->InitVertexIterator();
1068 IsVtx = !domain2->MoreVertex();
1070 Vtx = domain2->Vertex();
1071 if (Abs(BRepBlend_BlendTool::Parameter(Vtx,rst)-Solinv(1)) <=
1072 BRepBlend_BlendTool::Tolerance(Vtx,rst)) {
1073 IsVtx = Standard_True;
1076 domain2->NextVertex();
1077 IsVtx = !domain2->MoreVertex();
1080 if (!domain2->MoreVertex()) {
1081 IsVtx = Standard_False;
1083 // The section is recalculated by direct resolution, otherwise
1084 // incoherences between the parameter and the ground caused by yawn are returned.
1086 math_Vector infbound(1,3),supbound(1,3);
1087 math_Vector parinit(1,3),tolerance(1,3);
1088 Func.GetTolerance(tolerance,tolesp);
1089 Func.GetBounds(infbound,supbound);
1091 math_FunctionSetRoot rsnld2(Func,tolerance,30);
1092 parinit(1) = Solinv(3);
1093 parinit(2) = Solinv(4);
1094 parinit(3) = Solinv(1);
1095 Func.Set(Solinv(2));
1096 rsnld2.Perform(Func,parinit,infbound,supbound);
1097 if(!rsnld2.IsDone()) return Standard_False;
1098 rsnld2.Root(parinit);
1099 Solinv(3) = parinit(1);
1100 Solinv(4) = parinit(2);
1101 Solinv(1) = parinit(3);
1102 return Standard_True;
1104 return Standard_False;
1107 //=======================================================================
1108 //function : Recadre
1110 //=======================================================================
1112 Standard_Boolean BRepBlend_SurfRstLineBuilder::Recadre(Blend_SurfPointFuncInv& FinvP,
1113 math_Vector& Solinv,
1114 Standard_Boolean& IsVtx,
1115 Handle(Adaptor3d_HVertex)& Vtx)
1119 Standard_Real firstrst = rst->FirstParameter();
1120 Standard_Real lastrst = rst->LastParameter();
1121 Standard_Real wpoint = firstrst;
1122 if((sol(3) - firstrst) > (lastrst - sol(3))) wpoint = lastrst;
1123 p2drst = rst->Value(wpoint);
1124 gp_Pnt thepoint = surf2->Value(p2drst.X(),p2drst.Y());
1126 FinvP.Set(thepoint);
1127 math_Vector toler(1,3),infb(1,3),supb(1,3);
1128 FinvP.GetTolerance(toler,tolesp);
1129 FinvP.GetBounds(infb,supb);
1134 math_FunctionSetRoot rsnld(FinvP,toler,30);
1135 rsnld.Perform(FinvP,Solinv,infb,supb);
1136 if (!rsnld.IsDone()) {
1138 std::cout << "SurfRstLineBuilder :RSNLD not done "<< std::endl;
1140 return Standard_False;
1144 if(FinvP.IsSolution(Solinv,tolesp)){
1145 gp_Pnt2d p2d(Solinv(2),Solinv(3));
1146 TopAbs_State situ = domain1->Classify(p2d,Min(toler(2),toler(3)),0);
1147 if ((situ != TopAbs_IN) && (situ != TopAbs_ON)) {
1148 return Standard_False;
1150 domain2->Initialize(rst);
1151 domain2->InitVertexIterator();
1152 IsVtx = !domain2->MoreVertex();
1154 Vtx = domain2->Vertex();
1155 if (Abs(BRepBlend_BlendTool::Parameter(Vtx,rst)-wpoint) <=
1156 BRepBlend_BlendTool::Tolerance(Vtx,rst)) {
1157 IsVtx = Standard_True;
1160 domain2->NextVertex();
1161 IsVtx = !domain2->MoreVertex();
1164 if (!domain2->MoreVertex()) {
1165 IsVtx = Standard_False;
1167 return Standard_True;
1169 return Standard_False;
1172 //=======================================================================
1173 //function : Transition
1175 //=======================================================================
1177 void BRepBlend_SurfRstLineBuilder::Transition(const Standard_Boolean OnFirst,
1178 const Handle(Adaptor2d_HCurve2d)& Arc,
1179 const Standard_Real Param,
1180 IntSurf_Transition& TLine,
1181 IntSurf_Transition& TArc)
1183 Standard_Boolean computetranstionaveclacorde = 0;
1185 Blend_Point prevprev;
1187 if(previousP.IsTangencyPoint()){
1188 if(line->NbPoints() < 2) return;
1189 computetranstionaveclacorde = 1;
1191 prevprev = line->Point(2);
1194 prevprev = line->Point(line->NbPoints() - 1);
1201 gp_Vec d1u,d1v,normale,tgrst;
1203 Arc->D1(Param,p2d,dp2d);
1205 surf1->D1(p2d.X(),p2d.Y(),pbid,d1u,d1v);
1206 if(!computetranstionaveclacorde) tgline = previousP.TangentOnS1();
1207 else tgline = gp_Vec(prevprev.PointOnS(),previousP.PointOnS());
1210 surf2->D1(p2d.X(),p2d.Y(),pbid,d1u,d1v);
1211 if(!computetranstionaveclacorde) tgline = previousP.TangentOnS2();
1212 else tgline = gp_Vec(prevprev.PointOnC(),previousP.PointOnC());
1215 tgrst.SetLinearForm(dp2d.X(),d1u,dp2d.Y(),d1v);
1216 normale = d1u.Crossed(d1v);
1218 IntSurf::MakeTransition(tgline,tgrst,normale,TLine,TArc);
1221 //=======================================================================
1222 //function : MakeExtremity
1224 //=======================================================================
1226 void BRepBlend_SurfRstLineBuilder::MakeExtremity(BRepBlend_Extremity& Extrem,
1227 const Standard_Boolean OnFirst,
1228 const Handle(Adaptor2d_HCurve2d)& Arc,
1229 const Standard_Real Param,
1230 const Standard_Boolean IsVtx,
1231 const Handle(Adaptor3d_HVertex)& Vtx)
1233 IntSurf_Transition Tline,Tarc;
1235 Handle(Adaptor3d_TopolTool) Iter;
1237 Extrem.SetValue(previousP.PointOnS(),
1239 previousP.Parameter(),tolesp);
1240 if (!previousP.IsTangencyPoint())
1241 Extrem.SetTangent(previousP.TangentOnS());
1245 Extrem.SetValue(previousP.PointOnC(),
1247 previousP.Parameter(),tolesp);
1248 if (!previousP.IsTangencyPoint())
1249 Extrem.SetTangent(previousP.TangentOnC());
1255 Transition(OnFirst,Arc,Param,Tline,Tarc);
1256 Extrem.AddArc(Arc,Param,Tline,Tarc);
1259 Extrem.SetVertex(Vtx);
1260 while (Iter->More()) {
1261 Handle(Adaptor2d_HCurve2d) arc = Iter->Value();
1263 Iter->Initialize(arc);
1264 Iter->InitVertexIterator();
1265 while (Iter->MoreVertex()) {
1266 if (Iter->Identical(Vtx,Iter->Vertex())) {
1267 prm = BRepBlend_BlendTool::Parameter(Vtx,arc);
1268 Transition(OnFirst,arc,prm,Tline,Tarc);
1269 Extrem.AddArc(arc,prm,Tline,Tarc);
1275 Transition(OnFirst,arc,Param,Tline,Tarc);
1276 Extrem.AddArc(arc,Param,Tline,Tarc);
1283 //=======================================================================
1284 //function : CheckDeflectionOnSurf
1286 //=======================================================================
1288 Blend_Status BRepBlend_SurfRstLineBuilder::CheckDeflectionOnSurf(const Blend_Point& CurPoint)
1290 //Controls 3d of Blend_CSWalking.
1292 //rule by tests in U4 corresponds to 11.478 d
1293 const Standard_Real CosRef3D = 0.98;
1294 Standard_Real Cosi=0, Cosi2=0;
1295 Standard_Boolean curpointistangent = CurPoint.IsTangencyPoint();
1296 Standard_Boolean prevpointistangent = previousP.IsTangencyPoint();
1298 gp_Pnt Psurf = CurPoint.PointOnS();
1300 if(!curpointistangent){
1301 Tgsurf = CurPoint.TangentOnS();
1303 gp_Pnt prevP = previousP.PointOnS();
1305 if(!prevpointistangent){
1306 prevTg = previousP.TangentOnS();
1308 Standard_Real Norme,prevNorme = 0.;
1309 gp_Vec Corde(prevP,Psurf);
1310 Norme = Corde.SquareMagnitude();
1311 // if(!curpointistangent) curNorme = Tgsurf.SquareMagnitude();
1312 if(!prevpointistangent) prevNorme = prevTg.SquareMagnitude();
1314 if (Norme <= tolesp*tolesp){
1315 // it can be necessary to force same point
1316 return Blend_SamePoints;
1318 if(!prevpointistangent){
1319 if(prevNorme <= tolesp*tolesp) {
1320 return Blend_SamePoints;
1322 Cosi = sens*Corde*prevTg;
1323 if (Cosi <0.) { // angle 3d>pi/2. --> return back
1324 return Blend_Backward;
1327 Cosi2 = Cosi * Cosi / prevNorme / Norme;
1328 if (Cosi2 < CosRef3D) {
1329 return Blend_StepTooLarge;
1333 if(!curpointistangent){
1334 // Check if it is necessary to control the sign of prevtg*Tgsurf
1335 Cosi = sens*Corde*Tgsurf;
1336 Cosi2 = Cosi * Cosi / Tgsurf.SquareMagnitude() / Norme;
1337 if (Cosi2 < CosRef3D || Cosi < 0.) {
1338 return Blend_StepTooLarge;
1342 if(!curpointistangent && !prevpointistangent){
1343 // Estimation of the current arrow
1344 Standard_Real FlecheCourante =
1345 (prevTg.Normalized().XYZ()-Tgsurf.Normalized().XYZ()).SquareModulus()*Norme/64.;
1347 if (FlecheCourante <= 0.25*fleche*fleche) {
1348 return Blend_StepTooSmall;
1350 if (FlecheCourante > fleche*fleche) {
1352 return Blend_StepTooLarge;
1359 //=======================================================================
1360 //function : CheckDeflectionOnRst
1362 //=======================================================================
1364 Blend_Status BRepBlend_SurfRstLineBuilder::CheckDeflectionOnRst(const Blend_Point& CurPoint)
1366 //Controls 3D of Blend_CSWalking.
1368 // rule by tests in U4 corresponds to 11.478 d
1369 const Standard_Real CosRef3D = 0.98;
1370 Standard_Real Cosi, Cosi2;
1371 Standard_Boolean curpointistangent = CurPoint.IsTangencyPoint();
1372 Standard_Boolean prevpointistangent = previousP.IsTangencyPoint();
1374 gp_Pnt Psurf = CurPoint.PointOnC();
1376 if(!curpointistangent){
1377 Tgsurf = CurPoint.TangentOnC();
1379 gp_Pnt prevP = previousP.PointOnC();
1381 if(!prevpointistangent){
1382 prevTg = previousP.TangentOnC();
1384 Standard_Real Norme,prevNorme = 0.;
1385 gp_Vec Corde(prevP,Psurf);
1386 Norme = Corde.SquareMagnitude();
1387 // if(!curpointistangent) curNorme = Tgsurf.SquareMagnitude();
1388 if(!prevpointistangent) prevNorme = prevTg.SquareMagnitude();
1390 if (Norme <= tolesp*tolesp){
1391 // it can be necessary to force same point
1392 return Blend_SamePoints;
1394 if(!prevpointistangent){
1395 if(prevNorme <= tolesp*tolesp) {
1396 return Blend_SamePoints;
1398 Cosi = sens*Corde*prevTg;
1399 if (Cosi <0.) { // angle 3d>pi/2. --> return back
1400 return Blend_Backward;
1403 Cosi2 = Cosi * Cosi / prevNorme / Norme;
1404 if (Cosi2 < CosRef3D) {
1405 return Blend_StepTooLarge;
1409 if(!curpointistangent){
1410 // Check if it is necessary to control the sign of prevtg*Tgsurf
1411 Cosi = sens*Corde*Tgsurf;
1412 Cosi2 = Cosi * Cosi / Tgsurf.SquareMagnitude() / Norme;
1413 if (Cosi2 < CosRef3D || Cosi < 0.) {
1414 return Blend_StepTooLarge;
1418 if(!curpointistangent && !prevpointistangent){
1419 // Estimation of the current arrow
1420 Standard_Real FlecheCourante =
1421 (prevTg.Normalized().XYZ()-Tgsurf.Normalized().XYZ()).SquareModulus()*Norme/64.;
1423 if (FlecheCourante <= 0.25*fleche*fleche) {
1424 return Blend_StepTooSmall;
1426 if (FlecheCourante > fleche*fleche) {
1428 return Blend_StepTooLarge;
1434 static IntSurf_TypeTrans ConvOrToTra(const TopAbs_Orientation O)
1436 if(O == TopAbs_FORWARD) return IntSurf_In;
1440 //=======================================================================
1441 //function : TestArret
1443 //=======================================================================
1445 Blend_Status BRepBlend_SurfRstLineBuilder::TestArret(Blend_SurfRstFunction& Func,
1446 const Standard_Boolean TestDeflection,
1447 const Blend_Status State)
1452 gp_Vec2d tg2ds,tg2drst;
1453 Blend_Status StateS,StateRst;
1454 IntSurf_TypeTrans tras = IntSurf_Undecided, trarst = IntSurf_Undecided;
1455 Blend_Point curpoint;
1457 if (Func.IsSolution(sol,tolesp)) {
1458 Standard_Boolean curpointistangent = Func.IsTangencyPoint();
1459 pts = Func.PointOnS();
1460 ptrst = Func.PointOnRst();
1461 pt2drst = Func.Pnt2dOnRst();
1462 if(curpointistangent){
1463 curpoint.SetValue(pts,ptrst,param,sol(1),sol(2),
1464 pt2drst.X(),pt2drst.Y(),sol(3));
1467 tgs = Func.TangentOnS();
1468 tgrst = Func.TangentOnRst();
1469 tg2ds = Func.Tangent2dOnS();
1470 tg2drst = Func.Tangent2dOnRst();
1472 curpoint.SetValue(pts,ptrst,param,sol(1),sol(2),
1473 pt2drst.X(),pt2drst.Y(),sol(3),
1474 tgs,tgrst,tg2ds,tg2drst);
1476 if (TestDeflection) {
1477 StateS = CheckDeflectionOnSurf(curpoint);
1478 StateRst = CheckDeflectionOnRst(curpoint);
1481 StateS = StateRst = Blend_OK;
1483 if (StateS == Blend_Backward) {
1484 StateS = Blend_StepTooLarge;
1485 rebrou= Standard_True;
1487 if (StateRst == Blend_Backward) {
1488 StateRst = Blend_StepTooLarge;
1489 rebrou = Standard_True;
1491 if (StateS == Blend_StepTooLarge ||
1492 StateRst == Blend_StepTooLarge) {
1493 return Blend_StepTooLarge;
1496 if (!comptra && !curpointistangent) {
1498 Func.Decroch(sol,nors,tgsecs);
1500 Standard_Real testra = tgsecs.Dot(nors.Crossed(tgs));
1501 if (Abs(testra) > tolesp) {
1505 else if (testra >0.) {
1508 gp_Pnt2d p2drstref; gp_Vec2d tg2drstref;
1509 rst->D1(sol(3),p2drstref,tg2drstref);
1510 testra = tg2drst.Dot(tg2drstref);
1511 TopAbs_Orientation Or = domain2->Orientation(rst);
1512 if (Abs(testra) > 1.e-8) {
1514 trarst = ConvOrToTra(TopAbs::Reverse(Or));
1516 else if (testra >0.) {
1517 trarst = ConvOrToTra(Or);
1519 comptra = Standard_True;
1520 line->Set(tras,trarst);
1524 if (StateS == Blend_OK ||
1525 StateRst == Blend_OK ) {
1526 previousP = curpoint;
1529 if (StateS == Blend_StepTooSmall &&
1530 StateRst == Blend_StepTooSmall) {
1531 previousP = curpoint;
1532 if (State == Blend_OK) {
1533 return Blend_StepTooSmall;
1539 if (State == Blend_OK) {
1540 return Blend_SamePoints;
1546 return Blend_StepTooLarge;
1549 //=======================================================================
1550 //function : CheckInside
1552 //=======================================================================
1554 Standard_Boolean BRepBlend_SurfRstLineBuilder::CheckInside(Blend_SurfRstFunction& Func,
1555 TopAbs_State& SituOnC,
1556 TopAbs_State& SituOnS,
1557 Standard_Boolean& Decroch)
1559 math_Vector tolerance(1,3);
1560 Func.GetTolerance(tolerance,tolesp);
1562 Standard_Real w = sol(3);
1563 if(w < rst->FirstParameter() - tolerance(3)||
1564 w > rst->LastParameter() + tolerance(3)){
1565 SituOnC = TopAbs_OUT;
1567 else if (w > rst->FirstParameter() &&
1568 w < rst->LastParameter()){
1569 SituOnC = TopAbs_IN;
1571 else SituOnC = TopAbs_ON;
1574 gp_Pnt2d p2d(sol(1),sol(2));
1575 SituOnS = domain1->Classify(p2d,Min(tolerance(1),tolerance(2)),0);
1579 Decroch = Func.Decroch(sol,tgs,nors);
1581 return (SituOnC == TopAbs_IN && SituOnS == TopAbs_IN && !Decroch);