0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / AppDef / AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute.hxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile
18 #define _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
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;
42 class math_Matrix;
43
44
45
46 class AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute 
47 {
48 public:
49
50   DEFINE_STANDARD_ALLOC
51
52   
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:
61   //! A X = B.
62   //! Where A is the Bernstein matrix computed with the
63   //! parameters, B the points coordinates and X the poles
64   //! solutions.
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);
70   
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);
73   
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:
81   //! A X = B.
82   //! Where A is the BSpline functions matrix computed with
83   //! <parameters>, B the points coordinates and X the poles
84   //! solutions.
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);
90   
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);
93   
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);
97   
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);
100   
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);
105   
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);
112   
113   //! returns True if all has been correctly done.
114   Standard_EXPORT Standard_Boolean IsDone() const;
115   
116   //! returns the result of the approximation, i.e. all the
117   //! Curves.
118   //! An exception is raised if NotDone.
119   Standard_EXPORT AppParCurves_MultiCurve BezierValue();
120   
121   //! returns the result of the approximation, i.e. all the
122   //! Curves.
123   //! An exception is raised if NotDone.
124   Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue();
125   
126   //! returns the function matrix used to approximate the
127   //! set.
128   Standard_EXPORT const math_Matrix& FunctionMatrix() const;
129   
130   //! returns the derivative function matrix used
131   //! to approximate the set.
132   Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const;
133   
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
137   //! function F.
138   Standard_EXPORT void ErrorGradient (math_Vector& Grad, Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
139   
140   //! returns the distances between the points of the
141   //! multiline and the approximation curves.
142   Standard_EXPORT const math_Matrix& Distance();
143   
144   //! returns the maximum errors between the MultiLine
145   //! and the approximation curves. F is the sum of the square
146   //! distances.
147   Standard_EXPORT void Error (Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
148   
149   //! returns the value (P2 - P1)/ V1 if the first point
150   //! was a tangency point.
151   Standard_EXPORT Standard_Real FirstLambda() const;
152   
153   //! returns the value (PN - PN-1)/ VN if the last point
154   //! was a tangency point.
155   Standard_EXPORT Standard_Real LastLambda() const;
156   
157   //! returns the matrix of points value.
158   Standard_EXPORT const math_Matrix& Points() const;
159   
160   //! returns the matrix of resulting control points value.
161   Standard_EXPORT const math_Matrix& Poles() const;
162   
163   //! Returns the indexes of the first non null values of
164   //! A and DA.
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;
168
169
170
171
172 protected:
173
174   
175   //! is used by the constructors above.
176   Standard_EXPORT void Init (const AppDef_MultiLine& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint);
177   
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;
181   
182   //! returns the first point being fitted.
183   Standard_EXPORT Standard_Integer TheFirstPoint (const AppParCurves_Constraint FirstCons, const Standard_Integer FirstPoint) const;
184   
185   //! returns the last point being fitted.
186   Standard_EXPORT Standard_Integer TheLastPoint (const AppParCurves_Constraint LastCons, const Standard_Integer LastPoint) const;
187   
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);
190   
191   Standard_EXPORT void ComputeFunction (const math_Vector& Parameters);
192   
193   Standard_EXPORT void SearchIndex (math_IntegerVector& Index);
194   
195   //! computes internal matrixes for the resolution
196   Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Vector& TheB);
197   
198   //! computes internal matrixes for the resolution
199   Standard_EXPORT void MakeTAA (math_Vector& TheA);
200   
201   //! computes internal matrixes for the resolution
202   Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Matrix& TheB);
203
204
205
206
207 private:
208
209
210
211   AppParCurves_Constraint FirstConstraint;
212   AppParCurves_Constraint LastConstraint;
213   AppParCurves_MultiBSpCurve SCU;
214   Handle(TColStd_HArray1OfReal) myknots;
215   Handle(TColStd_HArray1OfInteger) mymults;
216   math_Matrix mypoles;
217   math_Matrix A;
218   math_Matrix DA;
219   math_Matrix B2;
220   math_Matrix mypoints;
221   math_Vector Vflatknots;
222   math_Vector Vec1t;
223   math_Vector Vec1c;
224   math_Vector Vec2t;
225   math_Vector Vec2c;
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;
234   Standard_Integer NA;
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;
246
247
248 };
249
250
251
252
253
254
255
256 #endif // _AppDef_BSpParLeastSquareOfMyBSplGradientOfBSplineCompute_HeaderFile