Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/gil/virtual_locator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_VIRTUAL_LOCATOR_HPP
0009 #define BOOST_GIL_VIRTUAL_LOCATOR_HPP
0010 
0011 #include <boost/gil/dynamic_step.hpp>
0012 #include <boost/gil/position_iterator.hpp>
0013 
0014 #include <boost/assert.hpp>
0015 #include <boost/iterator/iterator_facade.hpp>
0016 
0017 namespace boost { namespace gil {
0018 
0019 /// \ingroup PixelLocatorModel PixelBasedModel
0020 /// \brief A 2D locator over a virtual image
0021 /// Upon dereferencing, invokes a given function object passing it its coordinates.
0022 /// Models:
0023 ///   PixelLocatorConcept,
0024 ///   HasDynamicXStepTypeConcept,
0025 ///   HasDynamicYStepTypeConcept,
0026 ///   HasTransposedTypeConcept
0027 ///
0028 /// \tparam DerefFn Function object that given a point returns a reference.
0029 ///         Models PixelDereferenceAdaptorConcept.
0030 /// \tparam IsTransposed Indicates if locator should navigate in transposed mode.
0031 template <typename DerefFn, bool IsTransposed>
0032 class virtual_2d_locator
0033     : public pixel_2d_locator_base
0034         <
0035             virtual_2d_locator<DerefFn, IsTransposed>,
0036             position_iterator<DerefFn, IsTransposed>,
0037             position_iterator<DerefFn, 1-IsTransposed>
0038         >
0039 {
0040     using this_t = virtual_2d_locator<DerefFn, IsTransposed>;
0041 public:
0042     using parent_t = pixel_2d_locator_base
0043         <
0044             virtual_2d_locator<DerefFn, IsTransposed>,
0045             position_iterator<DerefFn, IsTransposed>,
0046             position_iterator<DerefFn, 1-IsTransposed>
0047         >;
0048     using const_t = virtual_2d_locator<typename DerefFn::const_t, IsTransposed>;
0049     using deref_fn_t = DerefFn;
0050     using point_t = typename parent_t::point_t;
0051     using coord_t = typename parent_t::coord_t;
0052     using x_coord_t = typename parent_t::x_coord_t;
0053     using y_coord_t = typename parent_t::y_coord_t;
0054     using x_iterator = typename parent_t::x_iterator;
0055     using y_iterator = typename parent_t::y_iterator;
0056 
0057     template <typename NewDerefFn>
0058     struct add_deref
0059     {
0060         using type = virtual_2d_locator<deref_compose<NewDerefFn, DerefFn>, IsTransposed>;
0061 
0062         static type make(this_t const& loc, NewDerefFn const& new_deref_fn)
0063         {
0064             return type(loc.pos(), loc.step(),
0065                 deref_compose<NewDerefFn, DerefFn>(new_deref_fn, loc.deref_fn()));
0066         }
0067     };
0068 
0069     virtual_2d_locator(
0070         point_t const& p = {0, 0},
0071         point_t const& step = {1, 1},
0072         deref_fn_t const& deref_fn = deref_fn_t())
0073         : y_pos_(p, step, deref_fn)
0074     {}
0075 
0076     template <typename D, bool TR>
0077     virtual_2d_locator(virtual_2d_locator<D, TR> const &loc, coord_t y_step)
0078         : y_pos_(loc.pos(), point_t(loc.step().x, loc.step().y * y_step), loc.deref_fn())
0079     {}
0080 
0081     template <typename D, bool TR>
0082     virtual_2d_locator(virtual_2d_locator<D, TR> const& loc, coord_t x_step, coord_t y_step, bool transpose = false)
0083         : y_pos_(loc.pos()
0084         , transpose ?
0085             point_t(loc.step().x * y_step, loc.step().y * x_step) :
0086             point_t(loc.step().x * x_step, loc.step().y * y_step)
0087         , loc.deref_fn())
0088     {
0089         BOOST_ASSERT(transpose == (IsTransposed != TR));
0090     }
0091 
0092     template <typename D, bool TR>
0093     virtual_2d_locator(virtual_2d_locator<D, TR> const& other) : y_pos_(other.y_pos_) {}
0094 
0095     virtual_2d_locator(virtual_2d_locator const& other) : y_pos_(other.y_pos_) {}
0096     virtual_2d_locator& operator=(virtual_2d_locator const& other) = default;
0097 
0098     bool operator==(const this_t& p) const { return y_pos_ == p.y_pos_; }
0099 
0100     auto x() -> x_iterator&
0101     {
0102         return *gil_reinterpret_cast<x_iterator*>(this);
0103     }
0104 
0105     auto x() const -> x_iterator const&
0106     {
0107         return *gil_reinterpret_cast_c<x_iterator const*>(this);
0108     }
0109 
0110     auto y() -> y_iterator& { return y_pos_; }
0111     auto y() const -> y_iterator const& { return y_pos_; }
0112 
0113     /// Returns the y distance between two x_iterators given the difference of their x positions
0114     auto y_distance_to(this_t const& it2, x_coord_t) const -> y_coord_t
0115     {
0116         return (it2.pos()[1 - IsTransposed] - pos()[1 - IsTransposed])
0117                 / step()[1 - IsTransposed];
0118     }
0119 
0120     /// \todo TODO: is there no gap at the end of each row?
0121     ///       i.e. can we use x_iterator to visit every pixel instead of nested loops?
0122     bool is_1d_traversable(x_coord_t) const { return false; }
0123 
0124     // Methods specific for virtual 2D locator
0125     auto pos() const -> point_t const& { return y_pos_.pos(); }
0126     auto step() const -> point_t const& { return y_pos_.step(); }
0127     auto deref_fn() const -> deref_fn_t const& { return y_pos_.deref_fn(); }
0128 
0129 private:
0130     template <typename D, bool TR>
0131     friend class virtual_2d_locator;
0132 
0133     y_iterator y_pos_; // current position, the step and the dereference object
0134 };
0135 
0136 /////////////////////////////
0137 //  PixelBasedConcept
0138 /////////////////////////////
0139 
0140 template <typename D, bool TR>
0141 struct channel_type<virtual_2d_locator<D, TR>>
0142     : channel_type<typename virtual_2d_locator<D, TR>::parent_t>
0143 {
0144 };
0145 
0146 template <typename D, bool TR>
0147 struct color_space_type<virtual_2d_locator<D, TR>>
0148     : color_space_type<typename virtual_2d_locator<D, TR>::parent_t>
0149 {
0150 };
0151 
0152 template <typename D, bool TR>
0153 struct channel_mapping_type<virtual_2d_locator<D, TR>>
0154     : channel_mapping_type<typename virtual_2d_locator<D, TR>::parent_t>
0155 {
0156 };
0157 
0158 template <typename D, bool TR>
0159 struct is_planar<virtual_2d_locator<D, TR>>
0160     : is_planar<typename virtual_2d_locator<D, TR>::parent_t>
0161 {
0162 };
0163 
0164 /////////////////////////////
0165 //  HasDynamicXStepTypeConcept
0166 /////////////////////////////
0167 
0168 template <typename D, bool TR>
0169 struct dynamic_x_step_type<virtual_2d_locator<D,TR>>
0170 {
0171     using type = virtual_2d_locator<D,TR>;
0172 };
0173 
0174 /////////////////////////////
0175 //  HasDynamicYStepTypeConcept
0176 /////////////////////////////
0177 
0178 template <typename D, bool TR>
0179 struct dynamic_y_step_type<virtual_2d_locator<D,TR>>
0180 {
0181     using type = virtual_2d_locator<D,TR>;
0182 };
0183 
0184 /////////////////////////////
0185 //  HasTransposedTypeConcept
0186 /////////////////////////////
0187 
0188 template <typename D, bool IsTransposed>
0189 struct transposed_type<virtual_2d_locator<D,IsTransposed>>
0190 {
0191     using type = virtual_2d_locator<D,1-IsTransposed>;
0192 };
0193 
0194 }}  // namespace boost::gil
0195 
0196 #endif