/usr/include/mia-2.4/mia/2d/iterator.hh is in libmia-2.4-dev 2.4.3-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | /* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2016 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_2d_iterator_hh
#define mia_2d_iterator_hh
#include <mia/2d/vector.hh>
NS_MIA_BEGIN
/**
@ingroup misc
\brief a 2D iterator that knows its position in the 2D grid ans supports iterating over
sub-ranges
Iterator to iterate over a sub-range of 2D data that is given on a grid.
Two iterators are considered to be equal, if their positions are equal.
\tparam the internal iterator that is used to iterate of the original
grid without skipping.
*/
template <typename I>
class range2d_iterator_with_boundary_flag: public std::forward_iterator_tag {
public:
/// data type reference
typedef typename I::reference reference;
/// data type pointer
typedef typename I::pointer pointer;
/// data type for the real iterator in the background
typedef I internal_iterator;
typedef typename I::value_type value_type;
/**
Enumerate to describe the various positions on the domain boundarys.
These boundaries correspond to the full domain of the data, not to
the sub-range this iteratior works on.
I.e. if the sub-range is a subset of the \a open domain (i.e. without its boundary)
then the iterator will never touch the domain boundary.
*/
enum EBoundary {
eb_none = 0, /**< no boundary */
eb_xlow = 1, /**< at low x-boundary */
eb_xhigh = 2, /**< at high x-boundary */
eb_x = 3, /**< at one of the x-boundaries */
eb_ylow = 4, /**< at low y-boundary */
eb_yhigh = 8, /**< at high y-boundary */
eb_y = 0xC, /**< at one of the y-boundaries */
};
/** standard constructor */
range2d_iterator_with_boundary_flag();
/**
Full constructor of the range iterator
@param pos iterator position to initialize the iterator with
@param size size of the original data field
@param start start of the iterator range
@param end end of the iterator range
@param iterator the iterator of the underlying 2D data structure
*/
range2d_iterator_with_boundary_flag(const C2DBounds& pos, const C2DBounds& size,
const C2DBounds& start, const C2DBounds& end, I iterator);
/**
End iterator, can't be dereferenced
This iterator is only there to define the end position of the range_iterator.
\param pos end position to set this iterator to.
*/
range2d_iterator_with_boundary_flag(const C2DBounds& pos);
/// assignment operator
range2d_iterator_with_boundary_flag<I>& operator = (const range2d_iterator_with_boundary_flag<I>& other);
/// copy constructore
range2d_iterator_with_boundary_flag(const range2d_iterator_with_boundary_flag<I>& other);
/// friend iterator type because we may want to copy a iterator to a const_iterator.
template <typename AI>
friend class range2d_iterator_with_boundary_flag;
/**
Constructor to construct the iterator from one that is based on another
iterator type. The usual idea is that a iterator may be converted into it's const variant.
\tparam AI the other iterator type. Iterator type I must be copy-constructable from
type AI
\param other
*/
template <typename AI>
range2d_iterator_with_boundary_flag(const range2d_iterator_with_boundary_flag<AI>& other);
/**
Assignment operator from another type of iterator
\tparam AI other iterator type. The assignment I b = a; with a of type AI must be defined.
\param other
*/
template <typename AI>
range2d_iterator_with_boundary_flag<I>& operator = (const range2d_iterator_with_boundary_flag<AI>& other);
/// prefix increment
range2d_iterator_with_boundary_flag<I>& operator ++();
/// postfix increment
range2d_iterator_with_boundary_flag<I> operator ++(int);
/// @returns current value the iterator points to
reference operator *() const;
/// @returns pointer to the current value the iterator points to
pointer operator ->() const;
/** \returns the current position within the 2D grid with respect to the
full size of the grid.
*/
const C2DBounds& pos() const;
/// @cond NOFRIENDDOC
template <typename T> friend
bool operator == (const range2d_iterator_with_boundary_flag<T>& left,
const range2d_iterator_with_boundary_flag<T>& right);
template <typename T> friend
bool operator != (const range2d_iterator_with_boundary_flag<T>& left,
const range2d_iterator_with_boundary_flag<T>& right);
/// @endcond
/**
Return the internal iterator
*/
internal_iterator get_point();
/// \returns the flags describing whether the iterator is on a domain boundary.
int get_boundary_flags() const;
private:
void increment_y();
void increment_z();
C2DBounds m_pos;
C2DBounds m_size;
C2DBounds m_begin;
C2DBounds m_end;
int m_xstride;
I m_iterator;
int m_boundary;
};
template <typename I>
template <typename AI>
range2d_iterator_with_boundary_flag<I>& range2d_iterator_with_boundary_flag<I>::operator = (const range2d_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_boundary = other.m_boundary;
return *this;
}
template <typename I>
template <typename AI>
range2d_iterator_with_boundary_flag<I>::range2d_iterator_with_boundary_flag(const range2d_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_iterator(other.m_iterator),
m_boundary(other.m_boundary)
{
}
template <typename T>
bool operator == (const range2d_iterator_with_boundary_flag<T>& left, const range2d_iterator_with_boundary_flag<T>& right)
{
return left.m_pos == right.m_pos;
}
template <typename T>
bool operator != (const range2d_iterator_with_boundary_flag<T>& left, const range2d_iterator_with_boundary_flag<T>& right)
{
return left.m_pos != right.m_pos;
}
template <typename I>
class range2d_iterator: public std::iterator<std::forward_iterator_tag, typename I::value_type>
{
public:
/// data type reference
typedef typename I::reference reference;
/// data type pointer
typedef typename I::pointer pointer;
/// data type for the real iterator in the background
typedef I internal_iterator;
typedef typename I::value_type value_type;
/** standard constructor */
range2d_iterator();
/**
Full constructor of the range iterator
@param pos iterator position to initialize the iterator with
@param size size of the original data field
@param start start of the iterator range
@param end end of the iterator range
@param iterator the iterator of the underlying 2D data structure
*/
range2d_iterator(const C2DBounds& pos, const C2DBounds& size,
const C2DBounds& start, const C2DBounds& end, I iterator);
/**
End iterator, can't be dereferenced
This iterator is only there to define the end position of the range_iterator.
\param pos end position to set this iterator to.
*/
range2d_iterator(const C2DBounds& pos);
/// assignment operator
range2d_iterator<I>& operator = (const range2d_iterator<I>& other);
/// copy constructore
range2d_iterator(const range2d_iterator<I>& other);
/// friend iterator type because we may want to copy a iterator to a const_iterator.
template <typename AI>
friend class range2d_iterator;
/**
Constructor to construct the iterator from one that is based on another
iterator type. The usual idea is that a iterator may be converted into it's const variant.
\tparam AI the other iterator type. Iterator type I must be copy-constructable from
type AI
\param other
*/
template <typename AI>
range2d_iterator(const range2d_iterator<AI>& other);
/**
Assignment operator from another type of iterator
\tparam AI other iterator type. The assignment I b = a; with a of type AI must be defined.
\param other
*/
template <typename AI>
range2d_iterator<I>& operator = (const range2d_iterator<AI>& other);
/// prefix increment
range2d_iterator<I>& operator ++();
/// postfix increment
range2d_iterator<I> operator ++(int);
/// @returns current value the iterator points to
reference operator *() const;
/// @returns pointer to the current value the iterator points to
pointer operator ->() const;
/** \returns the current position within the 2D grid with respect to the
full size of the grid.
*/
const C2DBounds& pos() const;
/// @cond NOFRIENDDOC
template <typename T> friend
bool operator == (const range2d_iterator<T>& left, const range2d_iterator<T>& right);
/// @endcond
/**
Return the internal iterator
*/
internal_iterator get_point();
range2d_iterator_with_boundary_flag<I> with_boundary_flag() const;
private:
void increment_y();
void increment_z();
C2DBounds m_pos;
C2DBounds m_size;
C2DBounds m_begin;
C2DBounds m_end;
int m_xstride;
I m_iterator;
};
template <typename I>
template <typename AI>
range2d_iterator<I>& range2d_iterator<I>::operator = (const range2d_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;
return *this;
}
template <typename I>
template <typename AI>
range2d_iterator<I>::range2d_iterator(const range2d_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_iterator(other.m_iterator)
{
}
/**
Compare two range iterators. There equivalence is only decided based on the grid position.
*/
template <typename I>
bool operator == (const range2d_iterator<I>& left, const range2d_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;
}
/**
Compare two range iterators. There equivalence is only decided based on the grid position.
*/
template <typename I>
bool operator != (const range2d_iterator<I>& a, const range2d_iterator<I>& b)
{
return !(a == b);
}
NS_MIA_END
namespace std {
template <typename I>
class iterator_traits< mia::range2d_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::range2d_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
|