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