0026431: Can't cut a sphere from a cylinder
[occt.git] / src / BRepApprox / BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox.hxx
CommitLineData
42cf5bc1 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
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 _BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox_HeaderFile
18#define _BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox_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_Real.hxx>
32#include <Standard_Integer.hxx>
33#include <Standard_Boolean.hxx>
34#include <TColStd_Array1OfReal.hxx>
35#include <TColStd_Array1OfInteger.hxx>
36class StdFail_NotDone;
37class Standard_OutOfRange;
38class Standard_DimensionError;
39class Standard_NoSuchObject;
40class BRepApprox_TheMultiLineOfApprox;
41class BRepApprox_TheMultiLineToolOfApprox;
42class AppParCurves_MultiCurve;
43class AppParCurves_MultiBSpCurve;
44class math_Matrix;
45
46
47
48class BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox
49{
50public:
51
52 DEFINE_STANDARD_ALLOC
53
54
36b9ff75 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:
63 //! A X = B.
64 //! Where A is the Bernstein matrix computed with the
65 //! parameters, B the points coordinates and X the poles
66 //! solutions.
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).
42cf5bc1 71 Standard_EXPORT BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox(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);
72
36b9ff75 73 //! Initializes the fields of the object.
42cf5bc1 74 Standard_EXPORT BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox(const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const Standard_Integer NbPol);
75
36b9ff75 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:
83 //! A X = B.
84 //! Where A is the BSpline functions matrix computed with
85 //! <parameters>, B the points coordinates and X the poles
86 //! solutions.
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).
42cf5bc1 91 Standard_EXPORT BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox(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);
92
36b9ff75 93 //! Initializes the fields of the object.
42cf5bc1 94 Standard_EXPORT BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox(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);
95
36b9ff75 96 //! Is used after having initialized the fields.
97 //! The case "CurvaturePoint" is not treated in this method.
42cf5bc1 98 Standard_EXPORT void Perform (const math_Vector& Parameters);
99
36b9ff75 100 //! Is used after having initialized the fields.
42cf5bc1 101 Standard_EXPORT void Perform (const math_Vector& Parameters, const Standard_Real l1, const Standard_Real l2);
102
36b9ff75 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.
42cf5bc1 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);
107
36b9ff75 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.
42cf5bc1 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);
114
36b9ff75 115 //! returns True if all has been correctly done.
42cf5bc1 116 Standard_EXPORT Standard_Boolean IsDone() const;
117
36b9ff75 118 //! returns the result of the approximation, i.e. all the
119 //! Curves.
120 //! An exception is raised if NotDone.
42cf5bc1 121 Standard_EXPORT AppParCurves_MultiCurve BezierValue();
122
36b9ff75 123 //! returns the result of the approximation, i.e. all the
124 //! Curves.
125 //! An exception is raised if NotDone.
42cf5bc1 126 Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue();
127
36b9ff75 128 //! returns the function matrix used to approximate the
129 //! set.
42cf5bc1 130 Standard_EXPORT const math_Matrix& FunctionMatrix() const;
131
36b9ff75 132 //! returns the derivative function matrix used
133 //! to approximate the set.
42cf5bc1 134 Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const;
135
36b9ff75 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
139 //! function F.
42cf5bc1 140 Standard_EXPORT void ErrorGradient (math_Vector& Grad, Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
141
36b9ff75 142 //! returns the distances between the points of the
143 //! multiline and the approximation curves.
42cf5bc1 144 Standard_EXPORT const math_Matrix& Distance();
145
36b9ff75 146 //! returns the maximum errors between the MultiLine
147 //! and the approximation curves. F is the sum of the square
148 //! distances.
42cf5bc1 149 Standard_EXPORT void Error (Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
150
36b9ff75 151 //! returns the value (P2 - P1)/ V1 if the first point
152 //! was a tangency point.
42cf5bc1 153 Standard_EXPORT Standard_Real FirstLambda() const;
154
36b9ff75 155 //! returns the value (PN - PN-1)/ VN if the last point
156 //! was a tangency point.
42cf5bc1 157 Standard_EXPORT Standard_Real LastLambda() const;
158
36b9ff75 159 //! returns the matrix of points value.
42cf5bc1 160 Standard_EXPORT const math_Matrix& Points() const;
161
36b9ff75 162 //! returns the matrix of resulting control points value.
42cf5bc1 163 Standard_EXPORT const math_Matrix& Poles() const;
164
36b9ff75 165 //! Returns the indexes of the first non null values of
166 //! A and DA.
167 //! The values are non null from Index(ieme point) +1
168 //! to Index(ieme point) + degree +1.
42cf5bc1 169 Standard_EXPORT const math_IntegerVector& KIndex() const;
170
171
172
173
174protected:
175
176
36b9ff75 177 //! is used by the constuctors above.
42cf5bc1 178 Standard_EXPORT void Init (const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint);
179
36b9ff75 180 //! returns the number of second member columns.
181 //! Is used internally to initialize the fields.
42cf5bc1 182 Standard_EXPORT Standard_Integer NbBColumns (const BRepApprox_TheMultiLineOfApprox& SSP) const;
183
36b9ff75 184 //! returns the first point beeing fitted.
42cf5bc1 185 Standard_EXPORT Standard_Integer TheFirstPoint (const AppParCurves_Constraint FirstCons, const Standard_Integer FirstPoint) const;
186
36b9ff75 187 //! returns the last point beeing fitted.
42cf5bc1 188 Standard_EXPORT Standard_Integer TheLastPoint (const AppParCurves_Constraint LastCons, const Standard_Integer LastPoint) const;
189
36b9ff75 190 //! Affects the fields in the case of a constraint point.
42cf5bc1 191 Standard_EXPORT void Affect (const BRepApprox_TheMultiLineOfApprox& SSP, const Standard_Integer Index, AppParCurves_Constraint& Cons, math_Vector& Vt, math_Vector& Vc);
192
193 Standard_EXPORT void ComputeFunction (const math_Vector& Parameters);
194
195 Standard_EXPORT void SearchIndex (math_IntegerVector& Index);
196
36b9ff75 197 //! computes internal matrixes for the resolution
42cf5bc1 198 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Vector& TheB);
199
36b9ff75 200 //! computes internal matrixes for the resolution
42cf5bc1 201 Standard_EXPORT void MakeTAA (math_Vector& TheA);
202
36b9ff75 203 //! computes internal matrixes for the resolution
42cf5bc1 204 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Matrix& TheB);
205
206
207
208
209private:
210
211
212
213 AppParCurves_Constraint FirstConstraint;
214 AppParCurves_Constraint LastConstraint;
215 AppParCurves_MultiBSpCurve SCU;
216 Handle(TColStd_HArray1OfReal) myknots;
217 Handle(TColStd_HArray1OfInteger) mymults;
218 math_Matrix mypoles;
219 math_Matrix A;
220 math_Matrix DA;
221 math_Matrix B2;
222 math_Matrix mypoints;
223 math_Vector Vflatknots;
224 math_Vector Vec1t;
225 math_Vector Vec1c;
226 math_Vector Vec2t;
227 math_Vector Vec2c;
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;
236 Standard_Integer NA;
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;
248
249
250};
251
252
253
254
255
256
257
258#endif // _BRepApprox_BSpParLeastSquareOfMyBSplGradientOfTheComputeLineOfApprox_HeaderFile