$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fun_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_IMAGE_VMORPH_FUN_IMAGE_HH
28 # define MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH
29 
34 
35 # include <mln/core/internal/image_value_morpher.hh>
36 # include <mln/trait/images.hh>
37 # include <mln/value/set.hh>
38 
39 # include <mln/metal/if.hh>
40 # include <mln/metal/equal.hh>
41 
42 
43 namespace mln
44 {
45 
46  // Forward declaration.
47  template <typename F, typename I> struct fun_image;
48 
49  namespace internal
50  {
54  template <typename F, typename I>
55  struct data< fun_image<F,I> >
56  {
57  data(const F& f, const I& ima);
58  F f_;
59  const I ima_;
60  };
61 
62  } // end of namespace mln::internal
63 
64 
65 
66  namespace trait
67  {
68 
69  template <typename F, typename I>
70  struct image_< fun_image<F,I> > : default_image_morpher< I, mln_result(F), fun_image<F,I> >
71  {
72  // typedef trait::image::category::value_morpher category;
73  typedef trait::image::category::primary category; // does not work either
74  typedef trait::image::value_io::read_only value_io;
75  typedef trait::image::value_access::computed value_access;
76  typedef trait::image::value_storage::disrupted value_storage;
77 
78  private:
79  typedef mlc_equal(mln_trait_value_quant(mln_result(F)),
80  trait::value::quant::high) is_high_quant_;
81  public:
82  typedef mln_trait_value_kind(mln_result(F)) kind;
83  typedef mln_trait_value_nature(mln_result(F)) nature;
84  typedef mlc_if(is_high_quant_,
85  trait::image::quant::high,
86  trait::image::quant::low) quant;
87  };
88 
89  } // end of namespace mln::trait
90 
91 
92 
93 
97  //
98  template <typename F, typename I>
99  struct fun_image :
100  public internal::image_value_morpher< I, mln_result(F), fun_image<F,I> >
101  {
103  typedef mln_result(F) value;
104 
106  typedef mln_result(F) rvalue;
107 
109  typedef mln_result(F) lvalue;
110  // typedef mln::value::shell<F,I> lvalue; De-activated for 1.0
111 
113  typedef fun_image< tag::value_<mln_result(F)>, tag::image_<I> > skeleton;
114 
116  fun_image();
117 
119  fun_image(const Function_v2v<F>& f, const Image<I>& ima);
120 
122  fun_image(const Image<I>& ima);
123 
126  void init_(const Function_v2v<F>& f, const Image<I>& ima);
128 
130  mln_result(F) operator()(const mln_psite(I)& p) const;
131 
133  mln_result(F) operator()(const mln_psite(I)& p);
134  // lvalue operator()(const mln_psite(I)& p); De-activated for 1.0
135  };
136 
137 
138 
139  template <typename F, typename I>
140  fun_image<F, I>
141  operator << (const Function_v2v<F>& f, const Image<I>& ima);
142 
143 
144 
145 # ifndef MLN_INCLUDE_ONLY
146 
147 
148  template <typename F, typename I>
149  inline
151  operator << (const Function_v2v<F>& f, const Image<I>& ima)
152  {
153  fun_image<F, I> tmp(exact(f), exact(ima));
154  return tmp;
155  }
156 
157 
158  // internal::data< fun_image<T,I> >
159 
160  namespace internal
161  {
162 
163  template <typename F, typename I>
164  inline
165  data< fun_image<F,I> >::data(const F& f, const I& ima)
166  : f_(f),
167  ima_(ima)
168  {
169  }
170 
171  } // end of namespace mln::internal
172 
173  // fun_image<F,I>
174 
175  template <typename F, typename I>
176  inline
177  fun_image<F,I>::fun_image()
178  {
179  this->data_ = 0;
180  }
181 
182  template <typename F, typename I>
183  inline
184  fun_image<F,I>::fun_image(const Function_v2v<F>& f, const Image<I>& ima)
185  {
186  init_(f, ima);
187  }
188 
189  template <typename F, typename I>
190  inline
191  fun_image<F,I>::fun_image(const Image<I>& ima)
192  {
193  F f;
194  init_(f, ima);
195  }
196 
197  template <typename F, typename I>
198  inline
199  void
200  fun_image<F,I>::init_(const Function_v2v<F>& f, const Image<I>& ima)
201  {
202  mln_precondition(exact(ima).is_valid());
203  this->data_ = new internal::data<fun_image<F,I> >(exact(f), exact(ima));
204  }
205 
206  template <typename F, typename I>
207  inline
208  mln_result(F)
209  fun_image<F,I>::operator()(const mln_psite(I)& p) const
210  {
211  mln_precondition(this->data_->ima_.has(p));
212  return this->data_->f_( this->data_->ima_(p) );
213  }
214 
215  template <typename F, typename I>
216  inline
217  mln_result(F)
218  fun_image<F,I>::operator()(const mln_psite(I)& p)
219  {
220  mln_precondition(this->data_->ima_.has(p));
221  return this->data_->f_( this->data_->ima_(p) );
222 // return mln::value::shell<F, I>( this->data_->ima_, p ); De-activated for 1.0
223  }
224 
225 
226  // template <typename F, typename I>
227  // fun_image<F, I> fun_image(Function<F> &f, Image<I> &i)
228  // {
229  // return fun_image<F, I> (f, i);
230  // }
231 
232 
233 # endif // ! MLN_INCLUDE_ONLY
234 
235 } // end of namespace mln
236 
237 
238 #endif // ! MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH