G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsNurbsBasis.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 #include <gsCore/gsRationalBasis.h>
18 
19 #include <gsNurbs/gsBSplineBasis.h>
20 #include <gsNurbs/gsBoehm.h>
21 
22 
23 namespace gismo
24 {
25 
38 template<class T>
39 class gsNurbsBasis : public gsRationalBasis<gsBSplineBasis<T> >
40 {
41 public:
42 
43  typedef gsKnotVector<T> KnotVectorType;
44 
47 
50 
52 
53  typedef T Scalar_t;
54 
57 
58  typedef memory::shared_ptr< gsNurbsBasis > Ptr;
59  typedef memory::unique_ptr< gsNurbsBasis > uPtr;
60 
62  static const int Dim = 1;
63 
64 public:
65 
72  gsNurbsBasis(T u0, T u1, unsigned interior, int degree, unsigned mult_interior=1):
73  Base( gsBSplineBasis<T>(u0,01,interior,degree,mult_interior) )
74  {
75  // if( ! check() )
76  // gsWarn << "Warning: Inconsistent "<< *this<< "\n";
77  }
78 
80  gsNurbsBasis() : Base() { }
81 
84  Base( bs, give(w) ) { }
85 
87  gsNurbsBasis( const gsKnotVector<T> & KV ) :
88  Base( new gsBSplineBasis<T>(KV) )
89  { }
90 
93  Base( new gsBSplineBasis<T>(KV), give(w) ) { }
94 
96  gsNurbsBasis( const gsNurbsBasis & o) : Base(o) { }
97 
98  ~gsNurbsBasis() { } //destructor
99 
100 public:
101 
103  GISMO_CLONE_FUNCTION(gsNurbsBasis)
104 
105  GISMO_MAKE_GEOMETRY_NEW
106 
108  std::ostream &print(std::ostream &os) const
109  {
110  os << "NURBS Basis: deg=" << this->degree()
111  << ", size=" << this->size() << ", knot vector:\n";
112  os << this->knots() << ", weights: [ ";
113  os << this->weights().transpose() << " ]";
114  return os;
115  }
116 
117  using Base::source;
118 
119 // ***********************************************
120 // Additional members which forward to gsBSplineBasis
121 // ***********************************************
122 
124  T domainStart() const { return this->source().domainStart(); };
125 
127  T domainEnd() const { return this->source().domainEnd(); };
128 
130  inline unsigned firstActive(const T & u) const { return this->source().firstActive(u); }
131 
136  inline index_t numActive() const { return this->source().numActive(); }
137 
141  { return this->source().firstActive(u); };
142 
143  // /// Returns the knot vector of the basis
144  const KnotVectorType & knots() const { return this->source().knots(); }
145  KnotVectorType & knots() { return this->source().knots(); }
146 
148  void insertKnot( T val, int i = 1)
149  {
150  // TO DO: There is also Oslo Algorithm and others
151  gsBoehm( this->knots(), this->weights(), val, i );
152  }
153 
155  template <class It>
156  void insertKnots( It begin, It end )
157  {
158  gsBoehmRefine( this->knots(), this->weights(), this->degree(), begin, end);
159  }
160 
162  void uniformRefine(int numKnots = 1, int mul=1, int dir = -1)
163  {
164  GISMO_UNUSED(dir);
165  // TO DO ; replace this with global refinemnt by
166  // Lane-Riesenfeld-like Algorithm
167  std::vector<T> newKnots;
168  this->knots().getUniformRefinementKnots(numKnots, newKnots,mul);
169  this->insertKnots( newKnots.begin(), newKnots.end() );
170  }
171 
173  void uniform_k_refine(int const & i = 1)
174  {
175  //m_p += i;
176  //m_knots->degreeElevate(i);
177  //m_knots->uniformRefine();
178  };
179 
180 }; // class gsNurbsBasis
181 
182 
183 } // namespace gismo
void gsBoehm(KnotVectorType &knots, Mat &coefs, T val, int r=1, bool update_knots=true)
Performs insertion of multiple knot on &quot;knots&quot; and coefficients &quot;coefs&quot;.
Definition: gsBoehm.hpp:29
gsConstantBasis< T > BoundaryBasisType
Associated Boundary basis type.
Definition: gsNurbsBasis.h:56
Class defining a dummy basis of constant functions. This is used for compatibility reasons...
Definition: gsConstantBasis.h:34
gsNurbsBasis()
Default empty constructor.
Definition: gsNurbsBasis.h:80
A NURBS function of one argument, with arbitrary target dimension.
Definition: gsNurbs.h:39
index_t size() const
size
Definition: gsRationalBasis.h:137
Class that creates a rational counterpart for a given basis.
Definition: gsRationalBasis.h:47
Boehm&#39;s algorithm for knot insertion.
void gsBoehmRefine(KnotVectorType &knots, Mat &coefs, int p, ValIt valBegin, ValIt valEnd, bool update_knots=true)
Definition: gsBoehm.hpp:163
S give(S &x)
Definition: gsMemory.h:266
gsNurbsBasis(T u0, T u1, unsigned interior, int degree, unsigned mult_interior=1)
Construct a NURBS basis with unit weights.
Definition: gsNurbsBasis.h:72
gsBSplineBasis< T > Family_t
The family type.
Definition: gsNurbsBasis.h:46
#define index_t
Definition: gsConfig.h:32
short_t degree(short_t i=0) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsRationalBasis.h:162
memory::shared_ptr< gsFunctionSet > Ptr
Shared pointer for gsFunctionSet.
Definition: gsFunctionSet.h:223
void uniformRefine(int numKnots=1, int mul=1, int dir=-1)
Refine the basis uniformly by inserting numKnots new knots per knot span.
Definition: gsNurbsBasis.h:162
gsNurbsBasis(const gsNurbsBasis &o)
Copy Constructor.
Definition: gsNurbsBasis.h:96
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
index_t numActive() const
Number of active basis functions at an arbitrary parameter value.
Definition: gsNurbsBasis.h:136
gsMatrix< unsigned, 1 > * firstActive(const gsMatrix< T, 1 > &u) const
Definition: gsNurbsBasis.h:140
memory::unique_ptr< gsFunctionSet > uPtr
Unique pointer for gsFunctionSet.
Definition: gsFunctionSet.h:226
Provides declaration of BSplineBasis class.
gsNurbsBasis(gsBSplineBasis< T > *bs, gsMatrix< T > w)
Construct NURBS basis by a Bspline basis plus weights.
Definition: gsNurbsBasis.h:83
Provides forward declarations of types and structs.
gsNurbsBasis(const gsKnotVector< T > &KV, gsMatrix< T > w)
Construct a rational counterpart of B-spline basis given by knots and weights.
Definition: gsNurbsBasis.h:92
void uniform_k_refine(int const &i=1)
Apply k-refinement to the basis i times.
Definition: gsNurbsBasis.h:173
const gsBSplineBasis< T > & source() const
Returns the source basis of the rational basis.
Definition: gsRationalBasis.h:283
const gsMatrix< T > & weights() const
Returns the weights of the rational basis.
Definition: gsRationalBasis.h:290
gsNurbsBasis(const gsKnotVector< T > &KV)
Construct NURBS basis of a knot vector.
Definition: gsNurbsBasis.h:87
Provides declaration of RationalBasis class.
A univariate NURBS basis.
Definition: gsNurbsBasis.h:39
void insertKnot(T val, int i=1)
Insert a new knot val with multiplicity i.
Definition: gsNurbsBasis.h:148
static const int Dim
Dimension of the parameter domain.
Definition: gsNurbsBasis.h:62
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
unsigned firstActive(const T &u) const
Returns the index of the first active (ie. non-zero) basis function at point u.
Definition: gsNurbsBasis.h:130
Class for representing a knot vector.
Definition: gsKnotVector.h:79
void insertKnots(It begin, It end)
Insert the new knots given by the range [begin..end).
Definition: gsNurbsBasis.h:156
T domainEnd() const
Returns the starting value of the domain of the basis.
Definition: gsNurbsBasis.h:127
gsNurbs< T > GeometryType
Associated geometry type.
Definition: gsNurbsBasis.h:49
T domainStart() const
Returns the starting value of the domain of the basis.
Definition: gsNurbsBasis.h:124
GISMO_MAKE_GEOMETRY_NEW std::ostream & print(std::ostream &os) const
Clone function. Used to make a copy of a derived basis.
Definition: gsNurbsBasis.h:108