88 typedef std::vector<T> knotContainer;
89 typedef std::vector<mult_t> multContainer;
97 typedef typename std::vector<T>::const_iterator
iterator;
98 typedef std::reverse_iterator<iterator> reverse_iterator;
103 typedef std::reverse_iterator<uiterator> reverse_uiterator;
108 typedef std::reverse_iterator<smart_iterator> reverse_smart_iterator;
113 typedef reverse_iterator const_reverse_iterator;
122 reverse_iterator
rbegin()
const;
124 reverse_iterator
rend()
const;
141 reverse_uiterator
urbegin()
const;
143 reverse_uiterator
urend()
const;
150 reverse_smart_iterator
rsbegin()
const;
152 reverse_smart_iterator
rsend()
const;
178 void insert(T knot, mult_t mult = 1 );
183 template<
typename iterType>
184 void insert( iterType ibeg, iterType iend )
189 knotContainer temp(m_repKnots.size()+(iend-ibeg) );
190 std::merge(
begin(),
end(), ibeg, iend, temp.begin() );
192 m_repKnots.swap(temp);
204 void remove(
uiterator uit, mult_t mult = 1 );
207 void remove(
const T knot, mult_t mult = 1 );
221 mult_t
multLast()
const {
return m_multSum.back() - m_multSum.end()[-2]; }
242 inline size_t size()
const {
return m_repKnots.size(); }
245 inline size_t uSize()
const {
return m_multSum.size(); }
250 GISMO_ASSERT( static_cast<size_t>(i) < m_repKnots.size(),
251 "Index "<<i<<
" not in the knot vector.");
252 return m_repKnots[i];
259 "Unique index "<<i<<
" not in the knot vector.");
275 return knotContainer(this->
ubegin(),this->
uend());
282 operator const knotContainer& ()
const {
return m_repKnots;}
285 const T *
data()
const {
return m_repKnots.data(); }
326 std::ostream &
print(std::ostream &os =
gsInfo )
const;
331 typedef typename knotContainer::iterator nonConstIterator ;
332 typedef typename multContainer::iterator nonConstMultIterator;
337 GISMO_ASSERT(
size() > static_cast<size_t>(2*m_deg+1),
"Not enough knots.");
338 return begin() + m_deg;
344 GISMO_ASSERT(
size() > static_cast<size_t>(2*m_deg+1),
"Not enough knots.");
345 return end() - (m_deg + 1);
351 {
return sbegin() + m_deg; }
356 {
return send() - (m_deg + 1); }
386 void trimLeft (
const mult_t numKnots);
396 it += math::min( (
size_t)m_deg,
size() );
410 static bool isConsistent(
const knotContainer & repKnots,
411 const multContainer & multSums);
416 return (m_repKnots == other.m_repKnots) &&
417 (m_multSum == other.m_multSum ) &&
418 (m_deg == other.m_deg);
424 void rebuildMultSum();
429 knotContainer m_repKnots;
432 multContainer m_multSum;
461 mult_t mult_interior=1,
470 template<
typename iterType>
473 insert(begOfKnots,endOfKnots);
488 unsigned mult_interior,
497 unsigned mult_interior = 1,
508 T grading = 0.5,
unsigned mult_interior = 1)
510 initGraded( 0.0, 1.0, numKnots - 2, degree, grading, mult_interior);
515 T grading,
unsigned mult_interior = 1)
520 m_repKnots.reserve( 2*(m_deg+1) + interior*mult_interior );
521 m_multSum .reserve(interior+2);
523 const T h = (u1-u0) / (T)(interior+1);
525 m_repKnots.insert(m_repKnots.begin(), m_deg+1, u0);
526 m_multSum .push_back(m_deg+1);
528 for (
unsigned i=1; i<=interior; i++ )
530 m_repKnots.insert(m_repKnots.end(), mult_interior,
531 math::pow(T(i)*h, 1.0/grading) );
532 m_multSum .push_back( mult_interior + m_multSum.back() );
534 m_repKnots.insert(m_repKnots.end(), m_deg+1, u1);
535 m_multSum .push_back( m_deg+1 + m_multSum.back() );
591 std::vector<T>& result)
const;
599 std::vector<T>& result)
const;
624 void insert(
const knotContainer &knots,
int mult = 1 )
626 for(
int i = 0; i < mult; ++i)
627 insert( knots.begin(), knots.end() );
646 template<
typename iterType>
651 input.insert(input.begin(),
begin,
end);
652 std::sort(input.begin(), input.end());
654 knotContainer newKnots;
655 T segmentsPerSpan = knotsPerSpan + 1;
659 for(
typename multContainer::const_iterator it= input.begin();
662 for( mult_t k = 1; k <= knotsPerSpan; ++k )
664 spanBegin =*(this->
ubegin()+*it);
665 spanEnd =*(this->
ubegin()+*it+1);
666 newKnot = ( (segmentsPerSpan-(T)(k)) * spanBegin + (T)(k) * spanEnd ) / segmentsPerSpan;
667 newKnots.push_back( newKnot );
670 insert(newKnots.begin(), newKnots.end());
695 unsigned mult_interior = 1)
697 return initUniform(u0, u1, interior, degree + 1, mult_interior, degree );
724 return m_repKnots.front();
731 return m_repKnots.back();
741 void refineSpans(
const std::vector<unsigned> & spanIndices, mult_t knotsPerSpan = 1)
743 multContainer transformedIndices;
744 transformedIndices.reserve(spanIndices.size());
745 for( std::vector<unsigned>::const_iterator it = spanIndices.begin();
746 it != spanIndices.end();
748 transformedIndices.push_back(static_cast<mult_t>(*it));
750 return refineSpans( transformedIndices, knotsPerSpan );
755 void refineSpans(
const multContainer & spanIndices, mult_t knotsPerSpan = 1);
762 m_repKnots.reserve(
size()+2*i);
763 m_repKnots.insert(m_repKnots.begin(), i, m_repKnots.front() );
764 m_repKnots.insert(m_repKnots.end() , i, m_repKnots.back() );
767 std::transform(m_multSum.begin(), m_multSum.end(), m_multSum.begin(),
768 GS_BIND2ND(std::plus<mult_t>(), i) );
769 m_multSum.back() += i;
778 remove(
uend() - 1, i );
787 if ( itr.multiplicity() > m_deg )
788 remove( itr, itr.multiplicity() - m_deg );
801 template<
typename iterType>
810 const knotContainer&
get()
const
819 inline bool has(T knot)
const
821 return std::binary_search(
ubegin(),
uend(), knot);
830 return (
ubegin() + i).multiplicity();
837 return (
ubegin()+i).firstAppearance();
846 return (
ubegin()+i).lastAppearance();
855 return (
ubegin()+i).multSum();
861 return ! ((*this)==other);
865 inline T
at (
const size_t & i)
const
867 return m_repKnots.at(i);
875 if(
math::abs(*uit - (*uit-(T)(1)) - df) > tol )
884 const int dp1 = m_deg + 1;
908 mult_t mult = 1)
const;
911 std::string
detail()
const;
943 std::ostream& operator << (std::ostream& out, const gsKnotVector<T> KV )
950 #ifdef GISMO_WITH_PYBIND11
955 void pybind11_init_gsKnotVector(pybind11::module &m);
957 #endif // GISMO_WITH_PYBIND11
963 #ifndef GISMO_BUILD_LIB
964 #include GISMO_HPP_HEADER(gsKnotVector.hpp)
966 #ifdef gsKnotVector_EXPORT
967 #include GISMO_HPP_HEADER(gsKnotVector.hpp)
968 #undef EXTERN_CLASS_TEMPLATE
969 #define EXTERN_CLASS_TEMPLATE CLASS_TEMPLATE_INST
973 EXTERN_CLASS_TEMPLATE gsKnotVector<real_t>;
Class representing a domain. i.e. a collection of elements (triangles, rectangles, cubes, simplices.
Definition: gsDomain.h:31
const T & operator()(const mult_t i) const
Provides the knot with unique index i.
Definition: gsKnotVector.h:256
reverse_iterator rbegin() const
Returns reverse iterator pointing past the end of the repeated knots.
Definition: gsKnotVector.hpp:147
internal::gsUKnotIterator< T > uiterator
Definition: gsKnotVector.h:102
knotContainer unique() const
Returns unique knots.
Definition: gsKnotVector.h:273
const T * data() const
Returns a pointer to the beginning of the vector of knots.
Definition: gsKnotVector.h:285
static bool isConsistent(const knotContainer &repKnots, const multContainer &multSums)
Sanity check.
Definition: gsKnotVector.hpp:542
gsKnotVector knotIntersection(const gsKnotVector &b) const
Computes the intersection of knot-vectors this and b.
Definition: gsKnotVector.hpp:201
multContainer multiplicities() const
Returns vector of multiplicities of the knots.
Definition: gsKnotVector.hpp:714
void affineTransformTo(T newBeg, T newEnd)
Definition: gsKnotVector.hpp:450
void refineSpans(iterType begin, iterType end, mult_t knotsPerSpan)
Inserts knotsPerSpan knots between each two knots between begin and end.
Definition: gsKnotVector.h:647
unsigned u_multiplicityIndex(size_t const &i) const
Definition: gsKnotVector.h:828
int deduceDegree() const
Definition: gsKnotVector.hpp:706
gsMatrix< T > greville() const
Definition: gsKnotVector.h:540
Abstracgt Base class representing a domain. i.e. a collection of elements (triangles, rectangles, cubes, simplices.
std::string detail() const
Return a string with detailed information on the knot vector.
Definition: gsKnotVector.hpp:800
void trimLeft(const mult_t numKnots)
Removes the left-most numKnots from the knot-vector.
Definition: gsKnotVector.hpp:390
smart_iterator sbegin() const
Returns the smart iterator pointing to the beginning of the repeated knots.
Definition: gsKnotVector.hpp:259
void initClamped(int degree, unsigned numKnots=2, unsigned mult_interior=1)
Definition: gsKnotVector.hpp:693
reverse_uiterator urbegin() const
Returns reverse unique iterator pointing past the end of the unique knots.
Definition: gsKnotVector.hpp:247
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...
mult_t maxInteriorMultiplicity() const
Returns the maximum multiplicity in the interior.
Definition: gsKnotVector.hpp:724
#define short_t
Definition: gsConfig.h:35
reverse_uiterator urend() const
Returns reverse unique iterator pointing to the beginning of the unique knots.
Definition: gsKnotVector.hpp:253
smart_iterator domainSEnd() const
Definition: gsKnotVector.h:355
size_t numElements() const
Number of knot intervals inside domain.
Definition: gsKnotVector.h:268
index_t numLeftGhosts() const
Definition: gsKnotVector.h:393
void addConstant(T amount)
Adds amount to all the knots.
Definition: gsKnotVector.hpp:839
void set_degree(short_t p)
Sets the degree to p.
Definition: gsKnotVector.h:631
void trimRight(const mult_t numKnots)
Removes the right-most numKnots from the knot-vector.
Definition: gsKnotVector.hpp:403
bool operator==(const gsKnotVector< T > &other) const
Compare with another knot vector.
Definition: gsKnotVector.h:414
void erase(const mult_t first, const mult_t last)
Removes the knots in the range [first,last)
Definition: gsKnotVector.hpp:376
void insert(iterType ibeg, iterType iend)
Definition: gsKnotVector.h:184
reverse_smart_iterator rsend() const
Returns the reverse smart iterator pointing to the beginning of the repeated knots.
Definition: gsKnotVector.hpp:277
Struct that defines the boundary sides and corners and types of a geometric object.
Definition: gsBoundary.h:55
mult_t multiplicity(T u) const
Definition: gsKnotVector.hpp:421
iterator domainEnd() const
Returns an iterator pointing to the end-knot of the domain.
Definition: gsKnotVector.h:342
void transform(T c, T d)
See affineTransform().
Definition: gsKnotVector.h:735
void centers_into(gsMatrix< T > &result) const
Definition: gsKnotVector.hpp:1025
void supportIndex_into(const mult_t &i, gsMatrix< index_t > &result) const
Definition: gsKnotVector.hpp:1066
gsAsConstMatrix< T > asMatrix() const
Returns the knots as a matrix of size 1 x size()
Definition: gsKnotVector.h:169
uiterator domainUEnd() const
Returns a unique iterator pointing to the ending knot of the domain.
Definition: gsKnotVector.h:367
size_t size() const
Number of knots (including repetitions).
Definition: gsKnotVector.h:242
#define index_t
Definition: gsConfig.h:32
internal::gsKnotIterator< T > smart_iterator
Definition: gsKnotVector.h:107
std::vector< T >::const_iterator iterator
Definition: gsKnotVector.h:97
void greville_into(gsMatrix< T > &result) const
Definition: gsKnotVector.hpp:991
unsigned knotsUntilSpan(const size_t &i) const
Definition: gsKnotVector.h:853
T last() const
Get the last knot.
Definition: gsKnotVector.h:728
void initClamped(T u0, T u1, int degree, unsigned interior=0, unsigned mult_interior=1)
Resets the knot vector so that it is uniform and has clamped endknots.
Definition: gsKnotVector.h:694
void insert(T knot, mult_t mult=1)
Inserts knot knot into the knot vector with multiplicity mult.
Definition: gsKnotVector.hpp:325
iterator domainBegin() const
Returns an iterator pointing to the starting knot of the domain.
Definition: gsKnotVector.h:335
void refineSpans(const std::vector< unsigned > &spanIndices, mult_t knotsPerSpan=1)
Because of type compatibility, cf. the other version.
Definition: gsKnotVector.h:741
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
iterator iFind(const T u) const
Returns an iterator to the last occurrence of the knot at the beginning of the knot interval containi...
Definition: gsKnotVector.hpp:779
uiterator uFind(const T u) const
Returns the uiterator pointing to the knot at the beginning of the knot interval containing u...
Definition: gsKnotVector.hpp:747
void append(iterType begin, iterType end)
Adds the knots between begin and end to the knot vector.
Definition: gsKnotVector.h:802
const T & operator[](const mult_t i) const
Provides the i-th knot (numbered including repetitions).
Definition: gsKnotVector.h:248
void getUniformRefinementKnots(mult_t knotsPerSpan, knotContainer &result, mult_t mult=1) const
Definition: gsKnotVector.hpp:1048
T minIntervalLength() const
Returns the minimum interval length of the knot sequence.
Definition: gsKnotVector.hpp:527
gsKnotVector(short_t deg, const iterType begOfKnots, const iterType endOfKnots)
Definition: gsKnotVector.h:471
void initUniform(unsigned numKnots, unsigned mult_ends, unsigned mult_interior=1, short_t degree=-1)
Definition: gsKnotVector.h:495
gsKnotVector()
Empty constructor sets the degree to -1 and leaves the knots empty.
Definition: gsKnotVector.h:157
void degreeReduce(const short_t &i)
Converse to degreeElevate.
Definition: gsKnotVector.hpp:944
std::vector< T > coarsen(index_t knotRemove=1, index_t knotSkip=1, mult_t mul=-1)
Definition: gsKnotVector.hpp:952
void initGraded(unsigned numKnots, int degree, T grading=0.5, unsigned mult_interior=1)
Definition: gsKnotVector.h:507
T first() const
Get the first knot.
Definition: gsKnotVector.h:721
const mult_t * multSumData() const
Definition: gsKnotVector.h:289
mult_t minInteriorMultiplicity() const
Returns the minimum multiplicity in the interior.
Definition: gsKnotVector.hpp:733
uiterator domainUBegin() const
Returns a unique iterator pointing to the starting knot of the domain.
Definition: gsKnotVector.h:359
std::ostream & print(std::ostream &os=gsInfo) const
Definition: gsKnotVector.hpp:493
void increaseMultiplicity(const mult_t i=1, bool boundary=false)
Definition: gsKnotVector.hpp:874
void uniformRefine(mult_t numKnots=1, mult_t mult=1)
Definition: gsKnotVector.hpp:820
uiterator ubegin() const
Returns unique iterator pointing to the beginning of the unique knots.
Definition: gsKnotVector.hpp:235
void insert(const knotContainer &knots, int mult=1)
Insert knots into the knot vector.
Definition: gsKnotVector.h:624
index_t numRightGhosts() const
Definition: gsKnotVector.h:402
#define gsInfo
Definition: gsDebug.h:43
uiterator uLowerBound(const T u) const
Returns a uiterator pointing to the first knot which does not compare less than u.
Definition: gsKnotVector.hpp:771
void symDifference(const gsKnotVector< T > &other, std::vector< T > &result) const
Computes the symmetric difference between this knot-vector and other.
Definition: gsKnotVector.hpp:172
smart_iterator domainSBegin() const
Definition: gsKnotVector.h:350
mult_t multFirst() const
Returns the multiplicity of the first knot.
Definition: gsKnotVector.h:218
virtual knotContainer breaks() const
Returns unique knots of the domain (i.e., including the endpoints of the domain). ...
Definition: gsKnotVector.h:897
Provides forward declarations of types and structs.
T maxIntervalLength() const
Returns the maximum interval length of the knot sequence.
Definition: gsKnotVector.hpp:518
bool check() const
Checks whether the knot vector is in a consistent state.
Definition: gsKnotVector.hpp:536
iterator beginAt(mult_t upos) const
Definition: gsKnotVector.hpp:131
Creates a mapped object or data pointer to a const matrix without copying data.
Definition: gsLinearAlgebra.h:127
void difference(const gsKnotVector< T > &other, std::vector< T > &result) const
Computes the difference between this knot-vector and other.
Definition: gsKnotVector.hpp:159
T uValue(const size_t &i) const
Provides the knot with unique index i.
Definition: gsKnotVector.h:264
uiterator uUpperBound(const T u) const
Returns an iterator pointing to the first knot which compares greater than u.
Definition: gsKnotVector.hpp:763
Provides implementation of knot vector iterators.
gsKnotVector(short_t degree)
Sets the degree and leaves the knots uninitialized.
Definition: gsKnotVector.h:446
void degreeElevate(const short_t &i=1)
Definition: gsKnotVector.hpp:937
uiterator uend() const
Returns unique iterator pointing past the end of the unique knots.
Definition: gsKnotVector.hpp:241
void reduceMultiplicity(const mult_t i=1, bool boundary=false)
Definition: gsKnotVector.hpp:903
void swap(gsKnotVector &other)
Swaps with other knot vector.
Definition: gsKnotVector.hpp:302
void degreeDecrease(int const &i=1, bool updateInterior=false)
Inverse of degreeIncrease.
Definition: gsKnotVector.h:775
iterator end() const
Returns iterator pointing past the end of the repeated knots.
Definition: gsKnotVector.hpp:124
T at(const size_t &i) const
Returns the value of the i - th knot (counted with repetitions).
Definition: gsKnotVector.h:865
unsigned firstKnotIndex(const size_t &i) const
Definition: gsKnotVector.h:835
void reverse()
Better directly use affineTransformTo.
Definition: gsKnotVector.hpp:468
mult_t multLast() const
Returns the multiplicity of the last knot.
Definition: gsKnotVector.h:221
Class for representing a knot vector.
Definition: gsKnotVector.h:79
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4486
mult_t multiplicityIndex(mult_t i) const
Definition: gsKnotVector.hpp:430
iterator begin() const
Returns iterator pointing to the beginning of the repeated knots.
Definition: gsKnotVector.hpp:117
unsigned lastKnotIndex(const size_t &i) const
Definition: gsKnotVector.h:844
size_t uSize() const
Number of unique knots (i.e., without repetitions).
Definition: gsKnotVector.h:245
bool inDomain(const T u) const
Checks, whether the given value is inside the domain.
Definition: gsKnotVector.h:375
bool isOpen() const
Definition: gsKnotVector.h:882
gsKnotVector * clone() const
Returns a pointer to a copy.
Definition: gsKnotVector.hpp:312
reverse_smart_iterator rsbegin() const
Returns the reverse smart iterator pointing past the end of the repeated knots.
Definition: gsKnotVector.hpp:271
void degreeIncrease(int const &i=1)
Definition: gsKnotVector.h:759
smart_iterator send() const
Returns the smart iterator pointing past the end of the repeated knots.
Definition: gsKnotVector.hpp:265
gsKnotVector knotUnion(const gsKnotVector &b) const
Computes the union of knot-vectors this and b.
Definition: gsKnotVector.hpp:187
reverse_iterator rend() const
Returns reverse iterator pointing to the beginning of the repeated knots.
Definition: gsKnotVector.hpp:229
int degree() const
Returns the degree of the knot vector.
Definition: gsKnotVector.hpp:700
void initGraded(T u0, T u1, unsigned interior, int degree, T grading, unsigned mult_interior=1)
Resets the knot vector so that its knots are graded.
Definition: gsKnotVector.h:514
iterator endAt(mult_t upos) const
Definition: gsKnotVector.hpp:139
bool operator!=(const gsKnotVector< T > &other) const
Compares with another knot vector.
Definition: gsKnotVector.h:859
bool includes(const gsKnotVector< T > &other) const
Returns true if every knot of other (counted with repetitions) is found within this knot-vector...
Definition: gsKnotVector.hpp:153
bool has(T knot) const
Definition: gsKnotVector.h:819
bool isUniform(T tol=1e-9) const
Checks whether the knot vector is uniform.
Definition: gsKnotVector.h:871
void initUniform(T first, T last, unsigned interior, unsigned mult_ends, unsigned mult_interior, short_t degree=-1)
Definition: gsKnotVector.hpp:643