Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:12:13

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 _GeomAPI_Interpolate_HeaderFile
0018 #define _GeomAPI_Interpolate_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <gp_Vec.hxx>
0025 #include <NCollection_Array1.hxx>
0026 #include <NCollection_HArray1.hxx>
0027 #include <Geom_BSplineCurve.hxx>
0028 
0029 class gp_Vec;
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
0037 //! will than be only C1
0038 //! Describes functions for building a constrained 3D BSpline curve.
0039 //! The curve is defined by a table of points
0040 //! through which it passes, and if required:
0041 //! -   by a parallel table of reals which gives the
0042 //! value of the parameter of each point through
0043 //! which the resulting BSpline curve passes, and
0044 //! -   by vectors tangential to these points.
0045 //! An Interpolate object provides a framework for:
0046 //! -   defining the constraints of the BSpline curve,
0047 //! -   implementing the interpolation algorithm, and
0048 //! -   consulting the results.
0049 class GeomAPI_Interpolate
0050 {
0051 public:
0052   DEFINE_STANDARD_ALLOC
0053 
0054   //! Initializes an algorithm for constructing a
0055   //! constrained BSpline curve passing through the points of the table Points.
0056   //! Tangential vectors can then be assigned, using the function Load.
0057   //! If PeriodicFlag is true, the constrained BSpline
0058   //! curve will be periodic and closed. In this case,
0059   //! the junction point is the first point of the table Points.
0060   //! The tolerance value Tolerance is used to check that:
0061   //! -   points are not too close to each other, or
0062   //! -   tangential vectors (defined using the
0063   //! function Load) are not too small.
0064   //! The resulting BSpline curve will be "C2"
0065   //! continuous, except where a tangency
0066   //! constraint is defined on a point through which
0067   //! the curve passes (by using the Load function).
0068   //! In this case, it will be only "C1" continuous.
0069   //! Once all the constraints are defined, use the
0070   //! function Perform to compute the curve.
0071   //! Warning
0072   //! -   There must be at least 2 points in the table Points.
0073   //! -   If PeriodicFlag is false, there must be as
0074   //! many parameters in the array Parameters as
0075   //! there are points in the array Points.
0076   //! -   If PeriodicFlag is true, there must be one
0077   //! more parameter in the table Parameters: this
0078   //! is used to give the parameter on the
0079   //! resulting BSpline curve of the junction point
0080   //! of the curve (which is also the first point of the table Points).
0081   //! Exceptions
0082   //! -   Standard_ConstructionError if the
0083   //! distance between two consecutive points in
0084   //! the table Points is less than or equal to Tolerance.
0085   //! -   Standard_OutOfRange if:
0086   //! -   there are less than two points in the table Points, or
0087   //! -   conditions relating to the respective
0088   //! number of elements in the parallel tables
0089   //! Points and Parameters are not respected.
0090   Standard_EXPORT GeomAPI_Interpolate(const occ::handle<NCollection_HArray1<gp_Pnt>>& Points,
0091                                       const bool                                      PeriodicFlag,
0092                                       const double                                    Tolerance);
0093 
0094   //! Initializes an algorithm for constructing a
0095   //! constrained BSpline curve passing through the points of the table
0096   //! Points, where the parameters of each of its
0097   //! points are given by the parallel table Parameters.
0098   //! Tangential vectors can then be assigned, using the function Load.
0099   //! If PeriodicFlag is true, the constrained BSpline
0100   //! curve will be periodic and closed. In this case,
0101   //! the junction point is the first point of the table Points.
0102   //! The tolerance value Tolerance is used to check that:
0103   //! -   points are not too close to each other, or
0104   //! -   tangential vectors (defined using the
0105   //! function Load) are not too small.
0106   //! The resulting BSpline curve will be "C2"
0107   //! continuous, except where a tangency
0108   //! constraint is defined on a point through which
0109   //! the curve passes (by using the Load function).
0110   //! In this case, it will be only "C1" continuous.
0111   //! Once all the constraints are defined, use the
0112   //! function Perform to compute the curve.
0113   //! Warning
0114   //! -   There must be at least 2 points in the table Points.
0115   //! -   If PeriodicFlag is false, there must be as
0116   //! many parameters in the array Parameters as
0117   //! there are points in the array Points.
0118   //! -   If PeriodicFlag is true, there must be one
0119   //! more parameter in the table Parameters: this
0120   //! is used to give the parameter on the
0121   //! resulting BSpline curve of the junction point
0122   //! of the curve (which is also the first point of the table Points).
0123   //! Exceptions
0124   //! -   Standard_ConstructionError if the
0125   //! distance between two consecutive points in
0126   //! the table Points is less than or equal to Tolerance.
0127   //! -   Standard_OutOfRange if:
0128   //! -   there are less than two points in the table Points, or
0129   //! -   conditions relating to the respective
0130   //! number of elements in the parallel tables
0131   //! Points and Parameters are not respected.
0132   Standard_EXPORT GeomAPI_Interpolate(const occ::handle<NCollection_HArray1<gp_Pnt>>& Points,
0133                                       const occ::handle<NCollection_HArray1<double>>& Parameters,
0134                                       const bool                                      PeriodicFlag,
0135                                       const double                                    Tolerance);
0136 
0137   //! Assigns this constrained BSpline curve to be
0138   //! tangential to vectors InitialTangent and FinalTangent
0139   //! at its first and last points respectively (i.e.
0140   //! the first and last points of the table of
0141   //! points through which the curve passes, as
0142   //! defined at the time of initialization).
0143   Standard_EXPORT void Load(const gp_Vec& InitialTangent,
0144                             const gp_Vec& FinalTangent,
0145                             const bool    Scale = true);
0146 
0147   //! Assigns this constrained BSpline curve to be
0148   //! tangential to vectors defined in the table Tangents,
0149   //! which is parallel to the table of points
0150   //! through which the curve passes, as
0151   //! defined at the time of initialization. Vectors
0152   //! in the table Tangents are defined only if
0153   //! the flag given in the parallel table
0154   //! TangentFlags is true: only these vectors
0155   //! are set as tangency constraints.
0156   Standard_EXPORT void Load(const NCollection_Array1<gp_Vec>&             Tangents,
0157                             const occ::handle<NCollection_HArray1<bool>>& TangentFlags,
0158                             const bool                                    Scale = true);
0159 
0160   //! Clears all tangency constraints on this
0161   //! constrained BSpline curve (as initialized by the function Load).
0162   Standard_EXPORT void ClearTangents();
0163 
0164   //! Computes the constrained BSpline curve.
0165   //! Use the function IsDone to verify that the
0166   //! computation is successful, and then the function Curve to obtain the result.
0167   Standard_EXPORT void Perform();
0168 
0169   //! Returns the computed BSpline curve.
0170   //! Raises StdFail_NotDone if the interpolation fails.
0171   Standard_EXPORT const occ::handle<Geom_BSplineCurve>& Curve() const;
0172   Standard_EXPORT operator occ::handle<Geom_BSplineCurve>() const;
0173 
0174   //! Returns true if the constrained BSpline curve is successfully constructed.
0175   //! Note: in this case, the result is given by the function Curve.
0176   Standard_EXPORT bool IsDone() const;
0177 
0178 private:
0179   //! Interpolates in a non periodic fashion
0180   Standard_EXPORT void PerformNonPeriodic();
0181 
0182   //! Interpolates in a C1 periodic fashion
0183   Standard_EXPORT void PerformPeriodic();
0184 
0185   double                                   myTolerance;
0186   occ::handle<NCollection_HArray1<gp_Pnt>> myPoints;
0187   bool                                     myIsDone;
0188   occ::handle<Geom_BSplineCurve>           myCurve;
0189   occ::handle<NCollection_HArray1<gp_Vec>> myTangents;
0190   occ::handle<NCollection_HArray1<bool>>   myTangentFlags;
0191   occ::handle<NCollection_HArray1<double>> myParameters;
0192   bool                                     myPeriodic;
0193   bool                                     myTangentRequest;
0194 };
0195 
0196 #endif // _GeomAPI_Interpolate_HeaderFile