Boost GIL


virtual_locator.hpp
1//
2// Copyright 2005-2007 Adobe Systems Incorporated
3//
4// Distributed under the Boost Software License, Version 1.0
5// See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt
7//
8#ifndef BOOST_GIL_VIRTUAL_LOCATOR_HPP
9#define BOOST_GIL_VIRTUAL_LOCATOR_HPP
10
11#include <boost/gil/dynamic_step.hpp>
12#include <boost/gil/position_iterator.hpp>
13
14#include <boost/assert.hpp>
15
16namespace boost { namespace gil {
17
30template <typename DerefFn, bool IsTransposed>
33 <
34 virtual_2d_locator<DerefFn, IsTransposed>,
35 position_iterator<DerefFn, IsTransposed>,
36 position_iterator<DerefFn, 1-IsTransposed>
37 >
38{
40public:
42 <
45 position_iterator<DerefFn, 1-IsTransposed>
46 >;
48 using deref_fn_t = DerefFn;
49 using point_t = typename parent_t::point_t;
50 using coord_t = typename parent_t::coord_t;
51 using x_coord_t = typename parent_t::x_coord_t;
52 using y_coord_t = typename parent_t::y_coord_t;
53 using x_iterator = typename parent_t::x_iterator;
54 using y_iterator = typename parent_t::y_iterator;
55
56 template <typename NewDerefFn>
57 struct add_deref
58 {
60
61 static type make(this_t const& loc, NewDerefFn const& new_deref_fn)
62 {
63 return type(loc.pos(), loc.step(),
64 deref_compose<NewDerefFn, DerefFn>(new_deref_fn, loc.deref_fn()));
65 }
66 };
67
69 point_t const& p = {0, 0},
70 point_t const& step = {1, 1},
71 deref_fn_t const& deref_fn = deref_fn_t())
72 : y_pos_(p, step, deref_fn)
73 {}
74
75 template <typename D, bool TR>
76 virtual_2d_locator(virtual_2d_locator<D, TR> const &loc, coord_t y_step)
77 : y_pos_(loc.pos(), point_t(loc.step().x, loc.step().y * y_step), loc.deref_fn())
78 {}
79
80 template <typename D, bool TR>
81 virtual_2d_locator(virtual_2d_locator<D, TR> const& loc, coord_t x_step, coord_t y_step, bool transpose = false)
82 : y_pos_(loc.pos()
83 , transpose ?
84 point_t(loc.step().x * y_step, loc.step().y * x_step) :
85 point_t(loc.step().x * x_step, loc.step().y * y_step)
86 , loc.deref_fn())
87 {
88 BOOST_ASSERT(transpose == (IsTransposed != TR));
89 }
90
91 template <typename D, bool TR>
92 virtual_2d_locator(virtual_2d_locator<D, TR> const& other) : y_pos_(other.y_pos_) {}
93
94 virtual_2d_locator(virtual_2d_locator const& other) : y_pos_(other.y_pos_) {}
95 virtual_2d_locator& operator=(virtual_2d_locator const& other) = default;
96
97 bool operator==(const this_t& p) const { return y_pos_ == p.y_pos_; }
98
99 auto x() -> x_iterator&
100 {
101 return *gil_reinterpret_cast<x_iterator*>(this);
102 }
103
104 auto x() const -> x_iterator const&
105 {
106 return *gil_reinterpret_cast_c<x_iterator const*>(this);
107 }
108
109 auto y() -> y_iterator& { return y_pos_; }
110 auto y() const -> y_iterator const& { return y_pos_; }
111
113 auto y_distance_to(this_t const& it2, x_coord_t) const -> y_coord_t
114 {
115 return (it2.pos()[1 - IsTransposed] - pos()[1 - IsTransposed])
116 / step()[1 - IsTransposed];
117 }
118
121 bool is_1d_traversable(x_coord_t) const { return false; }
122
123 // Methods specific for virtual 2D locator
124 auto pos() const -> point_t const& { return y_pos_.pos(); }
125 auto step() const -> point_t const& { return y_pos_.step(); }
126 auto deref_fn() const -> deref_fn_t const& { return y_pos_.deref_fn(); }
127
128private:
129 template <typename D, bool TR>
130 friend class virtual_2d_locator;
131
132 y_iterator y_pos_; // current position, the step and the dereference object
133};
134
136// PixelBasedConcept
138
139template <typename D, bool TR>
140struct channel_type<virtual_2d_locator<D, TR>>
141 : channel_type<typename virtual_2d_locator<D, TR>::parent_t>
142{
143};
144
145template <typename D, bool TR>
146struct color_space_type<virtual_2d_locator<D, TR>>
147 : color_space_type<typename virtual_2d_locator<D, TR>::parent_t>
148{
149};
150
151template <typename D, bool TR>
152struct channel_mapping_type<virtual_2d_locator<D, TR>>
153 : channel_mapping_type<typename virtual_2d_locator<D, TR>::parent_t>
154{
155};
156
157template <typename D, bool TR>
158struct is_planar<virtual_2d_locator<D, TR>>
159 : is_planar<typename virtual_2d_locator<D, TR>::parent_t>
160{
161};
162
164// HasDynamicXStepTypeConcept
166
167template <typename D, bool TR>
168struct dynamic_x_step_type<virtual_2d_locator<D,TR>>
169{
170 using type = virtual_2d_locator<D,TR>;
171};
172
174// HasDynamicYStepTypeConcept
176
177template <typename D, bool TR>
178struct dynamic_y_step_type<virtual_2d_locator<D,TR>>
179{
180 using type = virtual_2d_locator<D,TR>;
181};
182
184// HasTransposedTypeConcept
186
187template <typename D, bool IsTransposed>
188struct transposed_type<virtual_2d_locator<D,IsTransposed>>
189{
190 using type = virtual_2d_locator<D,1-IsTransposed>;
191};
192
193}} // namespace boost::gil
194
195#endif
Composes two dereference function objects. Similar to std::unary_compose but needs to pull some alias...
Definition utilities.hpp:128
base class for models of PixelLocatorConcept
Definition locator.hpp:109
2D point both axes of which have the same dimension typeModels: Point2DConcept
Definition point.hpp:36
An iterator that remembers its current X,Y position and invokes a function object with it upon derefe...
Definition position_iterator.hpp:40
A 2D locator over a virtual image Upon dereferencing, invokes a given function object passing it its ...
Definition virtual_locator.hpp:38
auto y_distance_to(this_t const &it2, x_coord_t) const -> y_coord_t
Returns the y distance between two x_iterators given the difference of their x positions.
Definition virtual_locator.hpp:113
bool is_1d_traversable(x_coord_t) const
Definition virtual_locator.hpp:121
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36