Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
thrubin_image.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 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_VMORPH_THRUBIN_IMAGE_HH
28 # define MLN_CORE_IMAGE_VMORPH_THRUBIN_IMAGE_HH
29 
34 
35 # include <mln/core/internal/image_value_morpher.hh>
36 # include <mln/core/concept/meta_function.hh>
37 # include <mln/metal/bexpr.hh>
38 # include <mln/trait/functions.hh>
39 
40 
41 namespace mln
42 {
43 
44  // Forward declaration.
45  template <typename I1, typename I2, typename F> class thrubin_image;
46 
47  namespace internal
48  {
50  template <typename I1, typename I2, typename F>
51  struct data< thrubin_image<I1, I2, F> >
52  {
53  data(I1& ima1, I2& ima2, const F& f);
54 
55  I1 ima_;
56  I2 ima2_;
57  F f_;
58  };
59 
60  } // end of namespace mln::internal
61 
62 
63  namespace trait
64  {
65 
66  template <typename I1, typename I2, typename F>
67  struct image_< thrubin_image<I1, I2, F> > : image_< I1 > // Same as I except...
68  {
69  // ...these changes.
70  typedef trait::image::category::value_morpher category;
71  typedef mln_internal_trait_image_speed_from(I1) speed; // Un-fastest.
72  typedef trait::image::value_access::computed value_access;
73  typedef trait::image::vw_io::read vw_io;
74  };
75 
76  } // end of namespace mln::trait
77 
81  template <typename I1, typename I2, typename F>
82  class thrubin_image : public internal::image_value_morpher< I1, typename F::result, thrubin_image<I1,I2,F> >
83  {
84  public:
85 
86  thrubin_image();
87  thrubin_image(I1& ima1, I2& ima2);
88  thrubin_image(I1& ima1, I2& ima2, const F& f);
89 
91  typedef thrubin_image<tag::image_<I1>, tag::image_<I2>, F> skeleton;
92 
94  typedef mln_psite(I1) psite;
95 
97  typedef mln_result(F) value;
98 
100  typedef value rvalue;
101  typedef value lvalue; // Workaround for write operator()
102 
103  rvalue operator()(const mln_psite(I1)& p) const;
104  rvalue operator()(const mln_psite(I1)& p);
105 
106  void init_(I1& ima1, I2& ima2, const F& f);
107 
109  operator thrubin_image<const I1, const I2, F>() const;
110  };
111 
112  template <typename I1, typename I2, typename F>
113  thrubin_image<I1, I2, F>
114  thru(const mln::Function<F>& f,
115  Image<I1>& ima1, Image<I2>& ima2);
116 
117  template <typename I1, typename I2, typename F>
118  const thrubin_image<const I1, const I2, F>
119  thru(const mln::Function<F>& f,
120  const Image<I1>& ima1, const Image<I2>& ima2);
121 
122  template <typename I1, typename I2, typename M>
123  thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
124  thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I1>& ima2);
125 
126  template <typename I1, typename I2, typename M>
127  const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
128  thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2);
129 
130 # ifndef MLN_INCLUDE_ONLY
131 
132  // internal::data< thrubin_image<I,S> >
133 
134  namespace internal
135  {
136 
137  template <typename I1, typename I2, typename F>
138  inline
139  data< thrubin_image<I1, I2, F> >::data(I1& ima1, I2& ima2, const F& f)
140  : ima_(ima1), ima2_(ima2),
141  f_(f)
142  {
143  }
144 
145  } // end of namespace mln::internal
146 
147  // thrubin_image<I>
148 
149  template <typename I1, typename I2, typename F>
150  inline
152  {
153  }
154 
155  template <typename I1, typename I2, typename F>
156  inline
157  thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2, const F& f)
158  {
159  mln_precondition(ima1.is_valid());
160  mln_precondition(ima2.is_valid());
161  init_(ima1, ima2, f);
162  }
163 
164  template <typename I1, typename I2, typename F>
165  inline
166  thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2)
167  {
168  mln_precondition(ima1.is_valid());
169  mln_precondition(ima2.is_valid());
170  init_(ima1, ima2, F());
171  }
172 
173  template <typename I1, typename I2, typename F>
174  inline
175  void
176  thrubin_image<I1, I2, F>::init_(I1& ima1, I2& ima2, const F& f)
177  {
178  mln_precondition(! this->is_valid());
179  mln_precondition(ima1.is_valid());
180  mln_precondition(ima2.is_valid());
181  this->data_ = new internal::data< thrubin_image<I1, I2, F> >(ima1, ima2, f);
182  }
183 
184  template <typename I1, typename I2, typename F>
185  inline
187  {
188  thrubin_image<const I1, const I2, F> tmp(this->data_->ima_, this->data_->ima2_, this->data_->f_);
189  return tmp;
190  }
191 
192  template <typename I1, typename I2, typename F>
193  inline
195  thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p) const
196  {
197  mln_precondition(this->is_valid());
198  return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p));
199  }
200 
201  template <typename I1, typename I2, typename F>
202  inline
203  typename thrubin_image<I1, I2, F>::rvalue
204  thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p)
205  {
206  mln_precondition(this->is_valid());
207  return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p));
208  }
209 
210  // thrubin
211  template <typename I1, typename I2, typename F>
212  thrubin_image<I1, I2, F>
213  thru(const mln::Function<F>& f,
214  Image<I1>& ima1, Image<I2>& ima2)
215  {
216  thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), exact(f).state());
217  return tmp;
218  }
219 
220  template <typename I1, typename I2, typename F>
221  const thrubin_image<const I1, const I2, F>
222  thru(const mln::Function<F>& f,
223  const Image<I1>& ima1, const Image<I2>& ima2)
224  {
225  thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), exact(f).state());
226  return tmp;
227  }
228 
229  template <typename I1, typename I2, typename M>
230  thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
231  thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I2>& ima2)
232  {
233  typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F;
234  thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state()));
235 
236  return tmp;
237  }
238 
239  template <typename I1, typename I2, typename M>
240  const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
241  thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2)
242  {
243  typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F;
244  thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state()));
245 
246  return tmp;
247  }
248 
249 # endif // ! MLN_INCLUDE_ONLY
250 
251 } // end of namespace mln
252 
253 
254 #endif // ! MLN_CORE_IMAGE_VMORPH_THRUBIN_IMAGE_HH