29 struct gsCurveIntersectionResult;
50 class gsBSpline :
public gsGeoTraits<1,T>::GeometryBase
60 typedef memory::shared_ptr< gsBSpline >
Ptr;
63 typedef memory::unique_ptr< gsBSpline >
uPtr;
77 if( this->
basis().isPeriodic() )
91 this->
basis().setPeriodic();
103 GISMO_ERROR(
"Wrong number of coefficients for periodic basis.");
108 if( this->
m_coefs.rows() + KV.degree() + 1 !=
static_cast<int>( this->
knots().size() ) )
109 gsWarn <<
"gsBSpline Warning: #Knots="<< this->
knots().size()<<
", #coefs="<< this->
m_coefs.rows() <<
"\n";
127 this->
m_basis =
new Basis(u0, u1, interior, degree, mult_interior, periodic );
131 "Knot vector with clamped knots should lead to m_periodic == 1.");
135 "You should give at least as many coefficients as the size of the basis after converting to periodic.");
137 gsWarn <<
"Some of the last coefficients are going to be lost during conversion to periodic basis.\n";
143 "Number of coefficients does not match the size of the basis.");
149 GISMO_BASIS_ACCESSORS
154 std::ostream &
print(std::ostream &os)
const
156 os <<
"BSpline curve "<<
"of degree "<< this->
basis().degree()<<
", "<< this->
basis().knots() <<
".\n";
157 os <<
"with control points "<< this->
m_coefs.row(0)<<
" ... "<<this->
m_coefs.bottomRows(1) <<
".\n";
158 if( this->
basis().isPeriodic() )
159 os <<
"Periodic with overlay " << this->
basis().numCrossingFunctions() <<
".\n";
170 KnotVectorType &
knots(
const int i = 0)
173 GISMO_ASSERT( i==0,
"Requested knots of invalid direction "<< i );
174 return this->
basis().knots();
178 const KnotVectorType &
knots(
const int i = 0)
const
181 GISMO_ASSERT( i==0,
"Requested knots of invalid direction "<< i );
182 return this->
basis().knots();
189 GISMO_ASSERT( i==0,
"Requested knots of invalid direction "<< i );
190 return this->
basis().degree();
198 void makeCompatible( gsGeometry<T> * )
203 void merge( gsGeometry<T> * otherG );
211 gsBSpline<T>
segmentFromTo(T u0, T u1, T tolerance=1e-15)
const;
219 void splitAt(T u0, gsBSpline<T>& left, gsBSpline<T>& right, T tolerance=1e-15)
const;
224 gsMultiPatch<T>
toBezier(T tolerance=1e-15)
const;
232 std::vector<internal::gsCurveIntersectionResult<T>>
intersect(
const gsBSpline<T>& other, T tolerance = 1e-5, T curvatureTolerance=1+1e-6)
const;
255 if( this->
basis().isPeriodic() )
260 && (*(inEnd-1) < *(this->
knots().end()-1)),
261 "Please, ask me to insert knots inside the knot interval only." );
263 std::vector<T> newKnots(inBegin,inEnd);
268 T activeLength = this->
basis()._activeLength();
269 T blue1 = *(this->
basis().knots().begin() + this->
degree() );
270 T blue2 = *(this->
basis().knots().end() - this->
degree() );
271 typename std::vector<T>::iterator begin = newKnots.begin();
272 typename std::vector<T>::iterator end = newKnots.end();
273 for(
typename std::vector<T>::iterator it = begin; it != end; ++it )
277 else if( *it > blue2 )
279 else if( (*it == blue1) || (*it == blue2) )
283 gsWarn <<
"Interrupting insertKnots(): Cannot insert value equal to the p+1st knot from the beginning or end into a periodic curve.\n";
293 std::sort( begin, end );
315 assert( p.cols()==1 );
317 std::vector<T> roots;
322 slv.allRoots( *
this, roots, 0, p(0,0), 1e-6, 100);
323 for (
typename std::vector<T>::const_iterator it=roots.begin();
324 it != roots.end(); ++it)
328 for (i=1; i!=dim; ++i )
329 if (
math::abs( ev(i,0) - p(i,0) ) > tol )
350 this->
basis().setPeriodic(flag);
354 inline int numCoefs()
const {
return this->
m_coefs.rows() - this->
basis().numCrossingFunctions(); }
356 inline bool isPeriodic()
const {
return this->
basis().isPeriodic(); }
362 return ( this->
basis().isPeriodic() ||
391 void swapDirections(
const unsigned i,
const unsigned j);
402 #ifdef GISMO_WITH_PYBIND11
407 void pybind11_init_gsBSpline(pybind11::module &m);
409 #endif // GISMO_WITH_PYBIND11
433 #ifndef GISMO_BUILD_LIB
434 #include GISMO_HPP_HEADER(gsBSpline.hpp)
bool isPatchCorner(gsMatrix< T > const &v, T tol=1e-3) const
Return true if point u is an endpoint (corner) of the curve with tolerance tol.
Definition: gsBSpline.hpp:291
gsMatrix< T > sample(int npoints=50) const
Sample npoints uniformly distributed (in parameter domain) points on the curve.
Definition: gsBSpline.h:338
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
void merge(gsGeometry< T > *otherG)
Merge other B-spline into this one.
Definition: gsBSpline.hpp:29
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition: gsGeometry.h:624
T pseudoCurvature() const
Definition: gsBSpline.hpp:189
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
gsBSpline(const Basis &basis, gsMatrix< T > coefs)
Construct B-Spline by basis and coefficient matrix.
Definition: gsBSpline.h:74
gsMatrix< T > parameterRange() const
Returns the range of parameters as a matrix with two columns, [lower upper].
Definition: gsGeometry.hpp:198
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition: gsGeometry.h:627
#define short_t
Definition: gsConfig.h:35
gsBSpline()
Default empty constructor.
Definition: gsBSpline.h:68
bool isOn(gsMatrix< T > const &u, T tol=1e-3) const
Return true if point u is on the curve with tolerance tol.
Definition: gsBSpline.hpp:265
void setFurthestCorner(gsMatrix< T > const &v)
Modifies the parameterization such that the point v is the ending point of the curve. Assumes that v is either the starting or the ending point of the curve.
Definition: gsBSpline.hpp:326
Boehm'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
Provides declaration of Geometry abstract interface.
memory::unique_ptr< gsBSpline > uPtr
Unique pointer for gsBSpline.
Definition: gsBSpline.h:63
#define index_t
Definition: gsConfig.h:32
T domainEnd() const
Returns the end value of the domain of the basis.
Definition: gsBSpline.h:167
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
void setOriginCorner(gsMatrix< T > const &v)
Modifies the parameterization such that the point v is the starting point of the curve. Assumes that v is either the starting or the ending point of the curve.
Definition: gsBSpline.hpp:315
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
void insertKnot(T knot, index_t i=1)
Definition: gsBSpline.hpp:249
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition: gsVector.h:35
#define gsWarn
Definition: gsDebug.h:50
Provides declaration of BSplineBasis class.
bool isClosed(T tol=1e-10) const
Returns true if this curve is closed.
Definition: gsBSpline.h:360
gsMatrix< T > gsPointGrid(gsVector< T > const &a, gsVector< T > const &b, gsVector< unsigned > const &np)
Construct a Cartesian grid of uniform points in a hypercube, using np[i] points in direction i...
Definition: gsPointGrid.hpp:82
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsBSpline.h:154
KnotVectorType & knots(const int i=0)
Returns a reference to the knot vector.
Definition: gsBSpline.h:170
void setPeriodic(bool flag=true)
Tries to convert the curve into periodic.
Definition: gsBSpline.h:348
std::vector< internal::gsCurveIntersectionResult< T > > intersect(const gsBSpline< T > &other, T tolerance=1e-5, T curvatureTolerance=1+1e-6) const
Definition: gsBSpline.hpp:156
const KnotVectorType & knots(const int i=0) const
Returns a (const )reference to the knot vector.
Definition: gsBSpline.h:178
void degreeElevate(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition: gsBSpline.hpp:347
void insertKnots(It inBegin, It inEnd)
Definition: gsBSpline.h:253
gsMultiPatch< T > toBezier(T tolerance=1e-15) const
Definition: gsBSpline.hpp:138
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsGeometry.hpp:166
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
Provides functions to generate structured point data.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Class for representing a knot vector.
Definition: gsKnotVector.h:79
memory::shared_ptr< gsBSpline > Ptr
Shared pointer for gsBSpline.
Definition: gsBSpline.h:60
This is the main header file that collects wrappers of Eigen for linear algebra.
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4488
Definition: gsBSplineSolver.h:113
void findCorner(const gsMatrix< T > &v, gsVector< index_t, 1 > &curr, T tol=1e-3)
returns the tensor-index curr of the corner control point v, or an invalid index if the corner is not...
Definition: gsBSpline.hpp:298
Provides classes and functions to solve equations involving B-splines.
gsBSpline(T u0, T u1, unsigned interior, int degree, gsMatrix< T > coefs, unsigned mult_interior=1, bool periodic=false)
Construct a B-spline from an interval and knot vector specification.
Definition: gsBSpline.h:124
gsBSpline< T > segmentFromTo(T u0, T u1, T tolerance=1e-15) const
Definition: gsBSpline.hpp:87
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
T domainStart() const
Returns the starting value of the domain of the basis.
Definition: gsBSpline.h:164
gsBSpline(KnotVectorType KV, gsMatrix< T > coefs, bool periodic=false)
Construct B-Spline by a knot vector and coefficient matrix.
Definition: gsBSpline.h:82
short_t degree(short_t i=0) const
Returns the degree of the B-spline.
Definition: gsBSpline.h:186
bool contains(gsMatrix< T > const &p, T const &tol=1e-6)
Returns true iff the point p is contained (approximately) on the curve, with the given tolerance...
Definition: gsBSpline.h:313
short_t geoDim() const
Dimension n of the absent physical space.
Definition: gsGeometry.h:292
void splitAt(T u0, gsBSpline< T > &left, gsBSpline< T > &right, T tolerance=1e-15) const
Definition: gsBSpline.hpp:255
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340