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