1 // Created on: 1995-06-06
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-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 _BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox_HeaderFile
18 #define _BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox_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_Real.hxx>
32 #include <Standard_Integer.hxx>
33 #include <Standard_Boolean.hxx>
34 #include <TColStd_Array1OfReal.hxx>
35 #include <TColStd_Array1OfInteger.hxx>
36 class StdFail_NotDone;
37 class Standard_OutOfRange;
38 class Standard_DimensionError;
39 class Standard_NoSuchObject;
40 class BRepApprox_TheMultiLineOfApprox;
41 class BRepApprox_TheMultiLineToolOfApprox;
42 class AppParCurves_MultiCurve;
43 class AppParCurves_MultiBSpCurve;
48 class BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox
55 //! given a MultiLine, this algorithm computes the least
56 //! square resolution using the Householder-QR method.
57 //! If the first and/or the last point is a constraint
58 //! point, the value of the tangency or curvature is
59 //! computed in the resolution.
60 //! NbPol is the number of control points wanted
61 //! for the approximating curves.
62 //! The system to solve is the following:
64 //! Where A is the Bernstein matrix computed with the
65 //! parameters, B the points coordinates and X the poles
67 //! The matrix A is the same for each coordinate x, y and z
68 //! and is also the same for each MultiLine point because
69 //! they are approximated in parallel(so with the same
70 //! parameter, only the vector B changes).
71 Standard_EXPORT BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox(const BRepApprox_TheMultiLineOfApprox& 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);
73 //! Initializes the fields of the object.
74 Standard_EXPORT BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox(const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const Standard_Integer NbPol);
76 //! given a MultiLine, this algorithm computes the least
77 //! square resolution using the Householder-QR method.
78 //! If the first and/or the last point is a constraint
79 //! point, the value of the tangency or curvature is
80 //! computed in the resolution.
81 //! Deg is the degree wanted for the approximating curves.
82 //! The system to solve is the following:
84 //! Where A is the BSpline functions matrix computed with
85 //! <parameters>, B the points coordinates and X the poles
87 //! The matrix A is the same for each coordinate x, y and z
88 //! and is also the same for each MultiLine point because
89 //! they are approximated in parallel(so with the same
90 //! parameter, only the vector B changes).
91 Standard_EXPORT BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox(const BRepApprox_TheMultiLineOfApprox& 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);
93 //! Initializes the fields of the object.
94 Standard_EXPORT BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox(const BRepApprox_TheMultiLineOfApprox& 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);
96 //! Is used after having initialized the fields.
97 //! The case "CurvaturePoint" is not treated in this method.
98 Standard_EXPORT void Perform (const math_Vector& Parameters);
100 //! Is used after having initialized the fields.
101 Standard_EXPORT void Perform (const math_Vector& Parameters, const Standard_Real l1, const Standard_Real l2);
103 //! Is used after having initialized the fields.
104 //! <V1t> is the tangent vector at the first point.
105 //! <V2t> is the tangent vector at the last point.
106 Standard_EXPORT void Perform (const math_Vector& Parameters, const math_Vector& V1t, const math_Vector& V2t, const Standard_Real l1, const Standard_Real l2);
108 //! Is used after having initialized the fields.
109 //! <V1t> is the tangent vector at the first point.
110 //! <V2t> is the tangent vector at the last point.
111 //! <V1c> is the tangent vector at the first point.
112 //! <V2c> is the tangent vector at the last point.
113 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);
115 //! returns True if all has been correctly done.
116 Standard_EXPORT Standard_Boolean IsDone() const;
118 //! returns the result of the approximation, i.e. all the
120 //! An exception is raised if NotDone.
121 Standard_EXPORT AppParCurves_MultiCurve BezierValue();
123 //! returns the result of the approximation, i.e. all the
125 //! An exception is raised if NotDone.
126 Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue();
128 //! returns the function matrix used to approximate the
130 Standard_EXPORT const math_Matrix& FunctionMatrix() const;
132 //! returns the derivative function matrix used
133 //! to approximate the set.
134 Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const;
136 //! returns the maximum errors between the MultiLine
137 //! and the approximation curves. F is the sum of the square
138 //! distances. Grad is the derivative vector of the
140 Standard_EXPORT void ErrorGradient (math_Vector& Grad, Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
142 //! returns the distances between the points of the
143 //! multiline and the approximation curves.
144 Standard_EXPORT const math_Matrix& Distance();
146 //! returns the maximum errors between the MultiLine
147 //! and the approximation curves. F is the sum of the square
149 Standard_EXPORT void Error (Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
151 //! returns the value (P2 - P1)/ V1 if the first point
152 //! was a tangency point.
153 Standard_EXPORT Standard_Real FirstLambda() const;
155 //! returns the value (PN - PN-1)/ VN if the last point
156 //! was a tangency point.
157 Standard_EXPORT Standard_Real LastLambda() const;
159 //! returns the matrix of points value.
160 Standard_EXPORT const math_Matrix& Points() const;
162 //! returns the matrix of resulting control points value.
163 Standard_EXPORT const math_Matrix& Poles() const;
165 //! Returns the indexes of the first non null values of
167 //! The values are non null from Index(ieme point) +1
168 //! to Index(ieme point) + degree +1.
169 Standard_EXPORT const math_IntegerVector& KIndex() const;
177 //! is used by the constuctors above.
178 Standard_EXPORT void Init (const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint);
180 //! returns the number of second member columns.
181 //! Is used internally to initialize the fields.
182 Standard_EXPORT Standard_Integer NbBColumns (const BRepApprox_TheMultiLineOfApprox& SSP) const;
184 //! returns the first point beeing fitted.
185 Standard_EXPORT Standard_Integer TheFirstPoint (const AppParCurves_Constraint FirstCons, const Standard_Integer FirstPoint) const;
187 //! returns the last point beeing fitted.
188 Standard_EXPORT Standard_Integer TheLastPoint (const AppParCurves_Constraint LastCons, const Standard_Integer LastPoint) const;
190 //! Affects the fields in the case of a constraint point.
191 Standard_EXPORT void Affect (const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer Index, AppParCurves_Constraint& Cons, math_Vector& Vt, math_Vector& Vc);
193 Standard_EXPORT void ComputeFunction (const math_Vector& Parameters);
195 Standard_EXPORT void SearchIndex (math_IntegerVector& Index);
197 //! computes internal matrixes for the resolution
198 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Vector& TheB);
200 //! computes internal matrixes for the resolution
201 Standard_EXPORT void MakeTAA (math_Vector& TheA);
203 //! computes internal matrixes for the resolution
204 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Matrix& TheB);
213 AppParCurves_Constraint FirstConstraint;
214 AppParCurves_Constraint LastConstraint;
215 AppParCurves_MultiBSpCurve SCU;
216 Handle(TColStd_HArray1OfReal) myknots;
217 Handle(TColStd_HArray1OfInteger) mymults;
222 math_Matrix mypoints;
223 math_Vector Vflatknots;
228 math_Matrix theError;
229 math_IntegerVector myindex;
230 Standard_Real lambda1;
231 Standard_Real lambda2;
232 Standard_Integer FirstP;
233 Standard_Integer LastP;
234 Standard_Integer Nlignes;
235 Standard_Integer Ninc;
237 Standard_Integer myfirstp;
238 Standard_Integer mylastp;
239 Standard_Integer resinit;
240 Standard_Integer resfin;
241 Standard_Integer nbP2d;
242 Standard_Integer nbP;
243 Standard_Integer nbpoles;
244 Standard_Integer deg;
245 Standard_Boolean done;
246 Standard_Boolean iscalculated;
247 Standard_Boolean isready;
258 #endif // _BRepApprox_ParLeastSquareOfMyGradientbisOfTheComputeLineOfApprox_HeaderFile