8 #ifndef BOOST_GIL_ITERATOR_FROM_2D_HPP
9 #define BOOST_GIL_ITERATOR_FROM_2D_HPP
11 #include <boost/gil/concepts.hpp>
12 #include <boost/gil/locator.hpp>
13 #include <boost/gil/pixel_iterator.hpp>
14 #include <boost/gil/point.hpp>
16 #include <boost/iterator/iterator_facade.hpp>
20 namespace boost {
namespace gil {
42 template <
typename Loc2>
44 typename Loc2::value_type,
45 std::random_access_iterator_tag,
46 typename Loc2::reference,
47 typename Loc2::coord_t> {
50 typedef iterator_facade<iterator_from_2d<Loc2>,
51 typename Loc2::value_type,
52 std::random_access_iterator_tag,
53 typename Loc2::reference,
54 typename Loc2::coord_t> parent_t;
55 typedef typename parent_t::reference reference;
56 typedef typename parent_t::difference_type difference_type;
57 typedef typename Loc2::x_iterator x_iterator;
58 typedef typename Loc2::point_t point_t;
60 std::ptrdiff_t width()
const {
return _width; }
61 std::ptrdiff_t x_pos()
const {
return _coords.x; }
62 std::ptrdiff_t y_pos()
const {
return _coords.y; }
66 reference
operator[](difference_type d)
const {
return *(*
this+d); }
68 bool is_1d_traversable()
const {
return _p.is_1d_traversable(width()); }
69 x_iterator& x() {
return _p.x(); }
72 iterator_from_2d(
const Loc2& p, std::ptrdiff_t width, std::ptrdiff_t x=0, std::ptrdiff_t y=0) : _coords(x,y), _width(width), _p(p) {}
73 iterator_from_2d(
const iterator_from_2d& pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {}
74 template <
typename Loc> iterator_from_2d(
const iterator_from_2d<Loc>& pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {}
77 template <
typename Loc>
friend class iterator_from_2d;
78 friend class boost::iterator_core_access;
79 reference dereference()
const {
return *_p; }
83 if (_coords.x>=_width) {
86 _p+=point_t(-_width,1);
95 _p+=point_t(_width,-1);
99 BOOST_FORCEINLINE
void advance(difference_type d) {
100 if (_width==0)
return;
102 if (_coords.x+d>=0) {
103 delta.x=(_coords.x+(std::ptrdiff_t)d)%_width - _coords.x;
104 delta.y=(_coords.x+(std::ptrdiff_t)d)/_width;
106 delta.x=(_coords.x+(std::ptrdiff_t)d*(1-_width))%_width -_coords.x;
107 delta.y=-(_width-_coords.x-(std::ptrdiff_t)d-1)/_width;
114 difference_type distance_to(
const iterator_from_2d& it)
const {
115 if (_width==0)
return 0;
116 return (it.y_pos()-_coords.y)*_width + (it.x_pos()-_coords.x);
119 bool equal(
const iterator_from_2d& it)
const {
120 assert(_width==it.width());
121 return _coords==it._coords && _p==it._p;
125 std::ptrdiff_t _width;
129 template <
typename Loc>
130 struct const_iterator_type<iterator_from_2d<Loc> > {
131 typedef iterator_from_2d<typename Loc::const_t> type;
134 template <
typename Loc>
135 struct iterator_is_mutable<iterator_from_2d<Loc> > :
public iterator_is_mutable<typename Loc::x_iterator> {};
142 template <
typename Loc>
143 struct dynamic_x_step_type<iterator_from_2d<Loc> > {
144 typedef iterator_from_2d<typename dynamic_x_step_type<Loc>::type> type;
152 template <
typename Loc>
153 struct color_space_type<iterator_from_2d<Loc> > :
public color_space_type<Loc> {};
155 template <
typename Loc>
156 struct channel_mapping_type<iterator_from_2d<Loc> > :
public channel_mapping_type<Loc> {};
158 template <
typename Loc>
159 struct is_planar<iterator_from_2d<Loc> > :
public is_planar<Loc> {};
161 template <
typename Loc>
162 struct channel_type<iterator_from_2d<Loc> > :
public channel_type<Loc> {};
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept.
Definition: iterator_from_2d.hpp:43
GIL's 2-dimensional locator over immutable GIL pixels.
Definition: concepts.hpp:1606
BOOST_FORCEINLINE bool equal(boost::gil::iterator_from_2d< Loc1 > first, boost::gil::iterator_from_2d< Loc1 > last, boost::gil::iterator_from_2d< Loc2 > first2)
std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition: algorithm.hpp:915
reference operator[](difference_type d) const
Definition: iterator_from_2d.hpp:66