1 // Created on: 1995-01-27 2 // Created by: Jacques GOUSSARD 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 _GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox_HeaderFile 18 #define _GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox_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> 36 class StdFail_NotDone; 37 class Standard_OutOfRange; 38 class Standard_DimensionError; 39 class Standard_NoSuchObject; 40 class GeomInt_TheMultiLineOfWLApprox; 41 class GeomInt_TheMultiLineToolOfWLApprox; 42 class AppParCurves_MultiCurve; 43 class AppParCurves_MultiBSpCurve; 44 class math_Matrix; 45 46 47 48 class GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox 49 { 50 public: 51 52 DEFINE_STANDARD_ALLOC 53 54 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). 71 Standard_EXPORT GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox(const GeomInt_TheMultiLineOfWLApprox& 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 73 //! Initializes the fields of the object. 74 Standard_EXPORT GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox(const GeomInt_TheMultiLineOfWLApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint, const AppParCurves_Constraint FirstCons, const AppParCurves_Constraint LastCons, const Standard_Integer NbPol); 75 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). 91 Standard_EXPORT GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox(const GeomInt_TheMultiLineOfWLApprox& 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 93 //! Initializes the fields of the object. 94 Standard_EXPORT GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox(const GeomInt_TheMultiLineOfWLApprox& 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 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); 99 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); 102 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); 107 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); 114 115 //! returns True if all has been correctly done. 116 Standard_EXPORT Standard_Boolean IsDone() const; 117 118 //! returns the result of the approximation, i.e. all the 119 //! Curves. 120 //! An exception is raised if NotDone. 121 Standard_EXPORT AppParCurves_MultiCurve BezierValue(); 122 123 //! returns the result of the approximation, i.e. all the 124 //! Curves. 125 //! An exception is raised if NotDone. 126 Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue(); 127 128 //! returns the function matrix used to approximate the 129 //! set. 130 Standard_EXPORT const math_Matrix& FunctionMatrix() const; 131 132 //! returns the derivative function matrix used 133 //! to approximate the set. 134 Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const; 135 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. 140 Standard_EXPORT void ErrorGradient (math_Vector& Grad, Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d); 141 142 //! returns the distances between the points of the 143 //! multiline and the approximation curves. 144 Standard_EXPORT const math_Matrix& Distance(); 145 146 //! returns the maximum errors between the MultiLine 147 //! and the approximation curves. F is the sum of the square 148 //! distances. 149 Standard_EXPORT void Error (Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d); 150 151 //! returns the value (P2 - P1)/ V1 if the first point 152 //! was a tangency point. 153 Standard_EXPORT Standard_Real FirstLambda() const; 154 155 //! returns the value (PN - PN-1)/ VN if the last point 156 //! was a tangency point. 157 Standard_EXPORT Standard_Real LastLambda() const; 158 159 //! returns the matrix of points value. 160 Standard_EXPORT const math_Matrix& Points() const; 161 162 //! returns the matrix of resulting control points value. 163 Standard_EXPORT const math_Matrix& Poles() const; 164 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. 169 Standard_EXPORT const math_IntegerVector& KIndex() const; 170 171 172 173 174 protected: 175 176 177 //! is used by the constructors above. 178 Standard_EXPORT void Init (const GeomInt_TheMultiLineOfWLApprox& SSP, const Standard_Integer FirstPoint, const Standard_Integer LastPoint); 179 180 //! returns the number of second member columns. 181 //! Is used internally to initialize the fields. 182 Standard_EXPORT Standard_Integer NbBColumns (const GeomInt_TheMultiLineOfWLApprox& SSP) const; 183 184 //! returns the first point being fitted. 185 Standard_EXPORT Standard_Integer TheFirstPoint (const AppParCurves_Constraint FirstCons, const Standard_Integer FirstPoint) const; 186 187 //! returns the last point being fitted. 188 Standard_EXPORT Standard_Integer TheLastPoint (const AppParCurves_Constraint LastCons, const Standard_Integer LastPoint) const; 189 190 //! Affects the fields in the case of a constraint point. 191 Standard_EXPORT void Affect (const GeomInt_TheMultiLineOfWLApprox& 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 197 //! computes internal matrixes for the resolution 198 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Vector& TheB); 199 200 //! computes internal matrixes for the resolution 201 Standard_EXPORT void MakeTAA (math_Vector& TheA); 202 203 //! computes internal matrixes for the resolution 204 Standard_EXPORT void MakeTAA (math_Vector& TheA, math_Matrix& TheB); 205 206 207 208 209 private: 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 // _GeomInt_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfWLApprox_HeaderFile 259