Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_VIRTUAL_LOCATOR_HPP Chris@16: #define GIL_VIRTUAL_LOCATOR_HPP Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file Chris@16: /// \brief Locator for virtual image views Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated on February 12, 2007 Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #include Chris@16: #include "position_iterator.hpp" Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: /// \brief A 2D locator over a virtual image. Upon dereferencing, invokes a given function object passing it its coordinates. Models: PixelLocatorConcept, HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, HasTransposedTypeConcept Chris@16: /// \ingroup PixelLocatorModel PixelBasedModel Chris@16: /// Chris@16: template // A function object that given a point returns a reference. Models PixelDereferenceAdaptorConcept Chris@16: class virtual_2d_locator : public pixel_2d_locator_base, position_iterator, position_iterator > { Chris@16: typedef virtual_2d_locator this_t; Chris@16: public: Chris@16: typedef pixel_2d_locator_base, position_iterator, position_iterator > parent_t; Chris@16: typedef virtual_2d_locator const_t; Chris@16: Chris@16: typedef Deref deref_fn_t; Chris@16: typedef typename parent_t::point_t point_t; Chris@16: Chris@16: typedef typename parent_t::coord_t coord_t; Chris@16: typedef typename parent_t::x_coord_t x_coord_t; Chris@16: typedef typename parent_t::y_coord_t y_coord_t; Chris@16: typedef typename parent_t::x_iterator x_iterator; Chris@16: typedef typename parent_t::y_iterator y_iterator; Chris@16: Chris@16: template struct add_deref { Chris@16: typedef virtual_2d_locator,IsTransposed > type; Chris@16: static type make(const virtual_2d_locator& loc, const NewDeref& nderef) { Chris@16: return type(loc.pos(), loc.step(), deref_compose(nderef,loc.deref_fn())); Chris@16: } Chris@16: }; Chris@16: Chris@16: 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) {} Chris@16: template virtual_2d_locator(const virtual_2d_locator& loc, coord_t y_step) Chris@16: : _p(loc.pos(), point_t(loc.step().x,loc.step().y*y_step), loc.deref_fn()) {} Chris@16: template virtual_2d_locator(const virtual_2d_locator& loc, coord_t x_step, coord_t y_step, bool transpose=false) Chris@16: : _p(loc.pos(), transpose ? Chris@16: point_t(loc.step().x*y_step,loc.step().y*x_step) : Chris@16: point_t(loc.step().x*x_step,loc.step().y*y_step), loc.deref_fn()) { assert(transpose==(IsTransposed!=TR));} Chris@16: Chris@16: template virtual_2d_locator(const virtual_2d_locator& pl) : _p(pl._p) {} Chris@16: virtual_2d_locator(const virtual_2d_locator& pl) : _p(pl._p) {} Chris@16: Chris@16: bool operator==(const this_t& p) const { return _p==p._p; } Chris@16: Chris@16: x_iterator& x() { return *gil_reinterpret_cast(this); } Chris@16: y_iterator& y() { return _p; } Chris@16: x_iterator const& x() const { return *gil_reinterpret_cast_c(this); } Chris@16: y_iterator const& y() const { return _p; } Chris@16: Chris@16: // Returns the y distance between two x_iterators given the difference of their x positions Chris@16: 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]; } Chris@16: 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? Chris@16: Chris@16: // Methods specific for virtual 2D locator Chris@16: const point_t& pos() const { return _p.pos(); } Chris@16: const point_t& step() const { return _p.step(); } Chris@16: const deref_fn_t& deref_fn() const { return _p.deref_fn(); } Chris@16: private: Chris@16: template friend class virtual_2d_locator; Chris@16: y_iterator _p; // contains the current position, the step and the dereference object Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // PixelBasedConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct channel_type > : public channel_type::parent_t> { Chris@16: }; Chris@16: Chris@16: template Chris@16: struct color_space_type > : public color_space_type::parent_t> { Chris@16: }; Chris@16: Chris@16: template Chris@16: struct channel_mapping_type > : public channel_mapping_type::parent_t> { Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_planar > : public is_planar::parent_t> { Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // HasDynamicXStepTypeConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct dynamic_x_step_type > { Chris@16: typedef virtual_2d_locator type; Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // HasDynamicYStepTypeConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct dynamic_y_step_type > { Chris@16: typedef virtual_2d_locator type; Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // HasTransposedTypeConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct transposed_type > { Chris@16: typedef virtual_2d_locator type; Chris@16: }; Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif