Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:12:42

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_POSITION_ITERATOR_HPP
0009 #define BOOST_GIL_POSITION_ITERATOR_HPP
0010 
0011 #include <boost/gil/locator.hpp>
0012 
0013 #include <boost/iterator/iterator_facade.hpp>
0014 
0015 #include <type_traits>
0016 
0017 namespace boost { namespace gil {
0018 
0019 /// \defgroup PixelIteratorModelVirtual position_iterator
0020 /// \ingroup PixelIteratorModel
0021 /// \brief An iterator that remembers its current X,Y position and invokes a function object with it upon dereferencing.
0022 /// Models PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept. Used to create virtual image views.
0023 
0024 /// \brief An iterator that remembers its current X,Y position and invokes a function object with it upon dereferencing.
0025 /// Used to create virtual image views.
0026 /// Models: StepIteratorConcept, PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept
0027 /// \ingroup PixelIteratorModelVirtual PixelBasedModel
0028 /// \tparam Deref A function object that given a point returns a pixel reference. Models PixelDereferenceAdaptorConcept
0029 /// \tparam Dim Dimension to advance along
0030 template <typename Deref, int Dim>
0031 struct position_iterator : public iterator_facade<position_iterator<Deref,Dim>,
0032                                                   typename Deref::value_type,
0033                                                   std::random_access_iterator_tag,
0034                                                   typename Deref::reference,
0035                                                   typename Deref::argument_type::template axis<Dim>::coord_t> {
0036     using parent_t = iterator_facade<position_iterator<Deref,Dim>,
0037                             typename Deref::value_type,
0038                             std::random_access_iterator_tag,
0039                             typename Deref::reference,
0040                             typename Deref::argument_type::template axis<Dim>::coord_t>;
0041     using difference_type = typename parent_t::difference_type;
0042     using reference = typename parent_t::reference;
0043     using point_t = typename Deref::argument_type;
0044 
0045     position_iterator() {}
0046     position_iterator(point_t const& p, point_t const& step, Deref const& d) : _p(p), _step(step), _d(d) {}
0047 
0048     position_iterator(position_iterator const& p) : _p(p._p), _step(p._step), _d(p._d) {}
0049     
0050     template <typename D>
0051     position_iterator(position_iterator<D,Dim> const& p) : _p(p._p), _step(p._step), _d(p._d) {}
0052     
0053     auto operator=(position_iterator const& p) -> position_iterator&
0054     {
0055         _p=p._p;
0056         _d=p._d;
0057         _step=p._step;
0058         return *this;
0059     }
0060 
0061     auto pos() const -> point_t const& { return _p; }
0062     auto step() const -> point_t const& { return _step; }
0063     auto deref_fn() const -> Deref const& { return _d; }
0064 
0065     void set_step(difference_type s) { _step[Dim]=s; }
0066     /// For some reason operator[] provided by iterator_adaptor returns a custom class that is convertible to reference
0067     /// We require our own reference because it is registered in iterator_traits
0068     auto operator[](difference_type d) const -> reference
0069     {
0070         point_t p=_p;
0071         p[Dim]+=d*_step[Dim];
0072         return _d(p);
0073     }
0074 
0075 private:
0076     point_t _p, _step;
0077     Deref   _d;
0078 
0079     template <typename DE, int DI> friend struct position_iterator;
0080     friend class boost::iterator_core_access;
0081     reference dereference()     const { return _d(_p); }
0082     void increment()                  { _p[Dim]+=_step[Dim]; }
0083     void decrement()                  { _p[Dim]-=_step[Dim]; }
0084     void advance(difference_type d)   { _p[Dim]+=d*_step[Dim]; }
0085 
0086     difference_type distance_to(const position_iterator& it) const { return (it._p[Dim]-_p[Dim])/_step[Dim]; }
0087     bool equal(const position_iterator& it) const { return _p==it._p; }
0088 };
0089 
0090 template <typename Deref,int Dim>
0091 struct const_iterator_type<position_iterator<Deref,Dim> > {
0092     using type = position_iterator<typename Deref::const_t,Dim>;
0093 };
0094 
0095 template <typename Deref, int Dim>
0096 struct iterator_is_mutable<position_iterator<Deref, Dim>>
0097     : std::integral_constant<bool, Deref::is_mutable>
0098 {
0099 };
0100 
0101 /////////////////////////////
0102 //  PixelBasedConcept
0103 /////////////////////////////
0104 
0105 template <typename Deref,int Dim>
0106 struct color_space_type<position_iterator<Deref,Dim> > : public color_space_type<typename Deref::value_type> {};
0107 
0108 template <typename Deref,int Dim>
0109 struct channel_mapping_type<position_iterator<Deref,Dim> > : public channel_mapping_type<typename Deref::value_type> {};
0110 
0111 template <typename Deref,int Dim>
0112 struct is_planar<position_iterator<Deref, Dim>> : std::false_type {};
0113 
0114 template <typename Deref,int Dim>
0115 struct channel_type<position_iterator<Deref,Dim> > : public channel_type<typename Deref::value_type> {};
0116 
0117 /////////////////////////////
0118 //  HasDynamicXStepTypeConcept
0119 /////////////////////////////
0120 
0121 template <typename Deref,int Dim>
0122 struct dynamic_x_step_type<position_iterator<Deref,Dim> > {
0123     using type = position_iterator<Deref,Dim>;
0124 };
0125 
0126 } }  // namespace boost::gil
0127 
0128 #endif