1 // Created on: 1991-12-02
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1991-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 #ifndef _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile
18 #define _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <AppParCurves_Constraint.hxx>
25 #include <AppParCurves_MultiBSpCurve.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <TColStd_HArray1OfInteger.hxx>
28 #include <math_Matrix.hxx>
29 #include <math_Vector.hxx>
30 #include <math_IntegerVector.hxx>
31 #include <Standard_Integer.hxx>
32 #include <TColStd_Array1OfReal.hxx>
33 #include <TColStd_Array1OfInteger.hxx>
34 class StdFail_NotDone;
35 class Standard_OutOfRange;
36 class Standard_DimensionError;
37 class Standard_NoSuchObject;
38 class AppDef_MultiLine;
39 class AppDef_MyLineTool;
40 class AppParCurves_MultiCurve;
41 class AppParCurves_MultiBSpCurve;
46 class AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute
53 //! given a MultiLine, this algorithm computes the least
54 //! square resolution using the Householder-QR method.
55 //! If the first and/or the last point is a constraint
56 //! point, the value of the tangency or curvature is
57 //! computed in the resolution.
58 //! NbPol is the number of control points wanted
59 //! for the approximating curves.
60 //! The system to solve is the following:
62 //! Where A is the Bernstein matrix computed with the
63 //! parameters, B the points coordinates and X the poles
65 //! The matrix A is the same for each coordinate x, y and z
66 //! and is also the same for each MultiLine point because
67 //! they are approximated in parallel(so with the same
68 //! parameter, only the vector B changes).
69 Standard_EXPORT AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute(const AppDef_MultiLine& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const math_Vector& Parameters, const Standard_Integer NbPol);
71 //! Initializes the fields of the object.
72 Standard_EXPORT AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute(const AppDef_MultiLine& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const Standard_Integer NbPol);
74 //! given a MultiLine, this algorithm computes the least
75 //! square resolution using the Householder-QR method.
76 //! If the first and/or the last point is a constraint
77 //! point, the value of the tangency or curvature is
78 //! computed in the resolution.
79 //! Deg is the degree wanted for the approximating curves.
80 //! The system to solve is the following:
82 //! Where A is the BSpline functions matrix computed with
83 //! <parameters>, B the points coordinates and X the poles
85 //! The matrix A is the same for each coordinate x, y and z
86 //! and is also the same for each MultiLine point because
87 //! they are approximated in parallel(so with the same
88 //! parameter, only the vector B changes).
89 Standard_EXPORT AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute(const AppDef_MultiLine& SSP, const TColStd_Array1OfReal& Knots, const TColStd_Array1OfInteger& Mults, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const math_Vector& Parameters, const Standard_Integer NbPol);
91 //! Initializes the fields of the object.
92 Standard_EXPORT AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute(const AppDef_MultiLine& SSP, const TColStd_Array1OfReal& Knots, const TColStd_Array1OfInteger& Mults, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const Standard_Integer NbPol);
94 //! Is used after having initialized the fields.
95 //! The case "CurvaturePoint" is not treated in this method.
96 Standard_EXPORT void Perform (const math_Vector& Parameters);
98 //! Is used after having initialized the fields.
99 Standard_EXPORT void Perform (const math_Vector& Parameters, const Standard_Real l1, const Standard_Real l2);
101 //! Is used after having initialized the fields.
102 //! <V1t> is the tangent vector at the first point.
103 //! <V2t> is the tangent vector at the last point.
104 Standard_EXPORT void Perform (const math_Vector& Parameters, const math_Vector& V1t, const math_Vector& V2t, const Standard_Real l1, const Standard_Real l2);
106 //! Is used after having initialized the fields.
107 //! <V1t> is the tangent vector at the first point.
108 //! <V2t> is the tangent vector at the last point.
109 //! <V1c> is the tangent vector at the first point.
110 //! <V2c> is the tangent vector at the last point.
111 Standard_EXPORT void Perform (const math_Vector& Parameters, const math_Vector& V1t, const math_Vector& V2t, const math_Vector& V1c, const math_Vector& V2c, const Standard_Real l1, const Standard_Real l2);
113 //! returns True if all has been correctly done.
114 Standard_EXPORT Standard_Boolean IsDone() const;
116 //! returns the result of the approximation, i.e. all the
118 //! An exception is raised if NotDone.
119 Standard_EXPORT AppParCurves_MultiCurve BezierValue();
121 //! returns the result of the approximation, i.e. all the
123 //! An exception is raised if NotDone.
124 Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue();
126 //! returns the function matrix used to approximate the
128 Standard_EXPORT const math_Matrix& FunctionMatrix() const;
130 //! returns the derivative function matrix used
131 //! to approximate the set.
132 Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const;
134 //! returns the maximum errors between the MultiLine
135 //! and the approximation curves. F is the sum of the square
136 //! distances. Grad is the derivative vector of the
138 Standard_EXPORT void ErrorGradient (math_Vector& Grad, Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
140 //! returns the distances between the points of the
141 //! multiline and the approximation curves.
142 Standard_EXPORT const math_Matrix& Distance();
144 //! returns the maximum errors between the MultiLine
145 //! and the approximation curves. F is the sum of the square
147 Standard_EXPORT void Error (Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
149 //! returns the value (P2 - P1)/ V1 if the first point
150 //! was a tangency point.
151 Standard_EXPORT Standard_Real FirstLambda() const;
153 //! returns the value (PN - PN-1)/ VN if the last point
154 //! was a tangency point.
155 Standard_EXPORT Standard_Real LastLambda() const;
157 //! returns the matrix of points value.
158 Standard_EXPORT const math_Matrix& Points() const;
160 //! returns the matrix of resulting control points value.
161 Standard_EXPORT const math_Matrix& Poles() const;
163 //! Returns the indexes of the first non null values of
165 //! The values are non null from Index(ieme point) +1
166 //! to Index(ieme point) + degree +1.
167 Standard_EXPORT const math_IntegerVector& KIndex() const;
175 //! is used by the constructors above.
176 Standard_EXPORT void Init (const AppDef_MultiLine& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint);
178 //! returns the number of second member columns.
179 //! Is used internally to initialize the fields.
180 Standard_EXPORT Standard_Integer NbBColumns (const AppDef_MultiLine& SSP) const;
182 //! returns the first point being fitted.
183 Standard_EXPORT Standard_Integer TheFirstPoint (const AppParCurves_Constraint FirstCons, const Standard_Integer FirstPoint) const;
185 //! returns the last point being fitted.
186 Standard_EXPORT Standard_Integer TheLastPoint (const AppParCurves_Constraint LastCons, const Standard_Integer LastPoint) const;
188 //! Affects the fields in the case of a constraint point.
189 Standard_EXPORT void Affect (const AppDef_MultiLine& SSP, const Standard_Integer Index, AppParCurves_Constraint& Cons, math_Vector& Vt, math_Vector& Vc);
191 Standard_EXPORT void ComputeFunction (const math_Vector& Parameters);
193 Standard_EXPORT void SearchIndex (math_IntegerVector& Index);
195 //! computes internal matrixes for the resolution
196 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Vector& TheB);
198 //! computes internal matrixes for the resolution
199 Standard_EXPORT void MakeTAA (math_Vector& TheA);
201 //! computes internal matrixes for the resolution
202 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Matrix& TheB);
211 AppParCurves_Constraint FirstConstraint;
212 AppParCurves_Constraint LastConstraint;
213 AppParCurves_MultiBSpCurve SCU;
214 Handle(TColStd_HArray1OfReal) myknots;
215 Handle(TColStd_HArray1OfInteger) mymults;
220 math_Matrix mypoints;
221 math_Vector Vflatknots;
226 math_Matrix theError;
227 math_IntegerVector myindex;
228 Standard_Real lambda1;
229 Standard_Real lambda2;
230 Standard_Integer FirstP;
231 Standard_Integer LastP;
232 Standard_Integer Nlignes;
233 Standard_Integer Ninc;
235 Standard_Integer myfirstp;
236 Standard_Integer mylastp;
237 Standard_Integer resinit;
238 Standard_Integer resfin;
239 Standard_Integer nbP2d;
240 Standard_Integer nbP;
241 Standard_Integer nbpoles;
242 Standard_Integer deg;
243 Standard_Boolean done;
244 Standard_Boolean iscalculated;
245 Standard_Boolean isready;
256 #endif // _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile