G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsLagrangePoly.h
1 // defined over a Lagrange basis
2 
3 #pragma once
4 
5 #include <ostream>
6 
8 #include <gsCore/gsGeometry.h>
9 #include "gsLagrangeBasis.h"
10 
11 
12 namespace gismo
13 {
14 
25 template<class T>
26 class gsLagrangePoly : public gsGeoTraits<1,T>::GeometryBase
27 {
28 
29 public:
30  typedef gsLagrangeBasis<T> Basis;
31  typedef typename gsGeoTraits<1,T>::GeometryBase Base;
32 
34  typedef memory::shared_ptr< gsLagrangePoly > Ptr;
35 
37  typedef memory::unique_ptr< gsLagrangePoly > uPtr;
38 
40  gsLagrangePoly() : Base() { }
41 
44  Base( basis, give(coefs)) { }
45 
47  gsLagrangePoly( const unsigned & p, const gsMatrix<T> & coefs, const T & u0=0, const T & u1= 1) : Base()
48  {
49  gsLagrangeBasis<T> * lagrange_basis = new Basis(u0,u1,p-1);
51  Base::m_basis=lagrange_basis;
52  GISMO_ASSERT( lagrange_basis->size() == this->m_coefs.rows(),
53  "The coefficient matrix of the geometry (rows="<<this->m_coefs.rows()<<") does not match the number of basis functions in its basis("<< lagrange_basis->size() <<").");
54  }
55 
58  gsLagrangePoly( const gsBSpline<T> & bezier_curve, int part) : Base()
59  {
60  gsBSplineBasis<T> basis = bezier_curve.basis();
61  gsKnotVector<T> * bezier_knots = &basis.knots();
62  T start = (*bezier_knots)[part];
63  T end = (*bezier_knots)[part+1];
64  gsLagrangeBasis<T> * lagrange_basis = new gsLagrangeBasis<T>(0,1, basis.degree()-1);
65  gsMatrix<T> lagrange_coeffs;
66  const std::vector<T> * lagrange_breaks = lagrange_basis->get_m_breaks();
67  gsMatrix<T> u(1,lagrange_breaks->size());
68  for(unsigned i = 0;i<lagrange_breaks->size();i++)
69  {
70  u(0,i)=start+(end-start)*lagrange_breaks->at(i);
71  }
72  bezier_curve.eval_into(u,lagrange_coeffs);
73  Base::m_coefs=lagrange_coeffs.transpose();
74  Base::m_basis=lagrange_basis;
75  GISMO_ASSERT( lagrange_basis->size() == this->m_coefs.rows(),
76  "The coefficient matrix of the geometry (rows="<<this->m_coefs.rows()<<") does not match the number of basis functions in its basis("<< lagrange_basis->size() <<").");
77  }
78 
79 
80 public:
81 
82  GISMO_BASIS_ACCESSORS
83 
84  GISMO_CLONE_FUNCTION(gsLagrangePoly)
85 
86 
87  std::ostream &print(std::ostream &os) const
88  {
89  os << "Lagrange curve of degree "<<
90  this->basis().degree()<< ", over [" << domainStart()
91  << " " << domainEnd() << "] with breaks ";
92  for ( typename std::vector<T>::const_iterator itr=
93  this->basis().get_m_breaks()->begin(); itr != this->basis().get_m_breaks()->end(); ++itr )
94  os << *itr << ", ";
95  return os;
96  }
97 
98 
100 // Additional members for univariate B-Splines
102 
104  T domainStart() const { return this->basis().get_m_start(); }
105 
107  T domainEnd() const { return this->basis().get_m_end(); }
108 
113  {
114  gsMatrix<T> transformMat;
115  this->basis().getTransformationLagrangeBezier(transformMat);
116  gsMatrix<T> newCoefs = transformMat*this->coefs();
117  unsigned deg = this->basis().degree();
118  gsBSpline<T> * bezCurve = new gsBSpline<T>(0.0,1.0,0,deg,newCoefs);
119  return bezCurve;
120  }
121 
124  {
125  this->basis().reparameterizeToZeroOne();
126  }
127 
128 // Data members
129 private:
130 
131 }; // class gsLagrangePoly
132 
133 
134 
135 }; // namespace gismo
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition: gsGeometry.h:624
const std::vector< T > * get_m_breaks() const
Returns the breaks vector of this basis.
Definition: gsLagrangeBasis.h:325
T domainEnd() const
Returns the end value of the domain of the basis.
Definition: gsLagrangePoly.h:107
memory::shared_ptr< gsLagrangePoly > Ptr
Shared pointer for gsLagrangePoly.
Definition: gsLagrangePoly.h:34
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition: gsGeometry.h:627
short_t degree(short_t i) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsBSplineBasis.h:322
memory::unique_ptr< gsLagrangePoly > uPtr
Unique pointer for gsLagrangePoly.
Definition: gsLagrangePoly.h:37
S give(S &x)
Definition: gsMemory.h:266
Provides declaration of Geometry abstract interface.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
gsLagrangePoly(const Basis &basis, gsMatrix< T > coefs)
Construct B-Spline by basis and coefficient matrix.
Definition: gsLagrangePoly.h:43
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
The geometry class of a Lagrange Polyomial curve.
Definition: gsLagrangeBasis.h:17
GISMO_BASIS_ACCESSORS std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsLagrangePoly.h:87
gsLagrangePoly()
Default empty constructor.
Definition: gsLagrangePoly.h:40
const KnotVectorType & knots(int i=0) const
Returns the knot vector of the basis.
Definition: gsBSplineBasis.h:369
gsLagrangePoly(const unsigned &p, const gsMatrix< T > &coefs, const T &u0=0, const T &u1=1)
Construct Lagrange curve by degree, coefficient matrix and domain.
Definition: gsLagrangePoly.h:47
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
gsBSpline< T > * transformToBezier()
Definition: gsLagrangePoly.h:112
gsLagrangePoly(const gsBSpline< T > &bezier_curve, int part)
Definition: gsLagrangePoly.h:58
T domainStart() const
Returns the starting value of the domain of the basis.
Definition: gsLagrangePoly.h:104
void reparameterizeToZeroOne()
reparameterize this curve to [0,1]
Definition: gsLagrangePoly.h:123
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsGeometry.hpp:166
Class for representing a knot vector.
Definition: gsKnotVector.h:79
This is the main header file that collects wrappers of Eigen for linear algebra.
short_t size() const
Returns the number of basis functions in the basis.
Definition: gsLagrangeBasis.h:239
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
A univariate Lagrange basis.
Definition: gsLagrangeBasis.h:16
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340