Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 09:15:30

0001 // Created on: 1991-12-02
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _AppDef_ParLeastSquareOfMyGradientOfCompute_HeaderFile
0018 #define _AppDef_ParLeastSquareOfMyGradientOfCompute_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <AppParCurves_Constraint.hxx>
0025 #include <AppParCurves_MultiBSpCurve.hxx>
0026 #include <TColStd_HArray1OfReal.hxx>
0027 #include <TColStd_HArray1OfInteger.hxx>
0028 #include <math_Matrix.hxx>
0029 #include <math_Vector.hxx>
0030 #include <math_IntegerVector.hxx>
0031 #include <Standard_Real.hxx>
0032 #include <Standard_Integer.hxx>
0033 #include <TColStd_Array1OfReal.hxx>
0034 #include <TColStd_Array1OfInteger.hxx>
0035 class StdFail_NotDone;
0036 class Standard_OutOfRange;
0037 class Standard_DimensionError;
0038 class Standard_NoSuchObject;
0039 class AppDef_MultiLine;
0040 class AppDef_MyLineTool;
0041 class AppParCurves_MultiCurve;
0042 class AppParCurves_MultiBSpCurve;
0043 class math_Matrix;
0044 
0045 class AppDef_ParLeastSquareOfMyGradientOfCompute
0046 {
0047 public:
0048   DEFINE_STANDARD_ALLOC
0049 
0050   //! given a MultiLine, this algorithm computes the least
0051   //! square resolution using the Householder-QR method.
0052   //! If the first and/or the last point is a constraint
0053   //! point, the value of the tangency or curvature is
0054   //! computed in the resolution.
0055   //! NbPol is the number of control points wanted
0056   //! for the approximating curves.
0057   //! The system to solve is the following:
0058   //! A X = B.
0059   //! Where A is the Bernstein matrix computed with the
0060   //! parameters, B the points coordinates and X the poles
0061   //! solutions.
0062   //! The matrix A is the same for each coordinate x, y and z
0063   //! and is also the same for each MultiLine point because
0064   //! they are approximated in parallel(so with the same
0065   //! parameter, only the vector B changes).
0066   Standard_EXPORT AppDef_ParLeastSquareOfMyGradientOfCompute(
0067     const AppDef_MultiLine&       SSP,
0068     const Standard_Integer        FirstPoint,
0069     const Standard_Integer        LastPoint,
0070     const AppParCurves_Constraint FirstCons,
0071     const AppParCurves_Constraint LastCons,
0072     const math_Vector&            Parameters,
0073     const Standard_Integer        NbPol);
0074 
0075   //! Initializes the fields of the object.
0076   Standard_EXPORT AppDef_ParLeastSquareOfMyGradientOfCompute(
0077     const AppDef_MultiLine&       SSP,
0078     const Standard_Integer        FirstPoint,
0079     const Standard_Integer        LastPoint,
0080     const AppParCurves_Constraint FirstCons,
0081     const AppParCurves_Constraint LastCons,
0082     const Standard_Integer        NbPol);
0083 
0084   //! given a MultiLine, this algorithm computes the least
0085   //! square resolution using the Householder-QR method.
0086   //! If the first and/or the last point is a constraint
0087   //! point, the value of the tangency or curvature is
0088   //! computed in the resolution.
0089   //! Deg is the degree wanted for the approximating curves.
0090   //! The system to solve is the following:
0091   //! A X = B.
0092   //! Where A is the BSpline functions matrix computed with
0093   //! <parameters>, B the points coordinates and X the poles
0094   //! solutions.
0095   //! The matrix A is the same for each coordinate x, y and z
0096   //! and is also the same for each MultiLine point because
0097   //! they are approximated in parallel(so with the same
0098   //! parameter, only the vector B changes).
0099   Standard_EXPORT AppDef_ParLeastSquareOfMyGradientOfCompute(
0100     const AppDef_MultiLine&        SSP,
0101     const TColStd_Array1OfReal&    Knots,
0102     const TColStd_Array1OfInteger& Mults,
0103     const Standard_Integer         FirstPoint,
0104     const Standard_Integer         LastPoint,
0105     const AppParCurves_Constraint  FirstCons,
0106     const AppParCurves_Constraint  LastCons,
0107     const math_Vector&             Parameters,
0108     const Standard_Integer         NbPol);
0109 
0110   //! Initializes the fields of the object.
0111   Standard_EXPORT AppDef_ParLeastSquareOfMyGradientOfCompute(
0112     const AppDef_MultiLine&        SSP,
0113     const TColStd_Array1OfReal&    Knots,
0114     const TColStd_Array1OfInteger& Mults,
0115     const Standard_Integer         FirstPoint,
0116     const Standard_Integer         LastPoint,
0117     const AppParCurves_Constraint  FirstCons,
0118     const AppParCurves_Constraint  LastCons,
0119     const Standard_Integer         NbPol);
0120 
0121   //! Is used after having initialized the fields.
0122   //! The case "CurvaturePoint" is not treated in this method.
0123   Standard_EXPORT void Perform(const math_Vector& Parameters);
0124 
0125   //! Is used after having initialized the fields.
0126   Standard_EXPORT void Perform(const math_Vector&  Parameters,
0127                                const Standard_Real l1,
0128                                const Standard_Real l2);
0129 
0130   //! Is used after having initialized the fields.
0131   //! <V1t> is the tangent vector at the first point.
0132   //! <V2t> is the tangent vector at the last point.
0133   Standard_EXPORT void Perform(const math_Vector&  Parameters,
0134                                const math_Vector&  V1t,
0135                                const math_Vector&  V2t,
0136                                const Standard_Real l1,
0137                                const Standard_Real l2);
0138 
0139   //! Is used after having initialized the fields.
0140   //! <V1t> is the tangent vector at the first point.
0141   //! <V2t> is the tangent vector at the last point.
0142   //! <V1c> is the tangent vector at the first point.
0143   //! <V2c> is the tangent vector at the last point.
0144   Standard_EXPORT void Perform(const math_Vector&  Parameters,
0145                                const math_Vector&  V1t,
0146                                const math_Vector&  V2t,
0147                                const math_Vector&  V1c,
0148                                const math_Vector&  V2c,
0149                                const Standard_Real l1,
0150                                const Standard_Real l2);
0151 
0152   //! returns True if all has been correctly done.
0153   Standard_EXPORT Standard_Boolean IsDone() const;
0154 
0155   //! returns the result of the approximation, i.e. all the
0156   //! Curves.
0157   //! An exception is raised if NotDone.
0158   Standard_EXPORT AppParCurves_MultiCurve BezierValue();
0159 
0160   //! returns the result of the approximation, i.e. all the
0161   //! Curves.
0162   //! An exception is raised if NotDone.
0163   Standard_EXPORT const AppParCurves_MultiBSpCurve& BSplineValue();
0164 
0165   //! returns the function matrix used to approximate the
0166   //! set.
0167   Standard_EXPORT const math_Matrix& FunctionMatrix() const;
0168 
0169   //! returns the derivative function matrix used
0170   //! to approximate the set.
0171   Standard_EXPORT const math_Matrix& DerivativeFunctionMatrix() const;
0172 
0173   //! returns the maximum errors between the MultiLine
0174   //! and the approximation curves. F is the sum of the square
0175   //! distances. Grad is the derivative vector of the
0176   //! function F.
0177   Standard_EXPORT void ErrorGradient(math_Vector&   Grad,
0178                                      Standard_Real& F,
0179                                      Standard_Real& MaxE3d,
0180                                      Standard_Real& MaxE2d);
0181 
0182   //! returns the distances between the points of the
0183   //! multiline and the approximation curves.
0184   Standard_EXPORT const math_Matrix& Distance();
0185 
0186   //! returns the maximum errors between the MultiLine
0187   //! and the approximation curves. F is the sum of the square
0188   //! distances.
0189   Standard_EXPORT void Error(Standard_Real& F, Standard_Real& MaxE3d, Standard_Real& MaxE2d);
0190 
0191   //! returns the value (P2 - P1)/ V1 if the first point
0192   //! was a tangency point.
0193   Standard_EXPORT Standard_Real FirstLambda() const;
0194 
0195   //! returns the value (PN - PN-1)/ VN if the last point
0196   //! was a tangency point.
0197   Standard_EXPORT Standard_Real LastLambda() const;
0198 
0199   //! returns the matrix of points value.
0200   Standard_EXPORT const math_Matrix& Points() const;
0201 
0202   //! returns the matrix of resulting control points value.
0203   Standard_EXPORT const math_Matrix& Poles() const;
0204 
0205   //! Returns the indexes of the first non null values of
0206   //! A and DA.
0207   //! The values are non null from Index(ieme point) +1
0208   //! to Index(ieme point) + degree +1.
0209   Standard_EXPORT const math_IntegerVector& KIndex() const;
0210 
0211 protected:
0212   //! is used by the constructors above.
0213   Standard_EXPORT void Init(const AppDef_MultiLine& SSP,
0214                             const Standard_Integer  FirstPoint,
0215                             const Standard_Integer  LastPoint);
0216 
0217   //! returns the number of second member columns.
0218   //! Is used internally to initialize the fields.
0219   Standard_EXPORT Standard_Integer NbBColumns(const AppDef_MultiLine& SSP) const;
0220 
0221   //! returns the first point being fitted.
0222   Standard_EXPORT Standard_Integer TheFirstPoint(const AppParCurves_Constraint FirstCons,
0223                                                  const Standard_Integer        FirstPoint) const;
0224 
0225   //! returns the last point being fitted.
0226   Standard_EXPORT Standard_Integer TheLastPoint(const AppParCurves_Constraint LastCons,
0227                                                 const Standard_Integer        LastPoint) const;
0228 
0229   //! Affects the fields in the case of a constraint point.
0230   Standard_EXPORT void Affect(const AppDef_MultiLine&  SSP,
0231                               const Standard_Integer   Index,
0232                               AppParCurves_Constraint& Cons,
0233                               math_Vector&             Vt,
0234                               math_Vector&             Vc);
0235 
0236   Standard_EXPORT void ComputeFunction(const math_Vector& Parameters);
0237 
0238   Standard_EXPORT void SearchIndex(math_IntegerVector& Index);
0239 
0240   //! computes internal matrixes for the resolution
0241   Standard_EXPORT void MakeTAA(math_Vector& TheA, math_Vector& TheB);
0242 
0243   //! computes internal matrixes for the resolution
0244   Standard_EXPORT void MakeTAA(math_Vector& TheA);
0245 
0246   //! computes internal matrixes for the resolution
0247   Standard_EXPORT void MakeTAA(math_Vector& TheA, math_Matrix& TheB);
0248 
0249 private:
0250   AppParCurves_Constraint          FirstConstraint;
0251   AppParCurves_Constraint          LastConstraint;
0252   AppParCurves_MultiBSpCurve       SCU;
0253   Handle(TColStd_HArray1OfReal)    myknots;
0254   Handle(TColStd_HArray1OfInteger) mymults;
0255   math_Matrix                      mypoles;
0256   math_Matrix                      A;
0257   math_Matrix                      DA;
0258   math_Matrix                      B2;
0259   math_Matrix                      mypoints;
0260   math_Vector                      Vflatknots;
0261   math_Vector                      Vec1t;
0262   math_Vector                      Vec1c;
0263   math_Vector                      Vec2t;
0264   math_Vector                      Vec2c;
0265   math_Matrix                      theError;
0266   math_IntegerVector               myindex;
0267   Standard_Real                    lambda1;
0268   Standard_Real                    lambda2;
0269   Standard_Integer                 FirstP;
0270   Standard_Integer                 LastP;
0271   Standard_Integer                 Nlignes;
0272   Standard_Integer                 Ninc;
0273   Standard_Integer                 NA;
0274   Standard_Integer                 myfirstp;
0275   Standard_Integer                 mylastp;
0276   Standard_Integer                 resinit;
0277   Standard_Integer                 resfin;
0278   Standard_Integer                 nbP2d;
0279   Standard_Integer                 nbP;
0280   Standard_Integer                 nbpoles;
0281   Standard_Integer                 deg;
0282   Standard_Boolean                 done;
0283   Standard_Boolean                 iscalculated;
0284   Standard_Boolean                 isready;
0285 };
0286 
0287 #endif // _AppDef_ParLeastSquareOfMyGradientOfCompute_HeaderFile