1 // Created on: 1997-09-23
2 // Created by: Roman BORISOV
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.
17 #include <ProjLib_CompProjectedCurve.ixx>
18 #include <ProjLib_HCompProjectedCurve.hxx>
20 #include <gp_Mat2d.hxx>
21 #include <Extrema_ExtPS.hxx>
22 #include <Precision.hxx>
23 #include <Extrema_ExtCS.hxx>
24 #include <TColgp_HSequenceOfPnt.hxx>
25 #include <Extrema_GenLocateExtPS.hxx>
26 #include <Extrema_POnSurf.hxx>
27 #include <Extrema_POnCurv.hxx>
28 #include <ProjLib_PrjResolve.hxx>
29 #include <GeomAbs_CurveType.hxx>
30 #include <GeomLib.hxx>
32 #define FuncTol 1.e-10
34 #ifdef OCCT_DEBUG_CHRONO
35 #include <OSD_Timer.hxx>
37 static OSD_Chronometer chr_init_point, chr_dicho_bound;
39 Standard_EXPORT Standard_Real t_init_point, t_dicho_bound;
40 Standard_EXPORT Standard_Integer init_point_count, dicho_bound_count;
42 static void InitChron(OSD_Chronometer& ch)
48 static void ResultChron( OSD_Chronometer & ch, Standard_Real & time)
58 //=======================================================================
60 //purpose : computes first derivative of the projected curve
61 //=======================================================================
63 static void d1(const Standard_Real t,
64 const Standard_Real u,
65 const Standard_Real v,
67 const Handle(Adaptor3d_HCurve)& Curve,
68 const Handle(Adaptor3d_HSurface)& Surface)
71 gp_Vec DS1_u, DS1_v, DS2_u, DS2_uv, DS2_v, DC1_t;
72 Surface->D2(u, v, S, DS1_u, DS1_v, DS2_u, DS2_v, DS2_uv);
73 Curve->D1(t, C, DC1_t);
74 gp_Vec Ort(C, S);// Ort = S - C
76 gp_Vec2d dE_dt(-DC1_t*DS1_u, -DC1_t*DS1_v);
77 gp_XY dE_du(DS1_u*DS1_u + Ort*DS2_u,
78 DS1_u*DS1_v + Ort*DS2_uv);
79 gp_XY dE_dv(DS1_v*DS1_u + Ort*DS2_uv,
80 DS1_v*DS1_v + Ort*DS2_v);
82 Standard_Real det = dE_du.X()*dE_dv.Y() - dE_du.Y()*dE_dv.X();
83 if (fabs(det) < gp::Resolution()) Standard_ConstructionError::Raise();
85 gp_Mat2d M(gp_XY(dE_dv.Y()/det, -dE_du.Y()/det),
86 gp_XY(-dE_dv.X()/det, dE_du.X()/det));
88 V = - gp_Vec2d(gp_Vec2d(M.Row(1))*dE_dt, gp_Vec2d(M.Row(2))*dE_dt);
91 //=======================================================================
93 //purpose : computes second derivative of the projected curve
94 //=======================================================================
96 static void d2(const Standard_Real t,
97 const Standard_Real u,
98 const Standard_Real v,
99 gp_Vec2d& V1, gp_Vec2d& V2,
100 const Handle(Adaptor3d_HCurve)& Curve,
101 const Handle(Adaptor3d_HSurface)& Surface)
104 gp_Vec DS1_u, DS1_v, DS2_u, DS2_uv, DS2_v,
105 DS3_u, DS3_v, DS3_uuv, DS3_uvv,
107 Surface->D3(u, v, S, DS1_u, DS1_v, DS2_u, DS2_v, DS2_uv,
108 DS3_u, DS3_v, DS3_uuv, DS3_uvv);
109 Curve->D2(t, C, DC1_t, DC2_t);
112 gp_Vec2d dE_dt(-DC1_t*DS1_u, -DC1_t*DS1_v);
113 gp_XY dE_du(DS1_u*DS1_u + Ort*DS2_u,
114 DS1_u*DS1_v + Ort*DS2_uv);
115 gp_XY dE_dv(DS1_v*DS1_u + Ort*DS2_uv,
116 DS1_v*DS1_v + Ort*DS2_v);
118 Standard_Real det = dE_du.X()*dE_dv.Y() - dE_du.Y()*dE_dv.X();
119 if (fabs(det) < gp::Resolution()) Standard_ConstructionError::Raise();
121 gp_Mat2d M(gp_XY(dE_dv.Y()/det, -dE_du.Y()/det),
122 gp_XY(-dE_dv.X()/det, dE_du.X()/det));
125 V1 = - gp_Vec2d(gp_Vec2d(M.Row(1))*dE_dt, gp_Vec2d(M.Row(2))*dE_dt);
127 /* Second derivative */
129 // Computation of d2E_dt2 = S1
130 gp_Vec2d d2E_dt(-DC2_t*DS1_u, -DC2_t*DS1_v);
132 // Computation of 2*(d2E/dtdX)(dX/dt) = S2
133 gp_Vec2d d2E1_dtdX(-DC1_t*DS2_u,
135 gp_Vec2d d2E2_dtdX(-DC1_t*DS2_uv,
137 gp_Vec2d S2 = 2*gp_Vec2d(d2E1_dtdX*V1, d2E2_dtdX*V1);
139 // Computation of (d2E/dX2)*(dX/dt)2 = S3
141 // Row11 = (d2E1/du2, d2E1/dudv)
143 gp_Vec2d Row11(3*DS1_u*DS2_u + Ort*DS3_u,
144 tmp = 2*DS1_u*DS2_uv +
145 DS1_v*DS2_u + Ort*DS3_uuv);
147 // Row12 = (d2E1/dudv, d2E1/dv2)
148 gp_Vec2d Row12(tmp, DS2_v*DS1_u + 2*DS1_v*DS2_uv +
151 // Row21 = (d2E2/du2, d2E2/dudv)
152 gp_Vec2d Row21(DS2_u*DS1_v + 2*DS1_u*DS2_uv + Ort*DS3_uuv,
153 tmp = 2*DS2_uv*DS1_v + DS1_u*DS2_v + Ort*DS3_uvv);
155 // Row22 = (d2E2/duv, d2E2/dvdv)
156 gp_Vec2d Row22(tmp, 3*DS1_v*DS2_v + Ort*DS3_v);
158 gp_Vec2d S3(V1*gp_Vec2d(Row11*V1, Row12*V1),
159 V1*gp_Vec2d(Row21*V1, Row22*V1));
161 gp_Vec2d Sum = d2E_dt + S2 + S3;
163 V2 = - gp_Vec2d(gp_Vec2d(M.Row(1))*Sum, gp_Vec2d(M.Row(2))*Sum);
165 //=======================================================================
166 //function : d1CurveOnSurf
167 //purpose : computes first derivative of the 3d projected curve
168 //=======================================================================
171 static void d1CurvOnSurf(const Standard_Real t,
172 const Standard_Real u,
173 const Standard_Real v,
175 const Handle(Adaptor3d_HCurve)& Curve,
176 const Handle(Adaptor3d_HSurface)& Surface)
180 gp_Vec DS1_u, DS1_v, DS2_u, DS2_uv, DS2_v, DC1_t;
181 Surface->D2(u, v, S, DS1_u, DS1_v, DS2_u, DS2_v, DS2_uv);
182 Curve->D1(t, C, DC1_t);
183 gp_Vec Ort(C, S);// Ort = S - C
185 gp_Vec2d dE_dt(-DC1_t*DS1_u, -DC1_t*DS1_v);
186 gp_XY dE_du(DS1_u*DS1_u + Ort*DS2_u,
187 DS1_u*DS1_v + Ort*DS2_uv);
188 gp_XY dE_dv(DS1_v*DS1_u + Ort*DS2_uv,
189 DS1_v*DS1_v + Ort*DS2_v);
191 Standard_Real det = dE_du.X()*dE_dv.Y() - dE_du.Y()*dE_dv.X();
192 if (fabs(det) < gp::Resolution()) Standard_ConstructionError::Raise();
194 gp_Mat2d M(gp_XY(dE_dv.Y()/det, -dE_du.Y()/det),
195 gp_XY(-dE_dv.X()/det, dE_du.X()/det));
197 V2d = - gp_Vec2d(gp_Vec2d(M.Row(1))*dE_dt, gp_Vec2d(M.Row(2))*dE_dt);
199 V = DS1_u * V2d.X() + DS1_v * V2d.Y();
204 //=======================================================================
205 //function : d2CurveOnSurf
206 //purpose : computes second derivative of the 3D projected curve
207 //=======================================================================
209 static void d2CurvOnSurf(const Standard_Real t,
210 const Standard_Real u,
211 const Standard_Real v,
212 gp_Vec& V1 , gp_Vec& V2 ,
213 const Handle(Adaptor3d_HCurve)& Curve,
214 const Handle(Adaptor3d_HSurface)& Surface)
218 gp_Vec DS1_u, DS1_v, DS2_u, DS2_uv, DS2_v,
219 DS3_u, DS3_v, DS3_uuv, DS3_uvv,
221 Surface->D3(u, v, S, DS1_u, DS1_v, DS2_u, DS2_v, DS2_uv,
222 DS3_u, DS3_v, DS3_uuv, DS3_uvv);
223 Curve->D2(t, C, DC1_t, DC2_t);
226 gp_Vec2d dE_dt(-DC1_t*DS1_u, -DC1_t*DS1_v);
227 gp_XY dE_du(DS1_u*DS1_u + Ort*DS2_u,
228 DS1_u*DS1_v + Ort*DS2_uv);
229 gp_XY dE_dv(DS1_v*DS1_u + Ort*DS2_uv,
230 DS1_v*DS1_v + Ort*DS2_v);
232 Standard_Real det = dE_du.X()*dE_dv.Y() - dE_du.Y()*dE_dv.X();
233 if (fabs(det) < gp::Resolution()) Standard_ConstructionError::Raise();
235 gp_Mat2d M(gp_XY(dE_dv.Y()/det, -dE_du.Y()/det),
236 gp_XY(-dE_dv.X()/det, dE_du.X()/det));
239 V12d = - gp_Vec2d(gp_Vec2d(M.Row(1))*dE_dt, gp_Vec2d(M.Row(2))*dE_dt);
241 /* Second derivative */
243 // Computation of d2E_dt2 = S1
244 gp_Vec2d d2E_dt(-DC2_t*DS1_u, -DC2_t*DS1_v);
246 // Computation of 2*(d2E/dtdX)(dX/dt) = S2
247 gp_Vec2d d2E1_dtdX(-DC1_t*DS2_u,
249 gp_Vec2d d2E2_dtdX(-DC1_t*DS2_uv,
251 gp_Vec2d S2 = 2*gp_Vec2d(d2E1_dtdX*V12d, d2E2_dtdX*V12d);
253 // Computation of (d2E/dX2)*(dX/dt)2 = S3
255 // Row11 = (d2E1/du2, d2E1/dudv)
257 gp_Vec2d Row11(3*DS1_u*DS2_u + Ort*DS3_u,
258 tmp = 2*DS1_u*DS2_uv +
259 DS1_v*DS2_u + Ort*DS3_uuv);
261 // Row12 = (d2E1/dudv, d2E1/dv2)
262 gp_Vec2d Row12(tmp, DS2_v*DS1_u + 2*DS1_v*DS2_uv +
265 // Row21 = (d2E2/du2, d2E2/dudv)
266 gp_Vec2d Row21(DS2_u*DS1_v + 2*DS1_u*DS2_uv + Ort*DS3_uuv,
267 tmp = 2*DS2_uv*DS1_v + DS1_u*DS2_v + Ort*DS3_uvv);
269 // Row22 = (d2E2/duv, d2E2/dvdv)
270 gp_Vec2d Row22(tmp, 3*DS1_v*DS2_v + Ort*DS3_v);
272 gp_Vec2d S3(V12d*gp_Vec2d(Row11*V12d, Row12*V12d),
273 V12d*gp_Vec2d(Row21*V12d, Row22*V12d));
275 gp_Vec2d Sum = d2E_dt + S2 + S3;
277 V22d = - gp_Vec2d(gp_Vec2d(M.Row(1))*Sum, gp_Vec2d(M.Row(2))*Sum);
279 V1 = DS1_u * V12d.X() + DS1_v * V12d.Y();
280 V2 = DS2_u * V12d.X() *V12d.X()
282 + 2 * DS2_uv * V12d.X() *V12d.Y()
283 + DS2_v * V12d.Y() * V12d.Y()
287 //=======================================================================
288 //function : ExactBound
289 //purpose : computes exact boundary point
290 //=======================================================================
292 static Standard_Boolean ExactBound(gp_Pnt& Sol,
293 const Standard_Real NotSol,
294 const Standard_Real Tol,
295 const Standard_Real TolU,
296 const Standard_Real TolV,
297 const Handle(Adaptor3d_HCurve)& Curve,
298 const Handle(Adaptor3d_HSurface)& Surface)
300 Standard_Real U0, V0, t, t1, t2, FirstU, LastU, FirstV, LastV;
304 FirstU = Surface->FirstUParameter();
305 LastU = Surface->LastUParameter();
306 FirstV = Surface->FirstVParameter();
307 LastV = Surface->LastVParameter();
308 // Here we have to compute the boundary that projection is going to intersect
310 //these variables are to estimate which boundary has more apportunity
312 Standard_Real RU1, RU2, RV1, RV2;
313 d1(Sol.X(), U0, V0, D2d, Curve, Surface);
314 // Here we assume that D2d != (0, 0)
315 if(Abs(D2d.X()) < gp::Resolution())
317 RU1 = Precision::Infinite();
318 RU2 = Precision::Infinite();
322 else if(Abs(D2d.Y()) < gp::Resolution())
326 RV1 = Precision::Infinite();
327 RV2 = Precision::Infinite();
331 RU1 = gp_Pnt2d(U0, V0).
332 Distance(gp_Pnt2d(FirstU, V0 + (FirstU - U0)*D2d.Y()/D2d.X()));
333 RU2 = gp_Pnt2d(U0, V0).
334 Distance(gp_Pnt2d(LastU, V0 + (LastU - U0)*D2d.Y()/D2d.X()));
335 RV1 = gp_Pnt2d(U0, V0).
336 Distance(gp_Pnt2d(U0 + (FirstV - V0)*D2d.X()/D2d.Y(), FirstV));
337 RV2 = gp_Pnt2d(U0, V0).
338 Distance(gp_Pnt2d(U0 + (LastV - V0)*D2d.X()/D2d.Y(), LastV));
340 TColgp_SequenceOfPnt Seq;
341 Seq.Append(gp_Pnt(FirstU, RU1, 2));
342 Seq.Append(gp_Pnt(LastU, RU2, 2));
343 Seq.Append(gp_Pnt(FirstV, RV1, 3));
344 Seq.Append(gp_Pnt(LastV, RV2, 3));
345 Standard_Integer i, j;
346 for(i = 1; i <= 3; i++)
347 for(j = 1; j <= 4-i; j++)
348 if(Seq(j).Y() < Seq(j+1).Y())
351 swp = Seq.Value(j+1);
352 Seq.ChangeValue(j+1) = Seq.Value(j);
353 Seq.ChangeValue(j) = swp;
357 t1 = Min(Sol.X(), NotSol);
358 t2 = Max(Sol.X(), NotSol);
360 Standard_Boolean isDone = Standard_False;
361 while (!Seq.IsEmpty())
365 Seq.Remove(Seq.Length());
366 ProjLib_PrjResolve aPrjPS(Curve->Curve(),
368 Standard_Integer(P.Z()));
369 if(Standard_Integer(P.Z()) == 2)
371 aPrjPS.Perform(t, P.X(), V0, gp_Pnt2d(Tol, TolV),
372 gp_Pnt2d(t1, Surface->FirstVParameter()),
373 gp_Pnt2d(t2, Surface->LastVParameter()), FuncTol);
374 if(!aPrjPS.IsDone()) continue;
375 POnS = aPrjPS.Solution();
376 Sol = gp_Pnt(POnS.X(), P.X(), POnS.Y());
377 isDone = Standard_True;
382 aPrjPS.Perform(t, U0, P.X(), gp_Pnt2d(Tol, TolU),
383 gp_Pnt2d(t1, Surface->FirstUParameter()),
384 gp_Pnt2d(t2, Surface->LastUParameter()), FuncTol);
385 if(!aPrjPS.IsDone()) continue;
386 POnS = aPrjPS.Solution();
387 Sol = gp_Pnt(POnS.X(), POnS.Y(), P.X());
388 isDone = Standard_True;
396 //=======================================================================
397 //function : DichExactBound
398 //purpose : computes exact boundary point
399 //=======================================================================
401 static void DichExactBound(gp_Pnt& Sol,
402 const Standard_Real NotSol,
403 const Standard_Real Tol,
404 const Standard_Real TolU,
405 const Standard_Real TolV,
406 const Handle(Adaptor3d_HCurve)& Curve,
407 const Handle(Adaptor3d_HSurface)& Surface)
409 #ifdef OCCT_DEBUG_CHRONO
410 InitChron(chr_dicho_bound);
413 Standard_Real U0, V0, t;
417 ProjLib_PrjResolve aPrjPS(Curve->Curve(), Surface->Surface(), 1);
419 Standard_Real aNotSol = NotSol;
420 while (fabs(Sol.X() - aNotSol) > Tol)
422 t = (Sol.X() + aNotSol)/2;
423 aPrjPS.Perform(t, U0, V0, gp_Pnt2d(TolU, TolV),
424 gp_Pnt2d(Surface->FirstUParameter(),Surface->FirstVParameter()),
425 gp_Pnt2d(Surface->LastUParameter(),Surface->LastVParameter()),
426 FuncTol, Standard_True);
430 POnS = aPrjPS.Solution();
431 Sol = gp_Pnt(t, POnS.X(), POnS.Y());
437 #ifdef OCCT_DEBUG_CHRONO
438 ResultChron(chr_dicho_bound,t_dicho_bound);
443 //=======================================================================
444 //function : InitialPoint
446 //=======================================================================
448 static Standard_Boolean InitialPoint(const gp_Pnt& Point,
449 const Standard_Real t,
450 const Handle(Adaptor3d_HCurve)& C,
451 const Handle(Adaptor3d_HSurface)& S,
452 const Standard_Real TolU,
453 const Standard_Real TolV,
458 ProjLib_PrjResolve aPrjPS(C->Curve(), S->Surface(), 1);
459 Standard_Real ParU,ParV;
460 Extrema_ExtPS aExtPS;
461 aExtPS.Initialize(S->Surface(), S->FirstUParameter(),
462 S->LastUParameter(), S->FirstVParameter(),
463 S->LastVParameter(), TolU, TolV);
465 aExtPS.Perform(Point);
466 Standard_Integer argmin = 0;
467 if (aExtPS.IsDone() && aExtPS.NbExt())
469 Standard_Integer i, Nend;
470 // Search for the nearest solution which is also a normal projection
471 Nend = aExtPS.NbExt();
472 for(i = 1; i <= Nend; i++)
474 Extrema_POnSurf POnS = aExtPS.Point(i);
475 POnS.Parameter(ParU, ParV);
476 aPrjPS.Perform(t, ParU, ParV, gp_Pnt2d(TolU, TolV),
477 gp_Pnt2d(S->FirstUParameter(), S->FirstVParameter()),
478 gp_Pnt2d(S->LastUParameter(), S->LastVParameter()),
479 FuncTol, Standard_True);
481 if (argmin == 0 || aExtPS.SquareDistance(i) < aExtPS.SquareDistance(argmin)) argmin = i;
484 if( argmin == 0 ) return Standard_False;
487 Extrema_POnSurf POnS = aExtPS.Point(argmin);
488 POnS.Parameter(U, V);
489 return Standard_True;
493 //=======================================================================
494 //function : ProjLib_CompProjectedCurve
496 //=======================================================================
498 ProjLib_CompProjectedCurve::ProjLib_CompProjectedCurve()
506 //=======================================================================
507 //function : ProjLib_CompProjectedCurve
509 //=======================================================================
511 ProjLib_CompProjectedCurve::ProjLib_CompProjectedCurve
512 (const Handle(Adaptor3d_HSurface)& theSurface,
513 const Handle(Adaptor3d_HCurve)& theCurve,
514 const Standard_Real theTolU,
515 const Standard_Real theTolV)
516 : mySurface (theSurface),
519 mySequence(new ProjLib_HSequenceOfHSequenceOfPnt()),
527 //=======================================================================
528 //function : ProjLib_CompProjectedCurve
530 //=======================================================================
532 ProjLib_CompProjectedCurve::ProjLib_CompProjectedCurve
533 (const Handle(Adaptor3d_HSurface)& theSurface,
534 const Handle(Adaptor3d_HCurve)& theCurve,
535 const Standard_Real theTolU,
536 const Standard_Real theTolV,
537 const Standard_Real theMaxDist)
538 : mySurface (theSurface),
541 mySequence(new ProjLib_HSequenceOfHSequenceOfPnt()),
544 myMaxDist (theMaxDist)
549 //=======================================================================
552 //=======================================================================
554 void ProjLib_CompProjectedCurve::Init()
558 Standard_Real Tol;// Tolerance for ExactBound
559 Standard_Integer i, Nend = 0;
560 Standard_Boolean FromLastU=Standard_False;
562 //new part (to discard far solutions)
563 //Method Extrema_ExtCS gives wrong result(ex. sphere and segment orthogonal to it)
564 Standard_Real TolC = Precision::Confusion(), TolS = Precision::Confusion();
565 Extrema_ExtCS CExt(myCurve->Curve(),
566 mySurface->Surface(),
569 if (CExt.IsDone() && CExt.NbExt())
571 // Search for the minimum solution
575 Standard_Real min_val2;
576 min_val2 = CExt.SquareDistance(1);
577 for(i = 2; i <= Nend; i++)
578 if (CExt.SquareDistance(i) < min_val2) min_val2 = CExt.SquareDistance(i);
579 if(min_val2 > myMaxDist * myMaxDist) return;
584 Standard_Real FirstU, LastU, Step, DecStep, SearchStep, WalkStep, t;
586 FirstU = myCurve->FirstParameter();
587 LastU = myCurve->LastParameter();
588 const Standard_Real MinStep = 0.01*(LastU - FirstU),
589 MaxStep = 0.1*(LastU - FirstU);
590 SearchStep = 10*MinStep;
593 //Initialization of aPrjPS
594 Standard_Real Uinf = mySurface->FirstUParameter();
595 Standard_Real Usup = mySurface->LastUParameter();
596 Standard_Real Vinf = mySurface->FirstVParameter();
597 Standard_Real Vsup = mySurface->LastVParameter();
599 ProjLib_PrjResolve aPrjPS(myCurve->Curve(), mySurface->Surface(), 1);
602 Standard_Boolean new_part;
603 Standard_Real prevDeb=0.;
604 Standard_Boolean SameDeb=Standard_False;
607 gp_Pnt Triple, prevTriple;
612 //Search for the begining a new continuous part
613 //To avoid infinite computation in some difficult cases
614 new_part = Standard_False;
615 if(t > FirstU && Abs(t-prevDeb) <= Precision::PConfusion()) SameDeb=Standard_True;
616 while(t <= LastU && !new_part && !FromLastU && !SameDeb)
619 if (t == LastU) FromLastU=Standard_True;
620 Standard_Boolean initpoint=Standard_False;
621 Standard_Real U = 0., V = 0.;
623 Standard_Real ParT,ParU,ParV;
625 // Search an initpoint in the list of Extrema Curve-Surface
626 if(Nend != 0 && !CExt.IsParallel())
628 for (i=1;i<=Nend;i++)
632 CExt.Points(i,P1,P2);
634 P2.Parameter(ParU, ParV);
636 aPrjPS.Perform(ParT, ParU, ParV, gp_Pnt2d(myTolU, myTolV),
637 gp_Pnt2d(mySurface->FirstUParameter(),mySurface->FirstVParameter()),
638 gp_Pnt2d(mySurface->LastUParameter(), mySurface->LastVParameter()),
639 FuncTol, Standard_True);
640 if ( aPrjPS.IsDone() && P1.Parameter() > Max(FirstU,t-Step+Precision::PConfusion())
641 && P1.Parameter() <= t)
647 initpoint = Standard_True;
654 myCurve->D0(t,CPoint);
655 #ifdef OCCT_DEBUG_CHRONO
656 InitChron(chr_init_point);
658 initpoint=InitialPoint(CPoint, t,myCurve,mySurface, myTolU, myTolV, U, V);
659 #ifdef OCCT_DEBUG_CHRONO
660 ResultChron(chr_init_point,t_init_point);
666 // When U or V lie on surface joint in some cases we cannot use them
667 // as initial point for aPrjPS, so we switch them
670 if((Abs(U - Uinf) < mySurface->UResolution(Precision::PConfusion())) &&
671 mySurface->IsUPeriodic())
673 d1(t, U, V, D, myCurve, mySurface);
674 if (D.X() < 0) U = Usup;
676 else if((Abs(U - Usup) < mySurface->UResolution(Precision::PConfusion())) &&
677 mySurface->IsUPeriodic())
679 d1(t, U, V, D, myCurve, mySurface);
680 if (D.X() > 0) U = Uinf;
683 if((Abs(V - Vinf) < mySurface->VResolution(Precision::PConfusion())) &&
684 mySurface->IsVPeriodic())
686 d1(t, U, V, D, myCurve, mySurface);
687 if (D.Y() < 0) V = Vsup;
689 else if((Abs(V - Vsup) <= mySurface->VResolution(Precision::PConfusion())) &&
690 mySurface->IsVPeriodic())
692 d1(t, U, V, D, myCurve, mySurface);
693 if (D.Y() > 0) V = Vinf;
699 // Here we are going to stop if the distance between projection and
700 // corresponding curve point is greater than myMaxDist
703 mySurface->D0(U, V, POnS);
704 d = CPoint.Distance(POnS);
712 Triple = gp_Pnt(t, U, V);
715 //Search for exact boundary point
716 Tol = Min(myTolU, myTolV);
718 d1(Triple.X(), Triple.Y(), Triple.Z(), D, myCurve, mySurface);
719 Tol /= Max(Abs(D.X()), Abs(D.Y()));
721 if(!ExactBound(Triple, t - Step, Tol,
722 myTolU, myTolV, myCurve, mySurface))
725 cout<<"There is a problem with ExactBound computation"<<endl;
727 DichExactBound(Triple, t - Step, Tol, myTolU, myTolV,
731 new_part = Standard_True;
735 if(t == LastU) break;
744 if (!new_part) break;
747 //We have found a new continuous part
748 Handle(TColgp_HSequenceOfPnt) hSeq = new TColgp_HSequenceOfPnt();
749 mySequence->Append(hSeq);
751 mySequence->Value(myNbCurves)->Append(Triple);
754 if (Triple.X() == LastU) break;//return;
756 //Computation of WalkStep
758 Standard_Real MagnD1, MagnD2;
759 d2CurvOnSurf(Triple.X(), Triple.Y(), Triple.Z(), D1, D2, myCurve, mySurface);
760 MagnD1 = D1.Magnitude();
761 MagnD2 = D2.Magnitude();
762 if(MagnD2 < Precision::Confusion()) WalkStep = MaxStep;
763 else WalkStep = Min(MaxStep, Max(MinStep, 0.1*MagnD1/MagnD2));
768 t = Triple.X() + Step;
769 if (t > LastU) t = LastU;
770 Standard_Real prevStep = Step;
771 Standard_Real U0, V0;
772 gp_Pnt2d aLowBorder(mySurface->FirstUParameter(),mySurface->FirstVParameter());
773 gp_Pnt2d aUppBorder(mySurface->LastUParameter(), mySurface->LastVParameter());
774 gp_Pnt2d aTol(myTolU, myTolV);
775 //Here we are trying to prolong continuous part
776 while (t <= LastU && new_part)
779 U0 = Triple.Y() + (Step / prevStep) * (Triple.Y() - prevTriple.Y());
780 V0 = Triple.Z() + (Step / prevStep) * (Triple.Z() - prevTriple.Z());
781 // adjust U0 to be in [mySurface->FirstUParameter(),mySurface->LastUParameter()]
782 U0 = Min(Max(U0, aLowBorder.X()), aUppBorder.X());
783 // adjust V0 to be in [mySurface->FirstVParameter(),mySurface->LastVParameter()]
784 V0 = Min(Max(V0, aLowBorder.Y()), aUppBorder.Y());
787 aPrjPS.Perform(t, U0, V0, aTol,
788 aLowBorder, aUppBorder, FuncTol, Standard_True);
792 if (DecStep <= MinStep)
794 //Search for exact boundary point
795 Tol = Min(myTolU, myTolV);
797 d1(Triple.X(), Triple.Y(), Triple.Z(), D, myCurve, mySurface);
798 Tol /= Max(Abs(D.X()), Abs(D.Y()));
800 if(!ExactBound(Triple, t, Tol, myTolU, myTolV,
804 cout<<"There is a problem with ExactBound computation"<<endl;
806 DichExactBound(Triple, t, Tol, myTolU, myTolV,
810 if((Triple.X() - mySequence->Value(myNbCurves)->Value(mySequence->Value(myNbCurves)->Length()).X()) > 1.e-10)
811 mySequence->Value(myNbCurves)->Append(Triple);
812 if((LastU - Triple.X()) < Tol) {t = LastU + 1; break;}//return;
815 t = Triple.X() + Step;
816 if (t > (LastU-MinStep/2) )
822 new_part = Standard_False;
827 DecStep=DecStep / 2.;
828 Step = Max (MinStep , DecStep);
829 t = Triple .X() + Step;
830 if (t > (LastU-MinStep/4) )
842 Triple = gp_Pnt(t, aPrjPS.Solution().X(), aPrjPS.Solution().Y());
844 if (mySurface->GetType() == GeomAbs_SurfaceOfRevolution &&
845 (Abs (Triple.Z() - mySurface->FirstVParameter()) < Precision::Confusion() ||
846 Abs (Triple.Z() - mySurface->LastVParameter() ) < Precision::Confusion() ))
848 // Go out from possible attraktor.
851 InitialPoint(myCurve->Value(t), t, myCurve, mySurface, myTolU, myTolV, U, V);
852 if (Abs (Abs(U - Triple.Y()) - mySurface->UPeriod()) < Precision::Confusion())
854 // Handle period jump.
861 if((Triple.X() - mySequence->Value(myNbCurves)->Value(mySequence->Value(myNbCurves)->Length()).X()) > 1.e-10)
862 mySequence->Value(myNbCurves)->Append(Triple);
863 if (t == LastU) {t = LastU + 1; break;}//return;
865 //Computation of WalkStep
866 d2CurvOnSurf(Triple.X(), Triple.Y(), Triple.Z(), D1, D2, myCurve, mySurface);
867 MagnD1 = D1.Magnitude();
868 MagnD2 = D2.Magnitude();
869 if(MagnD2 < Precision::Confusion() ) WalkStep = MaxStep;
870 else WalkStep = Min(MaxStep, Max(MinStep, 0.1*MagnD1/MagnD2));
874 if (t > (LastU-MinStep/2) )
883 // Sequence postproceeding
886 // 1. Removing poor parts
887 Standard_Integer NbPart=myNbCurves;
888 Standard_Integer ipart=1;
889 for(i = 1; i <= NbPart; i++) {
890 // Standard_Integer NbPoints = mySequence->Value(i)->Length();
891 if(mySequence->Value(ipart)->Length() < 2) {
892 mySequence->Remove(ipart);
898 if(myNbCurves == 0) return;
900 // 2. Removing common parts of bounds
901 for(i = 1; i < myNbCurves; i++)
903 if(mySequence->Value(i)->Value(mySequence->Value(i)->Length()).X() >=
904 mySequence->Value(i+1)->Value(1).X())
905 mySequence->ChangeValue(i+1)->ChangeValue(1).SetX(mySequence->Value(i)->Value(mySequence->Value(i)->Length()).X() + 1.e-12);
908 // 3. Computation of the maximum distance from each part of curve to surface
910 myMaxDistance = new TColStd_HArray1OfReal(1, myNbCurves);
911 myMaxDistance->Init(0);
912 for(i = 1; i <= myNbCurves; i++)
913 for(j = 1; j <= mySequence->Value(i)->Length(); j++)
915 gp_Pnt POnC, POnS, Triple;
916 Standard_Real Distance;
917 Triple = mySequence->Value(i)->Value(j);
918 myCurve->D0(Triple.X(), POnC);
919 mySurface->D0(Triple.Y(), Triple.Z(), POnS);
920 Distance = POnC.Distance(POnS);
921 if (myMaxDistance->Value(i) < Distance)
922 myMaxDistance->ChangeValue(i) = Distance;
926 // 4. Check the projection to be a single point
928 gp_Pnt2d Pmoy, Pcurr, P;
929 Standard_Real AveU, AveV;
930 mySnglPnts = new TColStd_HArray1OfBoolean(1, myNbCurves);
931 for(i = 1; i <= myNbCurves; i++) mySnglPnts->SetValue(i, Standard_True);
933 for(i = 1; i <= myNbCurves; i++)
935 //compute an average U and V
937 for(j = 1, AveU = 0., AveV = 0.; j <= mySequence->Value(i)->Length(); j++)
939 AveU += mySequence->Value(i)->Value(j).Y();
940 AveV += mySequence->Value(i)->Value(j).Z();
942 AveU /= mySequence->Value(i)->Length();
943 AveV /= mySequence->Value(i)->Length();
945 Pmoy.SetCoord(AveU,AveV);
946 for(j = 1; j <= mySequence->Value(i)->Length(); j++)
949 gp_Pnt2d(mySequence->Value(i)->Value(j).Y(), mySequence->Value(i)->Value(j).Z());
950 if (Pcurr.Distance(Pmoy) > ((myTolU < myTolV) ? myTolV : myTolU))
952 mySnglPnts->SetValue(i, Standard_False);
958 // 5. Check the projection to be an isoparametric curve of the surface
960 myUIso = new TColStd_HArray1OfBoolean(1, myNbCurves);
961 for(i = 1; i <= myNbCurves; i++) myUIso->SetValue(i, Standard_True);
963 myVIso = new TColStd_HArray1OfBoolean(1, myNbCurves);
964 for(i = 1; i <= myNbCurves; i++) myVIso->SetValue(i, Standard_True);
966 for(i = 1; i <= myNbCurves; i++) {
967 if (IsSinglePnt(i, P)|| mySequence->Value(i)->Length() <=2) {
968 myUIso->SetValue(i, Standard_False);
969 myVIso->SetValue(i, Standard_False);
973 // new test for isoparametrics
975 if ( mySequence->Value(i)->Length() > 2) {
976 //compute an average U and V
978 for(j = 1, AveU = 0., AveV = 0.; j <= mySequence->Value(i)->Length(); j++) {
979 AveU += mySequence->Value(i)->Value(j).Y();
980 AveV += mySequence->Value(i)->Value(j).Z();
982 AveU /= mySequence->Value(i)->Length();
983 AveV /= mySequence->Value(i)->Length();
985 // is i-part U-isoparametric ?
986 for(j = 1; j <= mySequence->Value(i)->Length(); j++)
988 if(Abs(mySequence->Value(i)->Value(j).Y() - AveU) > myTolU)
990 myUIso->SetValue(i, Standard_False);
995 // is i-part V-isoparametric ?
996 for(j = 1; j <= mySequence->Value(i)->Length(); j++)
998 if(Abs(mySequence->Value(i)->Value(j).Z() - AveV) > myTolV)
1000 myVIso->SetValue(i, Standard_False);
1008 //=======================================================================
1011 //=======================================================================
1013 void ProjLib_CompProjectedCurve::Load(const Handle(Adaptor3d_HSurface)& S)
1018 //=======================================================================
1021 //=======================================================================
1023 void ProjLib_CompProjectedCurve::Load(const Handle(Adaptor3d_HCurve)& C)
1028 //=======================================================================
1029 //function : GetSurface
1031 //=======================================================================
1033 const Handle(Adaptor3d_HSurface)& ProjLib_CompProjectedCurve::GetSurface() const
1039 //=======================================================================
1040 //function : GetCurve
1042 //=======================================================================
1044 const Handle(Adaptor3d_HCurve)& ProjLib_CompProjectedCurve::GetCurve() const
1049 //=======================================================================
1050 //function : GetTolerance
1052 //=======================================================================
1054 void ProjLib_CompProjectedCurve::GetTolerance(Standard_Real& TolU,
1055 Standard_Real& TolV) const
1061 //=======================================================================
1062 //function : NbCurves
1064 //=======================================================================
1066 Standard_Integer ProjLib_CompProjectedCurve::NbCurves() const
1070 //=======================================================================
1073 //=======================================================================
1075 void ProjLib_CompProjectedCurve::Bounds(const Standard_Integer Index,
1076 Standard_Real& Udeb,
1077 Standard_Real& Ufin) const
1079 if(Index < 1 || Index > myNbCurves) Standard_NoSuchObject::Raise();
1080 Udeb = mySequence->Value(Index)->Value(1).X();
1081 Ufin = mySequence->Value(Index)->Value(mySequence->Value(Index)->Length()).X();
1083 //=======================================================================
1084 //function : IsSinglePnt
1086 //=======================================================================
1088 Standard_Boolean ProjLib_CompProjectedCurve::IsSinglePnt(const Standard_Integer Index, gp_Pnt2d& P) const
1090 if(Index < 1 || Index > myNbCurves) Standard_NoSuchObject::Raise();
1091 P = gp_Pnt2d(mySequence->Value(Index)->Value(1).Y(), mySequence->Value(Index)->Value(1).Z());
1092 return mySnglPnts->Value(Index);
1095 //=======================================================================
1098 //=======================================================================
1100 Standard_Boolean ProjLib_CompProjectedCurve::IsUIso(const Standard_Integer Index, Standard_Real& U) const
1102 if(Index < 1 || Index > myNbCurves) Standard_NoSuchObject::Raise();
1103 U = mySequence->Value(Index)->Value(1).Y();
1104 return myUIso->Value(Index);
1106 //=======================================================================
1109 //=======================================================================
1111 Standard_Boolean ProjLib_CompProjectedCurve::IsVIso(const Standard_Integer Index, Standard_Real& V) const
1113 if(Index < 1 || Index > myNbCurves) Standard_NoSuchObject::Raise();
1114 V = mySequence->Value(Index)->Value(1).Z();
1115 return myVIso->Value(Index);
1117 //=======================================================================
1120 //=======================================================================
1122 gp_Pnt2d ProjLib_CompProjectedCurve::Value(const Standard_Real t) const
1128 //=======================================================================
1131 //=======================================================================
1133 void ProjLib_CompProjectedCurve::D0(const Standard_Real U,gp_Pnt2d& P) const
1135 Standard_Integer i, j;
1136 Standard_Real Udeb, Ufin;
1137 Standard_Boolean found = Standard_False;
1139 for(i = 1; i <= myNbCurves; i++)
1141 Bounds(i, Udeb, Ufin);
1142 if (U >= Udeb && U <= Ufin)
1144 found = Standard_True;
1148 if (!found) Standard_DomainError::Raise("ProjLib_CompProjectedCurve::D0");
1150 Standard_Real U0, V0;
1152 Standard_Integer End = mySequence->Value(i)->Length();
1153 for(j = 1; j < End; j++)
1154 if ((U >= mySequence->Value(i)->Value(j).X()) && (U <= mySequence->Value(i)->Value(j + 1).X())) break;
1156 // U0 = mySequence->Value(i)->Value(j).Y();
1157 // V0 = mySequence->Value(i)->Value(j).Z();
1159 // Cubic Interpolation
1160 if(mySequence->Value(i)->Length() < 4 ||
1161 (Abs(U-mySequence->Value(i)->Value(j).X()) <= Precision::PConfusion()) )
1163 U0 = mySequence->Value(i)->Value(j).Y();
1164 V0 = mySequence->Value(i)->Value(j).Z();
1166 else if (Abs(U-mySequence->Value(i)->Value(j+1).X())
1167 <= Precision::PConfusion())
1169 U0 = mySequence->Value(i)->Value(j+1).Y();
1170 V0 = mySequence->Value(i)->Value(j+1).Z();
1175 if (j > mySequence->Value(i)->Length() - 2)
1176 j = mySequence->Value(i)->Length() - 2;
1178 gp_Vec2d I1, I2, I3, I21, I22, I31, Y1, Y2, Y3, Y4, Res;
1179 Standard_Real X1, X2, X3, X4;
1181 X1 = mySequence->Value(i)->Value(j - 1).X();
1182 X2 = mySequence->Value(i)->Value(j).X();
1183 X3 = mySequence->Value(i)->Value(j + 1).X();
1184 X4 = mySequence->Value(i)->Value(j + 2).X();
1186 Y1 = gp_Vec2d(mySequence->Value(i)->Value(j - 1).Y(),
1187 mySequence->Value(i)->Value(j - 1).Z());
1188 Y2 = gp_Vec2d(mySequence->Value(i)->Value(j).Y(),
1189 mySequence->Value(i)->Value(j).Z());
1190 Y3 = gp_Vec2d(mySequence->Value(i)->Value(j + 1).Y(),
1191 mySequence->Value(i)->Value(j + 1).Z());
1192 Y4 = gp_Vec2d(mySequence->Value(i)->Value(j + 2).Y(),
1193 mySequence->Value(i)->Value(j + 2).Z());
1195 I1 = (Y1 - Y2)/(X1 - X2);
1196 I2 = (Y2 - Y3)/(X2 - X3);
1197 I3 = (Y3 - Y4)/(X3 - X4);
1199 I21 = (I1 - I2)/(X1 - X3);
1200 I22 = (I2 - I3)/(X2 - X4);
1202 I31 = (I21 - I22)/(X1 - X4);
1204 Res = Y1 + (U - X1)*(I1 + (U - X2)*(I21 + (U - X3)*I31));
1209 if(U0 < mySurface->FirstUParameter()) U0 = mySurface->FirstUParameter();
1210 else if(U0 > mySurface->LastUParameter()) U0 = mySurface->LastUParameter();
1212 if(V0 < mySurface->FirstVParameter()) V0 = mySurface->FirstVParameter();
1213 else if(V0 > mySurface->LastVParameter()) V0 = mySurface->LastVParameter();
1215 //End of cubic interpolation
1217 ProjLib_PrjResolve aPrjPS(myCurve->Curve(), mySurface->Surface(), 1);
1218 aPrjPS.Perform(U, U0, V0, gp_Pnt2d(myTolU, myTolV),
1219 gp_Pnt2d(mySurface->FirstUParameter(), mySurface->FirstVParameter()),
1220 gp_Pnt2d(mySurface->LastUParameter(), mySurface->LastVParameter()));
1221 P = aPrjPS.Solution();
1224 //=======================================================================
1227 //=======================================================================
1229 void ProjLib_CompProjectedCurve::D1(const Standard_Real t,
1237 d1(t, u, v, V, myCurve, mySurface);
1239 //=======================================================================
1242 //=======================================================================
1244 void ProjLib_CompProjectedCurve::D2(const Standard_Real t,
1253 d2(t, u, v, V1, V2, myCurve, mySurface);
1255 //=======================================================================
1258 //=======================================================================
1260 gp_Vec2d ProjLib_CompProjectedCurve::DN(const Standard_Real t,
1261 const Standard_Integer N) const
1263 if (N < 1 ) Standard_OutOfRange::Raise("ProjLib_CompProjectedCurve : N must be greater than 0");
1279 Standard_NotImplemented::Raise("ProjLib_CompProjectedCurve::DN");
1283 //=======================================================================
1284 //function : GetSequence
1286 //=======================================================================
1288 const Handle(ProjLib_HSequenceOfHSequenceOfPnt)& ProjLib_CompProjectedCurve::GetSequence() const
1292 //=======================================================================
1293 //function : FirstParameter
1295 //=======================================================================
1297 Standard_Real ProjLib_CompProjectedCurve::FirstParameter() const
1299 return myCurve->FirstParameter();
1302 //=======================================================================
1303 //function : LastParameter
1305 //=======================================================================
1307 Standard_Real ProjLib_CompProjectedCurve::LastParameter() const
1309 return myCurve->LastParameter();
1312 //=======================================================================
1313 //function : MaxDistance
1315 //=======================================================================
1317 Standard_Real ProjLib_CompProjectedCurve::MaxDistance(const Standard_Integer Index) const
1319 if(Index < 1 || Index > myNbCurves) Standard_NoSuchObject::Raise();
1320 return myMaxDistance->Value(Index);
1323 //=======================================================================
1324 //function : NbIntervals
1326 //=======================================================================
1328 Standard_Integer ProjLib_CompProjectedCurve::NbIntervals(const GeomAbs_Shape S) const
1330 const_cast<ProjLib_CompProjectedCurve*>(this)->myTabInt.Nullify();
1332 return myTabInt->Length() - 1;
1335 //=======================================================================
1336 //function : Intervals
1338 //=======================================================================
1340 void ProjLib_CompProjectedCurve::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) const
1342 if (myTabInt.IsNull()) BuildIntervals (S);
1343 T = myTabInt->Array1();
1346 //=======================================================================
1347 //function : BuildIntervals
1349 //=======================================================================
1351 void ProjLib_CompProjectedCurve::BuildIntervals(const GeomAbs_Shape S) const
1353 GeomAbs_Shape SforS = GeomAbs_CN;
1371 Standard_OutOfRange::Raise();
1373 Standard_Integer i, j, k;
1374 Standard_Integer NbIntCur = myCurve->NbIntervals(S);
1375 Standard_Integer NbIntSurU = mySurface->NbUIntervals(SforS);
1376 Standard_Integer NbIntSurV = mySurface->NbVIntervals(SforS);
1378 TColStd_Array1OfReal CutPntsT(1, NbIntCur+1);
1379 TColStd_Array1OfReal CutPntsU(1, NbIntSurU+1);
1380 TColStd_Array1OfReal CutPntsV(1, NbIntSurV+1);
1382 myCurve->Intervals(CutPntsT, S);
1383 mySurface->UIntervals(CutPntsU, SforS);
1384 mySurface->VIntervals(CutPntsV, SforS);
1386 Standard_Real Tl, Tr, Ul, Ur, Vl, Vr, Tol;
1388 Handle(TColStd_HArray1OfReal) BArr = NULL,
1393 // proccessing projection bounds
1394 BArr = new TColStd_HArray1OfReal(1, 2*myNbCurves);
1395 for(i = 1; i <= myNbCurves; i++)
1396 Bounds(i, BArr->ChangeValue(2*i - 1), BArr->ChangeValue(2*i));
1398 // proccessing curve discontinuities
1400 CArr = new TColStd_HArray1OfReal(1, NbIntCur - 1);
1401 for(i = 1; i <= CArr->Length(); i++)
1402 CArr->ChangeValue(i) = CutPntsT(i + 1);
1405 // proccessing U-surface discontinuities
1406 TColStd_SequenceOfReal TUdisc;
1408 for(k = 2; k <= NbIntSurU; k++) {
1409 // cout<<"CutPntsU("<<k<<") = "<<CutPntsU(k)<<endl;
1410 for(i = 1; i <= myNbCurves; i++)
1411 for(j = 1; j < mySequence->Value(i)->Length(); j++) {
1412 Ul = mySequence->Value(i)->Value(j).Y();
1413 Ur = mySequence->Value(i)->Value(j + 1).Y();
1415 if(Abs(Ul - CutPntsU(k)) <= myTolU)
1416 TUdisc.Append(mySequence->Value(i)->Value(j).X());
1417 else if(Abs(Ur - CutPntsU(k)) <= myTolU)
1418 TUdisc.Append(mySequence->Value(i)->Value(j + 1).X());
1419 else if((Ul < CutPntsU(k) && CutPntsU(k) < Ur) ||
1420 (Ur < CutPntsU(k) && CutPntsU(k) < Ul))
1423 V = (mySequence->Value(i)->Value(j).Z()
1424 + mySequence->Value(i)->Value(j +1).Z())/2;
1425 ProjLib_PrjResolve Solver(myCurve->Curve(), mySurface->Surface(), 2);
1429 Triple = mySequence->Value(i)->Value(j);
1430 d1(Triple.X(), Triple.Y(), Triple.Z(), D, myCurve, mySurface);
1431 if (Abs(D.X()) < Precision::Confusion())
1434 Tol = Min(myTolU, myTolU / Abs(D.X()));
1436 Tl = mySequence->Value(i)->Value(j).X();
1437 Tr = mySequence->Value(i)->Value(j + 1).X();
1439 Solver.Perform((Tl + Tr)/2, CutPntsU(k), V,
1440 gp_Pnt2d(Tol, myTolV),
1441 gp_Pnt2d(Tl, mySurface->FirstVParameter()),
1442 gp_Pnt2d(Tr, mySurface->LastVParameter()));
1446 TUdisc.Append(Solver.Solution().X());
1451 for(i = 2; i <= TUdisc.Length(); i++)
1452 if(TUdisc(i) - TUdisc(i-1) < Precision::PConfusion())
1457 UArr = new TColStd_HArray1OfReal(1, TUdisc.Length());
1458 for(i = 1; i <= UArr->Length(); i++)
1459 UArr->ChangeValue(i) = TUdisc(i);
1461 // proccessing V-surface discontinuities
1462 TColStd_SequenceOfReal TVdisc;
1464 for(k = 2; k <= NbIntSurV; k++)
1465 for(i = 1; i <= myNbCurves; i++)
1467 // cout<<"CutPntsV("<<k<<") = "<<CutPntsV(k)<<endl;
1468 for(j = 1; j < mySequence->Value(i)->Length(); j++) {
1470 Vl = mySequence->Value(i)->Value(j).Z();
1471 Vr = mySequence->Value(i)->Value(j + 1).Z();
1473 if(Abs(Vl - CutPntsV(k)) <= myTolV)
1474 TVdisc.Append(mySequence->Value(i)->Value(j).X());
1475 else if (Abs(Vr - CutPntsV(k)) <= myTolV)
1476 TVdisc.Append(mySequence->Value(i)->Value(j + 1).X());
1477 else if((Vl < CutPntsV(k) && CutPntsV(k) < Vr) ||
1478 (Vr < CutPntsV(k) && CutPntsV(k) < Vl))
1481 U = (mySequence->Value(i)->Value(j).Y()
1482 + mySequence->Value(i)->Value(j +1).Y())/2;
1483 ProjLib_PrjResolve Solver(myCurve->Curve(), mySurface->Surface(), 3);
1487 Triple = mySequence->Value(i)->Value(j);
1488 d1(Triple.X(), Triple.Y(), Triple.Z(), D, myCurve, mySurface);
1489 if (Abs(D.Y()) < Precision::Confusion())
1492 Tol = Min(myTolV, myTolV / Abs(D.Y()));
1494 Tl = mySequence->Value(i)->Value(j).X();
1495 Tr = mySequence->Value(i)->Value(j + 1).X();
1497 Solver.Perform((Tl + Tr)/2, U, CutPntsV(k),
1498 gp_Pnt2d(Tol, myTolV),
1499 gp_Pnt2d(Tl, mySurface->FirstUParameter()),
1500 gp_Pnt2d(Tr, mySurface->LastUParameter()));
1504 TVdisc.Append(Solver.Solution().X());
1509 for(i = 2; i <= TVdisc.Length(); i++)
1510 if(TVdisc(i) - TVdisc(i-1) < Precision::PConfusion())
1515 VArr = new TColStd_HArray1OfReal(1, TVdisc.Length());
1516 for(i = 1; i <= VArr->Length(); i++)
1517 VArr->ChangeValue(i) = TVdisc(i);
1521 TColStd_SequenceOfReal Fusion;
1524 GeomLib::FuseIntervals(BArr->ChangeArray1(),
1525 CArr->ChangeArray1(),
1526 Fusion, Precision::PConfusion());
1527 BArr = new TColStd_HArray1OfReal(1, Fusion.Length());
1528 for(i = 1; i <= BArr->Length(); i++)
1529 BArr->ChangeValue(i) = Fusion(i);
1535 GeomLib::FuseIntervals(BArr->ChangeArray1(),
1536 UArr->ChangeArray1(),
1537 Fusion, Precision::PConfusion());
1538 BArr = new TColStd_HArray1OfReal(1, Fusion.Length());
1539 for(i = 1; i <= BArr->Length(); i++)
1540 BArr->ChangeValue(i) = Fusion(i);
1546 GeomLib::FuseIntervals(BArr->ChangeArray1(),
1547 VArr->ChangeArray1(),
1548 Fusion, Precision::PConfusion());
1549 BArr = new TColStd_HArray1OfReal(1, Fusion.Length());
1550 for(i = 1; i <= BArr->Length(); i++)
1551 BArr->ChangeValue(i) = Fusion(i);
1554 const_cast<ProjLib_CompProjectedCurve*>(this)->myTabInt = new TColStd_HArray1OfReal(1, BArr->Length());
1555 for(i = 1; i <= BArr->Length(); i++)
1556 myTabInt->ChangeValue(i) = BArr->Value(i);
1560 //=======================================================================
1563 //=======================================================================
1565 Handle(Adaptor2d_HCurve2d) ProjLib_CompProjectedCurve::Trim
1566 (const Standard_Real First,
1567 const Standard_Real Last,
1568 const Standard_Real Tol) const
1570 Handle(ProjLib_HCompProjectedCurve) HCS =
1571 new ProjLib_HCompProjectedCurve(*this);
1572 HCS->ChangeCurve2d().Load(mySurface);
1573 HCS->ChangeCurve2d().Load(myCurve->Trim(First,Last,Tol));
1577 //=======================================================================
1578 //function : GetType
1580 //=======================================================================
1582 GeomAbs_CurveType ProjLib_CompProjectedCurve::GetType() const
1584 return GeomAbs_OtherCurve;