$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tr_image.hh
1 // Copyright (C) 2007, 2009, 2012, 2013 EPITA Research and Development
2 // 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_IMORPH_TR_IMAGE_HH
28 # define MLN_CORE_IMAGE_IMORPH_TR_IMAGE_HH
29 
34 
35 # include <cmath>
36 
37 # include <mln/core/internal/image_identity.hh>
38 # include <mln/algebra/vec.hh>
39 # include <mln/value/set.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename S, typename I, typename T> struct tr_image;
47 
48  namespace internal
49  {
50 
54  template <typename S, typename I, typename T>
55  struct data< tr_image<S,I,T> >
56  {
57  data(const S& s, const I& ima, const T& tr);
58 
59  I ima_;
60  T tr_;
61  S s_;
62  };
63 
64  } // end of namespace mln::internal
65 
66  namespace trait
67  {
68 
69  template <typename S, typename I, typename T>
70  struct image_< tr_image<S,I,T> >
71  : public image_<I> // Same as I except...
72  {
73  // ...these changes.
74  typedef trait::image::value_io::read_only value_io;
75  typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
76  };
77 
78  } // end of namespace mln::trait
79 
80 
84  //
85  template <typename S, typename I, typename T>
86  struct tr_image :
87  public mln::internal::image_identity< I, S, tr_image<S,I,T> >
88  {
89 
91  typedef
93 
95  typedef mln_psite(I) psite;
96 
98  typedef mln_site(I) site;
99 
101  typedef mln_value(I) value;
102 
104  typedef mln_value(I) lvalue; // FIXME: Depends on lvalue presence in I.
105 
107  typedef mln_value(I) rvalue;
108 
110  typedef tr_image< S, tag::image_<I>, T> skeleton;
111 
112 
114  tr_image(const S& s, const I& ima, const T& tr);
115  /* FIXME: What's the purpose of this ctor? AFAIK, morphers
116  objects (and images in general) cannot have their structure /
117  core data altered after they're built. Here, there's a
118  (partial) exception: this morpher provides set_tr(), but has no
119  set_ima(). I (Roland) don't see the point in keeping this ctor
120  if we do not provide set_ima(). */
121  tr_image();
122 
125  void init_(const S& s, const I& ima, const T& tr);
127 
129  bool is_valid() const;
130 
132  using super_::has;
133 
134  enum { dim_ = site::dim };
136 
138  bool has(const vec_t& v) const;
139 
142  //using super_::operator();
143 
144  mln_value(I) operator()(const psite& p) const;
145  mln_value(I) operator()(const psite& p);
146 
148  void set_tr(T& tr);
149 
151  const T& tr() const;
152 
154  const S& domain() const;
155  };
156 
157 
159  template <typename S, typename I, typename T>
160  tr_image<S, I, T>
161  apply_tr(const Site_Set<S>& s, const Image<I>& ima,
162  const Function_v2v<T>& tr);
163 
166  template <typename I, typename T>
167  tr_image<mln_domain(I), I, T>
168  apply_tr(const Image<I>& ima, const Function_v2v<T>& tr);
169 
170 
171 
172 # ifndef MLN_INCLUDE_ONLY
173 
174  namespace internal
175  {
176 
177  // internal::data< tr_image<I,S> >
178 
179  template <typename S, typename I, typename T>
180  inline
181  data< tr_image<S,I,T> >::data(const S& s, const I& ima, const T& tr)
182  : ima_(ima),
183  tr_(tr),
184  s_(s)
185  {
186  }
187 
188  } // end of namespace mln::internal
189 
190  template <typename S, typename I, typename T>
191  inline
192  tr_image<S,I,T>::tr_image(const S& s, const I& ima, const T& tr)
193  {
194  init_(s, ima, tr);
195  }
196 
197  template <typename S, typename I, typename T>
198  inline
199  void
200  tr_image<S,I,T>::init_(const S& s, const I& ima, const T& tr)
201  {
202  mln_precondition(ima.is_valid());
203  this->data_ = new internal::data< tr_image<S,I,T> >(s, ima, tr);
204  }
205 
206  template <typename S, typename I, typename T>
207  inline
208  bool
209  tr_image<S,I,T>::is_valid() const
210  {
211  mln_invariant(this->delegatee_()->is_valid());
212  return true;
213  }
214 
215  template <typename S, typename I, typename T>
216  inline
217  bool
218  tr_image<S,I,T>::has(const vec_t& v) const
219  {
220  mln_psite(I) p;
221  algebra::vec<site::dim, float> v2 = this->data_->tr_.inv()(v);
222  for (unsigned i = 0; i < site::dim; ++i)
223  p[i] = static_cast<int>(v2[i]);
224  return this->delegatee_().has(p);
225  }
226 
227 
228  template <typename S, typename I, typename T>
229  inline
230  mln_value(I)
231  tr_image<S,I,T>::operator()(const psite& p) const
232  {
233  algebra::vec<site::dim, float> v = p.to_vec();
234  return this->data_->ima_(this->data_->tr_.inv()(v));
235  }
236 
237  template <typename S, typename I, typename T>
238  inline
239  mln_value(I)
240  tr_image<S,I,T>::operator()(const psite& p)
241  {
242  algebra::vec<site::dim, float> v = p.to_vec();
243  return this->data_->ima_(this->data_->tr_.inv()(v));
244  }
245 
246  template <typename S, typename I, typename T>
247  inline
248  void
249  tr_image<S,I,T>::set_tr(T& tr)
250  {
251  this->data_->tr_ = tr;
252  }
253 
254  template <typename S, typename I, typename T>
255  inline
256  const T&
257  tr_image<S,I,T>::tr() const
258  {
259  return this->data_->tr_;
260  }
261 
262  template <typename S, typename I, typename T>
263  inline
264  const S&
265  tr_image<S,I,T>::domain() const
266  {
267  return this->data_->s_;
268  }
269 
270 
271  template <typename S, typename I, typename T>
272  inline
273  tr_image<S,I,T>
274  transposed_image(const Site_Set<S>& s, const Image<I>& ima,
275  const Function_v2v<T>& t)
276  {
277  tr_image<S,I,T> tmp(exact(s), exact(ima), exact(t));
278  return tmp;
279  }
280 
281 
283 
284  template <typename S, typename I, typename T>
285  tr_image<S, I, T>
286  apply_tr(const Site_Set<S>& s, const Image<I>& ima,
287  const Function_v2v<T>& tr)
288  {
289  tr_image<S, I, T> tmp(exact(s), exact(ima), exact(tr));
290  return tmp;
291  }
292 
293  template <typename I, typename T>
294  tr_image<mln_domain(I), I, T>
295  apply_tr(const Image<I>& ima, const Function_v2v<T>& tr)
296  {
297  tr_image<mln_domain(I), I, T> tmp(exact(ima).domain(), exact(ima),
298  exact(tr));
299  return tmp;
300  }
301 
302 # endif // ! MLN_INCLUDE_ONLY
303 
304 } // end of namespace mln
305 
306 
307 #endif // ! MLN_CORE_IMAGE_IMORPH_TR_IMAGE_HH