20 template<
typename T>
class gsKnotIterator;
33 friend class gsKnotVector<T>;
34 friend class gsKnotIterator<T>;
36 typedef typename gsKnotVector<T>::mult_t mult_t;
37 typedef std::random_access_iterator_tag iterator_category;
38 typedef const gsKnotVector<T> knotVector;
40 typedef std::ptrdiff_t difference_type;
41 typedef const T& reference;
42 typedef const T* pointer;
43 typedef const mult_t* mltpointer;
59 void setValue(
const T val)
61 std::fill(const_cast<T*>(m_raw) + firstAppearance(),
62 const_cast<T*>(m_raw) + multSum(), val);
72 : m_mlt(NULL), m_raw(NULL), m_upos(0), m_sh(0), m_dbg(0)
84 explicit gsUKnotIterator(knotVector & KV,
const mult_t upos = 0,
const index_t s = 0)
85 : m_mlt ( KV.multSumData() ), m_raw ( KV.data() ),
86 m_upos( upos ), m_sh (s )
89 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
91 GISMO_ENSURE(upos < m_dbg,
"Invalid iterator position "<< upos
92 <<
" for knot vector with "<<KV.uSize()<<
" unique knots");
100 static inline gsUKnotIterator End(knotVector & KV)
102 return gsUKnotIterator(KV, KV.uSize(),KV.numLeftGhosts());
110 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
111 GISMO_ENSURE(m_upos >= 0 && m_upos + 1 < m_dbg,
"Access to invalid knot position.");
113 return m_raw[m_mlt[m_upos]-1];
116 pointer operator-> ()
const {
return m_raw+m_mlt[m_upos]-1 ;}
118 gsUKnotIterator& operator++()
121 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
122 GISMO_ENSURE(m_upos < m_dbg,
"Invalid knot-iterator increment: "
123 << m_upos <<
" is past the end position ("<<m_dbg-1<<
").");
128 gsUKnotIterator& operator--()
130 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
131 GISMO_ENSURE(m_upos > 0 && m_upos < m_dbg,
"Invalid knot-iterator decrement");
137 gsUKnotIterator operator++(
int) { gsUKnotIterator tmp(*
this); ++(*this);
return tmp; }
138 gsUKnotIterator operator--(
int) { gsUKnotIterator tmp(*
this); --(*this);
return tmp; }
152 bool operator == (
const gsUKnotIterator& other)
const
153 {
return m_upos == other.m_upos;}
167 bool operator != (
const gsUKnotIterator& other)
const {
return m_upos != other.m_upos;}
168 bool operator < (
const gsUKnotIterator& other)
const {
return m_upos < other.m_upos;}
169 bool operator > (
const gsUKnotIterator& other)
const {
return m_upos > other.m_upos;}
170 bool operator <= (
const gsUKnotIterator& other)
const {
return m_upos <= other.m_upos;}
171 bool operator >= (
const gsUKnotIterator& other)
const {
return m_upos >= other.m_upos;}
177 reference operator[] (ptrdiff_t a)
const
179 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
180 GISMO_ENSURE(m_upos+a>=0 && m_upos+a+1 < m_dbg,
"Invalid access to non-existent knot.");
182 return m_raw[m_mlt[m_upos+a]-1];
189 gsUKnotIterator& operator+=(
const difference_type & a)
192 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
194 GISMO_ENSURE(m_dbg<2 || (m_upos >= 0 && m_upos < m_dbg),
195 "Iterator jumped to invalid knot position.");
204 gsUKnotIterator
operator+(
const difference_type & a)
const
206 gsUKnotIterator tmp(*
this);
214 gsUKnotIterator& operator-=(
const difference_type & a)
216 return operator+=(-a);
223 gsUKnotIterator operator-(
const difference_type & a)
const
225 gsUKnotIterator tmp(*
this);
229 friend difference_type operator-(
const gsUKnotIterator & l,
const gsUKnotIterator & r)
230 {
return l.m_upos - r.m_upos; }
235 reference value()
const
237 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
238 GISMO_ENSURE(m_upos >= 0 && m_upos + 1< m_dbg,
"Access to invalid knot position.");
247 mult_t multiplicity()
const
249 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
250 GISMO_ENSURE(m_upos >= 0 && m_upos + 1< m_dbg,
"Access to invalid knot position.");
256 mltpointer mp = m_mlt + m_upos;
257 return *mp - *(mp-1);
265 mult_t uIndex()
const {
return m_upos-m_sh;}
272 mult_t uCardinalIndex()
const {
return m_upos;}
282 mult_t firstAppearance()
const
284 return 0 == m_upos ? 0 : m_mlt[m_upos-1];
295 mult_t lastAppearance()
const
297 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
298 GISMO_ENSURE(m_upos >= 0 && m_upos + 1< m_dbg,
"Access to invalid knot position.");
300 return m_mlt[m_upos] - 1;
311 mult_t multSum()
const
312 {
return m_mlt[m_upos];}
335 template <
typename T>
339 friend class gsKnotVector<T>;
341 typedef typename gsKnotVector<T>::mult_t mult_t;
342 typedef std::random_access_iterator_tag iterator_category;
343 typedef const gsKnotVector<T> knotVector;
344 typedef T value_type;
345 typedef std::ptrdiff_t difference_type;
346 typedef const T& reference;
347 typedef const T* pointer;
348 typedef const mult_t* mltpointer;
351 gsUKnotIterator<T> m_uit;
354 #if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
376 explicit gsKnotIterator(knotVector & KV,
const mult_t upos = 0,
const index_t s = 0)
377 : m_uit(KV,upos,s), m_pos(firstAppearance())
379 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
382 "Invalid iterator position "<< upos
383 <<
" for knot vector with "<<KV.uSize()<<
" unique knots");
391 static inline gsKnotIterator End(
const gsKnotVector<T> & KV)
393 return gsKnotIterator(KV, KV.uSize(),KV.numLeftGhosts());
401 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
403 "Access to invalid knot position.");
405 return m_uit.m_raw[m_pos];
408 pointer
get()
const {
return m_uit.m_raw+m_pos;}
409 pointer operator-> ()
const {
return get();}
411 gsKnotIterator& operator++()
413 if (++m_pos == m_uit.multSum())
415 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
416 GISMO_ENSURE(m_pos < m_dbg,
"Invalid knot-iterator increment: "
417 << m_pos <<
" is past the end position ("<<m_dbg-1<<
").");
422 gsKnotIterator& operator--()
424 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
425 GISMO_ENSURE(m_pos > 0 && m_pos < m_dbg,
"Invalid knot-iterator decrement");
427 if ( m_pos-- == firstAppearance() )
432 gsKnotIterator operator++(
int) { gsKnotIterator tmp(*
this); ++(*this);
return tmp; }
433 gsKnotIterator operator--(
int) { gsKnotIterator tmp(*
this); --(*this);
return tmp; }
447 bool operator == (
const gsKnotIterator& other)
const
448 {
return m_pos == other.m_pos;}
462 bool operator != (
const gsKnotIterator& other)
const {
return m_pos != other.m_pos;}
463 bool operator < (
const gsKnotIterator& other)
const {
return m_pos < other.m_pos;}
464 bool operator > (
const gsKnotIterator& other)
const {
return m_pos > other.m_pos;}
465 bool operator <= (
const gsKnotIterator& other)
const {
return m_pos <= other.m_pos;}
466 bool operator >= (
const gsKnotIterator& other)
const {
return m_pos >= other.m_pos;}
472 reference operator[] (ptrdiff_t a)
const
474 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
475 GISMO_ENSURE(m_pos+a>=0 && m_pos+a+1 < m_dbg,
"Invalid access to non-existent knot.");
477 return m_uit.m_raw[m_pos+a];
484 reference operator() (ptrdiff_t a)
const
486 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
487 GISMO_ENSURE(m_pos+a>=0 && m_pos+a+1 < m_dbg,
"Invalid access to non-existent knot.");
497 const gsUKnotIterator<T> & uIterator()
const
508 m_pos = firstAppearance();
520 m_pos = firstAppearance();
524 void uAdd(
const difference_type & a)
527 m_pos = firstAppearance();
534 gsKnotIterator& operator+=(
const difference_type & a)
537 # if defined(_GLIBCXX_DEBUG) || _SECURE_SCL != 0
539 "Iterator jumped to invalid knot position.");
544 mltpointer end = m_uit.m_mlt + m_uit.m_upos;
545 mltpointer beg = end + a;
546 if (beg < m_uit.m_mlt) beg = m_uit.m_mlt;
548 m_uit.m_upos = std::upper_bound(beg, end, m_pos) - m_uit.m_mlt;
552 mltpointer beg = m_uit.m_mlt + m_uit.m_upos;
554 mltpointer end = std::min(m_uit.m_mlt + m_uit.m_dbg-1, beg + a);
555 m_uit.m_upos = std::upper_bound(beg, end, m_pos) - m_uit.m_mlt;
570 gsKnotIterator
operator+(
const difference_type & a)
const
572 gsKnotIterator tmp(*
this);
581 gsKnotIterator& operator-=(
const difference_type & a)
583 return operator+=(-a);
590 gsKnotIterator operator-(
const difference_type & a)
const
592 gsKnotIterator tmp(*
this);
596 friend difference_type operator-(
const gsKnotIterator & l,
const gsKnotIterator & r)
597 {
return l.m_pos - r.m_pos; }
602 reference value()
const {
return this->
operator*();}
608 mult_t multiplicity()
const
610 return m_uit.multiplicity();
617 mult_t index()
const {
return m_pos;}
623 mult_t uIndex()
const {
return m_uit.uIndex();}
630 mult_t uCardinalIndex()
const {
return m_uit.uCardinalIndex();}
639 mult_t firstAppearance()
const
640 {
return m_uit.firstAppearance();}
649 mult_t lastAppearance()
const
650 {
return m_uit.lastAppearance();}
660 mult_t multSum()
const
661 {
return m_uit.multSum();}
667 void backToFirstAppearance()
668 { m_pos = m_uit.firstAppearance();}
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
bool operator!=(gsVertex< T > const &lhs, gsVertex< T > const &rhs)
Definition: gsVertex.h:240
EIGEN_STRONG_INLINE mult_expr< E1, E2 > const operator*(_expr< E1 > const &u, _expr< E2 > const &v)
Multiplication operator for expressions.
Definition: gsExpressions.h:4561
EIGEN_STRONG_INLINE add_expr< E1, E2 > const operator+(_expr< E1 > const &u, _expr< E2 > const &v)
Addition operator for expressions.
Definition: gsExpressions.h:4609