$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
thru_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_THRU_IMAGE_HH
28 # define MLN_CORE_IMAGE_VMORPH_THRU_IMAGE_HH
29 
35 
36 # include <mln/core/internal/image_value_morpher.hh>
37 # include <mln/core/concept/meta_function.hh>
38 # include <mln/metal/bexpr.hh>
39 # include <mln/trait/functions.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename I, typename F> class thru_image;
47 
48  namespace internal
49  {
50  template <typename I, typename F> class thru_image_write;
51  template <typename I, typename F> class thru_image_read;
52 
56  template <typename I, typename F>
58  {
61  typedef mlc_if(mlc_and(mln_trait_fun_is_assignable(F),
62  mlc_and(mlc_not(mlc_is_const(I)),
63  mlc_equal(mln_trait_image_pw_io(I),
64  trait::image::pw_io::read_write))),
65  write, read) ret;
66  };
67 
71  template <typename I, typename F>
72  struct data< thru_image<I, F> >
73  {
74  data(I& ima, const F& f);
75 
76  I ima_;
77  F f_;
78  };
79 
80  } // end of namespace mln::internal
81 
82 
83  namespace trait
84  {
85 
86  template <typename I, typename F>
87  struct image_< thru_image<I, F> > : image_< typename mln::internal::thru_find_impl<I, F>::ret > // Same as I except...
88  {
89  // ...these changes.
90  typedef trait::image::category::value_morpher category;
91  typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
92  typedef trait::image::value_access::computed value_access;
93  };
94 
95  template <typename I, typename F>
96  struct image_< mln::internal::thru_image_write<I, F> > : image_< I > // Same as I except...
97  {
98  typedef trait::image::vw_io::read_write vw_io;
99  };
100 
101  template <typename I, typename F>
102  struct image_< mln::internal::thru_image_read<I, F> > : image_< I > // Same as I except...
103  {
104  typedef trait::image::vw_io::read vw_io;
105  };
106 
107  } // end of namespace mln::trait
108 
109 
110 
111  // FIXME: Doc!
112 
113  namespace internal
114  {
115 
116  template <typename I, typename F>
117  class thru_image_read : public internal::image_value_morpher< I, typename F::result, thru_image<I,F> >
118  {
119  public:
120 
123 
125  typedef mln_psite(I) psite;
126 
128  typedef mln_result(F) value;
129 
131  typedef value rvalue;
132  typedef value lvalue; // Workaround for write operator()
133 
134  rvalue operator()(const mln_psite(I)& p) const;
135  rvalue operator()(const mln_psite(I)& p);
136 
137  };
138 
139  // Inheritance from read ?!
140  template <typename I, typename F>
141  class thru_image_write : public thru_image_read<I,F>
142  {
143  public:
144 
146 // typedef typename F::template lresult<typename F::argument>::ret lvalue;
147  typedef typename F::lresult lvalue;
148 
150  lvalue operator()(const mln_psite(I)& p);
151 
152  };
153  }
154 
158  //
159  template <typename I, typename F>
161  {
162  public:
163 
164  thru_image();
165  thru_image(I& ima);
166  thru_image(I& ima, const F& f);
167 
168 
170  void init_(I& ima, const F& f);
172 
174  operator thru_image<const I, F>() const;
175  };
176 
177  template <typename I, typename F>
179  Image<I>& ima);
180 
181  template <typename I, typename F>
183  const Image<I>& ima);
184 
185  template <typename I, typename M>
187  thru(const mln::Meta_Function<M>& f, Image<I>& ima);
188 
189  template <typename I, typename M>
191  thru(const mln::Meta_Function<M>& f, const Image<I>& ima);
192 
193 # ifndef MLN_INCLUDE_ONLY
194 
195  // internal::data< thru_image<I,S> >
196 
197  namespace internal
198  {
199 
200  template <typename I, typename F>
201  inline
202  data< thru_image<I, F> >::data(I& ima, const F& f)
203  : ima_(ima),
204  f_(f)
205  {
206  }
207 
208  } // end of namespace mln::internal
209 
210  // thru_image<I>
211 
212  template <typename I, typename F>
213  inline
214  thru_image<I, F>::thru_image()
215  {
216  }
217 
218  template <typename I, typename F>
219  inline
220  thru_image<I, F>::thru_image(I& ima, const F& f)
221  {
222  mln_precondition(ima.is_valid());
223  init_(ima, f);
224  }
225 
226  template <typename I, typename F>
227  inline
228  thru_image<I, F>::thru_image(I& ima)
229  {
230  mln_precondition(ima.is_valid());
231  init_(ima, F());
232  }
233 
234  template <typename I, typename F>
235  inline
236  void
237  thru_image<I, F>::init_(I& ima, const F& f)
238  {
239  mln_precondition(! this->is_valid());
240  mln_precondition(ima.is_valid());
241  this->data_ = new internal::data< thru_image<I, F> >(ima, f);
242  }
243 
244  template <typename I, typename F>
245  inline
246  thru_image<I, F>::operator thru_image<const I, F>() const
247  {
248  thru_image<const I, F> tmp(this->data_->ima_, this->data_->f_);
249  return tmp;
250  }
251 
252  namespace internal
253  {
254 
255  template <typename I, typename F>
256  inline
257  typename thru_image_read<I, F>::rvalue
258  thru_image_read<I, F>::operator()(const mln_psite(I)& p) const
259  {
260  mln_precondition(this->is_valid());
261  return this->data_->f_(this->data_->ima_(p));
262  }
263 
264  template <typename I, typename F>
265  inline
266  typename thru_image_read<I, F>::rvalue
267  thru_image_read<I, F>::operator()(const mln_psite(I)& p)
268  {
269  mln_precondition(this->is_valid());
270  return this->data_->f_(this->data_->ima_(p));
271  }
272 
273  template <typename I, typename F>
274  inline
275  typename thru_image_write<I, F>::lvalue
276  thru_image_write<I, F>::operator()(const mln_psite(I)& p)
277  {
278  mln_precondition(this->is_valid());
279  return this->data_->f_(this->data_->ima_(p));
280  }
281 
282  }
283 
284  // thru
285  template <typename I, typename F>
286  thru_image<I, F> thru(const mln::Function<F>& f,
287  Image<I>& ima)
288  {
289  thru_image<I, F> tmp(exact(ima), exact(f));
290  return tmp;
291  }
292 
293  template <typename I, typename F>
294  thru_image<const I, F> thru(const mln::Function<F>& f,
295  const Image<I>& ima)
296  {
297  thru_image<const I, F> tmp(exact(ima), exact(f));
298  return tmp;
299  }
300 
301  template <typename I, typename M>
302  thru_image<I, mln_fun_with(M, mln_value(I))>
303  thru(const mln::Meta_Function<M>& f, Image<I>& ima)
304  {
305  typedef mln_fun_with(M, mln_value(I)) F;
306  thru_image<I, F> tmp(exact(ima), F(exact(f).state()));
307 
308  return tmp;
309  }
310 
311  template <typename I, typename M>
312  thru_image<const I, mln_fun_with(M, mln_value(I))>
313  thru(const mln::Meta_Function<M>& f, const Image<I>& ima)
314  {
315  typedef mln_fun_with(M, mln_value(I)) F;
316  thru_image<const I, F> tmp(exact(ima), F(exact(f).state()));
317 
318  return tmp;
319  }
320 
321 # endif // ! MLN_INCLUDE_ONLY
322 
323 } // end of namespace mln
324 
325 
326 #endif // ! MLN_CORE_IMAGE_VMORPH_THRU_IMAGE_HH