Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:19:08

0001 // Created on: 1995-06-06
0002 // Created by: Jean Yves LEBEY
0003 // Copyright (c) 1995-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 _BRepApprox_TheComputeLineBezierOfApprox_HeaderFile
0018 #define _BRepApprox_TheComputeLineBezierOfApprox_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <AppParCurves_MultiCurve.hxx>
0025 #include <NCollection_Sequence.hxx>
0026 #include <AppParCurves_MultiBSpCurve.hxx>
0027 #include <Approx_ParametrizationType.hxx>
0028 #include <NCollection_Array1.hxx>
0029 #include <NCollection_HArray1.hxx>
0030 #include <AppParCurves_ConstraintCouple.hxx>
0031 #include <Standard_Integer.hxx>
0032 #include <AppParCurves_Constraint.hxx>
0033 #include <math_Vector.hxx>
0034 class BRepApprox_TheMultiLineOfApprox;
0035 class BRepApprox_TheMultiLineToolOfApprox;
0036 class BRepApprox_MyGradientOfTheComputeLineBezierOfApprox;
0037 class BRepApprox_ParLeastSquareOfMyGradientOfTheComputeLineBezierOfApprox;
0038 class BRepApprox_ResConstraintOfMyGradientOfTheComputeLineBezierOfApprox;
0039 class BRepApprox_ParFunctionOfMyGradientOfTheComputeLineBezierOfApprox;
0040 class BRepApprox_Gradient_BFGSOfMyGradientOfTheComputeLineBezierOfApprox;
0041 class AppParCurves_MultiCurve;
0042 class AppParCurves_MultiBSpCurve;
0043 
0044 class BRepApprox_TheComputeLineBezierOfApprox
0045 {
0046 public:
0047   DEFINE_STANDARD_ALLOC
0048 
0049   //! The MultiLine <Line> will be approximated until tolerances
0050   //! will be reached.
0051   //! The approximation will be done from degreemin to degreemax
0052   //! with a cutting if the corresponding boolean is True.
0053   //! If <Squares> is True, the computation will be done with
0054   //! no iteration at all.
0055   Standard_EXPORT BRepApprox_TheComputeLineBezierOfApprox(
0056     const BRepApprox_TheMultiLineOfApprox& Line,
0057     const int                              degreemin       = 4,
0058     const int                              degreemax       = 8,
0059     const double                           Tolerance3d     = 1.0e-3,
0060     const double                           Tolerance2d     = 1.0e-6,
0061     const int                              NbIterations    = 5,
0062     const bool                             cutting         = true,
0063     const Approx_ParametrizationType       parametrization = Approx_ChordLength,
0064     const bool                             Squares         = false);
0065 
0066   //! The MultiLine <Line> will be approximated until tolerances
0067   //! will be reached.
0068   //! The approximation will be done from degreemin to degreemax
0069   //! with a cutting if the corresponding boolean is True.
0070   //! If <Squares> is True, the computation will be done with
0071   //! no iteration at all.
0072   Standard_EXPORT BRepApprox_TheComputeLineBezierOfApprox(
0073     const BRepApprox_TheMultiLineOfApprox& Line,
0074     const math_Vector&                     Parameters,
0075     const int                              degreemin    = 4,
0076     const int                              degreemax    = 8,
0077     const double                           Tolerance3d  = 1.0e-03,
0078     const double                           Tolerance2d  = 1.0e-06,
0079     const int                              NbIterations = 5,
0080     const bool                             cutting      = true,
0081     const bool                             Squares      = false);
0082 
0083   //! Initializes the fields of the algorithm.
0084   Standard_EXPORT BRepApprox_TheComputeLineBezierOfApprox(const math_Vector& Parameters,
0085                                                           const int          degreemin    = 4,
0086                                                           const int          degreemax    = 8,
0087                                                           const double       Tolerance3d  = 1.0e-03,
0088                                                           const double       Tolerance2d  = 1.0e-06,
0089                                                           const int          NbIterations = 5,
0090                                                           const bool         cutting      = true,
0091                                                           const bool         Squares      = false);
0092 
0093   //! Initializes the fields of the algorithm.
0094   Standard_EXPORT BRepApprox_TheComputeLineBezierOfApprox(
0095     const int                        degreemin       = 4,
0096     const int                        degreemax       = 8,
0097     const double                     Tolerance3d     = 1.0e-03,
0098     const double                     Tolerance2d     = 1.0e-06,
0099     const int                        NbIterations    = 5,
0100     const bool                       cutting         = true,
0101     const Approx_ParametrizationType parametrization = Approx_ChordLength,
0102     const bool                       Squares         = false);
0103 
0104   //! Initializes the fields of the algorithm.
0105   Standard_EXPORT void Init(const int                        degreemin       = 4,
0106                             const int                        degreemax       = 8,
0107                             const double                     Tolerance3d     = 1.0e-03,
0108                             const double                     Tolerance2d     = 1.0e-06,
0109                             const int                        NbIterations    = 5,
0110                             const bool                       cutting         = true,
0111                             const Approx_ParametrizationType parametrization = Approx_ChordLength,
0112                             const bool                       Squares         = false);
0113 
0114   //! runs the algorithm after having initialized the fields.
0115   Standard_EXPORT void Perform(const BRepApprox_TheMultiLineOfApprox& Line);
0116 
0117   //! changes the degrees of the approximation.
0118   Standard_EXPORT void SetDegrees(const int degreemin, const int degreemax);
0119 
0120   //! Changes the tolerances of the approximation.
0121   Standard_EXPORT void SetTolerances(const double Tolerance3d, const double Tolerance2d);
0122 
0123   //! changes the first and the last constraint points.
0124   Standard_EXPORT void SetConstraints(const AppParCurves_Constraint firstC,
0125                                       const AppParCurves_Constraint lastC);
0126 
0127   //! returns False if at a moment of the approximation,
0128   //! the status NoApproximation has been sent by the user
0129   //! when more points were needed.
0130   Standard_EXPORT bool IsAllApproximated() const;
0131 
0132   //! returns False if the status NoPointsAdded has been sent.
0133   Standard_EXPORT bool IsToleranceReached() const;
0134 
0135   //! returns the tolerances 2d and 3d of the <Index> MultiCurve.
0136   Standard_EXPORT void Error(const int Index, double& tol3d, double& tol2d) const;
0137 
0138   //! Returns the number of MultiCurve doing the approximation
0139   //! of the MultiLine.
0140   Standard_EXPORT int NbMultiCurves() const;
0141 
0142   //! returns the result of the approximation.
0143   Standard_EXPORT const AppParCurves_MultiCurve& Value(const int Index = 1) const;
0144 
0145   //! returns the result of the approximation.
0146   Standard_EXPORT AppParCurves_MultiCurve& ChangeValue(const int Index = 1);
0147 
0148   //! returns the result of the approximation.
0149   Standard_EXPORT const AppParCurves_MultiBSpCurve& SplineValue();
0150 
0151   //! returns the type of parametrization
0152   Standard_EXPORT Approx_ParametrizationType Parametrization() const;
0153 
0154   //! returns the new parameters of the approximation
0155   //! corresponding to the points of the multicurve <Index>.
0156   Standard_EXPORT const NCollection_Array1<double>& Parameters(const int Index = 1) const;
0157 
0158 private:
0159   //! is internally used in the algorithm.
0160   Standard_EXPORT bool Compute(const BRepApprox_TheMultiLineOfApprox& Line,
0161                                const int                              fpt,
0162                                const int                              lpt,
0163                                math_Vector&                           Para,
0164                                double&                                TheTol3d,
0165                                double&                                TheTol2d,
0166                                int&                                   indbad);
0167 
0168   //! is internally used in the algorithm.
0169   Standard_EXPORT bool ComputeCurve(const BRepApprox_TheMultiLineOfApprox& Line,
0170                                     const int                              firspt,
0171                                     const int                              lastpt);
0172 
0173   //! computes new parameters between firstP and lastP.
0174   Standard_EXPORT void Parameters(const BRepApprox_TheMultiLineOfApprox& Line,
0175                                   const int                              firstP,
0176                                   const int                              LastP,
0177                                   math_Vector&                           TheParameters) const;
0178 
0179   Standard_EXPORT double SearchFirstLambda(const BRepApprox_TheMultiLineOfApprox& Line,
0180                                            const math_Vector&                     Para,
0181                                            const math_Vector&                     V,
0182                                            const int                              index) const;
0183 
0184   Standard_EXPORT double SearchLastLambda(const BRepApprox_TheMultiLineOfApprox& Line,
0185                                           const math_Vector&                     Para,
0186                                           const math_Vector&                     V,
0187                                           const int                              index) const;
0188 
0189   Standard_EXPORT void FirstTangencyVector(const BRepApprox_TheMultiLineOfApprox& Line,
0190                                            const int                              index,
0191                                            math_Vector&                           V) const;
0192 
0193   Standard_EXPORT void LastTangencyVector(const BRepApprox_TheMultiLineOfApprox& Line,
0194                                           const int                              index,
0195                                           math_Vector&                           V) const;
0196 
0197   NCollection_Sequence<AppParCurves_MultiCurve>                   myMultiCurves;
0198   AppParCurves_MultiCurve                                         TheMultiCurve;
0199   AppParCurves_MultiBSpCurve                                      myspline;
0200   bool                                                            alldone;
0201   bool                                                            tolreached;
0202   Approx_ParametrizationType                                      Par;
0203   occ::handle<NCollection_HArray1<double>>                        myParameters;
0204   occ::handle<NCollection_HArray1<double>>                        myfirstParam;
0205   NCollection_Sequence<occ::handle<NCollection_HArray1<double>>>  myPar;
0206   NCollection_Sequence<double>                                    Tolers3d;
0207   NCollection_Sequence<double>                                    Tolers2d;
0208   occ::handle<NCollection_HArray1<AppParCurves_ConstraintCouple>> myConstraints;
0209   int                                                             mydegremin;
0210   int                                                             mydegremax;
0211   double                                                          mytol3d;
0212   double                                                          mytol2d;
0213   double                                                          currenttol3d;
0214   double                                                          currenttol2d;
0215   bool                                                            mycut;
0216   bool                                                            mysquares;
0217   int                                                             myitermax;
0218   AppParCurves_Constraint                                         myfirstC;
0219   AppParCurves_Constraint                                         mylastC;
0220   int                                                             myMultiLineNb;
0221   bool                                                            myIsClear;
0222 };
0223 
0224 #endif // _BRepApprox_TheComputeLineBezierOfApprox_HeaderFile