image.hpp 5.37 KB
Newer Older
edwin's avatar
edwin committed
1
2
3
4
#ifndef MLN_CORE_CONCEPT_IMAGE_HPP
# define MLN_CORE_CONCEPT_IMAGE_HPP

# include <mln/core/concept/object.hpp>
edwin.carlinet's avatar
edwin.carlinet committed
5
6
7
8
9
# include <mln/core/concept/check.hpp>
# include <mln/core/concept/pixel.hpp>

# include <mln/core/image_traits.hpp>

10
11
# include <boost/concept_check.hpp>
# include <boost/static_assert.hpp>
edwin.carlinet's avatar
edwin.carlinet committed
12

edwin's avatar
edwin committed
13
14
15

namespace mln {

Edwin Carlinet's avatar
Edwin Carlinet committed
16
17
  template <typename I> struct Image;
  template <typename I> struct IterableImage;
18

edwin's avatar
edwin committed
19
20
21
  template <typename I>
  struct Image : Object_<I>
  {
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  private:
    typedef image_traits<I> traits;

  public:
    typedef typename traits::accessible  accessible;
    typedef typename traits::category    category;

    BOOST_CONCEPT_USAGE(Image)
    {
      typedef typename I::value_type         value;
      typedef typename I::reference          reference;
      typedef typename I::const_reference    const_reference;
      typedef typename I::pixel_type         pixel;
      typedef typename I::const_pixel_type   const_pixel;


      typedef typename I::site_type          site_type;
      typedef typename I::point_type         point_type;
      typedef typename I::domain_type        domain_type;

      const domain_type& (I::*method) () const = &I::domain;
      (void) method;

      check(std::is_convertible<typename pixel::value_type, value> ());
      check(std::is_same<typename pixel::reference, reference> ());
      check(std::is_convertible<typename const_pixel::value_type, value> ());
      check(std::is_same<typename const_pixel::reference, const_reference> ());
edwin.carlinet's avatar
edwin.carlinet committed
49
50
51
52

      BOOST_CONCEPT_ASSERT((Pixel<pixel>));
      BOOST_CONCEPT_ASSERT((Pixel<const_pixel>));

Edwin Carlinet's avatar
Edwin Carlinet committed
53
54
55
56
      MLN_CONCEPT_BEGIN_CHECK_IF()
	BOOST_CONCEPT_ASSERT((IterableImage<I>));
      MLN_CONCEPT_END_CHECK_IF((std::is_convertible<category, forward_image_tag>::value))

edwin.carlinet's avatar
edwin.carlinet committed
57
      check(std::is_convertible<pixel, const_pixel> ());
Edwin Carlinet's avatar
Edwin Carlinet committed
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    }
  };

  template <typename I>
  struct AccessibleImage : Image<I>
  {
  public:
    typedef typename Image<I>::accessible accessible;

    static_assert(accessible::value, "Image must be accessible");

    BOOST_CONCEPT_USAGE(AccessibleImage)
    {
      typedef typename I::point_type        point_type;
      typedef typename I::reference         reference;
      typedef typename I::const_reference   const_reference;

      reference (I::*ptr) (point_type) = &I::operator();
      const_reference (I::*ptr2) (point_type) const = &I::operator();
      (void) ptr; (void) ptr2;
    }
edwin's avatar
edwin committed
80
81
  };

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  template <typename I>
  struct IterableImage : Image<I>
  {
  public:
    typedef typename Image<I>::category category;

    static_assert(std::is_convertible<category, forward_image_tag>::value,
                  "Image category must be iterable");

    BOOST_CONCEPT_USAGE(IterableImage)
    {
      typedef typename I::value_type         value_type;
      typedef typename I::reference         reference;
      typedef typename I::const_reference   const_reference;
      typedef typename I::pixel_type        pixel_type;
      typedef typename I::const_pixel_type  const_pixel_type;

      typedef typename I::value_range               value_range;
      typedef typename I::const_value_range         const_value_range;
      typedef typename I::pixel_range               pixel_range;
      typedef typename I::const_pixel_range         const_pixel_range;


      value_range       (I::*ptr1) () = &I::values;
      const_value_range (I::*ptr2) () const = &I::values;
      pixel_range       (I::*ptr3) () = &I::pixels;
      const_pixel_range (I::*ptr4) () const = &I::pixels;

      (void) ptr1;
      (void) ptr2;
      (void) ptr3;
      (void) ptr4;

115
116
117
118
      typedef typename value_range::iterator       value_iterator;
      typedef typename const_value_range::iterator const_value_iterator;
      typedef typename pixel_range::iterator       pixel_iterator;
      typedef typename const_pixel_range::iterator const_pixel_iterator;
119

120
       check(std::is_convertible<typename value_iterator::value_type, value_type> ());
121
      // "Iterator's value type is expected to be the image value type.");
122
       check(std::is_same<typename value_iterator::reference, reference> ());
123
      // "Iterator's reference is expected to be the image reference");
124
       check(std::is_convertible<typename const_value_iterator::value_type, value_type> ());
125
      // "Iterator's value type is expected to be the image value type");
126
      check(std::is_same<typename const_value_iterator::reference, const_reference> ());
127
128
      // "Iterator's reference type is expected to be the image const reference");

129
      //check(std::is_const<typename std::remove_reference<const_reference>::type > ());
130

131
132
      check(std::is_convertible<typename pixel_iterator::reference, pixel_type> ());
      check(std::is_same<typename pixel_iterator::value_type, pixel_type> ());
133
134
      // "Pixel Iterator's value type is expected to be the image pixel type");

135
136
      check(std::is_convertible<typename const_pixel_iterator::reference, const_pixel_type> ());
      check(std::is_same<typename const_pixel_iterator::value_type, const_pixel_type> ());
137
138
139
140
      // "Pixel Iterator's value type is expected to be the image const pixel type");

      check(std::is_same<typename pixel_type::image_type, I> ());
      check(std::is_same<typename const_pixel_type::image_type, const I> ());
Edwin Carlinet's avatar
Edwin Carlinet committed
141
142
143

      check(std::is_convertible<value_iterator, const_value_iterator> ());
      check(std::is_convertible<pixel_iterator, const_pixel_iterator> ());
144
145
146
147
148
    }
  };



edwin's avatar
edwin committed
149
150
151
152
153

} // end of namespace mln


#endif //!MLN_CORE_CONCEPT_IMAGE_HPP