1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
17 #include <TopoDS_Edge.hxx>
18 #include <Geom_Curve.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
21 #include <Adaptor3d_CurveOnSurface.hxx>
22 #include <Adaptor3d_HCurveOnSurface.hxx>
23 #include <GeomAbs_SurfaceType.hxx>
24 #include <BRep_Tool.hxx>
25 #include <Geom_Line.hxx>
26 #include <Geom_Plane.hxx>
27 #include <Geom_CylindricalSurface.hxx>
28 #include <Geom_ConicalSurface.hxx>
29 #include <Geom_SphericalSurface.hxx>
30 #include <Geom_ToroidalSurface.hxx>
34 #include <gp_Cylinder.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <GeomAdaptor_HSurface.hxx>
40 #include <Precision.hxx>
41 #include <Extrema_ExtCC.hxx>
42 //#include <Extrema_ExtCS.hxx>
43 #include <Extrema_POnCurv.hxx>
44 #include <IntCurveSurface_HInter.hxx>
46 #include <math_FunctionSample.hxx>
47 #include <math_FunctionAllRoots.hxx>
48 #include <TColgp_SequenceOfPnt.hxx>
50 // Modified by skv - Tue Aug 31 12:13:51 2004 OCC569
52 #include <Precision.hxx>
53 #include <IntSurf_Quadric.hxx>
54 #include <math_Function.hxx>
55 #include <math_BrentMinimum.hxx>
56 #include <math_Matrix.hxx>
57 #include <math_Vector.hxx>
58 #include <NCollection_Array1.hxx>
61 #include <Geom_Circle.hxx>
62 #include <Geom_Ellipse.hxx>
63 #include <Geom_Hyperbola.hxx>
64 #include <Geom_Parabola.hxx>
65 #include <Geom_BezierCurve.hxx>
66 #include <Geom_BSplineCurve.hxx>
67 #include <GeomLib.hxx>
71 static Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HCurveOnSurface)& theCurve);
72 static Standard_Boolean IsDegenerated(const IntSurf_Quadric& theQuadric);
74 static void FindVertex (const TheArc&,
75 const Handle(TheTopolTool)&,
77 IntStart_SequenceOfPathPoint&,
81 static void BoundedArc (const TheArc& A,
82 const Handle(TheTopolTool)& Domain,
83 const Standard_Real Pdeb,
84 const Standard_Real Pfin,
86 IntStart_SequenceOfPathPoint& pnt,
87 IntStart_SequenceOfSegment& seg,
88 const Standard_Real TolBoundary,
89 const Standard_Real TolTangency,
90 Standard_Boolean& Arcsol,
91 const Standard_Boolean RecheckOnRegularity);
93 static void PointProcess (const gp_Pnt&,
96 const Handle(TheTopolTool)&,
97 IntStart_SequenceOfPathPoint&,
101 static Standard_Integer TreatLC (const TheArc& A,
102 const Handle(TheTopolTool)& aDomain,
103 const IntSurf_Quadric& aQuadric,
104 const Standard_Real TolBoundary,
105 IntStart_SequenceOfPathPoint& pnt);
107 static Standard_Boolean IsRegularity(const TheArc& A,
108 const Handle(TheTopolTool)& aDomain);
110 class MinFunction : public math_Function
113 MinFunction(TheFunction &theFunc) : myFunc(&theFunc) {};
115 //returns value of the one-dimension-function when parameter
117 virtual Standard_Boolean Value(const Standard_Real theX,
118 Standard_Real& theFVal)
120 if(!myFunc->Value(theX, theFVal))
121 return Standard_False;
124 return Standard_True;
127 //see analogical method for abstract owner class math_Function
128 virtual Standard_Integer GetStateNumber()
138 //=======================================================================
139 //function : FindVertex
141 //=======================================================================
142 void FindVertex (const TheArc& A,
143 const Handle(TheTopolTool)& Domain,
145 IntStart_SequenceOfPathPoint& pnt,
146 const Standard_Real Toler)
149 // Find the vertex of the arc A restriction solutions. It stores
150 // Vertex in the list solutions pnt.
154 Standard_Real param,valf;
155 Standard_Integer itemp;
157 Domain->Initialize(A);
158 Domain->InitVertexIterator();
159 while (Domain->MoreVertex()) {
160 vtx = Domain->Vertex();
161 param = TheSOBTool::Parameter(vtx,A);
163 // Evaluate the function and look compared to tolerance of the
164 // Vertex. If distance <= tolerance then add a vertex to the list of solutions.
165 // The arc is already assumed in the load function.
167 Func.Value(param,valf);
168 if (Abs(valf) <= Toler) {
169 itemp = Func.GetStateNumber();
170 pnt.Append(IntStart_ThePathPoint(Func.Valpoint(itemp),Toler, vtx,A,param));
173 Domain->NextVertex();
177 Standard_Boolean IsDegenerated(const Handle(Adaptor3d_HCurveOnSurface)& theCurve)
179 if (theCurve->GetType() == GeomAbs_Circle)
181 gp_Circ aCirc = theCurve->Circle();
182 if (aCirc.Radius() <= Precision::Confusion())
183 return Standard_True;
185 return Standard_False;
188 Standard_Boolean IsDegenerated(const IntSurf_Quadric& theQuadric)
190 GeomAbs_SurfaceType TypeQuad = theQuadric.TypeQuadric();
191 if (TypeQuad == GeomAbs_Cone)
193 gp_Cone aCone = theQuadric.Cone();
194 Standard_Real aSemiAngle = Abs(aCone.SemiAngle());
195 if (aSemiAngle < 0.02 || aSemiAngle > 1.55)
196 return Standard_True;
198 return Standard_False;
204 SolInfo() : myMathIndex(-1), myValue(RealLast())
208 void Init(const math_FunctionAllRoots& theSolution, const Standard_Integer theIndex)
210 myMathIndex = theIndex;
211 myValue = theSolution.GetPoint(theIndex);
214 void Init(const IntCurveSurface_HInter& theSolution, const Standard_Integer theIndex)
216 myMathIndex = theIndex;
217 myValue = theSolution.Point(theIndex).W();
220 Standard_Real Value() const
225 Standard_Integer Index() const
230 bool operator>(const SolInfo& theOther) const
232 return myValue > theOther.myValue;
235 bool operator<(const SolInfo& theOther) const
237 return myValue < theOther.myValue;
240 bool operator==(const SolInfo& theOther) const
242 return myValue == theOther.myValue;
245 Standard_Real& ChangeValue()
251 Standard_Integer myMathIndex;
252 Standard_Real myValue;
256 void BoundedArc (const TheArc& A,
257 const Handle(TheTopolTool)& Domain,
258 const Standard_Real Pdeb,
259 const Standard_Real Pfin,
261 IntStart_SequenceOfPathPoint& pnt,
262 IntStart_SequenceOfSegment& seg,
263 const Standard_Real TolBoundary,
264 const Standard_Real TolTangency,
265 Standard_Boolean& Arcsol,
266 const Standard_Boolean RecheckOnRegularity)
268 // Recherche des points solutions et des bouts d arc solution sur un arc donne.
269 // On utilise la fonction math_FunctionAllRoots. Ne convient donc que pour
270 // des arcs ayant un point debut et un point de fin (intervalle ferme de
273 Standard_Integer i, Nbi = 0, Nbp = 0;
276 Standard_Real pardeb = 0., parfin = 0.;
277 Standard_Integer ideb,ifin,range,ranged,rangef;
279 // Creer l echantillonage (math_FunctionSample ou classe heritant)
280 // Appel a math_FunctionAllRoots
282 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
283 //@@@ La Tolerance est asociee a l arc ( Incoherence avec le cheminement )
284 //@@@ ( EpsX ~ 1e-5 et ResolutionU et V ~ 1e-9 )
285 //@@@ le vertex trouve ici n'est pas retrouve comme point d arret d une
286 //@@@ ligne de cheminement
287 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
288 Standard_Real EpsX = 1.e-10;
289 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
290 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
291 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
293 // Standard_Integer NbEchant = TheSOBTool::NbSamplesOnArc(A);
294 Standard_Integer NbEchant = Func.NbSamples();
295 if(NbEchant<100) NbEchant = 100; //-- lbr le 22 Avril 96
296 //-- Toujours des pbs
298 //-- Modif 24 Aout 93 -----------------------------
299 Standard_Real nTolTangency = TolTangency;
300 if((Pfin - Pdeb) < (TolTangency*10.0)) {
301 nTolTangency=(Pfin-Pdeb)*0.1;
303 if(EpsX>(nTolTangency+nTolTangency)) {
304 EpsX = nTolTangency * 0.1;
307 //--------------------------------------------------
308 //-- Plante avec un edge avec 2 Samples
309 //-- dont les extremites son solutions (f=0)
310 //-- et ou la derivee est nulle
311 //-- Exemple : un segment diametre d une sphere
312 //-- if(NbEchant<3) NbEchant = 3; //-- lbr le 19 Avril 95
313 //--------------------------------------------------
314 Standard_Real para=0,dist,maxdist;
316 //-------------------------------------------------------------- REJECTIONS le 15 oct 98
317 Standard_Boolean Rejection=Standard_True;
318 Standard_Real maxdr,maxr,minr,ur,dur;
323 for(i=1,ur=Pdeb;i<=6;i++) {
325 if(Func.Values(ur,F,D)) {
326 Standard_Real lminr,lmaxr;
332 if(lminr<minr) minr=lminr;
333 if(lmaxr>maxr) maxr=lmaxr;
334 if(minr<0.0 && maxr>0.0) {
335 Rejection=Standard_False;
343 dur=0.001+maxdr+(maxr-minr)*0.1;
346 if(minr<0.0 && maxr>0.0) {
347 Rejection=Standard_False;
351 Arcsol=Standard_False;
353 if(Rejection==Standard_False)
355 const IntSurf_Quadric& aQuadric = Func.Quadric();
356 GeomAbs_SurfaceType TypeQuad = aQuadric.TypeQuadric();
358 IntCurveSurface_HInter IntCS;
359 Standard_Boolean IsIntCSdone = Standard_False;
360 TColStd_SequenceOfReal Params;
362 #if (defined(_MSC_VER) && (_MSC_VER < 1600))
363 std::auto_ptr<math_FunctionAllRoots> pSol;
365 std::unique_ptr<math_FunctionAllRoots> pSol;
368 math_FunctionSample Echant(Pdeb,Pfin,NbEchant);
370 Standard_Boolean aelargir=Standard_True;
371 //modified by NIZNHY-PKV Thu Apr 12 09:25:19 2001 f
373 //maxdist = 100.0*TolBoundary;
374 maxdist = TolBoundary+TolTangency;
376 //modified by NIZNHY-PKV Thu Apr 12 09:25:23 2001 t
377 for(i=1; i<=NbEchant && aelargir;i++) {
378 Standard_Real u = Echant.GetParameter(i);
379 if(Func.Value(u,dist)) {
380 if(dist>maxdist || -dist>maxdist) {
381 aelargir=Standard_False;
385 if(!(aelargir && maxdist<0.01)) {
386 maxdist = TolBoundary;
389 if (TypeQuad != GeomAbs_OtherSurface) //intersection of boundary curve and quadric surface
392 Handle(Adaptor3d_HSurface) aSurf = Func.Surface();
393 Adaptor3d_CurveOnSurface ConS(A, aSurf);
394 GeomAbs_CurveType TypeConS = ConS.GetType();
396 Handle(Geom_Curve) CurveConS;
401 CurveConS = new Geom_Line(ConS.Line());
406 CurveConS = new Geom_Circle(ConS.Circle());
409 case GeomAbs_Ellipse:
411 CurveConS = new Geom_Ellipse(ConS.Ellipse());
414 case GeomAbs_Hyperbola:
416 CurveConS = new Geom_Hyperbola(ConS.Hyperbola());
419 case GeomAbs_Parabola:
421 CurveConS = new Geom_Parabola(ConS.Parabola());
424 case GeomAbs_BezierCurve:
426 CurveConS = ConS.Bezier();
429 case GeomAbs_BSplineCurve:
431 CurveConS = ConS.BSpline();
436 Standard_Real MaxDeviation, AverageDeviation;
437 GeomLib::BuildCurve3d(1.e-5, ConS, ConS.FirstParameter(), ConS.LastParameter(),
438 CurveConS, MaxDeviation, AverageDeviation);
443 Handle(Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
444 Handle(Geom_Surface) QuadSurf;
449 QuadSurf = new Geom_Plane(aQuadric.Plane());
452 case GeomAbs_Cylinder:
454 QuadSurf = new Geom_CylindricalSurface(aQuadric.Cylinder());
459 QuadSurf = new Geom_ConicalSurface(aQuadric.Cone());
464 QuadSurf = new Geom_SphericalSurface(aQuadric.Sphere());
469 QuadSurf = new Geom_ToroidalSurface(aQuadric.Torus());
475 Handle(GeomAdaptor_HSurface) GAHsurf = new GeomAdaptor_HSurface(QuadSurf);
477 if ((TypeConS == GeomAbs_Line ||
478 TypeConS == GeomAbs_Circle ||
479 TypeConS == GeomAbs_Ellipse ||
480 TypeConS == GeomAbs_Parabola ||
481 TypeConS == GeomAbs_Hyperbola) &&
482 TypeQuad != GeomAbs_Torus &&
483 !IsDegenerated(HConS) &&
484 !IsDegenerated(aQuadric))
486 //exact intersection for only canonic curves and real quadric surfaces
487 IntCS.Perform(HConS, GAHsurf);
490 IsIntCSdone = IntCS.IsDone();
493 Nbp = IntCS.NbPoints();
494 Nbi = IntCS.NbSegments();
496 //If we have not got intersection, it may be touch with some tolerance,
498 if (Nbp == 0 && Nbi == 0)
499 IsIntCSdone = Standard_False;
501 } //if (TypeQuad != GeomAbs_OtherSurface) - intersection of boundary curve and quadric surface
505 pSol.reset(new math_FunctionAllRoots(Func,Echant,EpsX,maxdist,maxdist)); //-- TolBoundary,nTolTangency);
507 if (!pSol->IsDone()) {throw Standard_Failure();}
509 Nbp=pSol->NbPoints();
512 //jgv: build solution on the whole boundary
513 if (RecheckOnRegularity && Nbp > 0 && IsRegularity(A, Domain))
515 //Standard_Real theTol = Domain->MaxTolerance(A);
517 Standard_Real theTol = 5.e-4;
518 math_FunctionAllRoots SolAgain(Func,Echant,EpsX,theTol,theTol); //-- TolBoundary,nTolTangency);
520 if (!SolAgain.IsDone()) {throw Standard_Failure();}
522 Standard_Integer Nbi_again = SolAgain.NbIntervals();
526 Standard_Integer NbSamples = 10;
527 Standard_Real delta = (Pfin - Pdeb)/NbSamples;
528 Standard_Real GlobalTol = theTol*10;
529 Standard_Boolean SolOnBoundary = Standard_True;
530 for (i = 0; i <= NbSamples; i++)
532 Standard_Real aParam = Pdeb + i*delta;
533 Standard_Real aValue;
534 Func.Value(aParam, aValue);
535 if (Abs(aValue) > GlobalTol)
537 SolOnBoundary = Standard_False;
544 for (i = 1; i <= Nbi_again; i++)
546 IntStart_TheSegment newseg;
548 // Recuperer point debut et fin, et leur parametre.
549 SolAgain.GetInterval(i,pardeb,parfin);
551 if (Abs(pardeb - Pdeb) <= Precision::PConfusion())
553 if (Abs(parfin - Pfin) <= Precision::PConfusion())
556 SolAgain.GetIntervalState(i,ideb,ifin);
558 //-- cout<<" Debug : IntStart_SearchOnBoundaries_1.gxx : i= "<<i<<" ParDeb:"<<pardeb<<" ParFin:"<<parfin<<endl;
560 ptdeb=Func.Valpoint(ideb);
561 ptfin=Func.Valpoint(ifin);
563 PointProcess(ptdeb,pardeb,A,Domain,pnt,theTol,ranged);
564 newseg.SetLimitPoint(pnt.Value(ranged),Standard_True);
565 PointProcess(ptfin,parfin,A,Domain,pnt,theTol,rangef);
566 newseg.SetLimitPoint(pnt.Value(rangef),Standard_False);
569 Arcsol=Standard_True;
573 } //if (RecheckOnRegularity && Nbp > 0 && IsRegularity(A, Domain))
574 ////////////////////////////////////////////
576 //-- detection du cas ou la fonction est quasi tangente et que les
577 //-- zeros sont quasi confondus.
578 //-- Dans ce cas on prend le point "milieu"
579 //-- On suppose que les solutions sont triees.
582 NCollection_Array1<SolInfo> aSI(1, Nbp);
587 aSI(i).Init(IntCS, i);
589 aSI(i).Init(*pSol, i);
592 std::sort(aSI.begin(), aSI.end());
594 //modified by NIZNHY-PKV Wed Mar 21 18:34:18 2001 f
595 //////////////////////////////////////////////////////////
596 // The treatment of the situation when line(arc) that is
597 // tangent to cylinder(domain).
598 // We should have only one solution i.e Nbp=1. Ok?
599 // But we have 2,3,.. solutions. That is wrong ersult.
600 // The TreatLC(...) function is dedicated to solve the pb.
601 // PKV Fri Mar 23 12:17:29 2001
603 Standard_Integer ip = TreatLC (A, Domain, aQuadric, TolBoundary, pnt);
605 //////////////////////////////////////////////////////////
606 //modified by NIZNHY-PKV Wed Mar 21 18:34:23 2001 t
608 // Using of old usual way proposed by Laurent
611 Standard_Real parap1 = aSI(i + 1).Value();
612 para = aSI(i).Value();
614 Standard_Real param=(para+parap1)*0.5;
616 if(Func.Value(param,ym)) {
617 if(Abs(ym)<maxdist) {
618 // Modified by skv - Tue Aug 31 12:13:51 2004 OCC569 Begin
619 // Consider this interval as tangent one. Treat it to find
620 // parameter with the lowest function value.
622 // Compute the number of nodes.
623 Standard_Real aTol = TolBoundary*1000.0;
627 // fix floating point exception 569, chl-922-e9
628 parap1 = (Abs(parap1) < 1.e9) ? parap1 : ((parap1 >= 0.) ? 1.e9 : -1.e9);
629 para = (Abs(para) < 1.e9) ? para : ((para >= 0.) ? 1.e9 : -1.e9);
631 Standard_Integer aNbNodes = RealToInt(Ceiling((parap1 - para)/aTol));
633 Standard_Real aVal = RealLast();
634 //Standard_Integer aNbNodes = 23;
635 Standard_Real aDelta = (parap1 - para)/(aNbNodes + 1.);
637 Standard_Real aCurPar;
638 Standard_Real aCurVal;
640 for (ii = 0; ii <= aNbNodes + 1; ii++) {
641 aCurPar = (ii < aNbNodes + 1) ? para + ii*aDelta : parap1;
643 if (Func.Value(aCurPar, aCurVal)) {
644 //if (aCurVal < aVal) {
645 if (Abs(aCurVal) < aVal) {
652 // Modified by skv - Tue Aug 31 12:13:51 2004 OCC569 End
653 aSI(i).ChangeValue() = Pdeb - 1;
654 aSI(i + 1).ChangeValue() = param;
659 for (i=1; i<=Nbp; i++) {
660 para = aSI(i).Value();
661 if((para-Pdeb)<EpsX || (Pfin-para)<EpsX)
664 if(!Func.Value(para,dist))
669 Standard_Integer anIndx = -1;
670 //const Standard_Real aParam = Sol->GetPoint(aSI(i).Index());
671 const Standard_Real aParam = aSI(i).Value();
675 (Abs(aParam - Pdeb) <= Precision::PConfusion() || Abs(aParam - Pfin) <= Precision::PConfusion()))
677 anIndx = pSol->GetPointState(aSI(i).Index());
681 gp_Pnt aPnt(anIndx < 0 ? Func.LastComputedPoint() : Func.Valpoint(anIndx));
683 if (dist > 0.1*Precision::Confusion())
685 //Precise found points. It results in following:
686 // 1. Make the vertex nearer to the intersection line
687 // (see description to issue #27252 in order to
688 // understand necessity).
689 // 2. Merge two near vertices to single point.
691 //All members in TabSol array has already been sorted in increase order.
692 //Now, we limit precise boundaries in order to avoid changing this order.
693 const Standard_Real aFPar = (i == 1) ? Pdeb : (para + aSI(i - 1).Value()) / 2.0;
694 const Standard_Real aLPar = (i == Nbp) ? Pfin : (para + aSI(i + 1).Value()) / 2.0;
696 MinFunction aNewFunc(Func);
697 math_BrentMinimum aMin(Precision::Confusion());
699 aMin.Perform(aNewFunc, aFPar, para, aLPar);
702 para = aMin.Location();
703 const gp_Pnt2d aP2d(A->Value(para));
704 aPnt = Func.Surface()->Value(aP2d.X(), aP2d.Y());
708 PointProcess(aPnt, para, A, Domain, pnt, TolBoundary, range);
713 // Pour chaque intervalle trouve faire
714 // Traiter les extremites comme des points
715 // Ajouter intervalle dans la liste des segments
718 Nbi = pSol->NbIntervals();
720 if (!RecheckOnRegularity && Nbp) {
721 //--cout<<" Debug : IntStart_SearchOnBoundaries_1.gxx :Nbp>0 0 <- Nbi "<<Nbi<<endl;
725 //-- cout<<" Debug : IntStart_SearchOnBoundaries_1.gxx : Nbi : "<<Nbi<<endl;
727 for (i=1; i<=Nbi; i++) {
728 IntStart_TheSegment newseg;
730 // Recuperer point debut et fin, et leur parametre.
733 IntCurveSurface_IntersectionSegment IntSeg = IntCS.Segment(i);
734 IntCurveSurface_IntersectionPoint End1 = IntSeg.FirstPoint();
735 IntCurveSurface_IntersectionPoint End2 = IntSeg.SecondPoint();
743 pSol->GetInterval(i,pardeb,parfin);
744 pSol->GetIntervalState(i,ideb,ifin);
746 //-- cout<<" Debug : IntStart_SearchOnBoundaries_1.gxx : i= "<<i<<" ParDeb:"<<pardeb<<" ParFin:"<<parfin<<endl;
748 ptdeb=Func.Valpoint(ideb);
749 ptfin=Func.Valpoint(ifin);
752 PointProcess(ptdeb,pardeb,A,Domain,pnt,TolBoundary,ranged);
753 newseg.SetLimitPoint(pnt.Value(ranged),Standard_True);
754 PointProcess(ptfin,parfin,A,Domain,pnt,TolBoundary,rangef);
755 newseg.SetLimitPoint(pnt.Value(rangef),Standard_False);
760 if((Abs(pardeb - Pdeb) < Precision::PConfusion()) &&
761 (Abs(parfin - Pfin) < Precision::PConfusion()))
763 Arcsol=Standard_True;
769 //=======================================================================
770 //function : ComputeBoundsfromInfinite
772 //=======================================================================
773 // - PROVISIONAL - TEMPORARY - NOT GOOD - NYI - TO DO
774 // - Temporary - temporary - not good - nyi - to do
775 void ComputeBoundsfromInfinite(TheFunction& Func,
778 Standard_Integer& NbEchant)
781 // - We are looking for parameters for start and end of the arc (2d curve)
782 // - Infinity, a way to intersect the quadric with a portion of arc
785 // - The quadric is a plane, a cylinder, a cone and a sphere.
786 // - Idea: We take any point on the arc and the fact grow
787 // - Terminals to the signed distance function values or is likely
790 // - WARNING: The following calculations provide a very estimated coarse parameters.
791 // - This avoids the raises and allows a case of Boxes
792 // - Inifinies walk. It will take this code
793 // - With curve surface intersections.
797 Standard_Real U0 = 0.0;
798 Standard_Real dU = 0.001;
799 Standard_Real Dist0,Dist1;
801 Func.Value(U0 , Dist0);
802 Func.Value(U0+dU, Dist1);
803 Standard_Real dDist = Dist1 - Dist0;
805 U0 -= dU*Dist0 / dDist;
807 Standard_Real Umin = U0 - 1e5;
808 Func.Value(Umin , Dist0);
809 Func.Value(Umin+dU, Dist1);
812 Umin -= dU*Dist0 / dDist;
817 Standard_Real Umax = U0 + 1e8;
818 Func.Value(Umax , Dist0);
819 Func.Value(Umax+dU, Dist1);
822 Umax -= dU*Dist0 / dDist;
827 if(Umin>U0) { Umin=U0-10.0; }
828 if(Umax<U0) { Umax=U0+10.0; }
830 PFin = Umax + 10. * (Umax - Umin);
831 PDeb = Umin - 10. * (Umax - Umin);
834 //-- Possibilite de Arc totalement inclu ds Quad
840 //=======================================================================
841 //function : PointProcess
843 //=======================================================================
844 void PointProcess (const gp_Pnt& Pt,
845 const Standard_Real Para,
847 const Handle(TheTopolTool)& Domain,
848 IntStart_SequenceOfPathPoint& pnt,
849 const Standard_Real Tol,
850 Standard_Integer& Range)
853 // Check to see if a solution point is coincident with a vertex.
854 // If confused, you should find this vertex in the list of
855 // Start. It then returns the position of this point in the list pnt.
856 // Otherwise, add the point in the list.
859 Standard_Boolean found,goon;
860 Standard_Real dist,toler;
862 Standard_Integer Nbsol = pnt.Length();
864 IntStart_ThePathPoint ptsol;
866 Domain->Initialize(A);
867 Domain->InitVertexIterator();
868 found = Standard_False;
869 goon = Domain->MoreVertex();
871 vtx = Domain->Vertex();
872 dist= Abs(Para-TheSOBTool::Parameter(vtx,A));
873 toler = TheSOBTool::Tolerance(vtx,A);
876 std::cout<<"IntStart_SearchOnBoundaries_1.gxx : ** WARNING ** Tol Vertex="<<toler<<std::endl;
877 std::cout<<" Ou Edge degenere Ou Kro pointu"<<std::endl;
878 if(toler>10000) toler=1e-7;
883 // Locate the vertex in the list of solutions
887 ptsol = pnt.Value(k);
888 if (!ptsol.IsNew()) {
889 //jag 940608 if (ptsol.Vertex() == vtx && ptsol.Arc() == A) {
890 if (Domain->Identical(ptsol.Vertex(),vtx) &&
892 Abs(ptsol.Parameter()-Para) <= toler) {
905 if (k<=Nbsol) { // We find the vertex
909 ptsol.SetValue(Pt,Tol,vtx,A,Para);
911 Range = pnt.Length();
913 found = Standard_True;
914 goon = Standard_False;
917 Domain->NextVertex();
918 goon = Domain->MoreVertex();
922 if (!found) { // No one is falling on a vertex
923 //jgv: do not add segment's extremities if they already exist
924 Standard_Boolean found_internal = Standard_False;
925 for (k = 1; k <= pnt.Length(); k++)
927 ptsol = pnt.Value(k);
928 if (ptsol.Arc() != A ||
929 !ptsol.IsNew()) //vertex
931 if (Abs(ptsol.Parameter()-Para) <= Precision::PConfusion())
933 found_internal = Standard_True;
937 /////////////////////////////////////////////////////////////
941 Standard_Real TOL=Tol;
943 //if(TOL>0.001) TOL=0.001;
944 if(TOL>0.005) TOL=0.005; //#24643
946 ptsol.SetValue(Pt,TOL,A,Para);
948 Range = pnt.Length();
953 //=======================================================================
954 //function : IsRegularity
956 //=======================================================================
957 Standard_Boolean IsRegularity(const TheArc& /*A*/,
958 const Handle(TheTopolTool)& aDomain)
960 Standard_Address anEAddress=aDomain->Edge();
961 if (anEAddress==NULL) {
962 return Standard_False;
965 TopoDS_Edge* anE=(TopoDS_Edge*)anEAddress;
967 return (BRep_Tool::HasContinuity(*anE));
970 //=======================================================================
973 //=======================================================================
974 Standard_Integer TreatLC (const TheArc& A,
975 const Handle(TheTopolTool)& aDomain,
976 const IntSurf_Quadric& aQuadric,
977 const Standard_Real TolBoundary,
978 IntStart_SequenceOfPathPoint& pnt)
980 Standard_Integer anExitCode=1, aNbExt;
982 Standard_Address anEAddress=aDomain->Edge();
983 if (anEAddress==NULL) {
987 TopoDS_Edge* anE=(TopoDS_Edge*)anEAddress;
989 if (BRep_Tool::Degenerated(*anE)) {
993 GeomAbs_CurveType aTypeE;
994 BRepAdaptor_Curve aBAC(*anE);
995 aTypeE=aBAC.GetType();
997 if (aTypeE!=GeomAbs_Line) {
1001 GeomAbs_SurfaceType aTypeS;
1002 aTypeS=aQuadric.TypeQuadric();
1004 if (aTypeS!=GeomAbs_Cylinder) {
1008 Standard_Real f, l, U1f, U1l, U2f, U2l, UEgde, TOL, aDist, aR, aRRel, Tol;
1009 Handle(Geom_Curve) aCEdge=BRep_Tool::Curve(*anE, f, l);
1011 gp_Cylinder aCyl=aQuadric.Cylinder();
1012 const gp_Ax1& anAx1=aCyl.Axis();
1014 Handle(Geom_Line) aCAxis=new Geom_Line (aLin);
1017 U1f = aCAxis->FirstParameter();
1018 U1l = aCAxis->LastParameter();
1020 U2f = aCEdge->FirstParameter();
1021 U2l = aCEdge->LastParameter();
1024 GeomAdaptor_Curve C1, C2;
1029 Tol = Precision::PConfusion();
1031 Extrema_ExtCC anExtCC(C1, C2, U1f, U1l, U2f, U2l, Tol, Tol);
1033 aNbExt=anExtCC.NbExt();
1039 Extrema_POnCurv PC1, PC2;
1041 anExtCC.Points(1, PC1, PC2);
1046 UEgde=PC2.Parameter();
1048 aDist=PEdge.Distance(P1);
1049 aRRel=fabs(aDist-aR)/aR;
1050 if (aRRel > TolBoundary) {
1054 if (UEgde < (f+TolBoundary) || UEgde > (l-TolBoundary)) {
1059 // It was done as into PointProcess(...) function
1060 //printf("TreatLC()=> tangent line is found\n");
1061 TOL=1000.*TolBoundary;
1062 if(TOL>0.001) TOL=0.001;
1064 IntStart_ThePathPoint ptsol;
1065 ptsol.SetValue(PEdge, TOL, A, UEgde);
1074 //=======================================================================
1075 //function : IntStart_SearchOnBoundaries::IntStart_SearchOnBoundaries
1077 //=======================================================================
1078 IntStart_SearchOnBoundaries::IntStart_SearchOnBoundaries ()
1079 : done(Standard_False),
1084 //=======================================================================
1085 //function : Perform
1087 //=======================================================================
1088 void IntStart_SearchOnBoundaries::Perform (TheFunction& Func,
1089 const Handle(TheTopolTool)& Domain,
1090 const Standard_Real TolBoundary,
1091 const Standard_Real TolTangency,
1092 const Standard_Boolean RecheckOnRegularity)
1095 done = Standard_False;
1099 Standard_Boolean Arcsol;
1100 Standard_Real PDeb,PFin, prm, tol;
1101 Standard_Integer i, nbknown, nbfound,index;
1106 if (Domain->More()) {
1107 all = Standard_True;
1110 all = Standard_False;
1113 while (Domain->More()) {
1114 TheArc A = Domain->Value();
1115 if (!TheSOBTool::HasBeenSeen(A)) {
1117 FindVertex(A,Domain,Func,spnt,TolBoundary);
1118 TheSOBTool::Bounds(A,PDeb,PFin);
1119 if(Precision::IsNegativeInfinite(PDeb) ||
1120 Precision::IsPositiveInfinite(PFin)) {
1121 Standard_Integer NbEchant;
1122 ComputeBoundsfromInfinite(Func,PDeb,PFin,NbEchant);
1124 BoundedArc(A,Domain,PDeb,PFin,Func,spnt,sseg,TolBoundary,TolTangency,Arcsol,RecheckOnRegularity);
1125 all = (all && Arcsol);
1129 // as it seems we'll never be here, because
1130 // TheSOBTool::HasBeenSeen(A) always returns FALSE
1131 nbfound = spnt.Length();
1133 // On recupere les points connus
1134 nbknown = TheSOBTool::NbPoints(A);
1135 for (i=1; i<=nbknown; i++) {
1136 TheSOBTool::Value(A,i,pt,tol,prm);
1137 if (TheSOBTool::IsVertex(A,i)) {
1139 TheSOBTool::Vertex(A,i,vtx);
1140 spnt.Append(IntStart_ThePathPoint(pt,tol,vtx,A,prm));
1143 spnt.Append(IntStart_ThePathPoint(pt,tol,A,prm));
1146 // On recupere les arcs solutions
1147 nbknown = TheSOBTool::NbSegments(A);
1148 for (i=1; i<=nbknown; i++) {
1149 IntStart_TheSegment newseg;
1151 if (TheSOBTool::HasFirstPoint(A,i,index)) {
1152 newseg.SetLimitPoint(spnt.Value(nbfound+index),Standard_True);
1154 if (TheSOBTool::HasLastPoint(A,i,index)) {
1155 newseg.SetLimitPoint(spnt.Value(nbfound+index),Standard_False);
1157 sseg.Append(newseg);
1159 all = (all& TheSOBTool::IsAllSolution(A));
1163 done = Standard_True;