0025649: crvtpoints command return wrong deflection in output.
[occt.git] / src / ProjLib / ProjLib_ComputeApproxOnPolarSurface.cxx
CommitLineData
b311480e 1// Created by: Bruno DUMORTIER
2// Copyright (c) 1995-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16#include <ProjLib_ComputeApproxOnPolarSurface.hxx>
368cdde6 17#include <AppCont_Function.hxx>
7fd59977 18#include <ElSLib.hxx>
19#include <ElCLib.hxx>
20#include <BSplCLib.hxx>
21#include <PLib.hxx>
22#include <Standard_NoSuchObject.hxx>
23#include <Geom_UndefinedDerivative.hxx>
24#include <gp_Trsf.hxx>
25#include <Precision.hxx>
26#include <Approx_FitAndDivide2d.hxx>
27#include <math.hxx>
28#include <AppParCurves_MultiCurve.hxx>
29#include <Geom_Surface.hxx>
30#include <Geom2d_BSplineCurve.hxx>
31#include <Geom2d_BezierCurve.hxx>
32#include <Geom2d_Line.hxx>
33#include <Geom2d_Circle.hxx>
34#include <Geom2d_Ellipse.hxx>
35#include <Geom2d_Hyperbola.hxx>
36#include <Geom2d_Parabola.hxx>
37#include <Geom2d_TrimmedCurve.hxx>
38#include <Geom_BSplineSurface.hxx>
39#include <Geom_BezierSurface.hxx>
40#include <Geom_BSplineCurve.hxx>
41#include <Geom_BezierCurve.hxx>
42#include <Geom_TrimmedCurve.hxx>
43
44#include <TColgp_Array1OfPnt2d.hxx>
45#include <TColgp_Array2OfPnt2d.hxx>
46#include <TColgp_Array1OfPnt.hxx>
47#include <TColgp_SequenceOfPnt2d.hxx>
48#include <TColStd_Array1OfReal.hxx>
49#include <TColStd_Array1OfInteger.hxx>
50#include <TColStd_SequenceOfReal.hxx>
51#include <TColStd_ListOfTransient.hxx>
52
53#include <GeomAbs_SurfaceType.hxx>
54#include <GeomAbs_CurveType.hxx>
7fd59977 55#include <Adaptor3d_Surface.hxx>
56#include <Adaptor3d_Curve.hxx>
57#include <Adaptor3d_HSurface.hxx>
58#include <Adaptor3d_HCurve.hxx>
59#include <Adaptor2d_HCurve2d.hxx>
60#include <Geom2dAdaptor_Curve.hxx>
61#include <Geom2dAdaptor_HCurve.hxx>
62#include <GeomAdaptor_HCurve.hxx>
63#include <GeomAdaptor.hxx>
64#include <GeomAdaptor_Surface.hxx>
65#include <TColgp_SequenceOfPnt.hxx>
66
67#include <gp_Pnt.hxx>
68#include <gp_Pnt2d.hxx>
69#include <gp_Vec2d.hxx>
70#include <Extrema_GenLocateExtPS.hxx>
71#include <Extrema_ExtPS.hxx>
72#include <GCPnts_QuasiUniformAbscissa.hxx>
73#include <Standard_DomainError.hxx>
74//#include <GeomLib_IsIso.hxx>
75//#include <GeomLib_CheckSameParameter.hxx>
76
0797d9d3 77#ifdef OCCT_DEBUG
7fd59977 78#ifdef DRAW
79#include <DrawTrSurf.hxx>
80#endif
81//static Standard_Integer compteur = 0;
82#endif
83
84//=======================================================================
85//function : Value
86//purpose : (OCC217 - apo)- Compute Point2d that project on polar surface(<Surf>) 3D<Curve>
87// <InitCurve2d> use for calculate start 2D point.
88//=======================================================================
89
90static gp_Pnt2d Function_Value(const Standard_Real U,
91 const Handle(Adaptor3d_HSurface)& Surf,
92 const Handle(Adaptor3d_HCurve)& Curve,
93 const Handle(Adaptor2d_HCurve2d)& InitCurve2d,
94 //OCC217
95 const Standard_Real DistTol3d, const Standard_Real tolU, const Standard_Real tolV)
96 //const Standard_Real Tolerance)
97{
98 //OCC217
99 //Standard_Real Tol3d = 100*Tolerance;
100
101 gp_Pnt2d p2d = InitCurve2d->Value(U) ;
102 gp_Pnt p = Curve->Value(U);
103// Curve->D0(U,p) ;
104 Standard_Real Uinf, Usup, Vinf, Vsup;
105 Uinf = Surf->Surface().FirstUParameter();
106 Usup = Surf->Surface().LastUParameter();
107 Vinf = Surf->Surface().FirstVParameter();
108 Vsup = Surf->Surface().LastVParameter();
109 Standard_Integer decalU = 0, decalV = 0;
110 Standard_Real U0 = p2d.X(), V0 = p2d.Y();
111
112 GeomAbs_SurfaceType Type = Surf->GetType();
113 if((Type != GeomAbs_BSplineSurface) &&
114 (Type != GeomAbs_BezierSurface) &&
115 (Type != GeomAbs_OffsetSurface) ) {
1d47d8d0 116 Standard_Real S = 0., T = 0.;
7fd59977 117 switch (Type) {
118// case GeomAbs_Plane:
119// {
120// gp_Pln Plane = Surf->Plane();
121// ElSLib::Parameters( Plane, p, S, T);
122// break;
123// }
124 case GeomAbs_Cylinder:
125 {
126 gp_Cylinder Cylinder = Surf->Cylinder();
127 ElSLib::Parameters( Cylinder, p, S, T);
c6541a0c
D
128 if(U0 < Uinf) decalU = -int((Uinf - U0)/(2*M_PI))-1;
129 if(U0 > Usup) decalU = int((U0 - Usup)/(2*M_PI))+1;
130 S += decalU*2*M_PI;
7fd59977 131 break;
132 }
133 case GeomAbs_Cone:
134 {
135 gp_Cone Cone = Surf->Cone();
136 ElSLib::Parameters( Cone, p, S, T);
c6541a0c
D
137 if(U0 < Uinf) decalU = -int((Uinf - U0)/(2*M_PI))-1;
138 if(U0 > Usup) decalU = int((U0 - Usup)/(2*M_PI))+1;
139 S += decalU*2*M_PI;
7fd59977 140 break;
141 }
142 case GeomAbs_Sphere:
143 {
144 gp_Sphere Sphere = Surf->Sphere();
145 ElSLib::Parameters( Sphere, p, S, T);
c6541a0c
D
146 if(U0 < Uinf) decalU = -int((Uinf - U0)/(2*M_PI))-1;
147 if(U0 > Usup) decalU = int((U0 - Usup)/(2*M_PI))+1;
148 S += decalU*2*M_PI;
149 if(V0 < Vinf) decalV = -int((Vinf - V0)/(2*M_PI))-1;
150 if(V0 > (Vsup+(Vsup-Vinf))) decalV = int((V0 - Vsup+(Vsup-Vinf))/(2*M_PI))+1;
151 T += decalV*2*M_PI;
152 if(0.4*M_PI < Abs(U0 - S) && Abs(U0 - S) < 1.6*M_PI) {
153 T = M_PI - T;
7fd59977 154 if(U0 < S)
c6541a0c 155 S -= M_PI;
7fd59977 156 else
c6541a0c 157 S += M_PI;
7fd59977 158 }
159 break;
160 }
161 case GeomAbs_Torus:
162 {
163 gp_Torus Torus = Surf->Torus();
164 ElSLib::Parameters( Torus, p, S, T);
c6541a0c
D
165 if(U0 < Uinf) decalU = -int((Uinf - U0)/(2*M_PI))-1;
166 if(U0 > Usup) decalU = int((U0 - Usup)/(2*M_PI))+1;
167 if(V0 < Vinf) decalV = -int((Vinf - V0)/(2*M_PI))-1;
168 if(V0 > Vsup) decalV = int((V0 - Vsup)/(2*M_PI))+1;
169 S += decalU*2*M_PI; T += decalV*2*M_PI;
7fd59977 170 break;
171 }
172 default:
173 Standard_NoSuchObject::Raise("ProjLib_ComputeApproxOnPolarSurface::Value");
174 }
175 return gp_Pnt2d(S, T);
176 }
177
178 //////////////////
179 Standard_Real Dist2Min = RealLast();
180 //OCC217
181 //Standard_Real tolU,tolV ;
182 //tolU = Tolerance;
183 //tolV = Tolerance;
184
185 Standard_Real uperiod =0, vperiod = 0, u, v;
186 // U0 and V0 are the points within the initialized period
187 // (periode with u and v),
188 // U1 and V1 are the points for construction of tops
189
190 if(Surf->IsUPeriodic() || Surf->IsUClosed()) {
191 uperiod = Surf->LastUParameter() - Surf->FirstUParameter();
192 }
193 if(Surf->IsVPeriodic() || Surf->IsVClosed()) {
194 vperiod = Surf->LastVParameter() - Surf->FirstVParameter();
195 }
eafb234b 196 if(U0 < Uinf) {
7fd59977 197 if(!uperiod)
198 U0 = Uinf;
199 else {
200 decalU = int((Uinf - U0)/uperiod)+1;
201 U0 += decalU*uperiod;
202 }
eafb234b 203 }
204 if(U0 > Usup) {
7fd59977 205 if(!uperiod)
206 U0 = Usup;
207 else {
208 decalU = -(int((U0 - Usup)/uperiod)+1);
209 U0 += decalU*uperiod;
210 }
eafb234b 211 }
212 if(V0 < Vinf) {
7fd59977 213 if(!vperiod)
214 V0 = Vinf;
215 else {
216 decalV = int((Vinf - V0)/vperiod)+1;
217 V0 += decalV*vperiod;
218 }
eafb234b 219 }
220 if(V0 > Vsup) {
7fd59977 221 if(!vperiod)
222 V0 = Vsup;
223 else {
224 decalV = -int((V0 - Vsup)/vperiod)-1;
225 V0 += decalV*vperiod;
226 }
eafb234b 227 }
7fd59977 228
229 // The surface around U0 is reduced
230 Standard_Real uLittle = (Usup - Uinf)/10, vLittle = (Vsup - Vinf)/10;
231 Standard_Real uInfLi = 0, vInfLi = 0,uSupLi = 0, vSupLi = 0;
232 if((U0 - Uinf) > uLittle) uInfLi = U0 - uLittle; else uInfLi = Uinf;
233 if((V0 - Vinf) > vLittle) vInfLi = V0 - vLittle; else vInfLi = Vinf;
234 if((Usup - U0) > uLittle) uSupLi = U0 + uLittle; else uSupLi = Usup;
235 if((Vsup - V0) > vLittle) vSupLi = V0 + vLittle; else vSupLi = Vsup;
236
237 // const Adaptor3d_Surface GAS = Surf->Surface();
238
239 GeomAdaptor_Surface SurfLittle;
240 if (Type == GeomAbs_BSplineSurface) {
241 Handle(Geom_Surface) GBSS(Surf->Surface().BSpline());
242 SurfLittle.Load(GBSS, uInfLi, uSupLi, vInfLi, vSupLi);
243 }
244 else if (Type == GeomAbs_BezierSurface) {
245 Handle(Geom_Surface) GS(Surf->Surface().Bezier());
246 SurfLittle.Load(GS, uInfLi, uSupLi, vInfLi, vSupLi);
247 }
248 else if (Type == GeomAbs_OffsetSurface) {
249 Handle(Geom_Surface) GS = GeomAdaptor::MakeSurface(Surf->Surface());
250 SurfLittle.Load(GS, uInfLi, uSupLi, vInfLi, vSupLi);
251 }
252 else {
253 Standard_NoSuchObject::Raise("");
254 }
255
256 Extrema_GenLocateExtPS locext(p, SurfLittle, U0, V0, tolU, tolV);
257 if (locext.IsDone()) {
258 Dist2Min = locext.SquareDistance();
259 if (Dist2Min < DistTol3d * DistTol3d) {
260 (locext.Point()).Parameter(u, v);
261 gp_Pnt2d pnt(u - decalU*uperiod,v - decalV*vperiod);
262 return pnt;
263 }
264 }
265
266 Extrema_ExtPS ext(p, SurfLittle, tolU, tolV) ;
267 if (ext.IsDone() && ext.NbExt()>=1 ) {
268 Dist2Min = ext.SquareDistance(1);
269 Standard_Integer GoodValue = 1;
270 for ( Standard_Integer i = 2 ; i <= ext.NbExt() ; i++ )
271 if( Dist2Min > ext.SquareDistance(i)) {
272 Dist2Min = ext.SquareDistance(i);
273 GoodValue = i;
274 }
275 if (Dist2Min < DistTol3d * DistTol3d) {
276 (ext.Point(GoodValue)).Parameter(u,v);
277 gp_Pnt2d pnt(u - decalU*uperiod,v - decalV*vperiod);
278 return pnt;
279 }
280 }
281
282 return p2d;
283}
284
285
286//=======================================================================
287//function : ProjLib_PolarFunction
288//purpose : (OCC217 - apo)- This class produce interface to call "gp_Pnt2d Function_Value(...)"
289//=======================================================================
290
368cdde6 291class ProjLib_PolarFunction : public AppCont_Function
7fd59977 292{
293 Handle(Adaptor3d_HCurve) myCurve;
368cdde6 294 Handle(Adaptor2d_HCurve2d) myInitialCurve2d;
295 Handle(Adaptor3d_HSurface) mySurface;
296 Standard_Real myTolU, myTolV;
297 Standard_Real myDistTol3d;
298
7fd59977 299 public :
368cdde6 300
7fd59977 301 ProjLib_PolarFunction(const Handle(Adaptor3d_HCurve) & C,
368cdde6 302 const Handle(Adaptor3d_HSurface)& Surf,
303 const Handle(Adaptor2d_HCurve2d)& InitialCurve2d,
304 const Standard_Real Tol3d)
305: myCurve(C),
7fd59977 306 myInitialCurve2d(InitialCurve2d),
307 mySurface(Surf),
7fd59977 308 myTolU(Surf->UResolution(Tol3d)),
309 myTolV(Surf->VResolution(Tol3d)),
368cdde6 310 myDistTol3d(100.0*Tol3d)
311 {
312 myNbPnt = 0;
313 myNbPnt2d = 1;
314 }
315
7fd59977 316 ~ProjLib_PolarFunction() {}
368cdde6 317
7fd59977 318 Standard_Real FirstParameter() const
368cdde6 319 {
320 return myCurve->FirstParameter();
321 }
322
7fd59977 323 Standard_Real LastParameter() const
368cdde6 324 {
325 return myCurve->LastParameter();
7fd59977 326 }
368cdde6 327
fa0f5a55 328 gp_Pnt2d Value(const Standard_Real t) const
329 {
330 return Function_Value
331 (t,mySurface,myCurve,myInitialCurve2d,myDistTol3d,myTolU,myTolV);
332 }
333
368cdde6 334 Standard_Boolean Value(const Standard_Real theT,
335 NCollection_Array1<gp_Pnt2d>& thePnt2d,
336 NCollection_Array1<gp_Pnt>& /*thePnt*/) const
337 {
338 thePnt2d(1) = Function_Value(theT, mySurface, myCurve, myInitialCurve2d, myDistTol3d, myTolU, myTolV);
339 return Standard_True;
340 }
341
342 Standard_Boolean D1(const Standard_Real /*theT*/,
343 NCollection_Array1<gp_Vec2d>& /*theVec2d*/,
344 NCollection_Array1<gp_Vec>& /*theVec*/) const
7fd59977 345 {return Standard_False;}
346};
347
348//=======================================================================
349//function : ProjLib_ComputeApproxOnPolarSurface
350//purpose :
351//=======================================================================
352
353ProjLib_ComputeApproxOnPolarSurface::ProjLib_ComputeApproxOnPolarSurface(){}
354
355
356//=======================================================================
357//function : ProjLib_ComputeApproxOnPolarSurface
358//purpose :
359//=======================================================================
360
361ProjLib_ComputeApproxOnPolarSurface::ProjLib_ComputeApproxOnPolarSurface
362(const Handle(Adaptor2d_HCurve2d)& InitialCurve2d,
363 const Handle(Adaptor3d_HCurve)& Curve,
364 const Handle(Adaptor3d_HSurface)& S,
365 const Standard_Real tol3d):myProjIsDone(Standard_False) //OCC217
366 //const Standard_Real tolerance):myProjIsDone(Standard_False)
367{
368 myTolerance = tol3d; //OCC217
369 //myTolerance = Max(Tolerance,Precision::PApproximation());
370 myBSpline = Perform(InitialCurve2d,Curve,S);
371}
372//=======================================================================
373//function : ProjLib_ComputeApproxOnPolarSurface
374//purpose : Process the case of sewing
375//=======================================================================
376
377ProjLib_ComputeApproxOnPolarSurface::ProjLib_ComputeApproxOnPolarSurface
378(const Handle(Adaptor2d_HCurve2d)& InitialCurve2d,
379 const Handle(Adaptor2d_HCurve2d)& InitialCurve2dBis,
380 const Handle(Adaptor3d_HCurve)& Curve,
381 const Handle(Adaptor3d_HSurface)& S,
382 const Standard_Real tol3d):myProjIsDone(Standard_False) //OCC217
383 //const Standard_Real tolerance):myProjIsDone(Standard_False)
384{// InitialCurve2d and InitialCurve2dBis are two pcurves of the sewing
385 myTolerance = tol3d; //OCC217
386 //myTolerance = Max(tolerance,Precision::PApproximation());
387 Handle(Geom2d_BSplineCurve) bsc = Perform(InitialCurve2d,Curve,S);
388 if(myProjIsDone) {
389 gp_Pnt2d P2dproj, P2d, P2dBis;
390 P2dproj = bsc->StartPoint();
391 P2d = InitialCurve2d->Value(InitialCurve2d->FirstParameter());
392 P2dBis = InitialCurve2dBis->Value(InitialCurve2dBis->FirstParameter());
393
394 Standard_Real Dist, DistBis;
395 Dist = P2dproj.Distance(P2d);
396 DistBis = P2dproj.Distance(P2dBis);
397 if( Dist < DistBis) {
398 // myBSpline2d is the pcurve that is found. It is translated to obtain myCurve2d
399 myBSpline = bsc;
400 Handle(Geom2d_Geometry) GG = myBSpline->Translated(P2d, P2dBis);
401 my2ndCurve = Handle(Geom2d_Curve)::DownCast(GG);
402 }
403 else {
404 my2ndCurve = bsc;
405 Handle(Geom2d_Geometry) GG = my2ndCurve->Translated(P2dBis, P2d);
406 myBSpline = Handle(Geom2d_BSplineCurve)::DownCast(GG);
407 }
408 }
409}
410
411//=======================================================================
412//function : ProjLib_ComputeApproxOnPolarSurface
413//purpose : case without curve of initialization
414//=======================================================================
415
416ProjLib_ComputeApproxOnPolarSurface::ProjLib_ComputeApproxOnPolarSurface
417(const Handle(Adaptor3d_HCurve)& Curve,
418 const Handle(Adaptor3d_HSurface)& S,
419 const Standard_Real tol3d):myProjIsDone(Standard_False) //OCC217
420 //const Standard_Real tolerance):myProjIsDone(Standard_False)
421{
422 myTolerance = tol3d; //OCC217
423 //myTolerance = Max(tolerance,Precision::PApproximation());
857ffd5e 424 const Handle(Adaptor2d_HCurve2d) InitCurve2d ;
7fd59977 425 myBSpline = Perform(InitCurve2d,Curve,S);
426}
427
428static Handle(Geom2d_BSplineCurve) Concat(Handle(Geom2d_BSplineCurve) C1,
429 Handle(Geom2d_BSplineCurve) C2)
430{
431 Standard_Integer deg, deg1, deg2;
432 deg1 = C1->Degree();
433 deg2 = C2->Degree();
434
435 if ( deg1 < deg2) {
436 C1->IncreaseDegree(deg2);
437 deg = deg2;
438 }
439 else if ( deg2 < deg1) {
440 C2->IncreaseDegree(deg1);
441 deg = deg1;
442 }
443 else deg = deg1;
444
445 Standard_Integer np1,np2,nk1,nk2,np,nk;
446 np1 = C1->NbPoles();
447 nk1 = C1->NbKnots();
448 np2 = C2->NbPoles();
449 nk2 = C2->NbKnots();
450 nk = nk1 + nk2 -1;
451 np = np1 + np2 -1;
452
453 TColStd_Array1OfReal K1(1,nk1); C1->Knots(K1);
454 TColStd_Array1OfInteger M1(1,nk1); C1->Multiplicities(M1);
455 TColgp_Array1OfPnt2d P1(1,np1); C1->Poles(P1);
456 TColStd_Array1OfReal K2(1,nk2); C2->Knots(K2);
457 TColStd_Array1OfInteger M2(1,nk2); C2->Multiplicities(M2);
458 TColgp_Array1OfPnt2d P2(1,np2); C2->Poles(P2);
459
460 // Compute the new BSplineCurve
461 TColStd_Array1OfReal K(1,nk);
462 TColStd_Array1OfInteger M(1,nk);
463 TColgp_Array1OfPnt2d P(1,np);
464
465 Standard_Integer i, count = 0;
466 // Set Knots and Mults
467 for ( i = 1; i <= nk1; i++) {
468 count++;
469 K(count) = K1(i);
470 M(count) = M1(i);
471 }
472 M(count) = deg;
473 for ( i = 2; i <= nk2; i++) {
474 count++;
475 K(count) = K2(i);
476 M(count) = M2(i);
477 }
478 // Set the Poles
479 count = 0;
480 for (i = 1; i <= np1; i++) {
481 count++;
482 P(count) = P1(i);
483 }
484 for (i = 2; i <= np2; i++) {
485 count++;
486 P(count) = P2(i);
487 }
488
489 Handle(Geom2d_BSplineCurve) BS =
490 new Geom2d_BSplineCurve(P,K,M,deg);
491 return BS;
492}
493
494
495//=======================================================================
496//function : Perform
497//purpose :
498//=======================================================================
499Handle(Geom2d_BSplineCurve) ProjLib_ComputeApproxOnPolarSurface::Perform
500(const Handle(Adaptor2d_HCurve2d)& InitialCurve2d,
501 const Handle(Adaptor3d_HCurve)& Curve,
502 const Handle(Adaptor3d_HSurface)& S)
503{
504 //OCC217
505 Standard_Real Tol3d = myTolerance;
506 Standard_Real ParamTol = Precision::PApproximation();
507
508 Handle(Adaptor2d_HCurve2d) AHC2d = InitialCurve2d;
509 Handle(Adaptor3d_HCurve) AHC = Curve;
510
511// if the curve 3d is a BSpline with degree C0, it is cut into sections with degree C1
512// -> bug cts18237
513 GeomAbs_CurveType typeCurve = Curve->GetType();
514 if(typeCurve == GeomAbs_BSplineCurve) {
515 TColStd_ListOfTransient LOfBSpline2d;
516 Handle(Geom_BSplineCurve) BSC = Curve->BSpline();
517 Standard_Integer nbInter = Curve->NbIntervals(GeomAbs_C1);
518 if(nbInter > 1) {
519 Standard_Integer i, j;
520 Handle(Geom_TrimmedCurve) GTC;
521 Handle(Geom2d_TrimmedCurve) G2dTC;
522 TColStd_Array1OfReal Inter(1,nbInter+1);
523 Curve->Intervals(Inter,GeomAbs_C1);
524 Standard_Real firstinter = Inter.Value(1), secondinter = Inter.Value(2);
525 // initialization 3d
526 GTC = new Geom_TrimmedCurve(BSC, firstinter, secondinter);
527 AHC = new GeomAdaptor_HCurve(GTC);
528
529 // if there is an initialization curve:
530 // - either this is a BSpline C0, with discontinuity at the same parameters of nodes
531 // and the sections C1 are taken
532 // - or this is a curve C1 and the sections of intrest are taken otherwise the curve is created.
533
534 // initialization 2d
535 Standard_Integer nbInter2d;
536 Standard_Boolean C2dIsToCompute;
537 C2dIsToCompute = InitialCurve2d.IsNull();
538 Handle(Geom2d_BSplineCurve) BSC2d;
539 Handle(Geom2d_Curve) G2dC;
540
541 if(!C2dIsToCompute) {
542 nbInter2d = InitialCurve2d->NbIntervals(GeomAbs_C1);
543 TColStd_Array1OfReal Inter2d(1,nbInter2d+1);
544 InitialCurve2d->Intervals(Inter2d,GeomAbs_C1);
545 j = 1;
546 for(i = 1,j = 1;i <= nbInter;i++)
547 if(Abs(Inter.Value(i) - Inter2d.Value(j)) < ParamTol) { //OCC217
548 //if(Abs(Inter.Value(i) - Inter2d.Value(j)) < myTolerance) {
549 if (j > nbInter2d) break;
550 j++;
551 }
552 if(j != (nbInter2d+1)) {
553 C2dIsToCompute = Standard_True;
554 }
555 }
556
557 if(C2dIsToCompute) {
558 AHC2d = BuildInitialCurve2d(AHC, S);
559 }
560 else {
561 typeCurve = InitialCurve2d->GetType();
562 switch (typeCurve) {
563 case GeomAbs_Line: {
564 G2dC = new Geom2d_Line(InitialCurve2d->Line());
565 break;
566 }
567 case GeomAbs_Circle: {
568 G2dC = new Geom2d_Circle(InitialCurve2d->Circle());
569 break;
570 }
571 case GeomAbs_Ellipse: {
572 G2dC = new Geom2d_Ellipse(InitialCurve2d->Ellipse());
573 break;
574 }
575 case GeomAbs_Hyperbola: {
576 G2dC = new Geom2d_Hyperbola(InitialCurve2d->Hyperbola());
577 break;
578 }
579 case GeomAbs_Parabola: {
580 G2dC = new Geom2d_Parabola(InitialCurve2d->Parabola());
581 break;
582 }
583 case GeomAbs_BezierCurve: {
584 G2dC = InitialCurve2d->Bezier();
585 break;
586 }
587 case GeomAbs_BSplineCurve: {
588 G2dC = InitialCurve2d->BSpline();
589 break;
590 }
591 case GeomAbs_OtherCurve:
592 default:
593 break;
594 }
595 gp_Pnt2d fp2d = G2dC->Value(firstinter), lp2d = G2dC->Value(secondinter);
596 gp_Pnt fps, lps, fpc, lpc;
597 S->D0(fp2d.X(), fp2d.Y(), fps);
598 S->D0(lp2d.X(), lp2d.Y(), lps);
599 Curve->D0(firstinter, fpc);
600 Curve->D0(secondinter, lpc);
601 //OCC217
602 if((fps.IsEqual(fpc, Tol3d)) &&
603 (lps.IsEqual(lpc, Tol3d))) {
604 //if((fps.IsEqual(fpc, myTolerance)) &&
605 // (lps.IsEqual(lpc, myTolerance))) {
606 G2dTC = new Geom2d_TrimmedCurve(G2dC, firstinter, secondinter);
607 Geom2dAdaptor_Curve G2dAC(G2dTC);
608 AHC2d = new Geom2dAdaptor_HCurve(G2dAC);
609 myProjIsDone = Standard_True;
610 }
611 else {
612 AHC2d = BuildInitialCurve2d(AHC, S);
613 C2dIsToCompute = Standard_True;
614 }
615 }
616
617 if(myProjIsDone) {
618 BSC2d = ProjectUsingInitialCurve2d(AHC, S, AHC2d);
619 if(BSC2d.IsNull()) return Handle(Geom2d_BSplineCurve)(); //IFV
620 LOfBSpline2d.Append(BSC2d);
621 }
622 else {
623 return Handle(Geom2d_BSplineCurve)();
624 }
625
626
627
628 Standard_Real iinter, ip1inter;
629 Standard_Integer nbK2d, deg;
630 nbK2d = BSC2d->NbKnots(); deg = BSC2d->Degree();
631
632 for(i = 2;i <= nbInter;i++) {
633 iinter = Inter.Value(i);
634 ip1inter = Inter.Value(i+1);
635 // general case 3d
636 GTC->SetTrim(iinter, ip1inter);
637 AHC = new GeomAdaptor_HCurve(GTC);
638
639 // general case 2d
640 if(C2dIsToCompute) {
641 AHC2d = BuildInitialCurve2d(AHC, S);
642 }
643 else {
644 gp_Pnt2d fp2d = G2dC->Value(iinter), lp2d = G2dC->Value(ip1inter);
645 gp_Pnt fps, lps, fpc, lpc;
646 S->D0(fp2d.X(), fp2d.Y(), fps);
647 S->D0(lp2d.X(), lp2d.Y(), lps);
648 Curve->D0(iinter, fpc);
649 Curve->D0(ip1inter, lpc);
650 //OCC217
651 if((fps.IsEqual(fpc, Tol3d)) &&
652 (lps.IsEqual(lpc, Tol3d))) {
653 //if((fps.IsEqual(fpc, myTolerance)) &&
654 // (lps.IsEqual(lpc, myTolerance))) {
655 G2dTC->SetTrim(iinter, ip1inter);
656 Geom2dAdaptor_Curve G2dAC(G2dTC);
657 AHC2d = new Geom2dAdaptor_HCurve(G2dAC);
658 myProjIsDone = Standard_True;
659 }
660 else {
661 AHC2d = BuildInitialCurve2d(AHC, S);
662 }
663 }
664 if(myProjIsDone) {
665 BSC2d = ProjectUsingInitialCurve2d(AHC, S, AHC2d);
666 if(BSC2d.IsNull()) {
667 return Handle(Geom2d_BSplineCurve)();
668 }
669 LOfBSpline2d.Append(BSC2d);
670 nbK2d += BSC2d->NbKnots() - 1;
671 deg = Max(deg, BSC2d->Degree());
672 }
673 else {
674 return Handle(Geom2d_BSplineCurve)();
675 }
676 }
677
678 Standard_Integer NbC = LOfBSpline2d.Extent();
679 Handle(Geom2d_BSplineCurve) CurBS;
680 CurBS = Handle(Geom2d_BSplineCurve)::DownCast(LOfBSpline2d.First());
681 LOfBSpline2d.RemoveFirst();
682 for (Standard_Integer ii = 2; ii <= NbC; ii++) {
683 Handle(Geom2d_BSplineCurve) BS =
684 Handle(Geom2d_BSplineCurve)::DownCast(LOfBSpline2d.First());
685 CurBS = Concat(CurBS,BS);
686 LOfBSpline2d.RemoveFirst();
687 }
688 return CurBS;
689 }
690 }
691
692 if(InitialCurve2d.IsNull()) {
693 AHC2d = BuildInitialCurve2d(Curve, S);
694 if(!myProjIsDone)
695 return Handle(Geom2d_BSplineCurve)();
696 }
697 return ProjectUsingInitialCurve2d(AHC, S, AHC2d);
698}
699
700//=======================================================================
701//function : ProjLib_BuildInitialCurve2d
702//purpose :
703//=======================================================================
704
705Handle(Adaptor2d_HCurve2d)
706 ProjLib_ComputeApproxOnPolarSurface::
707 BuildInitialCurve2d(const Handle(Adaptor3d_HCurve)& Curve,
708 const Handle(Adaptor3d_HSurface)& Surf)
709{
710 // discretize the Curve with quasiuniform deflection
711 // density at least NbOfPnts points
712 myProjIsDone = Standard_False;
713
714 //OCC217
715 Standard_Real Tol3d = myTolerance;
716 Standard_Real TolU = Surf->UResolution(Tol3d), TolV = Surf->VResolution(Tol3d);
717 Standard_Real DistTol3d = 100.0*Tol3d;
718
ee9451ab 719 Standard_Real uperiod = 0., vperiod = 0.;
720 if(Surf->IsUPeriodic() || Surf->IsUClosed())
721 uperiod = Surf->LastUParameter() - Surf->FirstUParameter();
722
723 if(Surf->IsVPeriodic() || Surf->IsVClosed())
724 vperiod = Surf->LastVParameter() - Surf->FirstVParameter();
725
726
7fd59977 727 // NO myTol is Tol2d !!!!
728 //Standard_Real TolU = myTolerance, TolV = myTolerance;
729 //Standard_Real Tol3d = 100*myTolerance; // At random Balthazar.
730
731 Standard_Integer NbOfPnts = 61;
732 GCPnts_QuasiUniformAbscissa QUA(Curve->GetCurve(),NbOfPnts);
733 TColgp_Array1OfPnt Pts(1,NbOfPnts);
734 TColStd_Array1OfReal Param(1,NbOfPnts);
735 Standard_Integer i, j;
736 for( i = 1; i <= NbOfPnts ; i++ ) {
737 Param(i) = QUA.Parameter(i);
738 Pts(i) = Curve->Value(Param(i));
739 }
740
741 TColgp_Array1OfPnt2d Pts2d(1,NbOfPnts);
742 TColStd_Array1OfInteger Mult(1,NbOfPnts);
743 Mult.Init(1);
744 Mult(1) = Mult(NbOfPnts) = 2;
745
ee9451ab 746 Standard_Real Uinf, Usup, Vinf, Vsup;
747 Uinf = Surf->Surface().FirstUParameter();
748 Usup = Surf->Surface().LastUParameter();
7fd59977 749 Vinf = Surf->Surface().FirstVParameter();
750 Vsup = Surf->Surface().LastVParameter();
751 GeomAbs_SurfaceType Type = Surf->GetType();
752 if((Type != GeomAbs_BSplineSurface) && (Type != GeomAbs_BezierSurface) &&
753 (Type != GeomAbs_OffsetSurface)) {
754 Standard_Real S, T;
755// Standard_Integer usens = 0, vsens = 0;
756 // to know the position relatively to the period
757 switch (Type) {
758// case GeomAbs_Plane:
759// {
760// gp_Pln Plane = Surf->Plane();
761// for ( i = 1 ; i <= NbOfPnts ; i++) {
762// ElSLib::Parameters( Plane, Pts(i), S, T);
763// Pts2d(i).SetCoord(S,T);
764// }
765// myProjIsDone = Standard_True;
766// break;
767// }
768 case GeomAbs_Cylinder:
769 {
770// Standard_Real Sloc, Tloc;
eafb234b 771 Standard_Real Sloc;
772 Standard_Integer usens = 0;
773 gp_Cylinder Cylinder = Surf->Cylinder();
774 ElSLib::Parameters( Cylinder, Pts(1), S, T);
775 Pts2d(1).SetCoord(S,T);
776 for ( i = 2 ; i <= NbOfPnts ; i++) {
777 Sloc = S;
778 ElSLib::Parameters( Cylinder, Pts(i), S, T);
779 if(Abs(Sloc - S) > M_PI) {
780 if(Sloc > S)
781 usens++;
782 else
783 usens--;
784 }
785 Pts2d(i).SetCoord(S+usens*2*M_PI,T);
786 }
787 myProjIsDone = Standard_True;
788 break;
7fd59977 789 }
790 case GeomAbs_Cone:
791 {
792// Standard_Real Sloc, Tloc;
eafb234b 793 Standard_Real Sloc;
794 Standard_Integer usens = 0;
795 gp_Cone Cone = Surf->Cone();
796 ElSLib::Parameters( Cone, Pts(1), S, T);
797 Pts2d(1).SetCoord(S,T);
798 for ( i = 2 ; i <= NbOfPnts ; i++) {
799 Sloc = S;
800 ElSLib::Parameters( Cone, Pts(i), S, T);
801 if(Abs(Sloc - S) > M_PI) {
802 if(Sloc > S)
803 usens++;
804 else
805 usens--;
806 }
807 Pts2d(i).SetCoord(S+usens*2*M_PI,T);
808 }
809 myProjIsDone = Standard_True;
810 break;
7fd59977 811 }
812 case GeomAbs_Sphere:
813 {
814 Standard_Real Sloc, Tloc;
815 Standard_Integer usens = 0, vsens = 0; //usens steps by half-period
816 Standard_Boolean vparit = Standard_False;
817 gp_Sphere Sphere = Surf->Sphere();
818 ElSLib::Parameters( Sphere, Pts(1), S, T);
819 Pts2d(1).SetCoord(S,T);
820 for ( i = 2 ; i <= NbOfPnts ; i++) {
821 Sloc = S;Tloc = T;
822 ElSLib::Parameters( Sphere, Pts(i), S, T);
eafb234b 823 if(1.6*M_PI < Abs(Sloc - S)) {
7fd59977 824 if(Sloc > S)
825 usens += 2;
826 else
827 usens -= 2;
eafb234b 828 }
c6541a0c 829 if(1.6*M_PI > Abs(Sloc - S) && Abs(Sloc - S) > 0.4*M_PI) {
7fd59977 830 vparit = !vparit;
831 if(Sloc > S)
832 usens++;
833 else
834 usens--;
835 if(Abs(Tloc - Vsup) < (Vsup - Vinf)/5)
836 vsens++;
837 else
838 vsens--;
839 }
840 if(vparit) {
c6541a0c 841 Pts2d(i).SetCoord(S+usens*M_PI,(M_PI - T)*(vsens-1));
7fd59977 842 }
843 else {
c6541a0c 844 Pts2d(i).SetCoord(S+usens*M_PI,T+vsens*M_PI);
7fd59977 845
846 }
847 }
848 myProjIsDone = Standard_True;
849 break;
850 }
851 case GeomAbs_Torus:
852 {
853 Standard_Real Sloc, Tloc;
854 Standard_Integer usens = 0, vsens = 0;
855 gp_Torus Torus = Surf->Torus();
856 ElSLib::Parameters( Torus, Pts(1), S, T);
857 Pts2d(1).SetCoord(S,T);
858 for ( i = 2 ; i <= NbOfPnts ; i++) {
859 Sloc = S; Tloc = T;
860 ElSLib::Parameters( Torus, Pts(i), S, T);
eafb234b 861 if(Abs(Sloc - S) > M_PI) {
7fd59977 862 if(Sloc > S)
863 usens++;
864 else
865 usens--;
eafb234b 866 }
867 if(Abs(Tloc - T) > M_PI) {
7fd59977 868 if(Tloc > T)
869 vsens++;
870 else
871 vsens--;
eafb234b 872 }
c6541a0c 873 Pts2d(i).SetCoord(S+usens*2*M_PI,T+vsens*2*M_PI);
7fd59977 874 }
875 myProjIsDone = Standard_True;
876 break;
877 }
878 default:
879 Standard_NoSuchObject::Raise("ProjLib_ComputeApproxOnPolarSurface::BuildInitialCurve2d");
880 }
881 }
882 else {
7fd59977 883 myProjIsDone = Standard_False;
884 Standard_Real Dist2Min = 1.e+200, u = 0., v = 0.;
885 gp_Pnt pntproj;
886
887 TColgp_SequenceOfPnt2d Sols;
888 Standard_Boolean areManyZeros = Standard_False;
889
890 Curve->D0(Param.Value(1), pntproj) ;
891 Extrema_ExtPS aExtPS(pntproj, Surf->Surface(), TolU, TolV) ;
f7e3c52f 892 Standard_Real aMinSqDist = RealLast();
893 if (aExtPS.IsDone())
894 {
895 for (i = 1; i <= aExtPS.NbExt(); i++)
896 {
897 Standard_Real aSqDist = aExtPS.SquareDistance(i);
898 if (aSqDist < aMinSqDist)
899 aMinSqDist = aSqDist;
900 }
901 }
902 if (aMinSqDist > DistTol3d * DistTol3d) //try to project with less tolerance
903 {
904 TolU = Min(TolU, Precision::PConfusion());
905 TolV = Min(TolV, Precision::PConfusion());
906 aExtPS.Initialize(Surf->Surface(),
907 Surf->Surface().FirstUParameter(), Surf->Surface().LastUParameter(),
908 Surf->Surface().FirstVParameter(), Surf->Surface().LastVParameter(),
909 TolU, TolV);
910 aExtPS.Perform(pntproj);
911 }
7fd59977 912
913 if( aExtPS.IsDone() && aExtPS.NbExt() >= 1 ) {
914
915 Standard_Integer GoodValue = 1;
916
917 for ( i = 1 ; i <= aExtPS.NbExt() ; i++ ) {
918 if( aExtPS.SquareDistance(i) < DistTol3d * DistTol3d ) {
919 if( aExtPS.SquareDistance(i) <= 1.e-18 ) {
920 aExtPS.Point(i).Parameter(u,v);
921 gp_Pnt2d p2d(u,v);
922 Standard_Boolean isSame = Standard_False;
923 for( j = 1; j <= Sols.Length(); j++ ) {
924 if( p2d.SquareDistance( Sols.Value(j) ) <= 1.e-18 ) {
925 isSame = Standard_True;
926 break;
927 }
928 }
929 if( !isSame ) Sols.Append( p2d );
930 }
931 if( Dist2Min > aExtPS.SquareDistance(i) ) {
932 Dist2Min = aExtPS.SquareDistance(i);
933 GoodValue = i;
934 }
935 }
936 }
937
938 if( Sols.Length() > 1 ) areManyZeros = Standard_True;
939
940 if( Dist2Min <= DistTol3d * DistTol3d) {
941 if( !areManyZeros ) {
942 aExtPS.Point(GoodValue).Parameter(u,v);
943 Pts2d(1).SetCoord(u,v);
944 myProjIsDone = Standard_True;
945 }
946 else {
947 Standard_Integer nbSols = Sols.Length();
948 Standard_Real Dist2Max = -1.e+200;
949 for( i = 1; i <= nbSols; i++ ) {
950 const gp_Pnt2d& aP1 = Sols.Value(i);
951 for( j = i+1; j <= nbSols; j++ ) {
952 const gp_Pnt2d& aP2 = Sols.Value(j);
953 Standard_Real aDist2 = aP1.SquareDistance(aP2);
954 if( aDist2 > Dist2Max ) Dist2Max = aDist2;
955 }
956 }
957 Standard_Real aMaxT2 = Max(TolU,TolV);
958 aMaxT2 *= aMaxT2;
959 if( Dist2Max > aMaxT2 ) {
960 Standard_Integer tPp = 0;
961 for( i = 1; i <= 5; i++ ) {
962 Standard_Integer nbExtOk = 0;
963 Standard_Integer indExt = 0;
964 Standard_Integer iT = 1 + (NbOfPnts - 1)/5*i;
965 Curve->D0( Param.Value(iT), pntproj );
966 Extrema_ExtPS aTPS( pntproj, Surf->Surface(), TolU, TolV );
967 Dist2Min = 1.e+200;
968 if( aTPS.IsDone() && aTPS.NbExt() >= 1 ) {
969 for( j = 1 ; j <= aTPS.NbExt() ; j++ ) {
970 if( aTPS.SquareDistance(j) < DistTol3d * DistTol3d ) {
971 nbExtOk++;
972 if( aTPS.SquareDistance(j) < Dist2Min ) {
973 Dist2Min = aTPS.SquareDistance(j);
974 indExt = j;
975 }
976 }
977 }
978 }
979 if( nbExtOk == 1 ) {
980 tPp = iT;
981 aTPS.Point(indExt).Parameter(u,v);
982 break;
983 }
984 }
985
986 if( tPp != 0 ) {
987 gp_Pnt2d aPp = gp_Pnt2d(u,v);
988 gp_Pnt2d aPn;
989 j = 1;
990 Standard_Boolean isFound = Standard_False;
991 while( !isFound ) {
992 Curve->D0( Param.Value(tPp+j), pntproj );
993 Extrema_ExtPS aTPS( pntproj, Surf->Surface(), TolU, TolV );
994 Dist2Min = 1.e+200;
995 Standard_Integer indExt = 0;
996 if( aTPS.IsDone() && aTPS.NbExt() >= 1 ) {
997 for( i = 1 ; i <= aTPS.NbExt() ; i++ ) {
998 if( aTPS.SquareDistance(i) < DistTol3d * DistTol3d && aTPS.SquareDistance(i) < Dist2Min ) {
999 Dist2Min = aTPS.SquareDistance(i);
1000 indExt = i;
1001 isFound = Standard_True;
1002 }
1003 }
1004 }
1005 if( isFound ) {
1006 aTPS.Point(indExt).Parameter(u,v);
1007 aPn = gp_Pnt2d(u,v);
1008 break;
1009 }
1010 j++;
1011 if( (tPp+j) > NbOfPnts ) break;
1012 }
1013
1014 if( isFound ) {
1015 gp_Vec2d atV(aPp,aPn);
1016 Standard_Boolean isChosen = Standard_False;
1017 for( i = 1; i <= nbSols; i++ ) {
1018 const gp_Pnt2d& aP1 = Sols.Value(i);
1019 gp_Vec2d asV(aP1,aPp);
1020 if( asV.Dot(atV) > 0. ) {
1021 isChosen = Standard_True;
1022 Pts2d(1).SetCoord(aP1.X(),aP1.Y());
1023 myProjIsDone = Standard_True;
1024 break;
1025 }
1026 }
1027 if( !isChosen ) {
1028 aExtPS.Point(GoodValue).Parameter(u,v);
1029 Pts2d(1).SetCoord(u,v);
1030 myProjIsDone = Standard_True;
1031 }
1032 }
1033 else {
1034 aExtPS.Point(GoodValue).Parameter(u,v);
1035 Pts2d(1).SetCoord(u,v);
1036 myProjIsDone = Standard_True;
1037 }
1038 }
1039 else {
1040 aExtPS.Point(GoodValue).Parameter(u,v);
1041 Pts2d(1).SetCoord(u,v);
1042 myProjIsDone = Standard_True;
1043 }
1044 }
1045 else {
1046 aExtPS.Point(GoodValue).Parameter(u,v);
1047 Pts2d(1).SetCoord(u,v);
1048 myProjIsDone = Standard_True;
1049 }
1050 }
1051 }
1052
1053 // calculate the following points with GenLocate_ExtPS
1054 // (and store the result and each parameter in a sequence)
1055 Standard_Integer usens = 0, vsens = 0;
1056 // to know the position relatively to the period
ee9451ab 1057 Standard_Real U0 = u, V0 = v, U1 = u, V1 = v;
7fd59977 1058 // U0 and V0 are the points in the initialized period
1059 // (period with u and v),
1060 // U1 and V1 are the points for construction of poles
1061
7fd59977 1062 for ( i = 2 ; i <= NbOfPnts ; i++)
1063 if(myProjIsDone) {
1064 myProjIsDone = Standard_False;
1065 Dist2Min = RealLast();
1066 Curve->D0(Param.Value(i), pntproj);
1067 Extrema_GenLocateExtPS aLocateExtPS
1068 (pntproj, Surf->Surface(), U0, V0, TolU, TolV) ;
1069
1070 if (aLocateExtPS.IsDone())
15173a08 1071 {
1072 if (aLocateExtPS.SquareDistance() < DistTol3d * DistTol3d)
1073 { //OCC217
1074 //if (aLocateExtPS.SquareDistance() < Tol3d * Tol3d) {
7fd59977 1075 (aLocateExtPS.Point()).Parameter(U0,V0);
1076 U1 = U0 + usens*uperiod;
1077 V1 = V0 + vsens*vperiod;
1078 Pts2d(i).SetCoord(U1,V1);
1079 myProjIsDone = Standard_True;
1080 }
15173a08 1081 else
1082 {
1083 Extrema_ExtPS aGlobalExtr(pntproj, Surf->Surface(), TolU, TolV);
1084 if (aGlobalExtr.IsDone())
1085 {
1086 Standard_Real LocalMinSqDist = RealLast();
1087 Standard_Integer imin = 0;
1088 for (Standard_Integer isol = 1; isol <= aGlobalExtr.NbExt(); isol++)
1089 {
1090 Standard_Real aSqDist = aGlobalExtr.SquareDistance(isol);
1091 if (aSqDist < LocalMinSqDist)
1092 {
1093 LocalMinSqDist = aSqDist;
1094 imin = isol;
1095 }
1096 }
1097 if (LocalMinSqDist < DistTol3d * DistTol3d)
1098 {
1099 Standard_Real LocalU, LocalV;
1100 aGlobalExtr.Point(imin).Parameter(LocalU, LocalV);
1101 if (uperiod > 0. && Abs(U0 - LocalU) >= uperiod/2.)
1102 {
1103 if (LocalU > U0)
1104 usens = -1;
1105 else
1106 usens = 1;
1107 }
1108 if (vperiod > 0. && Abs(V0 - LocalV) >= vperiod/2.)
1109 {
1110 if (LocalV > V0)
1111 vsens = -1;
1112 else
1113 vsens = 1;
1114 }
1115 U0 = LocalU; V0 = LocalV;
1116 U1 = U0 + usens*uperiod;
1117 V1 = V0 + vsens*vperiod;
1118 Pts2d(i).SetCoord(U1,V1);
1119 myProjIsDone = Standard_True;
7a8c6a36 1120
1121 if((i == 2) && (!IsEqual(uperiod, 0.0) || !IsEqual(vperiod, 0.0)))
1122 {//Make 1st point more precise for periodic surfaces
1123 const Standard_Integer aSize = 3;
1124 const gp_Pnt2d aP(Pts2d(2));
1125 Standard_Real aUpar[aSize], aVpar[aSize];
1126 Pts2d(1).Coord(aUpar[1], aVpar[1]);
1127 aUpar[0] = aUpar[1] - uperiod;
1128 aUpar[2] = aUpar[1] + uperiod;
1129 aVpar[0] = aVpar[1] - vperiod;
1130 aVpar[2] = aVpar[1] + vperiod;
1131
1132 Standard_Real aSQdistMin = RealLast();
1133 Standard_Integer aBestUInd = 1, aBestVInd = 1;
1134 const Standard_Integer aSizeU = IsEqual(uperiod, 0.0) ? 1 : aSize,
1135 aSizeV = IsEqual(vperiod, 0.0) ? 1 : aSize;
1136 for(Standard_Integer uInd = 0; uInd < aSizeU; uInd++)
1137 {
1138 for(Standard_Integer vInd = 0; vInd < aSizeV; vInd++)
1139 {
1140 Standard_Real aSQdist = aP.SquareDistance(gp_Pnt2d(aUpar[uInd], aVpar[vInd]));
1141 if(aSQdist < aSQdistMin)
1142 {
1143 aSQdistMin = aSQdist;
1144 aBestUInd = uInd;
1145 aBestVInd = vInd;
1146 }
1147 }
1148 }
1149
1150 Pts2d(1).SetCoord(aUpar[aBestUInd], aVpar[aBestVInd]);
1151 }//if(i == 2) condition
15173a08 1152 }
1153 }
1154 }
1155 }
7fd59977 1156 if(!myProjIsDone && uperiod) {
1157 Standard_Real Uinf, Usup, Uaux;
1158 Uinf = Surf->Surface().FirstUParameter();
1159 Usup = Surf->Surface().LastUParameter();
1160 if((Usup - U0) > (U0 - Uinf))
1161 Uaux = 2*Uinf - U0 + uperiod;
1162 else
1163 Uaux = 2*Usup - U0 - uperiod;
1164 Extrema_GenLocateExtPS locext(pntproj,
1165 Surf->Surface(),
1166 Uaux, V0, TolU, TolV);
1167 if (locext.IsDone())
1168 if (locext.SquareDistance() < DistTol3d * DistTol3d) { //OCC217
1169 //if (locext.SquareDistance() < Tol3d * Tol3d) {
1170 (locext.Point()).Parameter(u,v);
1171 if((Usup - U0) > (U0 - Uinf))
1172 usens--;
1173 else
1174 usens++;
1175 U0 = u; V0 = v;
1176 U1 = U0 + usens*uperiod;
1177 V1 = V0 + vsens*vperiod;
1178 Pts2d(i).SetCoord(U1,V1);
1179 myProjIsDone = Standard_True;
1180 }
1181 }
1182 if(!myProjIsDone && vperiod) {
1183 Standard_Real Vinf, Vsup, Vaux;
1184 Vinf = Surf->Surface().FirstVParameter();
1185 Vsup = Surf->Surface().LastVParameter();
1186 if((Vsup - V0) > (V0 - Vinf))
1187 Vaux = 2*Vinf - V0 + vperiod;
1188 else
1189 Vaux = 2*Vsup - V0 - vperiod;
1190 Extrema_GenLocateExtPS locext(pntproj,
1191 Surf->Surface(),
1192 U0, Vaux, TolU, TolV) ;
1193 if (locext.IsDone())
1194 if (locext.SquareDistance() < DistTol3d * DistTol3d) { //OCC217
1195 //if (locext.SquareDistance() < Tol3d * Tol3d) {
1196 (locext.Point()).Parameter(u,v);
1197 if((Vsup - V0) > (V0 - Vinf))
1198 vsens--;
1199 else
1200 vsens++;
1201 U0 = u; V0 = v;
1202 U1 = U0 + usens*uperiod;
1203 V1 = V0 + vsens*vperiod;
1204 Pts2d(i).SetCoord(U1,V1);
1205 myProjIsDone = Standard_True;
1206 }
1207 }
1208 if(!myProjIsDone && uperiod && vperiod) {
1209 Standard_Real Uaux, Vaux;
1210 if((Usup - U0) > (U0 - Uinf))
1211 Uaux = 2*Uinf - U0 + uperiod;
1212 else
1213 Uaux = 2*Usup - U0 - uperiod;
1214 if((Vsup - V0) > (V0 - Vinf))
1215 Vaux = 2*Vinf - V0 + vperiod;
1216 else
1217 Vaux = 2*Vsup - V0 - vperiod;
1218 Extrema_GenLocateExtPS locext(pntproj,
1219 Surf->Surface(),
1220 Uaux, Vaux, TolU, TolV);
1221 if (locext.IsDone())
1222 if (locext.SquareDistance() < DistTol3d * DistTol3d) {
1223 //if (locext.SquareDistance() < Tol3d * Tol3d) {
1224 (locext.Point()).Parameter(u,v);
1225 if((Usup - U0) > (U0 - Uinf))
1226 usens--;
1227 else
1228 usens++;
1229 if((Vsup - V0) > (V0 - Vinf))
1230 vsens--;
1231 else
1232 vsens++;
1233 U0 = u; V0 = v;
1234 U1 = U0 + usens*uperiod;
1235 V1 = V0 + vsens*vperiod;
1236 Pts2d(i).SetCoord(U1,V1);
1237 myProjIsDone = Standard_True;
1238 }
1239 }
1240 if(!myProjIsDone) {
1241 Extrema_ExtPS ext(pntproj, Surf->Surface(), TolU, TolV) ;
1242 if (ext.IsDone()) {
1243 Dist2Min = ext.SquareDistance(1);
1244 Standard_Integer GoodValue = 1;
1245 for ( j = 2 ; j <= ext.NbExt() ; j++ )
1246 if( Dist2Min > ext.SquareDistance(j)) {
1247 Dist2Min = ext.SquareDistance(j);
1248 GoodValue = j;
1249 }
1250 if (Dist2Min < DistTol3d * DistTol3d) {
1251 //if (Dist2Min < Tol3d * Tol3d) {
1252 (ext.Point(GoodValue)).Parameter(u,v);
eafb234b 1253 if(uperiod) {
7fd59977 1254 if((U0 - u) > (2*uperiod/3)) {
1255 usens++;
1256 }
1257 else
1258 if((u - U0) > (2*uperiod/3)) {
1259 usens--;
1260 }
eafb234b 1261 }
1262 if(vperiod) {
7fd59977 1263 if((V0 - v) > (vperiod/2)) {
1264 vsens++;
1265 }
1266 else
1267 if((v - V0) > (vperiod/2)) {
1268 vsens--;
1269 }
eafb234b 1270 }
7fd59977 1271 U0 = u; V0 = v;
1272 U1 = U0 + usens*uperiod;
1273 V1 = V0 + vsens*vperiod;
1274 Pts2d(i).SetCoord(U1,V1);
1275 myProjIsDone = Standard_True;
1276 }
1277 }
1278 }
1279 }
1280 else break;
1281 }
1282 }
1283 // -- Pnts2d is transformed into Geom2d_BSplineCurve, with the help of Param and Mult
1284 if(myProjIsDone) {
1285 myBSpline = new Geom2d_BSplineCurve(Pts2d,Param,Mult,1);
ee9451ab 1286 //jgv: put the curve into parametric range
1287 gp_Pnt2d MidPoint = myBSpline->Value(0.5*(myBSpline->FirstParameter() + myBSpline->LastParameter()));
1288 Standard_Real TestU = MidPoint.X(), TestV = MidPoint.Y();
1289 Standard_Real sense = 0.;
1290 if (uperiod)
1291 {
1292 if (TestU < Uinf - TolU)
1293 sense = 1.;
1294 else if (TestU > Usup + TolU)
1295 sense = -1;
1296 while (TestU < Uinf - TolU || TestU > Usup + TolU)
1297 TestU += sense * uperiod;
1298 }
1299 if (vperiod)
1300 {
1301 sense = 0.;
1302 if (TestV < Vinf - TolV)
1303 sense = 1.;
1304 else if (TestV > Vsup + TolV)
1305 sense = -1.;
1306 while (TestV < Vinf - TolV || TestV > Vsup + TolV)
1307 TestV += sense * vperiod;
1308 }
1309 gp_Vec2d Offset(TestU - MidPoint.X(), TestV - MidPoint.Y());
1310 if (Abs(Offset.X()) > gp::Resolution() ||
1311 Abs(Offset.Y()) > gp::Resolution())
1312 myBSpline->Translate(Offset);
1313 //////////////////////////////////////////
7fd59977 1314 Geom2dAdaptor_Curve GAC(myBSpline);
1315 Handle(Adaptor2d_HCurve2d) IC2d = new Geom2dAdaptor_HCurve(GAC);
0797d9d3 1316#ifdef OCCT_DEBUG
7fd59977 1317// char name [100];
1318// sprintf(name,"%s_%d","build",compteur++);
1319// DrawTrSurf::Set(name,myBSpline);
1320#endif
1321 return IC2d;
1322 }
1323 else {
1324// Modified by Sergey KHROMOV - Thu Apr 18 10:57:50 2002 Begin
1325// Standard_NoSuchObject_Raise_if(1,"ProjLib_Compu: build echec");
1326// Modified by Sergey KHROMOV - Thu Apr 18 10:57:51 2002 End
1327 return Handle(Adaptor2d_HCurve2d)();
1328 }
d3f26155 1329// myProjIsDone = Standard_False;
7fd59977 1330// Modified by Sergey KHROMOV - Thu Apr 18 10:58:01 2002 Begin
1331// Standard_NoSuchObject_Raise_if(1,"ProjLib_ComputeOnPS: build echec");
1332// Modified by Sergey KHROMOV - Thu Apr 18 10:58:02 2002 End
7fd59977 1333}
1334
1335
1336
1337
1338//=======================================================================
1339//function : ProjLib_ProjectUsingInitialCurve2d
1340//purpose :
1341//=======================================================================
1342Handle(Geom2d_BSplineCurve)
1343 ProjLib_ComputeApproxOnPolarSurface::
1344 ProjectUsingInitialCurve2d(const Handle(Adaptor3d_HCurve)& Curve,
1345 const Handle(Adaptor3d_HSurface)& Surf,
1346 const Handle(Adaptor2d_HCurve2d)& InitCurve2d)
1347{
1348 //OCC217
1349 Standard_Real Tol3d = myTolerance;
1350 Standard_Real DistTol3d = 1.0*Tol3d;
1351 Standard_Real TolU = Surf->UResolution(Tol3d), TolV = Surf->VResolution(Tol3d);
1352 Standard_Real Tol2d = Sqrt(TolU*TolU + TolV*TolV);
1353
1354 Standard_Integer i;
1355 GeomAbs_SurfaceType TheTypeS = Surf->GetType();
1356 GeomAbs_CurveType TheTypeC = Curve->GetType();
1357// Handle(Standard_Type) TheTypeS = Surf->DynamicType();
1358// Handle(Standard_Type) TheTypeC = Curve->DynamicType(); // si on a :
1359// if(TheTypeS == STANDARD_TYPE(Geom_BSplineSurface)) {
1360 if(TheTypeS == GeomAbs_Plane) {
1361 Standard_Real S, T;
1362 gp_Pln Plane = Surf->Plane();
1363 if(TheTypeC == GeomAbs_BSplineCurve) {
1364 Handle(Geom_BSplineCurve) BSC = Curve->BSpline();
1365 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1366 for(i = 1;i <= Curve->NbPoles();i++) {
1367 ElSLib::Parameters( Plane, BSC->Pole(i), S, T);
1368 Poles2d(i).SetCoord(S,T);
1369 }
1370 TColStd_Array1OfReal Knots(1, BSC->NbKnots());
1371 BSC->Knots(Knots);
1372 TColStd_Array1OfInteger Mults(1, BSC->NbKnots());
1373 BSC->Multiplicities(Mults);
1374 if(BSC->IsRational()) {
1375 TColStd_Array1OfReal Weights(1, BSC->NbPoles());
1376 BSC->Weights(Weights);
1377 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1378 BSC->Degree(), BSC->IsPeriodic()) ;
1379 }
1380 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1381 BSC->Degree(), BSC->IsPeriodic()) ;
1382
1383 }
1384 if(TheTypeC == GeomAbs_BezierCurve) {
1385 Handle(Geom_BezierCurve) BC = Curve->Bezier();
1386 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1387 for(i = 1;i <= Curve->NbPoles();i++) {
1388 ElSLib::Parameters( Plane, BC->Pole(i), S, T);
1389 Poles2d(i).SetCoord(S,T);
1390 }
1391 TColStd_Array1OfReal Knots(1, 2);
1392 Knots.SetValue(1,0.0);
1393 Knots.SetValue(2,1.0);
1394 TColStd_Array1OfInteger Mults(1, 2);
1395 Mults.Init(BC->NbPoles());
1396 if(BC->IsRational()) {
1397 TColStd_Array1OfReal Weights(1, BC->NbPoles());
1398 BC->Weights(Weights);
1399 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1400 BC->Degree(), BC->IsPeriodic()) ;
1401 }
1402 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1403 BC->Degree(), BC->IsPeriodic()) ;
1404 }
1405 }
1406 if(TheTypeS == GeomAbs_BSplineSurface) {
1407 Handle(Geom_BSplineSurface) BSS = Surf->BSpline();
1408 if((BSS->MaxDegree() == 1) &&
1409 (BSS->NbUPoles() == 2) &&
1410 (BSS->NbVPoles() == 2)) {
1411 gp_Pnt p11 = BSS->Pole(1,1);
1412 gp_Pnt p12 = BSS->Pole(1,2);
1413 gp_Pnt p21 = BSS->Pole(2,1);
1414 gp_Pnt p22 = BSS->Pole(2,2);
1415 gp_Vec V1(p11,p12);
1416 gp_Vec V2(p21,p22);
c6541a0c
D
1417 if(V1.IsEqual(V2,Tol3d,Tol3d/(p11.Distance(p12)*180/M_PI))){ //OCC217
1418 //if(V1.IsEqual(V2,myTolerance,myTolerance/(p11.Distance(p12)*180/M_PI))){
7fd59977 1419 // so the polar surface is plane
1420 // and if it is enough to projet the poles of Curve
1421 Standard_Integer Dist2Min = IntegerLast();
1422 Standard_Real u,v;
1423 //OCC217
1424 //Standard_Real TolU = Surf->UResolution(myTolerance)
1425 // , TolV = Surf->VResolution(myTolerance);
1426// gp_Pnt pntproj;
1427 if(TheTypeC == GeomAbs_BSplineCurve) {
1428 Handle(Geom_BSplineCurve) BSC = Curve->BSpline();
1429 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1430 for(i = 1;i <= Curve->NbPoles();i++) {
1431 myProjIsDone = Standard_False;
1432 Dist2Min = IntegerLast();
1433 Extrema_GenLocateExtPS extrloc(BSC->Pole(i),Surf->Surface(),(p11.X()+p22.X())/2,
1434 (p11.Y()+p22.Y())/2,TolU,TolV) ;
1435 if (extrloc.IsDone()) {
1436 Dist2Min = (Standard_Integer ) extrloc.SquareDistance();
1437 if (Dist2Min < DistTol3d * DistTol3d) { //OCC217
1438 //if (Dist2Min < myTolerance * myTolerance) {
1439 (extrloc.Point()).Parameter(u,v);
1440 Poles2d(i).SetCoord(u,v);
1441 myProjIsDone = Standard_True;
1442 }
1443 else break;
1444 }
1445 else break;
1446 if(!myProjIsDone)
1447 break;
1448 }
1449 if(myProjIsDone) {
1450 TColStd_Array1OfReal Knots(1, BSC->NbKnots());
1451 BSC->Knots(Knots);
1452 TColStd_Array1OfInteger Mults(1, BSC->NbKnots());
1453 BSC->Multiplicities(Mults);
1454 if(BSC->IsRational()) {
1455 TColStd_Array1OfReal Weights(1, BSC->NbPoles());
1456 BSC->Weights(Weights);
1457 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1458 BSC->Degree(), BSC->IsPeriodic()) ;
1459 }
1460 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1461 BSC->Degree(), BSC->IsPeriodic()) ;
1462
1463
1464 }
1465 }
1466 if(TheTypeC == GeomAbs_BezierCurve) {
1467 Handle(Geom_BezierCurve) BC = Curve->Bezier();
1468 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1469 for(i = 1;i <= Curve->NbPoles();i++) {
1470 Dist2Min = IntegerLast();
1471 Extrema_GenLocateExtPS extrloc(BC->Pole(i),Surf->Surface(),0.5,
1472 0.5,TolU,TolV) ;
1473 if (extrloc.IsDone()) {
1474 Dist2Min = (Standard_Integer ) extrloc.SquareDistance();
1475 if (Dist2Min < DistTol3d * DistTol3d) { //OCC217
1476 //if (Dist2Min < myTolerance * myTolerance) {
1477 (extrloc.Point()).Parameter(u,v);
1478 Poles2d(i).SetCoord(u,v);
1479 myProjIsDone = Standard_True;
1480 }
1481 else break;
1482 }
1483 else break;
1484 if(myProjIsDone)
1485 myProjIsDone = Standard_False;
1486 else break;
1487 }
1488 if(myProjIsDone) {
1489 TColStd_Array1OfReal Knots(1, 2);
1490 Knots.SetValue(1,0.0);
1491 Knots.SetValue(2,1.0);
1492 TColStd_Array1OfInteger Mults(1, 2);
1493 Mults.Init(BC->NbPoles());
1494 if(BC->IsRational()) {
1495 TColStd_Array1OfReal Weights(1, BC->NbPoles());
1496 BC->Weights(Weights);
1497 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1498 BC->Degree(), BC->IsPeriodic()) ;
1499 }
1500 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1501 BC->Degree(), BC->IsPeriodic()) ;
1502 }
1503 }
1504 }
1505 }
1506 }
1507 else if(TheTypeS == GeomAbs_BezierSurface) {
1508 Handle(Geom_BezierSurface) BS = Surf->Bezier();
1509 if((BS->MaxDegree() == 1) &&
1510 (BS->NbUPoles() == 2) &&
1511 (BS->NbVPoles() == 2)) {
1512 gp_Pnt p11 = BS->Pole(1,1);
1513 gp_Pnt p12 = BS->Pole(1,2);
1514 gp_Pnt p21 = BS->Pole(2,1);
1515 gp_Pnt p22 = BS->Pole(2,2);
1516 gp_Vec V1(p11,p12);
1517 gp_Vec V2(p21,p22);
c6541a0c
D
1518 if(V1.IsEqual(V2,Tol3d,Tol3d/(p11.Distance(p12)*180/M_PI))){ //OCC217
1519 //if (V1.IsEqual(V2,myTolerance,myTolerance/(p11.Distance(p12)*180/M_PI))){
7fd59977 1520 // and if it is enough to project the poles of Curve
1521 Standard_Integer Dist2Min = IntegerLast();
1522 Standard_Real u,v;
1523 //OCC217
1524 //Standard_Real TolU = Surf->UResolution(myTolerance)
1525 // , TolV = Surf->VResolution(myTolerance);
1526
1527// gp_Pnt pntproj;
1528 if(TheTypeC == GeomAbs_BSplineCurve) {
1529 Handle(Geom_BSplineCurve) BSC = Curve->BSpline();
1530 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1531 for(i = 1;i <= Curve->NbPoles();i++) {
1532 myProjIsDone = Standard_False;
1533 Dist2Min = IntegerLast();
1534 Extrema_GenLocateExtPS extrloc(BSC->Pole(i),Surf->Surface(),(p11.X()+p22.X())/2,
1535 (p11.Y()+p22.Y())/2,TolU,TolV) ;
1536 if (extrloc.IsDone()) {
1537 Dist2Min = (Standard_Integer ) extrloc.SquareDistance();
1538 if (Dist2Min < DistTol3d * DistTol3d) { //OCC217
1539 //if (Dist2Min < myTolerance * myTolerance) {
1540 (extrloc.Point()).Parameter(u,v);
1541 Poles2d(i).SetCoord(u,v);
1542 myProjIsDone = Standard_True;
1543 }
1544 else break;
1545 }
1546 else break;
1547 if(!myProjIsDone)
1548 break;
1549 }
1550 if(myProjIsDone) {
1551 TColStd_Array1OfReal Knots(1, BSC->NbKnots());
1552 BSC->Knots(Knots);
1553 TColStd_Array1OfInteger Mults(1, BSC->NbKnots());
1554 BSC->Multiplicities(Mults);
1555 if(BSC->IsRational()) {
1556 TColStd_Array1OfReal Weights(1, BSC->NbPoles());
1557 BSC->Weights(Weights);
1558 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1559 BSC->Degree(), BSC->IsPeriodic()) ;
1560 }
1561 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1562 BSC->Degree(), BSC->IsPeriodic()) ;
1563
1564
1565 }
1566 }
1567 if(TheTypeC == GeomAbs_BezierCurve) {
1568 Handle(Geom_BezierCurve) BC = Curve->Bezier();
1569 TColgp_Array1OfPnt2d Poles2d(1,Curve->NbPoles());
1570 for(i = 1;i <= Curve->NbPoles();i++) {
1571 Dist2Min = IntegerLast();
1572 Extrema_GenLocateExtPS extrloc(BC->Pole(i),Surf->Surface(),0.5,
1573 0.5,TolU,TolV) ;
1574 if (extrloc.IsDone()) {
1575 Dist2Min = (Standard_Integer ) extrloc.SquareDistance();
1576 if (Dist2Min < DistTol3d * DistTol3d) { //OCC217
1577 //if (Dist2Min < myTolerance * myTolerance) {
1578 (extrloc.Point()).Parameter(u,v);
1579 Poles2d(i).SetCoord(u,v);
1580 myProjIsDone = Standard_True;
1581 }
1582 else break;
1583 }
1584 else break;
1585 if(myProjIsDone)
1586 myProjIsDone = Standard_False;
1587 else break;
1588 }
1589 if(myProjIsDone) {
1590 TColStd_Array1OfReal Knots(1, 2);
1591 Knots.SetValue(1,0.0);
1592 Knots.SetValue(2,1.0);
1593 TColStd_Array1OfInteger Mults(1, 2);
1594 Mults.Init(BC->NbPoles());
1595 if(BC->IsRational()) {
1596 TColStd_Array1OfReal Weights(1, BC->NbPoles());
1597 BC->Weights(Weights);
1598 return new Geom2d_BSplineCurve(Poles2d, Weights, Knots, Mults,
1599 BC->Degree(), BC->IsPeriodic()) ;
1600 }
1601 return new Geom2d_BSplineCurve(Poles2d, Knots, Mults,
1602 BC->Degree(), BC->IsPeriodic()) ;
1603 }
1604 }
1605 }
1606 }
1607 }
1608
1609 ProjLib_PolarFunction F(Curve, Surf, InitCurve2d, Tol3d) ; //OCC217
1610 //ProjLib_PolarFunction F(Curve, Surf, InitCurve2d, myTolerance) ;
1611
0797d9d3 1612#ifdef OCCT_DEBUG
7fd59977 1613 Standard_Integer Nb = 50;
1614
1615 Standard_Real U, U1, U2;
1616 U1 = F.FirstParameter();
1617 U2 = F.LastParameter();
1618
1619 TColgp_Array1OfPnt2d DummyPoles(1,Nb+1);
1620 TColStd_Array1OfReal DummyKnots(1,Nb+1);
1621 TColStd_Array1OfInteger DummyMults(1,Nb+1);
1622 DummyMults.Init(1);
1623 DummyMults(1) = 2;
1624 DummyMults(Nb+1) = 2;
1625 for (Standard_Integer ij = 0; ij <= Nb; ij++) {
1626 U = (Nb-ij)*U1 + ij*U2;
1627 U /= Nb;
1628 DummyPoles(ij+1) = F.Value(U);
1629 DummyKnots(ij+1) = ij;
1630 }
1631 Handle(Geom2d_BSplineCurve) DummyC2d =
1632 new Geom2d_BSplineCurve(DummyPoles, DummyKnots, DummyMults, 1);
7fd59977 1633#ifdef DRAW
96a95605 1634 Standard_CString Temp = "bs2d";
7fd59977 1635 DrawTrSurf::Set(Temp,DummyC2d);
1636#endif
1637// DrawTrSurf::Set((Standard_CString ) "bs2d",DummyC2d);
1638 Handle(Geom2dAdaptor_HCurve) DDD =
1639 Handle(Geom2dAdaptor_HCurve)::DownCast(InitCurve2d);
1640
7fd59977 1641#ifdef DRAW
96a95605 1642 Temp = "initc2d";
7fd59977 1643 DrawTrSurf::Set(Temp,DDD->ChangeCurve2d().Curve());
1644#endif
1645// DrawTrSurf::Set((Standard_CString ) "initc2d",DDD->ChangeCurve2d().Curve());
1646#endif
1647
1648 Standard_Integer Deg1,Deg2;
1649// Deg1 = 8;
1650// Deg2 = 8;
1651 Deg1 = 2; //IFV
1652 Deg2 = 8; //IFV
1653
1654 Approx_FitAndDivide2d Fit(F,Deg1,Deg2,Tol3d,Tol2d, //OCC217
1655 //Approx_FitAndDivide2d Fit(F,Deg1,Deg2,myTolerance,myTolerance,
1656 Standard_True);
1657
1658 if(Fit.IsAllApproximated()) {
1659 Standard_Integer i;
1660 Standard_Integer NbCurves = Fit.NbMultiCurves();
1661 Standard_Integer MaxDeg = 0;
1662 // To transform the MultiCurve into BSpline, it is required that all
1663 // Bezier constituing it have the same degree -> Calculation of MaxDeg
1664 Standard_Integer NbPoles = 1;
1665 for (i = 1; i <= NbCurves; i++) {
1666 Standard_Integer Deg = Fit.Value(i).Degree();
1667 MaxDeg = Max ( MaxDeg, Deg);
1668 }
1669
1670 NbPoles = MaxDeg * NbCurves + 1; //Tops on the BSpline
1671 TColgp_Array1OfPnt2d Poles( 1, NbPoles);
1672
1673 TColgp_Array1OfPnt2d TempPoles( 1, MaxDeg + 1);//to augment the degree
1674
1675 TColStd_Array1OfReal Knots( 1, NbCurves + 1); //Nodes of the BSpline
1676
1677 Standard_Integer Compt = 1;
1678 for (i = 1; i <= NbCurves; i++) {
1679 Fit.Parameters(i, Knots(i), Knots(i+1));
1680 AppParCurves_MultiCurve MC = Fit.Value( i); //Load the Ith Curve
1681 TColgp_Array1OfPnt2d Poles2d( 1, MC.Degree() + 1);//Retrieve the tops
1682 MC.Curve(1, Poles2d);
1683
1684 //Eventual augmentation of the degree
1685 Standard_Integer Inc = MaxDeg - MC.Degree();
1686 if ( Inc > 0) {
1687// BSplCLib::IncreaseDegree( Inc, Poles2d, PLib::NoWeights(),
1688 BSplCLib::IncreaseDegree( MaxDeg, Poles2d, PLib::NoWeights(),
1689 TempPoles, PLib::NoWeights());
1690 //update of tops of the PCurve
1691 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
1692 Poles.SetValue( Compt, TempPoles( j));
1693 Compt++;
1694 }
1695 }
1696 else {
1697 //update of tops of the PCurve
1698 for (Standard_Integer j = 1 ; j <= MaxDeg + 1; j++) {
1699 Poles.SetValue( Compt, Poles2d( j));
1700 Compt++;
1701 }
1702 }
1703
1704 Compt--;
1705 }
1706
1707 //update of fields of ProjLib_Approx
1708 Standard_Integer NbKnots = NbCurves + 1;
368cdde6 1709
7fd59977 1710 TColStd_Array1OfInteger Mults( 1, NbKnots);
1711 Mults.Init(MaxDeg);
1712 Mults.SetValue( 1, MaxDeg + 1);
1713 Mults.SetValue(NbKnots, MaxDeg + 1);
1714 myProjIsDone = Standard_True;
1715 Handle(Geom2d_BSplineCurve) Dummy =
1716 new Geom2d_BSplineCurve(Poles,Knots,Mults,MaxDeg);
1717
1718 // try to smoother the Curve GeomAbs_C1.
1719
1720 Standard_Boolean OK = Standard_True;
1721
1722 for (Standard_Integer ij = 2; ij < NbKnots; ij++) {
1723 OK = OK && Dummy->RemoveKnot(ij,MaxDeg-1,Tol3d); //OCC217
1724 //OK = OK && Dummy->RemoveKnot(ij,MaxDeg-1,myTolerance);
1725 }
0797d9d3 1726#ifdef OCCT_DEBUG
7fd59977 1727 if (!OK) {
1728 cout << "ProjLib_ComputeApproxOnPolarSurface : Smoothing echoue"<<endl;
1729 }
1730#endif
1731 return Dummy;
1732 }
1733 return Handle(Geom2d_BSplineCurve)();
1734}
1735
1736//=======================================================================
1737//function : BSpline
1738//purpose :
1739//=======================================================================
1740
1741Handle(Geom2d_BSplineCurve)
1742 ProjLib_ComputeApproxOnPolarSurface::BSpline() const
1743
1744{
1745// Modified by Sergey KHROMOV - Thu Apr 18 11:16:46 2002 End
1746// Standard_NoSuchObject_Raise_if
1747// (!myProjIsDone,
1748// "ProjLib_ComputeApproxOnPolarSurface:BSpline");
1749// Modified by Sergey KHROMOV - Thu Apr 18 11:16:47 2002 End
1750 return myBSpline ;
1751}
1752
1753//=======================================================================
1754//function : Curve2d
1755//purpose :
1756//=======================================================================
1757
1758Handle(Geom2d_Curve)
1759 ProjLib_ComputeApproxOnPolarSurface::Curve2d() const
1760
1761{
1762 Standard_NoSuchObject_Raise_if
1763 (!myProjIsDone,
1764 "ProjLib_ComputeApproxOnPolarSurface:2ndCurve2d");
1765 return my2ndCurve ;
1766}
1767
1768
1769//=======================================================================
1770//function : IsDone
1771//purpose :
1772//=======================================================================
1773
1774Standard_Boolean ProjLib_ComputeApproxOnPolarSurface::IsDone() const
1775
1776{
1777 return myProjIsDone;
1778}