3d/iterator.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_3d_iterator_hh
#define mia_3d_iterator_hh
#include <mia/3d/vector.hh>
NS_MIA_BEGIN
template <typename I>
class EXPORT_3D range3d_iterator_with_boundary_flag: public std::forward_iterator_tag
{
public:
typedef typename I::reference reference;
typedef typename I::pointer pointer;
typedef typename I::value_type value_type;
typedef I internal_iterator;
enum EBoundary {
eb_none = 0,
eb_xlow = 1,
eb_xhigh = 2,
eb_x = 3,
eb_ylow = 4,
eb_yhigh = 8,
eb_y = 0xC,
eb_zlow = 0x10,
eb_zhigh = 0x20,
eb_z = 0x30
};
range3d_iterator_with_boundary_flag();
range3d_iterator_with_boundary_flag(const C3DBounds& pos, const C3DBounds& size,
const C3DBounds& start, const C3DBounds& end, I iterator);
range3d_iterator_with_boundary_flag(const C3DBounds& pos);
range3d_iterator_with_boundary_flag<I>& operator = (const range3d_iterator_with_boundary_flag<I>& other);
range3d_iterator_with_boundary_flag(const range3d_iterator_with_boundary_flag<I>& other);
template <typename AI>
friend class range3d_iterator_with_boundary_flag;
template <typename AI>
range3d_iterator_with_boundary_flag(const range3d_iterator_with_boundary_flag<AI>& other);
template <typename AI>
range3d_iterator_with_boundary_flag<I>& operator = (const range3d_iterator_with_boundary_flag<AI>& other);
range3d_iterator_with_boundary_flag<I>& operator ++();
range3d_iterator_with_boundary_flag<I> operator ++(int);
reference operator *() const;
pointer operator ->() const;
const C3DBounds& pos() const;
template <typename T> friend
bool operator == (const range3d_iterator_with_boundary_flag<T>& left, const range3d_iterator_with_boundary_flag<T>& right);
internal_iterator get_point();
int get_boundary_flags() const;
private:
void increment_y();
void increment_z();
C3DBounds m_pos;
C3DBounds m_size;
C3DBounds m_begin;
C3DBounds m_end;
int m_xstride;
int m_ystride;
I m_iterator;
int m_boundary;
};
template <typename I>
class EXPORT_3D range3d_iterator: public std::forward_iterator_tag
{
public:
typedef typename I::reference reference;
typedef typename I::pointer pointer;
typedef typename I::value_type value_type;
typedef I internal_iterator;
range3d_iterator();
range3d_iterator(const C3DBounds& pos, const C3DBounds& size,
const C3DBounds& start, const C3DBounds& end, I iterator);
range3d_iterator(const C3DBounds& pos);
range3d_iterator<I>& operator = (const range3d_iterator<I>& other);
range3d_iterator(const range3d_iterator<I>& other);
template <typename AI>
friend class range3d_iterator;
template <typename AI>
friend class range3d_iterator_with_boundary_flag;
template <typename AI>
range3d_iterator(const range3d_iterator<AI>& other);
template <typename AI>
range3d_iterator<I>& operator = (const range3d_iterator<AI>& other);
range3d_iterator<I>& operator ++();
range3d_iterator<I> operator ++(int);
reference operator *() const;
pointer operator ->() const;
const C3DBounds& pos() const;
template <typename T> friend
bool operator == (const range3d_iterator<T>& left, const range3d_iterator<T>& right);
internal_iterator get_point();
range3d_iterator_with_boundary_flag<I> with_boundary_flag() const;
const reference operator[] (int i) const;
private:
void increment_y();
void increment_z();
C3DBounds m_pos;
C3DBounds m_size;
C3DBounds m_begin;
C3DBounds m_end;
int m_xstride;
int m_ystride;
I m_iterator;
};
template <typename I>
template <typename AI>
range3d_iterator<I>& range3d_iterator<I>::operator = (const range3d_iterator<AI>& other)
{
m_pos = other.m_pos;
m_size = other.m_size;
m_begin = other.m_begin;
m_end = other.m_end;
m_iterator = other.m_iterator;
m_xstride = other.m_xstride;
m_ystride = other.m_ystride;
return *this;
}
template <typename I>
template <typename AI>
range3d_iterator<I>::range3d_iterator(const range3d_iterator<AI>& other):
m_pos(other.m_pos),
m_size(other.m_size),
m_begin(other.m_begin),
m_end(other.m_end),
m_xstride(other.m_xstride),
m_ystride(other.m_ystride),
m_iterator(other.m_iterator)
{
}
template <typename I>
const typename range3d_iterator<I>::reference
range3d_iterator<I>::operator[] (int i) const
{
return m_iterator[i];
}
template <typename I>
bool operator == (const range3d_iterator<I>& left, const range3d_iterator<I>& right)
{
// we really want these two to the same range
// assert(left.m_size == right.m_size);
// assert(left.m_begin == right.m_begin);
// assert(left.m_end == right.m_end);
return left.m_pos == right.m_pos;
}
template <typename I>
bool operator != (const range3d_iterator<I>& a, const range3d_iterator<I>& b)
{
return !(a == b);
}
template <typename I>
template <typename AI>
range3d_iterator_with_boundary_flag<I>& range3d_iterator_with_boundary_flag<I>::operator = (const range3d_iterator_with_boundary_flag<AI>& other)
{
m_pos = other.m_pos;
m_size = other.m_size;
m_begin = other.m_begin;
m_end = other.m_end;
m_iterator = other.m_iterator;
m_xstride = other.m_xstride;
m_ystride = other.m_ystride;
m_boundary = other.m_boundary;
return *this;
}
template <typename I>
template <typename AI>
range3d_iterator_with_boundary_flag<I>::range3d_iterator_with_boundary_flag(const range3d_iterator_with_boundary_flag<AI>& other):
m_pos(other.m_pos),
m_size(other.m_size),
m_begin(other.m_begin),
m_end(other.m_end),
m_xstride(other.m_xstride),
m_ystride(other.m_ystride),
m_iterator(other.m_iterator),
m_boundary(other.m_boundary)
{
}
template <typename I>
bool operator == (const range3d_iterator_with_boundary_flag<I>& left, const range3d_iterator_with_boundary_flag<I>& right)
{
// we really want these two to the same range
// assert(left.m_size == right.m_size);
// assert(left.m_begin == right.m_begin);
// assert(left.m_end == right.m_end);
return left.m_pos == right.m_pos;
}
template <typename I>
bool operator != (const range3d_iterator_with_boundary_flag<I>& a, const range3d_iterator_with_boundary_flag<I>& b)
{
return !(a == b);
}
NS_MIA_END
namespace std
{
template <typename I>
class iterator_traits< mia::range3d_iterator<I>>
{
public:
typedef typename I::difference_type difference_type;
typedef typename I::value_type value_type;
typedef typename I::pointer pointer;
typedef typename I::reference reference;
typedef forward_iterator_tag iterator_category;
};
template <typename I>
class iterator_traits< mia::range3d_iterator_with_boundary_flag<I>>
{
public:
typedef typename I::difference_type difference_type;
typedef typename I::value_type value_type;
typedef typename I::pointer pointer;
typedef typename I::reference reference;
typedef forward_iterator_tag iterator_category;
};
}
#endif
operator==
bool operator==(const range3d_iterator< I > &left, const range3d_iterator< I > &right)
Definition 3d/iterator.hh:352
operator!=
bool operator!=(const range3d_iterator< I > &a, const range3d_iterator< I > &b)
Definition 3d/iterator.hh:365
vector.hh
C3DBounds
T3DVector< unsigned int > C3DBounds
A unsinged int 3D Vector (used for 3D field sizes).
Definition 3d/vector.hh:415
operator==
bool operator==(const CAttribute &a, const CAttribute &b)
Definition attributes.hh:95
range3d_iterator_with_boundary_flag
a 3D iterator that knows its position in the 3D grid, has a flag indicating whether it is on a bounda...
Definition 3d/iterator.hh:44
range3d_iterator_with_boundary_flag::get_boundary_flags
int get_boundary_flags() const
range3d_iterator_with_boundary_flag::operator=
range3d_iterator_with_boundary_flag< I > & operator=(const range3d_iterator_with_boundary_flag< I > &other)
assignment operator
range3d_iterator_with_boundary_flag::pos
const C3DBounds & pos() const
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
range3d_iterator_with_boundary_flag()
range3d_iterator_with_boundary_flag::value_type
I::value_type value_type
data value type
Definition 3d/iterator.hh:53
range3d_iterator_with_boundary_flag::pointer
I::pointer pointer
data type pointer
Definition 3d/iterator.hh:50
range3d_iterator_with_boundary_flag::EBoundary
EBoundary
Definition 3d/iterator.hh:65
range3d_iterator_with_boundary_flag::eb_yhigh
@ eb_yhigh
Definition 3d/iterator.hh:71
range3d_iterator_with_boundary_flag::eb_x
@ eb_x
Definition 3d/iterator.hh:69
range3d_iterator_with_boundary_flag::eb_xhigh
@ eb_xhigh
Definition 3d/iterator.hh:68
range3d_iterator_with_boundary_flag::eb_zlow
@ eb_zlow
Definition 3d/iterator.hh:73
range3d_iterator_with_boundary_flag::eb_none
@ eb_none
Definition 3d/iterator.hh:66
range3d_iterator_with_boundary_flag::eb_xlow
@ eb_xlow
Definition 3d/iterator.hh:67
range3d_iterator_with_boundary_flag::eb_z
@ eb_z
Definition 3d/iterator.hh:75
range3d_iterator_with_boundary_flag::eb_ylow
@ eb_ylow
Definition 3d/iterator.hh:70
range3d_iterator_with_boundary_flag::eb_zhigh
@ eb_zhigh
Definition 3d/iterator.hh:74
range3d_iterator_with_boundary_flag::eb_y
@ eb_y
Definition 3d/iterator.hh:72
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
range3d_iterator_with_boundary_flag(const C3DBounds &pos, const C3DBounds &size, const C3DBounds &start, const C3DBounds &end, I iterator)
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
friend class range3d_iterator_with_boundary_flag
friend iterator type because we may want to copy a iterator to a const_iterator.
Definition 3d/iterator.hh:109
range3d_iterator_with_boundary_flag::internal_iterator
I internal_iterator
data type for the real iterator in the background
Definition 3d/iterator.hh:56
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
range3d_iterator_with_boundary_flag(const range3d_iterator_with_boundary_flag< I > &other)
copy constructore
range3d_iterator_with_boundary_flag::get_point
internal_iterator get_point()
range3d_iterator_with_boundary_flag::reference
I::reference reference
data type reference
Definition 3d/iterator.hh:47
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
range3d_iterator_with_boundary_flag(const C3DBounds &pos)
range3d_iterator
a 3D iterator that knows its position in the 3D grid ans supports iterating over sub-ranges
Definition 3d/iterator.hh:191
range3d_iterator::get_point
internal_iterator get_point()
range3d_iterator::with_boundary_flag
range3d_iterator_with_boundary_flag< I > with_boundary_flag() const
range3d_iterator::operator[]
const reference operator[](int i) const
Definition 3d/iterator.hh:342
range3d_iterator::pos
const C3DBounds & pos() const
range3d_iterator::range3d_iterator
range3d_iterator()
range3d_iterator::value_type
I::value_type value_type
data value type
Definition 3d/iterator.hh:199
range3d_iterator::range3d_iterator
range3d_iterator(const C3DBounds &pos, const C3DBounds &size, const C3DBounds &start, const C3DBounds &end, I iterator)
range3d_iterator::range3d_iterator
range3d_iterator(const C3DBounds &pos)
range3d_iterator::pointer
I::pointer pointer
data type pointer
Definition 3d/iterator.hh:196
range3d_iterator::internal_iterator
I internal_iterator
data type for the real iterator in the background
Definition 3d/iterator.hh:202
range3d_iterator::range3d_iterator_with_boundary_flag
friend class range3d_iterator_with_boundary_flag
friend iterator type because we may want to copy a iterator to a const_iterator.
Definition 3d/iterator.hh:238
range3d_iterator::range3d_iterator
range3d_iterator(const range3d_iterator< I > &other)
copy constructore
range3d_iterator::range3d_iterator
friend class range3d_iterator
friend iterator type because we may want to copy a iterator to a const_iterator.
Definition 3d/iterator.hh:234
range3d_iterator::operator=
range3d_iterator< I > & operator=(const range3d_iterator< I > &other)
assignment operator
range3d_iterator::reference
I::reference reference
data type reference
Definition 3d/iterator.hh:194
std::iterator_traits< mia::range3d_iterator< I > >::difference_type
I::difference_type difference_type
Definition 3d/iterator.hh:435
std::iterator_traits< mia::range3d_iterator< I > >::value_type
I::value_type value_type
Definition 3d/iterator.hh:436
std::iterator_traits< mia::range3d_iterator< I > >::iterator_category
forward_iterator_tag iterator_category
Definition 3d/iterator.hh:439
std::iterator_traits< mia::range3d_iterator< I > >::reference
I::reference reference
Definition 3d/iterator.hh:438
std::iterator_traits< mia::range3d_iterator< I > >::pointer
I::pointer pointer
Definition 3d/iterator.hh:437
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::value_type
I::value_type value_type
Definition 3d/iterator.hh:447
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::difference_type
I::difference_type difference_type
Definition 3d/iterator.hh:446
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::reference
I::reference reference
Definition 3d/iterator.hh:449
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::iterator_category
forward_iterator_tag iterator_category
Definition 3d/iterator.hh:450
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::pointer
I::pointer pointer
Definition 3d/iterator.hh:448
EXPORT_3D
#define EXPORT_3D
Definition defines3d.hh:45
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
mia
Definition convergence_measure.hh:31
std
Definition gsl_iterator.hh:324
operator*
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition sparse_solver.hh:182