Generic Image Library: virtual_locator.hpp Source File

Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page # virtual_locator.hpp Go to the documentation of this file.
    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://opensource.adobe.com/gil for most recent version including documentation.
    00009 */
    00010
    00011 /*************************************************************************************************/
    00012
    00013 #ifndef GIL_VIRTUAL_LOCATOR_HPP
    00014 #define GIL_VIRTUAL_LOCATOR_HPP
    00015
    00024
    00025 #include <boost/iterator/iterator_facade.hpp>
    00026 #include "position_iterator.hpp"
    00027
    00028 namespace boost { namespace gil {
    00029
    00033 template <typename Deref, bool IsTransposed>        // A function object that given a point returns a reference. Models PixelDereferenceAdaptorConcept
    00034 class virtual_2d_locator : public pixel_2d_locator_base<virtual_2d_locator<Deref,IsTransposed>, position_iterator<Deref,IsTransposed>, position_iterator<Deref,1-IsTransposed> > {
    00035     typedef virtual_2d_locator<Deref,IsTransposed>  this_t;
    00036 public:
    00037     typedef pixel_2d_locator_base<virtual_2d_locator<Deref,IsTransposed>, position_iterator<Deref,IsTransposed>, position_iterator<Deref,1-IsTransposed> > parent_t;
    00038     typedef virtual_2d_locator<typename Deref::const_t,IsTransposed>        const_t;
    00039
    00040     typedef Deref                                  deref_fn_t;
    00041     typedef typename parent_t::point_t             point_t;
    00042
    00043     typedef typename parent_t::coord_t             coord_t;
    00044     typedef typename parent_t::x_coord_t           x_coord_t;
    00045     typedef typename parent_t::y_coord_t           y_coord_t;
    00046     typedef typename parent_t::x_iterator          x_iterator;
    00047     typedef typename parent_t::y_iterator          y_iterator;
    00048
    00049     template <typename NewDeref> struct add_deref {
    00050         typedef virtual_2d_locator<deref_compose<NewDeref,Deref>,IsTransposed > type;
    00051         static type make(const virtual_2d_locator<Deref,IsTransposed>& loc, const NewDeref& nderef) {
    00052             return type(loc.pos(), loc.step(), deref_compose<NewDeref,Deref>(nderef,loc.deref_fn()));
    00053         }
    00054     };
    00055
    00056     virtual_2d_locator(const point_t& p=point_t(0,0), const point_t& step=point_t(1,1), const deref_fn_t& d=deref_fn_t()) : _p(p,step,d) {}
    00057     template <typename D, bool TR> virtual_2d_locator(const virtual_2d_locator<D,TR>& loc, coord_t y_step)
    00058         : _p(loc.pos(), point_t(loc.step().x,loc.step().y*y_step),     loc.deref_fn()) {}
    00059     template <typename D, bool TR> virtual_2d_locator(const virtual_2d_locator<D,TR>& loc, coord_t x_step, coord_t y_step, bool transpose=false)
    00060         : _p(loc.pos(), transpose ?
    00061                     point_t(loc.step().x*y_step,loc.step().y*x_step) :
    00062                     point_t(loc.step().x*x_step,loc.step().y*y_step), loc.deref_fn()) { assert(transpose==(IsTransposed!=TR));}
    00063
    00064     template <typename D, bool TR> virtual_2d_locator(const virtual_2d_locator<D,TR>& pl) : _p(pl._p) {}
    00065     virtual_2d_locator(const virtual_2d_locator& pl) : _p(pl._p) {}
    00066
    00067     bool              operator==(const this_t& p) const { return _p==p._p; }
    00068
    00069     x_iterator&       x()                               { return *gil_reinterpret_cast<x_iterator*>(this); }
    00070     y_iterator&       y()                               { return _p; }
    00071     x_iterator const& x()                         const { return *gil_reinterpret_cast_c<x_iterator const*>(this); }
    00072     y_iterator const& y()                         const { return _p; }
    00073
    00074     // Returns the y distance between two x_iterators given the difference of their x positions
    00075     y_coord_t y_distance_to(const this_t& it2, x_coord_t xDiff) const { return (it2.pos()[1-IsTransposed] - pos()[1-IsTransposed])/step()[1-IsTransposed]; }
    00076     bool      is_1d_traversable(x_coord_t)        const { return false; }   // is there no gap at the end of each row? I.e. can we use x_iterator to visit every pixel instead of nested loops?
    00077
    00078     // Methods specific for virtual 2D locator
    00079     const point_t&   pos()                        const { return _p.pos(); }
    00080     const point_t&   step()                       const { return _p.step(); }
    00081     const deref_fn_t& deref_fn()                  const { return _p.deref_fn(); }
    00082 private:
    00083     template <typename D, bool TR> friend class virtual_2d_locator;
    00084     y_iterator        _p;    // contains the current position, the step and the dereference object
    00085 };
    00086
    00088 //  PixelBasedConcept
    00090
    00091 template <typename D, bool TR>
    00092 struct channel_type<virtual_2d_locator<D,TR> > : public channel_type<typename virtual_2d_locator<D,TR>::parent_t> {
    00093 };
    00094
    00095 template <typename D, bool TR>
    00096 struct color_space_type<virtual_2d_locator<D,TR> > : public color_space_type<typename virtual_2d_locator<D,TR>::parent_t> {
    00097 };
    00098
    00099 template <typename D, bool TR>
    00100 struct channel_mapping_type<virtual_2d_locator<D,TR> > : public channel_mapping_type<typename virtual_2d_locator<D,TR>::parent_t> {
    00101 };
    00102
    00103 template <typename D, bool TR>
    00104 struct is_planar<virtual_2d_locator<D,TR> > : public is_planar<typename virtual_2d_locator<D,TR>::parent_t> {
    00105 };
    00106
    00108 //  HasDynamicXStepTypeConcept
    00110
    00111 template <typename D, bool TR>
    00112 struct dynamic_x_step_type<virtual_2d_locator<D,TR> > {
    00113     typedef virtual_2d_locator<D,TR> type;
    00114 };
    00115
    00117 //  HasDynamicYStepTypeConcept
    00119
    00120 template <typename D, bool TR>
    00121 struct dynamic_y_step_type<virtual_2d_locator<D,TR> > {
    00122     typedef virtual_2d_locator<D,TR> type;
    00123 };
    00124
    00126 //  HasTransposedTypeConcept
    00128
    00129 template <typename D, bool IsTransposed>
    00130 struct transposed_type<virtual_2d_locator<D,IsTransposed> > {
    00131     typedef virtual_2d_locator<D,1-IsTransposed> type;
    00132 };
    00133
    00134 } }  // namespace boost::gil
    00135
    00136 #endif