Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:16:52

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