Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:13:32

0001 // Created on: 1996-05-14
0002 // Created by: Philippe MANGIN / Jeannine PANCIATICI
0003 // Copyright (c) 1996-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_Variational_HeaderFile
0018 #define _AppDef_Variational_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <AppDef_MultiLine.hxx>
0025 #include <Standard_Integer.hxx>
0026 #include <AppParCurves_ConstraintCouple.hxx>
0027 #include <NCollection_Array1.hxx>
0028 #include <NCollection_HArray1.hxx>
0029 #include <GeomAbs_Shape.hxx>
0030 #include <AppParCurves_MultiBSpCurve.hxx>
0031 #include <Standard_OStream.hxx>
0032 #include <math_Vector.hxx>
0033 #include <AppParCurves_Constraint.hxx>
0034 #include <PLib_HermitJacobi.hxx>
0035 class AppDef_SmoothCriterion;
0036 class math_Matrix;
0037 class FEmTool_Curve;
0038 class FEmTool_Assembly;
0039 
0040 //! This class is used to smooth N points with constraints
0041 //! by minimization of quadratic criterium but also
0042 //! variational criterium in order to obtain " fair Curve "
0043 //! Computes the approximation of a Multiline by
0044 //! Variational optimization.
0045 class AppDef_Variational
0046 {
0047 public:
0048   DEFINE_STANDARD_ALLOC
0049 
0050   //! Constructor.
0051   //! Initialization of the fields.
0052   //! Warning:
0053   //! Nc0 : number of PassagePoint consraints
0054   //! Nc2 : number of TangencyPoint constraints
0055   //! Nc3 : number of CurvaturePoint constraints
0056   //! if ((MaxDegree-Continuity)*MaxSegment -Nc0 - 2*Nc1 -3*Nc2)
0057   //! is negative
0058   //! The problem is over-constrained.
0059   //!
0060   //! Limitation : The MultiLine from AppDef has to be composed by
0061   //! only one Line ( Dimension 2 or 3).
0062   Standard_EXPORT AppDef_Variational(
0063     const AppDef_MultiLine&                                                SSP,
0064     const int                                                              FirstPoint,
0065     const int                                                              LastPoint,
0066     const occ::handle<NCollection_HArray1<AppParCurves_ConstraintCouple>>& TheConstraints,
0067     const int                                                              MaxDegree   = 14,
0068     const int                                                              MaxSegment  = 100,
0069     const GeomAbs_Shape                                                    Continuity  = GeomAbs_C2,
0070     const bool                                                             WithMinMax  = false,
0071     const bool                                                             WithCutting = true,
0072     const double                                                           Tolerance   = 1.0,
0073     const int                                                              NbIterations = 2);
0074 
0075   //! Makes the approximation with the current fields.
0076   Standard_EXPORT void Approximate();
0077 
0078   //! returns True if the creation is done
0079   //! and correspond to the current fields.
0080   Standard_EXPORT bool IsCreated() const;
0081 
0082   //! returns True if the approximation is ok
0083   //! and correspond to the current fields.
0084   Standard_EXPORT bool IsDone() const;
0085 
0086   //! returns True if the problem is overconstrained
0087   //! in this case, approximation cannot be done.
0088   Standard_EXPORT bool IsOverConstrained() const;
0089 
0090   //! returns all the BSpline curves approximating the
0091   //! MultiLine from AppDef SSP after minimization of the parameter.
0092   Standard_EXPORT AppParCurves_MultiBSpCurve Value() const;
0093 
0094   //! returns the maximum of the distances between
0095   //! the points of the multiline and the approximation
0096   //! curves.
0097   Standard_EXPORT double MaxError() const;
0098 
0099   //! returns the index of the MultiPoint of ErrorMax
0100   Standard_EXPORT int MaxErrorIndex() const;
0101 
0102   //! returns the quadratic average of the distances between
0103   //! the points of the multiline and the approximation
0104   //! curves.
0105   Standard_EXPORT double QuadraticError() const;
0106 
0107   //! returns the distances between the points of the
0108   //! multiline and the approximation curves.
0109   Standard_EXPORT void Distance(math_Matrix& mat);
0110 
0111   //! returns the average error between
0112   //! the MultiLine from AppDef and the approximation.
0113   Standard_EXPORT double AverageError() const;
0114 
0115   //! returns the parameters uses to the approximations
0116   Standard_EXPORT const occ::handle<NCollection_HArray1<double>>& Parameters() const;
0117 
0118   //! returns the knots uses to the approximations
0119   Standard_EXPORT const occ::handle<NCollection_HArray1<double>>& Knots() const;
0120 
0121   //! returns the values of the quality criterium.
0122   Standard_EXPORT void Criterium(double& VFirstOrder,
0123                                  double& VSecondOrder,
0124                                  double& VThirdOrder) const;
0125 
0126   //! returns the Weights (as percent) associed to the criterium used in
0127   //! the optimization.
0128   Standard_EXPORT void CriteriumWeight(double& Percent1, double& Percent2, double& Percent3) const;
0129 
0130   //! returns the Maximum Degree used in the approximation
0131   Standard_EXPORT int MaxDegree() const;
0132 
0133   //! returns the Maximum of segment used in the approximation
0134   Standard_EXPORT int MaxSegment() const;
0135 
0136   //! returns the Continuity used in the approximation
0137   Standard_EXPORT GeomAbs_Shape Continuity() const;
0138 
0139   //! returns if the approximation search to minimize the
0140   //! maximum Error or not.
0141   Standard_EXPORT bool WithMinMax() const;
0142 
0143   //! returns if the approximation can insert new Knots or not.
0144   Standard_EXPORT bool WithCutting() const;
0145 
0146   //! returns the tolerance used in the approximation.
0147   Standard_EXPORT double Tolerance() const;
0148 
0149   //! returns the number of iterations used in the approximation.
0150   Standard_EXPORT int NbIterations() const;
0151 
0152   //! Prints on the stream o information on the current state
0153   //! of the object.
0154   //! MaxError,MaxErrorIndex,AverageError,QuadraticError,Criterium
0155   //! Distances,Degre,Nombre de poles, parametres, noeuds
0156   Standard_EXPORT void Dump(Standard_OStream& o) const;
0157 
0158   //! Define the constraints to approximate
0159   //! If this value is incompatible with the others fields
0160   //! this method modify nothing and returns false
0161   Standard_EXPORT bool SetConstraints(
0162     const occ::handle<NCollection_HArray1<AppParCurves_ConstraintCouple>>& aConstrainst);
0163 
0164   //! Defines the parameters used by the approximations.
0165   Standard_EXPORT void SetParameters(const occ::handle<NCollection_HArray1<double>>& param);
0166 
0167   //! Defines the knots used by the approximations
0168   //! If this value is incompatible with the others fields
0169   //! this method modify nothing and returns false
0170   Standard_EXPORT bool SetKnots(const occ::handle<NCollection_HArray1<double>>& knots);
0171 
0172   //! Define the Maximum Degree used in the approximation
0173   //! If this value is incompatible with the others fields
0174   //! this method modify nothing and returns false
0175   Standard_EXPORT bool SetMaxDegree(const int Degree);
0176 
0177   //! Define the maximum number of segments used in the approximation
0178   //! If this value is incompatible with the others fields
0179   //! this method modify nothing and returns false
0180   Standard_EXPORT bool SetMaxSegment(const int NbSegment);
0181 
0182   //! Define the Continuity used in the approximation
0183   //! If this value is incompatible with the others fields
0184   //! this method modify nothing and returns false
0185   Standard_EXPORT bool SetContinuity(const GeomAbs_Shape C);
0186 
0187   //! Define if the approximation search to minimize the
0188   //! maximum Error or not.
0189   Standard_EXPORT void SetWithMinMax(const bool MinMax);
0190 
0191   //! Define if the approximation can insert new Knots or not.
0192   //! If this value is incompatible with the others fields
0193   //! this method modify nothing and returns false
0194   Standard_EXPORT bool SetWithCutting(const bool Cutting);
0195 
0196   //! define the Weights (as percent) associed to the criterium used in
0197   //! the optimization.
0198   //!
0199   //! if Percent <= 0
0200   Standard_EXPORT void SetCriteriumWeight(const double Percent1,
0201                                           const double Percent2,
0202                                           const double Percent3);
0203 
0204   //! define the Weight (as percent) associed to the
0205   //! criterium Order used in the optimization : Others
0206   //! weights are updated.
0207   //! if Percent < 0
0208   //! if Order < 1 or Order > 3
0209   Standard_EXPORT void SetCriteriumWeight(const int Order, const double Percent);
0210 
0211   //! define the tolerance used in the approximation.
0212   Standard_EXPORT void SetTolerance(const double Tol);
0213 
0214   //! define the number of iterations used in the approximation.
0215   //! if Iter < 1
0216   Standard_EXPORT void SetNbIterations(const int Iter);
0217 
0218 private:
0219   Standard_EXPORT void TheMotor(occ::handle<AppDef_SmoothCriterion>& J,
0220                                 const double                         WQuadratic,
0221                                 const double                         WQuality,
0222                                 occ::handle<FEmTool_Curve>&          TheCurve,
0223                                 NCollection_Array1<double>&          Ecarts);
0224 
0225   Standard_EXPORT void Adjusting(occ::handle<AppDef_SmoothCriterion>& J,
0226                                  double&                              WQuadratic,
0227                                  double&                              WQuality,
0228                                  occ::handle<FEmTool_Curve>&          TheCurve,
0229                                  NCollection_Array1<double>&          Ecarts);
0230 
0231   Standard_EXPORT void Optimization(occ::handle<AppDef_SmoothCriterion>& J,
0232                                     FEmTool_Assembly&                    A,
0233                                     const bool                           ToAssemble,
0234                                     const double                         EpsDeg,
0235                                     occ::handle<FEmTool_Curve>&          Curve,
0236                                     const NCollection_Array1<double>&    Parameters) const;
0237 
0238   Standard_EXPORT void Project(const occ::handle<FEmTool_Curve>& C,
0239                                const NCollection_Array1<double>& Ti,
0240                                NCollection_Array1<double>&       ProjTi,
0241                                NCollection_Array1<double>&       Distance,
0242                                int&                              NumPoints,
0243                                double&                           MaxErr,
0244                                double&                           QuaErr,
0245                                double&                           AveErr,
0246                                const int                         NbIterations = 2) const;
0247 
0248   Standard_EXPORT void ACR(occ::handle<FEmTool_Curve>& Curve,
0249                            NCollection_Array1<double>& Ti,
0250                            const int                   Decima) const;
0251 
0252   Standard_EXPORT void SplitCurve(const occ::handle<FEmTool_Curve>& InCurve,
0253                                   const NCollection_Array1<double>& Ti,
0254                                   const double                      CurveTol,
0255                                   occ::handle<FEmTool_Curve>&       OutCurve,
0256                                   bool&                             iscut) const;
0257 
0258   Standard_EXPORT void Init();
0259 
0260   Standard_EXPORT void InitSmoothCriterion();
0261 
0262   Standard_EXPORT void InitParameters(double& Length);
0263 
0264   Standard_EXPORT void InitCriterionEstimations(const double Length,
0265                                                 double&      J1,
0266                                                 double&      J2,
0267                                                 double&      J3) const;
0268 
0269   Standard_EXPORT void EstTangent(const int ipnt, math_Vector& VTang) const;
0270 
0271   Standard_EXPORT void EstSecnd(const int          ipnt,
0272                                 const math_Vector& VTang1,
0273                                 const math_Vector& VTang2,
0274                                 const double       Length,
0275                                 math_Vector&       VScnd) const;
0276 
0277   Standard_EXPORT void InitCutting(const PLib_HermitJacobi&    aBase,
0278                                    const double                CurvTol,
0279                                    occ::handle<FEmTool_Curve>& aCurve) const;
0280 
0281   Standard_EXPORT void AssemblingConstraints(const occ::handle<FEmTool_Curve>& Curve,
0282                                              const NCollection_Array1<double>& Parameters,
0283                                              const double                      CBLONG,
0284                                              FEmTool_Assembly&                 A) const;
0285 
0286   Standard_EXPORT bool InitTthetaF(const int                     ndimen,
0287                                    const AppParCurves_Constraint typcon,
0288                                    const int                     begin,
0289                                    const int                     jndex);
0290 
0291   AppDef_MultiLine                                                mySSP;
0292   int                                                             myNbP3d;
0293   int                                                             myNbP2d;
0294   int                                                             myDimension;
0295   int                                                             myFirstPoint;
0296   int                                                             myLastPoint;
0297   int                                                             myNbPoints;
0298   occ::handle<NCollection_HArray1<double>>                        myTabPoints;
0299   occ::handle<NCollection_HArray1<AppParCurves_ConstraintCouple>> myConstraints;
0300   int                                                             myNbConstraints;
0301   occ::handle<NCollection_HArray1<double>>                        myTabConstraints;
0302   int                                                             myNbPassPoints;
0303   int                                                             myNbTangPoints;
0304   int                                                             myNbCurvPoints;
0305   occ::handle<NCollection_HArray1<int>>                           myTypConstraints;
0306   occ::handle<NCollection_HArray1<double>>                        myTtheta;
0307   occ::handle<NCollection_HArray1<double>>                        myTfthet;
0308   int                                                             myMaxDegree;
0309   int                                                             myMaxSegment;
0310   int                                                             myNbIterations;
0311   double                                                          myTolerance;
0312   GeomAbs_Shape                                                   myContinuity;
0313   int                                                             myNivCont;
0314   bool                                                            myWithMinMax;
0315   bool                                                            myWithCutting;
0316   double                                                          myPercent[3];
0317   double                                                          myCriterium[4];
0318   occ::handle<AppDef_SmoothCriterion>                             mySmoothCriterion;
0319   occ::handle<NCollection_HArray1<double>>                        myParameters;
0320   occ::handle<NCollection_HArray1<double>>                        myKnots;
0321   AppParCurves_MultiBSpCurve                                      myMBSpCurve;
0322   double                                                          myMaxError;
0323   int                                                             myMaxErrorIndex;
0324   double                                                          myAverageError;
0325   bool                                                            myIsCreated;
0326   bool                                                            myIsDone;
0327   bool                                                            myIsOverConstr;
0328 };
0329 
0330 #endif // _AppDef_Variational_HeaderFile