Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:17:36

0001 // Created on: 1994-08-18
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1994-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 _Geom2dAPI_Interpolate_HeaderFile
0018 #define _Geom2dAPI_Interpolate_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <gp_Pnt2d.hxx>
0025 #include <NCollection_Array1.hxx>
0026 #include <NCollection_HArray1.hxx>
0027 #include <gp_Vec2d.hxx>
0028 class Geom2d_BSplineCurve;
0029 class gp_Vec2d;
0030 
0031 //! This class is used to interpolate a BsplineCurve
0032 //! passing through an array of points, with a C2
0033 //! Continuity if tangency is not requested at the point.
0034 //! If tangency is requested at the point the continuity will
0035 //! be C1. If Perodicity is requested the curve will be closed
0036 //! and the junction will be the first point given. The curve will than be only C1
0037 //! The curve is defined by a table of points through which it passes, and if required
0038 //! by a parallel table of reals which gives the value of the parameter of each point through
0039 //! which the resulting BSpline curve passes, and by vectors tangential to these points.
0040 //! An Interpolate object provides a framework for: defining the constraints of the BSpline curve,
0041 //! -   implementing the interpolation algorithm, and consulting the results.
0042 class Geom2dAPI_Interpolate
0043 {
0044 public:
0045   DEFINE_STANDARD_ALLOC
0046 
0047   //! Tolerance is to check if the points are not too close to one an other
0048   //! It is also used to check if the tangent vector is not too small.
0049   //! There should be at least 2 points
0050   //! if PeriodicFlag is True then the curve will be periodic.
0051   Standard_EXPORT Geom2dAPI_Interpolate(const occ::handle<NCollection_HArray1<gp_Pnt2d>>& Points,
0052                                         const bool   PeriodicFlag,
0053                                         const double Tolerance);
0054 
0055   //! if PeriodicFlag is True then the curve will be periodic
0056   //! Warning:
0057   //! There should be as many parameters as there are points
0058   //! except if PeriodicFlag is True : then there should be one more
0059   //! parameter to close the curve
0060   Standard_EXPORT Geom2dAPI_Interpolate(const occ::handle<NCollection_HArray1<gp_Pnt2d>>& Points,
0061                                         const occ::handle<NCollection_HArray1<double>>& Parameters,
0062                                         const bool   PeriodicFlag,
0063                                         const double Tolerance);
0064 
0065   //! Assigns this constrained BSpline curve to be
0066   //! tangential to vectors InitialTangent and FinalTangent
0067   //! at its first and last points respectively (i.e.
0068   //! the first and last points of the table of
0069   //! points through which the curve passes, as
0070   //! defined at the time of initialization).
0071   //! <Scale> - boolean flag defining whether tangent vectors are to
0072   //! be scaled according to derivatives of lagrange interpolation.
0073   Standard_EXPORT void Load(const gp_Vec2d& InitialTangent,
0074                             const gp_Vec2d& FinalTangent,
0075                             const bool      Scale = true);
0076 
0077   //! Assigns this constrained BSpline curve to be
0078   //! tangential to vectors defined in the table Tangents,
0079   //! which is parallel to the table of points
0080   //! through which the curve passes, as
0081   //! defined at the time of initialization. Vectors
0082   //! in the table Tangents are defined only if
0083   //! the flag given in the parallel table
0084   //! TangentFlags is true: only these vectors
0085   //! are set as tangency constraints.
0086   //! <Scale> - boolean flag defining whether tangent vectors are to
0087   //! be scaled according to derivatives of lagrange interpolation.
0088   Standard_EXPORT void Load(const NCollection_Array1<gp_Vec2d>&           Tangents,
0089                             const occ::handle<NCollection_HArray1<bool>>& TangentFlags,
0090                             const bool                                    Scale = true);
0091 
0092   //! Clears all tangency constraints on this
0093   //! constrained BSpline curve (as initialized by the function Load).
0094   Standard_EXPORT void ClearTangents();
0095 
0096   //! Computes the constrained BSpline curve. Use the function IsDone to verify that the
0097   //! computation is successful, and then the function Curve to obtain the result.
0098   Standard_EXPORT void Perform();
0099 
0100   //! Returns the computed BSpline curve. Raises StdFail_NotDone if the interpolation fails.
0101   Standard_EXPORT const occ::handle<Geom2d_BSplineCurve>& Curve() const;
0102   Standard_EXPORT operator occ::handle<Geom2d_BSplineCurve>() const;
0103 
0104   //! Returns true if the constrained BSpline curve is successfully constructed.
0105   //! Note: in this case, the result is given by the function Curve.
0106   Standard_EXPORT bool IsDone() const;
0107 
0108 private:
0109   //! Interpolates in a non periodic fashion
0110   Standard_EXPORT void PerformNonPeriodic();
0111 
0112   //! Interpolates in a C1 periodic fashion
0113   Standard_EXPORT void PerformPeriodic();
0114 
0115   double                                     myTolerance;
0116   occ::handle<NCollection_HArray1<gp_Pnt2d>> myPoints;
0117   bool                                       myIsDone;
0118   occ::handle<Geom2d_BSplineCurve>           myCurve;
0119   occ::handle<NCollection_HArray1<gp_Vec2d>> myTangents;
0120   occ::handle<NCollection_HArray1<bool>>     myTangentFlags;
0121   occ::handle<NCollection_HArray1<double>>   myParameters;
0122   bool                                       myPeriodic;
0123   bool                                       myTangentRequest;
0124 };
0125 
0126 #endif // _Geom2dAPI_Interpolate_HeaderFile