1 // Created on: 1997-09-11
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 <Geom2dConvert_ApproxCurve.ixx>
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Vec2d.hxx>
20 #include <Geom2dAdaptor_HCurve.hxx>
21 #include <TColStd_HArray1OfReal.hxx>
22 #include <AdvApprox_PrefAndRec.hxx>
23 #include <AdvApprox_ApproxAFunction.hxx>
24 #include <TColgp_Array1OfPnt2d.hxx>
25 #include <Precision.hxx>
27 //=======================================================================
28 //class : Geom2dConvert_ApproxCurve_Eval
29 //purpose: evaluator class for approximation
30 //=======================================================================
32 class Geom2dConvert_ApproxCurve_Eval : public AdvApprox_EvaluatorFunction
35 Geom2dConvert_ApproxCurve_Eval (const Handle(Adaptor2d_HCurve2d)& theFunc,
36 Standard_Real First, Standard_Real Last)
37 : fonct(theFunc) { StartEndSav[0] = First; StartEndSav[1] = Last; }
39 virtual void Evaluate (Standard_Integer *Dimension,
40 Standard_Real StartEnd[2],
41 Standard_Real *Parameter,
42 Standard_Integer *DerivativeRequest,
43 Standard_Real *Result, // [Dimension]
44 Standard_Integer *ErrorCode);
47 Handle(Adaptor2d_HCurve2d) fonct;
48 Standard_Real StartEndSav[2];
51 void Geom2dConvert_ApproxCurve_Eval::Evaluate (Standard_Integer *Dimension,
52 Standard_Real StartEnd[2],
53 Standard_Real *Param, // Parameter at which evaluation
54 Standard_Integer *Order, // Derivative Request
55 Standard_Real *Result,// [Dimension]
56 Standard_Integer *ErrorCode)
59 Standard_Real par = *Param;
61 // Dimension is incorrect
65 // Parameter is incorrect
66 if ( par < StartEnd[0] || par > StartEnd[1] ) {
69 if(StartEnd[0] != StartEndSav[0] || StartEnd[1]!= StartEndSav[1])
71 fonct = fonct->Trim(StartEnd[0],StartEnd[1],Precision::PConfusion());
72 StartEndSav[0]=StartEnd[0];
73 StartEndSav[1]=StartEnd[1];
81 pnt = fonct->Value(par);
86 fonct->D1(par, pnt, v1);
91 fonct->D2(par, pnt, v1, v2);
96 Result[0] = Result[1] = 0.;
102 Geom2dConvert_ApproxCurve::Geom2dConvert_ApproxCurve(const Handle(Geom2d_Curve)& Curve,const Standard_Real Tol2d,const GeomAbs_Shape Order,const Standard_Integer MaxSegments,const Standard_Integer MaxDegree)
104 Handle(Geom2dAdaptor_HCurve) HCurve = new Geom2dAdaptor_HCurve (Curve);
105 Approximate(HCurve, Tol2d, Order, MaxSegments, MaxDegree);
108 Geom2dConvert_ApproxCurve::Geom2dConvert_ApproxCurve(const Handle(Adaptor2d_HCurve2d)& Curve,
109 const Standard_Real Tol2d,
110 const GeomAbs_Shape Order,
111 const Standard_Integer MaxSegments,
112 const Standard_Integer MaxDegree)
114 Approximate(Curve, Tol2d, Order, MaxSegments, MaxDegree);
117 void Geom2dConvert_ApproxCurve::Approximate(const Handle(Adaptor2d_HCurve2d)& theCurve,
118 const Standard_Real theTol2d,
119 const GeomAbs_Shape theOrder,
120 const Standard_Integer theMaxSegments,
121 const Standard_Integer theMaxDegree)
123 // Initialisation of input parameters of AdvApprox
125 Standard_Integer Num1DSS=0, Num2DSS=1, Num3DSS=0;
126 Handle(TColStd_HArray1OfReal) OneDTolNul, ThreeDTolNul;
127 Handle(TColStd_HArray1OfReal) TwoDTol = new TColStd_HArray1OfReal(1,Num2DSS);
128 TwoDTol->Init(theTol2d);
130 Standard_Real First = theCurve->FirstParameter();
131 Standard_Real Last = theCurve->LastParameter();
133 Standard_Integer NbInterv_C2 = theCurve->NbIntervals(GeomAbs_C2);
134 TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2+1);
135 theCurve->Intervals(CutPnts_C2,GeomAbs_C2);
136 Standard_Integer NbInterv_C3 = theCurve->NbIntervals(GeomAbs_C3);
137 TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3+1);
138 theCurve->Intervals(CutPnts_C3,GeomAbs_C3);
139 AdvApprox_PrefAndRec CutTool(CutPnts_C2,CutPnts_C3);
143 Geom2dConvert_ApproxCurve_Eval ev (theCurve, First, Last);
144 AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
145 OneDTolNul, TwoDTol, ThreeDTolNul,
146 First, Last, theOrder,
147 theMaxDegree, theMaxSegments,
150 myIsDone = aApprox.IsDone();
151 myHasResult = aApprox.HasResult();
154 TColgp_Array1OfPnt2d Poles(1,aApprox.NbPoles());
155 aApprox.Poles2d(1,Poles);
156 Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
157 Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
158 Standard_Integer Degree = aApprox.Degree();
159 myBSplCurve = new Geom2d_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
160 myMaxError = aApprox.MaxError(2, 1);
164 Handle(Geom2d_BSplineCurve) Geom2dConvert_ApproxCurve::Curve() const
169 Standard_Boolean Geom2dConvert_ApproxCurve::IsDone() const
174 Standard_Boolean Geom2dConvert_ApproxCurve::HasResult() const
179 Standard_Real Geom2dConvert_ApproxCurve::MaxError() const
184 void Geom2dConvert_ApproxCurve::Dump(Standard_OStream& o) const
186 o << "******* Dump of ApproxCurve *******" << endl;
187 o << "******* Error " << MaxError() << endl;