Boost GIL


pixel_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_CONCEPTS_PIXEL_LOCATOR_HPP
9 #define BOOST_GIL_CONCEPTS_PIXEL_LOCATOR_HPP
10 
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/concept_check.hpp>
13 #include <boost/gil/concepts/fwd.hpp>
14 #include <boost/gil/concepts/pixel.hpp>
15 #include <boost/gil/concepts/pixel_dereference.hpp>
16 #include <boost/gil/concepts/pixel_iterator.hpp>
17 #include <boost/gil/concepts/point.hpp>
18 #include <boost/gil/concepts/detail/utility.hpp>
19 
20 #include <cstddef>
21 #include <iterator>
22 #include <type_traits>
23 
24 #if defined(BOOST_CLANG)
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
27 #endif
28 
29 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
32 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
33 #endif
34 
35 namespace boost { namespace gil {
36 
40 
44 
48 
102 template <typename Loc>
104 {
105  void constraints()
106  {
107  gil_function_requires<Regular<Loc>>();
108 
109  // TODO: Should these be concept-checked instead of ignored? --mloskot
110 
111  using value_type = typename Loc::value_type;
112  ignore_unused_variable_warning(value_type{});
113 
114  // result of dereferencing
115  using reference = typename Loc::reference;
116  //ignore_unused_variable_warning(reference{});
117 
118  // result of operator-(pixel_locator, pixel_locator)
119  using difference_type = typename Loc::difference_type;
120  ignore_unused_variable_warning(difference_type{});
121 
122  // type used to store relative location (to allow for more efficient repeated access)
123  using cached_location_t = typename Loc::cached_location_t;
124  ignore_unused_variable_warning(cached_location_t{});
125 
126  // same as this type, but over const values
127  using const_t = typename Loc::const_t;
128  ignore_unused_variable_warning(const_t{});
129 
130  // same as difference_type
131  using point_t = typename Loc::point_t;
132  ignore_unused_variable_warning(point_t{});
133 
134  static std::size_t const N = Loc::num_dimensions; ignore_unused_variable_warning(N);
135 
136  using first_it_type = typename Loc::template axis<0>::iterator;
137  using last_it_type = typename Loc::template axis<N-1>::iterator;
138  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<first_it_type>>();
139  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<last_it_type>>();
140 
141  // point_t must be an N-dimensional point, each dimension of which must
142  // have the same type as difference_type of the corresponding iterator
143  gil_function_requires<PointNDConcept<point_t>>();
144  static_assert(point_t::num_dimensions == N, "");
145  static_assert(std::is_same
146  <
147  typename std::iterator_traits<first_it_type>::difference_type,
148  typename point_t::template axis<0>::coord_t
149  >::value, "");
150  static_assert(std::is_same
151  <
152  typename std::iterator_traits<last_it_type>::difference_type,
153  typename point_t::template axis<N-1>::coord_t
154  >::value, "");
155 
156  difference_type d;
157  loc += d;
158  loc -= d;
159  loc = loc + d;
160  loc = loc - d;
161  reference r1 = loc[d]; ignore_unused_variable_warning(r1);
162  reference r2 = *loc; ignore_unused_variable_warning(r2);
163  cached_location_t cl = loc.cache_location(d); ignore_unused_variable_warning(cl);
164  reference r3 = loc[d]; ignore_unused_variable_warning(r3);
165 
166  first_it_type fi = loc.template axis_iterator<0>();
167  fi = loc.template axis_iterator<0>(d);
168  last_it_type li = loc.template axis_iterator<N-1>();
169  li = loc.template axis_iterator<N-1>(d);
170 
171  using deref_t = PixelDereferenceAdaptorArchetype<typename Loc::value_type>;
172  using dtype = typename Loc::template add_deref<deref_t>::type;
173  // TODO: infinite recursion - FIXME?
174  //gil_function_requires<RandomAccessNDLocatorConcept<dtype>>();
175  }
176  Loc loc;
177 };
178 
219 template <typename Loc>
221 {
222  void constraints()
223  {
224  gil_function_requires<RandomAccessNDLocatorConcept<Loc>>();
225  static_assert(Loc::num_dimensions == 2, "");
226 
227  using dynamic_x_step_t = typename dynamic_x_step_type<Loc>::type;
228  using dynamic_y_step_t = typename dynamic_y_step_type<Loc>::type;
229  using transposed_t = typename transposed_type<Loc>::type;
230 
231  using cached_location_t = typename Loc::cached_location_t;
232  gil_function_requires<Point2DConcept<typename Loc::point_t>>();
233 
234  using x_iterator = typename Loc::x_iterator;
235  using y_iterator = typename Loc::y_iterator;
236  using x_coord_t = typename Loc::x_coord_t;
237  using y_coord_t = typename Loc::y_coord_t;
238 
239  x_coord_t xd = 0; ignore_unused_variable_warning(xd);
240  y_coord_t yd = 0; ignore_unused_variable_warning(yd);
241 
242  typename Loc::difference_type d;
243  typename Loc::reference r=loc(xd,yd); ignore_unused_variable_warning(r);
244 
245  dynamic_x_step_t loc2(dynamic_x_step_t(), yd);
246  dynamic_x_step_t loc3(dynamic_x_step_t(), xd, yd);
247 
248  using dynamic_xy_step_transposed_t = typename dynamic_y_step_type
249  <
251  >::type;
252  dynamic_xy_step_transposed_t loc4(loc, xd,yd,true);
253 
254  bool is_contiguous = loc.is_1d_traversable(xd);
255  ignore_unused_variable_warning(is_contiguous);
256 
257  loc.y_distance_to(loc, xd);
258 
259  loc = loc.xy_at(d);
260  loc = loc.xy_at(xd, yd);
261 
262  x_iterator xit = loc.x_at(d);
263  xit = loc.x_at(xd, yd);
264  xit = loc.x();
265 
266  y_iterator yit = loc.y_at(d);
267  yit = loc.y_at(xd, yd);
268  yit = loc.y();
269 
270  cached_location_t cl = loc.cache_location(xd, yd);
271  ignore_unused_variable_warning(cl);
272  }
273  Loc loc;
274 };
275 
289 template <typename Loc>
291 {
292  void constraints()
293  {
294  gil_function_requires<RandomAccess2DLocatorConcept<Loc>>();
295  gil_function_requires<PixelIteratorConcept<typename Loc::x_iterator>>();
296  gil_function_requires<PixelIteratorConcept<typename Loc::y_iterator>>();
297  using coord_t = typename Loc::coord_t;
298  static_assert(std::is_same<typename Loc::x_coord_t, typename Loc::y_coord_t>::value, "");
299  }
300  Loc loc;
301 };
302 
303 namespace detail {
304 
306 template <typename Loc>
308 {
309  void constraints()
310  {
311  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept
312  <
313  typename Loc::template axis<0>::iterator
314  >>();
315  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept
316  <
317  typename Loc::template axis<Loc::num_dimensions-1>::iterator
318  >>();
319 
320  typename Loc::difference_type d; initialize_it(d);
321  typename Loc::value_type v; initialize_it(v);
322  typename Loc::cached_location_t cl = loc.cache_location(d);
323  *loc = v;
324  loc[d] = v;
325  loc[cl] = v;
326  }
327  Loc loc;
328 };
329 
330 // \tparam Loc Models RandomAccess2DLocatorConcept
331 template <typename Loc>
332 struct RandomAccess2DLocatorIsMutableConcept
333 {
334  void constraints()
335  {
336  gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<Loc>>();
337  typename Loc::x_coord_t xd = 0; ignore_unused_variable_warning(xd);
338  typename Loc::y_coord_t yd = 0; ignore_unused_variable_warning(yd);
339  typename Loc::value_type v; initialize_it(v);
340  loc(xd, yd) = v;
341  }
342  Loc loc;
343 };
344 
345 } // namespace detail
346 
356 template <typename Loc>
358 {
359  void constraints()
360  {
361  gil_function_requires<RandomAccessNDLocatorConcept<Loc>>();
362  gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<Loc>>();
363  }
364 };
365 
373 template <typename Loc>
375 {
376  void constraints()
377  {
378  gil_function_requires<RandomAccess2DLocatorConcept<Loc>>();
379  gil_function_requires<detail::RandomAccess2DLocatorIsMutableConcept<Loc>>();
380  }
381 };
382 
390 template <typename Loc>
392 {
393  void constraints()
394  {
395  gil_function_requires<PixelLocatorConcept<Loc>>();
396  gil_function_requires<detail::RandomAccess2DLocatorIsMutableConcept<Loc>>();
397  }
398 };
399 
400 }} // namespace boost::gil
401 
402 #if defined(BOOST_CLANG)
403 #pragma clang diagnostic pop
404 #endif
405 
406 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
407 #pragma GCC diagnostic pop
408 #endif
409 
410 #endif
N-dimensional locator over mutable pixels.
Definition: pixel_locator.hpp:357
2-dimensional locator over mutable pixels
Definition: pixel_locator.hpp:374
2-dimensional locator over immutable values
Definition: pixel_locator.hpp:220
GIL's 2-dimensional locator over immutable GIL pixels.
Definition: pixel_locator.hpp:290
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
N-dimensional locator over immutable values.
Definition: pixel_locator.hpp:103
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17
GIL's 2-dimensional locator over mutable GIL pixels.
Definition: pixel_locator.hpp:391