Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
transformed_image.hh
1 // Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
2 // (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_DMORPH_TRANSFORMED_IMAGE_HH
28 # define MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
29 
36 
37 # include <mln/core/internal/image_domain_morpher.hh>
38 # include <mln/core/site_set/p_transformed.hh>
39 
40 
41 namespace mln
42 {
43 
44 
45  // Forward declaration.
46  template <typename I, typename F> struct transformed_image;
47 
48 
49  namespace internal
50  {
51 
53  template <typename I, typename F>
54  struct data< transformed_image<I,F> >
55  {
56  data(I& ima, const F& f);
57 
58  I ima_;
59  F f_;
60  p_transformed< mln_domain(I), F> domain_;
61  };
62 
63  } // end of namespace mln::internal
64 
65 
66 
67  namespace trait
68  {
69 
70  template <typename I, typename F>
71  struct image_< transformed_image<I,F> > : default_image_morpher< I,
72  mln_value(I),
73  transformed_image<I,F> >
74  {
75  typedef trait::image::category::domain_morpher category;
76 
77  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
78  typedef trait::image::ext_value::irrelevant ext_value;
79  typedef trait::image::ext_io::irrelevant ext_io;
80 
81  typedef trait::image::vw_io::none vw_io;
82  typedef trait::image::vw_set::none vw_set;
83  typedef trait::image::value_alignment::not_aligned value_alignment;
84  typedef trait::image::value_storage::disrupted value_storage;
85  };
86 
87  } // end of namespace mln::trait
88 
89 
90 
94  //
95  template <typename I, typename F>
96  struct transformed_image : public internal::image_domain_morpher< I,
97  p_transformed< mln_domain(I), F>,
98  transformed_image<I,F> >
99  {
101  typedef transformed_image< tag::image_<I>, tag::function_<F> > skeleton;
102 
105 
107  transformed_image(I& ima, const F& f);
108 
110  void init_(I& ima, const F& f);
111 
112 
115 
116 
118  mln_rvalue(I) operator()(const mln_psite(I)& p) const;
119 
122  mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
123 
124 
126  operator transformed_image<const I, F>() const;
127  };
128 
129 
130 
131  // Morpher creation.
132 
133  template <typename I, typename F>
134  transformed_image<const I, F>
135  transform_domain(const Image<I>& ima, const Function_v2v<F>& f);
136 
137  template <typename I, typename F>
138  transformed_image<I, F>
139  transform_domain(Image<I>& ima, const Function_v2v<F>& f);
140 
141 
142 
143 
144 # ifndef MLN_INCLUDE_ONLY
145 
146  // init_
147 
148  template <typename I, typename F, typename J>
149  inline
150  void init_(tag::image_t, transformed_image<I,F>& target, const J& model)
151  {
152  I ima;
153  init_(tag::image, ima, exact(model));
154  F f;
155  init_(tag::function, f, exact(model));
156  target.init_(ima, f);
157  }
158 
159  template <typename I, typename F>
160  void init_(tag::function_t, F& f, const transformed_image<I,F>& model)
161  {
162  f = model.domain().function();
163  }
164 
165 
166  // internal::data< transformed_image<I,F> >
167 
168  namespace internal
169  {
170 
171  template <typename I, typename F>
172  inline
173  data< transformed_image<I,F> >::data(I& ima, const F& f)
174  : ima_(ima),
175  f_(f),
176  domain_(ima.domain(), f)
177  {
178  }
179 
180  } // end of namespace mln::internal
181 
182 
183  // transformed_image<I,F>
184 
185  template <typename I, typename F>
186  inline
188  {
189  }
190 
191  template <typename I, typename F>
192  inline
194  {
195  init_(ima, f);
196  }
197 
198  template <typename I, typename F>
199  inline
200  void
201  transformed_image<I,F>::init_(I& ima, const F& f)
202  {
203  mln_precondition(! this->is_valid());
204  this->data_ = new internal::data< transformed_image<I,F> >(ima, f);
205  }
206 
207  template <typename I, typename F>
208  inline
209  const p_transformed< mln_domain(I), F>&
211  {
212  return this->data_->domain_;
213  }
214 
215  template <typename I, typename F>
216  inline
217  mln_rvalue(I)
218  transformed_image<I,F>::operator()(const mln_psite(I)& p) const
219  {
220  mln_precondition(this->delegatee_() != 0);
221  mln_precondition(exact(this)->has(p));
222  mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
223  return this->delegatee_()->operator()(this->data_->f_(p));
224  }
225 
226  template <typename I, typename F>
227  inline
228  mln_morpher_lvalue(I)
229  transformed_image<I,F>::operator()(const mln_psite(I)& p)
230  {
231  mln_precondition(this->delegatee_() != 0);
232  mln_precondition(exact(this)->has(p));
233  mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
234  return this->delegatee_()->operator()(this->data_->f_(p));
235  }
236 
237 
238  template <typename I, typename F>
239  inline
241  {
242  transformed_image<const I, F> tmp(this->data_->ima_,
243  this->data_->f_);
244  return tmp;
245  }
246 
247 
248  // Morpher creation.
249 
250  template <typename I, typename F>
251  inline
253  transform_domain(const Image<I>& ima, const Function_v2v<F>& f)
254  {
255  transformed_image<const I, F> tmp(exact(ima), exact(f));
256  return tmp;
257  }
258 
259  template <typename I, typename F>
260  inline
261  transformed_image<I, F>
262  transform_domain(Image<I>& ima, const Function_v2v<F>& f)
263  {
264  transformed_image<I, F> tmp(exact(ima), exact(f));
265  return tmp;
266  }
267 
268 # endif // ! MLN_INCLUDE_ONLY
269 
270 } // end of namespace mln
271 
272 
273 #endif // ! MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH