$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flat_image.hh
1 // Copyright (C) 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_IMAGE_FLAT_IMAGE_HH
28 # define MLN_CORE_IMAGE_FLAT_IMAGE_HH
29 
35 
36 # include <mln/core/internal/image_primary.hh>
37 # include <mln/value/set.hh>
38 
39 
40 namespace mln
41 {
42 
43 
44  // Forward declaration.
45  template <typename T, typename S> struct flat_image;
46 
47 
48  namespace internal
49  {
50 
54  template <typename T, typename S>
55  struct data< flat_image<T,S> >
56  {
57  data(const T& val, const S& pset);
58 
59  T val_;
60  S domain_;
61  };
62 
63  } // end of namespace mln::internal
64 
65 
66 
67  namespace trait
68  {
69 
70  template <typename T, typename S>
71  struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> >
72  {
73  // misc
74  typedef trait::image::category::primary category;
75  typedef trait::image::speed::fast speed;
76  typedef trait::image::size::regular size;
77 
78  // value
79  typedef trait::image::vw_io::read_write vw_io;
81  typedef trait::image::vw_set::none vw_set;
82  typedef trait::image::value_access::direct value_access;
83  typedef trait::image::value_storage::singleton value_storage;
84  typedef mln::trait::image::value_browsing::value_wise value_browsing;
85  typedef trait::image::value_alignment::with_grid value_alignment;
86  typedef trait::image::value_io::read_only value_io;
87 
88  // site / domain
89  typedef trait::image::pw_io::read pw_io;
90  typedef trait::image::localization::basic_grid localization; // FIXME
91  typedef trait::image::dimension::two_d dimension; // FIXME
92 
93  // extended domain
94  typedef trait::image::ext_domain::infinite ext_domain;
95  typedef trait::image::ext_value::single ext_value;
96  typedef trait::image::ext_io::read_only ext_io;
97  };
98 
99  } // end of namespace mln::trait
100 
101 
102 
106  //
107  template <typename T, typename S>
108  struct flat_image : public internal::image_primary< T, S, flat_image<T,S> >
109  {
111  typedef flat_image< tag::value_<T>, tag::domain_<S> > skeleton;
112 
113 
115  typedef T value;
116 
118  typedef const T& rvalue;
119 
121  typedef T& lvalue;
122 
123 
125  flat_image();
126 
128  flat_image(const T& val, const S& pset);
129 
132  void init_(const T& val, const S& pset);
134 
136  const S& domain() const;
137 
139  bool has(const mln_psite(S)& p) const;
140 
141 
143  const T& operator()(const mln_psite(S)& p) const;
144 
146  T& operator()(const mln_psite(S)& p);
147 
148 
151  const T& value_() const;
152  T& value_();
154  };
155 
156 
158  template <typename T, typename S, typename J>
159  void init_(tag::image_t, flat_image<T,S>& target, const J& model);
161 
162 
163 
164 # ifndef MLN_INCLUDE_ONLY
165 
166  // init_
167 
168  template <typename T, typename S, typename J>
169  inline
170  void init_(tag::image_t, flat_image<T,S>& target, const J& model)
171  {
172  S pset;
173  init_(tag::domain, pset, model);
174  T dummy;
175  target.init_(dummy, pset);
176  }
177 
178 
179  // internal::data< flat_image<T,S> >
180 
181  namespace internal
182  {
183 
184  template <typename T, typename S>
185  inline
186  data< flat_image<T,S> >::data(const T& val, const S& pset)
187  : val_(val),
188  domain_(pset)
189  {
190  }
191 
192  } // end of namespace mln::internal
193 
194 
195  // flat_image<T,S>
196 
197  template <typename T, typename S>
198  inline
199  flat_image<T,S>::flat_image()
200  {
201  }
202 
203  template <typename T, typename S>
204  inline
205  flat_image<T,S>::flat_image(const T& val, const S& pset)
206  {
207  init_(val, pset);
208  }
209 
210  template <typename T, typename S>
211  inline
212  void
213  flat_image<T,S>::init_(const T& val, const S& pset)
214  {
215  mln_precondition(! this->is_valid());
216  this->data_ = new internal::data< flat_image<T,S> >(val, pset);
217  }
218 
219  template <typename T, typename S>
220  inline
221  const S&
222  flat_image<T,S>::domain() const
223  {
224  return this->data_->domain_;
225  }
226 
227  template <typename T, typename S>
228  inline
229  bool
230  flat_image<T,S>::has(const mln_psite(S)&) const
231  {
232  return true;
233  }
234 
235  template <typename T, typename S>
236  inline
237  const T&
238  flat_image<T,S>::operator()(const mln_psite(S)&) const
239  {
240  mln_precondition(this->is_valid());
241  return this->data_->val_;
242  }
243 
244  template <typename T, typename S>
245  inline
246  T&
247  flat_image<T,S>::operator()(const mln_psite(S)&)
248  {
249  mln_precondition(this->is_valid());
250  return this->data_->val_;
251  }
252 
253  template <typename T, typename S>
254  inline
255  const T&
256  flat_image<T,S>::value_() const
257  {
258  mln_precondition(this->is_valid());
259  return this->data_->val_;
260  }
261 
262  template <typename T, typename S>
263  inline
264  T&
265  flat_image<T,S>::value_()
266  {
267  mln_precondition(this->is_valid());
268  return this->data_->val_;
269  }
270 
271 
272 
273 # endif // ! MLN_INCLUDE_ONLY
274 
275 } // end of namespace mln
276 
277 
278 #endif // ! MLN_CORE_IMAGE_FLAT_IMAGE_HH