Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:18:57

0001 // Created on: 1995-06-02
0002 // Created by: Xavier BENVENISTE
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 _Approx_SameParameter_HeaderFile
0018 #define _Approx_SameParameter_HeaderFile
0019 
0020 #include <Adaptor3d_CurveOnSurface.hxx>
0021 #include <Adaptor3d_Surface.hxx>
0022 
0023 class Geom_Curve;
0024 class Geom2d_Curve;
0025 class Geom_Surface;
0026 
0027 //! Approximation of a PCurve on a surface to make its
0028 //! parameter be the same that the parameter of a given 3d
0029 //! reference curve.
0030 class Approx_SameParameter
0031 {
0032 public:
0033   DEFINE_STANDARD_ALLOC
0034 
0035   //! Warning: the C3D and C2D must have the same parametric domain.
0036   Standard_EXPORT Approx_SameParameter(const occ::handle<Geom_Curve>&   C3D,
0037                                        const occ::handle<Geom2d_Curve>& C2D,
0038                                        const occ::handle<Geom_Surface>& S,
0039                                        const double                     Tol);
0040 
0041   //! Warning: the C3D and C2D must have the same parametric domain.
0042   Standard_EXPORT Approx_SameParameter(const occ::handle<Adaptor3d_Curve>&   C3D,
0043                                        const occ::handle<Geom2d_Curve>&      C2D,
0044                                        const occ::handle<Adaptor3d_Surface>& S,
0045                                        const double                          Tol);
0046 
0047   //! Warning: the C3D and C2D must have the same parametric domain.
0048   Standard_EXPORT Approx_SameParameter(const occ::handle<Adaptor3d_Curve>&   C3D,
0049                                        const occ::handle<Adaptor2d_Curve2d>& C2D,
0050                                        const occ::handle<Adaptor3d_Surface>& S,
0051                                        const double                          Tol);
0052 
0053   //!@Returns .false. if calculations failed,
0054   //! .true. if calculations succeed
0055   bool IsDone() const { return myDone; }
0056 
0057   //!@Returns tolerance (maximal distance) between 3d curve
0058   //! and curve on surface, generated by 2d curve and surface.
0059   double TolReached() const { return myTolReached; }
0060 
0061   //! Tells whether the original data had already the same
0062   //! parameter up to the tolerance : in that case nothing
0063   //! is done.
0064   bool IsSameParameter() const { return mySameParameter; }
0065 
0066   //! Returns the 2D curve that has the same parameter as
0067   //! the 3D curve once evaluated on the surface up to the
0068   //! specified tolerance.
0069   occ::handle<Geom2d_Curve> Curve2d() const { return myCurve2d; }
0070 
0071   //! Returns the 3D curve that has the same parameter as
0072   //! the 3D curve once evaluated on the surface up to the
0073   //! specified tolerance.
0074   occ::handle<Adaptor3d_Curve> Curve3d() const { return myC3d; }
0075 
0076   //! Returns the 3D curve on surface that has the same parameter as
0077   //! the 3D curve up to the specified tolerance.
0078   occ::handle<Adaptor3d_CurveOnSurface> CurveOnSurface() const { return myCurveOnSurface; }
0079 
0080 private:
0081   //! Internal data structure to unify access to the most actively used data.
0082   //! This structure is not intended to be class field since
0083   //! a lot of memory is used in intermediate computations.
0084   struct Approx_SameParameter_Data
0085   {
0086     Adaptor3d_CurveOnSurface myCOnS;  // Curve on surface.
0087     int                      myNbPnt; // Number of points.
0088     double*                  myPC3d;  // Parameters on 3d curve.
0089     double*                  myPC2d;  // Parameters on 2d curve.
0090 
0091     // Second data arrays. Used in loop over poles.
0092     double* myNewPC3d; // Parameters on 3d curve.
0093     double* myNewPC2d; // Parameters on 2d curve.
0094 
0095     // Parameters ranges.
0096     double myC3dPF; // Curve 3d Parameter First.
0097     double myC3dPL; // Curve 3d Parameter Last.
0098     double myC2dPF; // Curve 2d Parameter First.
0099     double myC2dPL; // Curve 2d Parameter Last.
0100 
0101     double myTol; // Working tolerance.
0102 
0103     // Swap data arrays and update number of points.
0104     void Swap(const int theNewNbPoints)
0105     {
0106       myNbPnt = theNewNbPoints;
0107       double* temp;
0108 
0109       // 3-D
0110       temp      = myPC3d;
0111       myPC3d    = myNewPC3d;
0112       myNewPC3d = temp;
0113 
0114       // 2-D
0115       temp      = myPC2d;
0116       myPC2d    = myNewPC2d;
0117       myNewPC2d = temp;
0118     }
0119   };
0120 
0121   Approx_SameParameter(const Approx_SameParameter&)            = delete;
0122   Approx_SameParameter& operator=(const Approx_SameParameter&) = delete;
0123 
0124   //! Computes the pcurve (internal use only).
0125   Standard_EXPORT void Build(const double Tol);
0126 
0127   //! Computes initial point distribution.
0128   bool BuildInitialDistribution(Approx_SameParameter_Data& theData) const;
0129 
0130   //! Increases initial number of samples in case of the C0 continuity.
0131   //! Return new number of points and corresponding data arrays.
0132   //@return true if new number of samples is good and false otherwise.
0133   bool IncreaseInitialNbSamples(Approx_SameParameter_Data& theData) const;
0134 
0135   //! Computes tangents on boundary points.
0136   //@return true if tangents are not null and false otherwise.
0137   bool ComputeTangents(const Adaptor3d_CurveOnSurface& theCOnS,
0138                        double&                         theFirstTangent,
0139                        double&                         theLastTangent) const;
0140 
0141   //! Method to check same parameter state
0142   //! and build dependency between 2d and 3d curves.
0143   //@return true if 2d and 3d curves have same parameter state and false otherwise.
0144   bool CheckSameParameter(Approx_SameParameter_Data& theData, double& theSqDist) const;
0145 
0146   //! Computes interpolated values.
0147   //!@Returns .false. if computations failed;
0148   bool Interpolate(const Approx_SameParameter_Data& theData,
0149                    const double                     aTangFirst,
0150                    const double                     aTangLast,
0151                    NCollection_Array1<double>&      thePoles,
0152                    NCollection_Array1<double>&      theFlatKnots) const;
0153 
0154   //! Increases number of poles in poles loop.
0155   //@return true if poles is changed and false otherwise.
0156   bool IncreaseNbPoles(const NCollection_Array1<double>& thePoles,
0157                        const NCollection_Array1<double>& theFlatKnots,
0158                        Approx_SameParameter_Data&        theData,
0159                        double&                           theBestSqTol) const;
0160 
0161   static const int myNbSamples    = 22; // To be consistent with "checkshape".
0162   static const int myMaxArraySize = 1000;
0163   const double     myDeltaMin; // Initialization is allowed only for integral types.
0164 
0165   bool                                  mySameParameter;
0166   bool                                  myDone;
0167   double                                myTolReached;
0168   occ::handle<Geom2d_Curve>             myCurve2d;
0169   occ::handle<Adaptor2d_Curve2d>        myHCurve2d;
0170   occ::handle<Adaptor3d_Curve>          myC3d;
0171   occ::handle<Adaptor3d_Surface>        mySurf;
0172   occ::handle<Adaptor3d_CurveOnSurface> myCurveOnSurface;
0173 };
0174 
0175 #endif // _Approx_SameParameter_HeaderFile