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