$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/concept/image.hh
1 // Copyright (C) 2007, 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_CONCEPT_IMAGE_HH
28 # define MLN_CORE_CONCEPT_IMAGE_HH
29 
33 
34 # include <mln/core/concept/site_set.hh>
35 # include <mln/core/concept/mesh.hh>
36 
37 # include <mln/core/trait/all.hh> // FIXME: Move out of core!
38 # include <mln/core/macros.hh>
39 # include <mln/core/site_set/box.hh>
40 
41 # include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
42 # include <mln/trait/images.hh>
43 
44 # include <mln/metal/abort.hh>
45 # include <mln/metal/is_a.hh>
46 # include <mln/metal/equal.hh>
47 
48 # include <mln/tag/init.hh>
49 
50 
51 namespace mln
52 {
53 
54 
55  // Forward declarations.
56  template <typename E> struct Image;
57  template <typename E> struct Literal;
58  template <typename D, typename W> struct w_window;
59 
60 
63  template <>
64  struct Image<void>
65  {
67  };
69 
70 
75  template <typename E>
76  struct Image : public Object<E>
77  {
79 
80  template <typename J>
81  Image<E>& operator=(const J& rhs);
82 
83  /*
84  // provided by internal::image_base:
85 
86  typedef domain_t;
87  typedef site;
88  typedef psite;
89 
90  typedef piter;
91  typedef fwd_piter;
92  typedef bkd_piter;
93 
94  bool has(const psite& p) const;
95  unsigned nsites() const; // If relevant.
96 
97  bool is_valid() const;
98 
99  typedef t_eligible_values_set;
100  const t_eligible_values_set& values_eligible() const;
101 
102  typedef t_values_space;
103  const t_values_space& values_space() const;
104 
105  typedef value;
106 
107  // to be provided in concrete image classes:
108 
109  typedef vset;
110  const vset& values() const;
111 
112  typedef rvalue;
113  typedef lvalue;
114  rvalue operator()(const psite& p) const;
115  lvalue operator()(const psite& p);
116 
117  const domain_t& domain() const;
118 
119  typedef skeleton;
120  */
121 
122  protected:
123  Image();
124  };
125 
126 
131  template <typename I, typename D, typename W>
132  void
133  from_to_(const Image<I>& from, w_window<D,W>& to);
134 
139  template <typename V, unsigned S, typename I>
140  void
141  from_to_(const V (&values)[S], Image<I>& to);
142 
143 
144 # ifndef MLN_INCLUDE_ONLY
145 
146 
147  namespace internal
148  {
149 
150  template <typename values_browsing_trait, typename E>
151  struct image_values_interface_check
152  {
153  static void run() { /* No Requirement */}
154  };
155 
156  template <typename E>
157  struct image_values_interface_check<
158  mln::trait::image::value_browsing::value_wise,
159  E>
160  {
161  static void run()
162  {
163  }
164  };
165 
166 
167  // check_init
168 
169  template < typename E,
170  typename A >
171  int check_init(void (E::*)(A))
172  {
173  return 0;
174  }
175 
176  template < typename E,
177  typename A1, typename A2 >
178  int check_init(void (E::*)(A1, A2))
179  {
180  return 0;
181  }
182 
183  template < typename E,
184  typename A1, typename A2, typename A3 >
185  int check_init(void (E::*)(A1, A2, A3))
186  {
187  return 0;
188  }
189 
190  } // end of namespace mln::internal
191 
192 
193  template <typename E>
194  template <typename J>
195  inline
196  Image<E>&
197  Image<E>::operator=(const J&)
198  {
203  mlc_abort(E)::check();
204  return *this;
205  }
206 
207 
208  template <typename E>
209  inline
211  {
212  // provided by internal::image_base:
213 
214  typedef mln_domain(E) domain_t;
215  typedef mln_site(E) site;
216  typedef mln_psite(E) psite;
217 
218  typedef mln_piter(E) piter;
219  typedef mln_fwd_piter(E) fwd_piter;
220  typedef mln_bkd_piter(E) bkd_piter;
221 
222  bool (E::*m1)(const psite& p) const = & E::has;
223  (void) m1;
224 
225  // Only some image types feature the 'nsites' method.
226 // unsigned (E::*m2)() const = & E::nsites;
227 // (void) m2;
228 
229  bool (E::*m3)() const = & E::is_valid;
230  (void) m3;
231 
232  typedef typename E::t_eligible_values_set t_eligible_values_set;
233 
234  const t_eligible_values_set& (E::*m4)() const = & E::values_eligible;
235  (void) m4;
236 
237  typedef typename E::t_values_space t_values_space;
238 
239  const t_values_space& (E::*m5)() const = & E::values_space;
240  (void) m5;
241 
242  // to be provided in concrete image classes:
243 
244  typedef mln_value(E) value;
245  typedef mln_rvalue(E) rvalue;
246  typedef mln_lvalue(E) lvalue;
247 
248  mlc_is_not_a(value, Literal)::check();
249 
250  // FIXME Doc
251  //typedef mln_vset(E) vset;
252  //const vset& (E::*m5)() const = & E::values;
253  //(void) m5;
254 
255  rvalue (E::*m6)(const psite& p) const = & E::operator();
256  (void) m6;
257 
258  lvalue (E::*m7)(const psite& p) = & E::operator();
259  (void) m7;
260 
261  const domain_t& (E::*m8)() const = & E::domain;
262  (void) m8;
263 
264  typedef typename E::skeleton skeleton;
265 
266  // Check E::init_ presence. Since its signature varies from an
267  // image type to another, that is the only thing we can ensure.
268  internal::check_init(& E::init_);
269 
271  internal::image_values_interface_check<mln_trait_image_value_browsing(E),
272  E>::run();
273  }
274 
275 
276  template <typename I, typename D, typename W>
277  void
278  from_to_(const Image<I>& from_, w_window<D,W>& to)
279  {
280  mlc_converts_to(mln_deduce(I, psite, delta), D)::check();
281  mlc_converts_to(mln_value(I), W)::check();
282  const I& ima = exact(from_);
283  to.clear();
284  mln_value(I) zero = literal::zero;
285  mln_piter(I) p(ima.domain());
286  for_all(p)
287  if (ima(p) != zero)
288  to.insert(ima(p), convert::to<D>(p));
289  }
290 
291  template <typename V, unsigned S, typename I>
292  void
293  from_to_(const V (&values)[S], Image<I>& to_)
294  {
295  mlc_bool(S != 0)::check();
296  mlc_converts_to(V, mln_value(I))::check();
297  typedef mln_site(I) P;
298  enum { d = P::dim,
299  s = mlc_root(d, S)::value };
300  metal::bool_<(mlc_pow_int(s, d) == S)>::check();
301 
302  I& to = exact(to_);
303  mln_precondition(! to.is_valid());
304 
305  box<P> b(all_to(0), all_to(s - 1));
306  to.init_(b);
307  mln_fwd_piter(box<P>) p(b);
308  unsigned i = 0;
309  for_all(p)
310  to(p) = values[i++];
311  }
312 
313 
314 # endif // ! MLN_INCLUDE_ONLY
315 
316 } // end of namespace mln
317 
318 # include <mln/core/routine/initialize.hh>
319 
320 
321 #endif // ! MLN_CORE_CONCEPT_IMAGE_HH