$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pw/internal/image_base.hh
1 // Copyright (C) 2009, 2010, 2012 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_PW_INTERNAL_IMAGE_BASE_HH
28 # define MLN_PW_INTERNAL_IMAGE_BASE_HH
29 
33 
34 # include <mln/core/internal/image_primary.hh>
35 # include <mln/core/routine/init.hh>
36 # include <mln/metal/unqualif.hh>
37 # include <mln/metal/not_equal.hh>
38 # include <mln/value/set.hh>
39 
40 
41 namespace mln
42 {
43 
44 
45  // Forward declaration.
46  namespace pw
47  {
48 
49  namespace internal
50  {
51 
52  template <typename F, typename S, typename E>
53  class image_base;
54 
55  } // end of namespace mln::pw::internal
56 
57  } // end of namespace mln::pw
58 
59  namespace trait
60  {
61 
62  // FIXME: the result type should *not* be qualified
63 
64  template <typename F, typename S, typename E>
65  struct pw_image_
66  : default_image_<mln_result(F),E>
67  {
68  private:
69  typedef typename F::mutable_result mutable_result;
70  typedef mlc_not_equal(mutable_result, void) is_mutable;
71 
72  public:
73  // misc
74  typedef trait::image::category::primary category;
75  typedef trait::image::speed::fast speed;
76  typedef trait::image::size::regular size;
77 
78  // value
79  typedef trait::image::vw_io::none vw_io;
80  typedef trait::image::vw_set::none vw_set;
81  typedef trait::image::value_access::computed value_access;
82  typedef trait::image::value_storage::disrupted value_storage;
83  typedef trait::image::value_browsing::site_wise_only value_browsing;
84  typedef trait::image::value_alignment::irrelevant value_alignment;
85  typedef mlc_if(is_mutable,
86  trait::image::value_io::read_write,
87  trait::image::value_io::read_only) value_io;
88 
89  // site / domain
90  typedef mlc_if(is_mutable,
91  trait::image::pw_io::read_write,
92  trait::image::pw_io::read) pw_io;
93  typedef /* FIXME: depends on S */ undef localization;
94  typedef /* FIXME: depends on S */ undef dimension;
95 
96  // extended domain
97  typedef trait::image::ext_domain::none ext_domain;
98  typedef trait::image::ext_value::irrelevant ext_value;
99  typedef trait::image::ext_io::irrelevant ext_io;
100  };
101 
102  } // end of namespace mln::trait
103 
104 
105  namespace pw
106  {
107 
108  namespace internal
109  {
110 
118  template <typename F, typename S, typename E>
120  : public mln::internal::image_primary<mln_result(F), S, E >
121  {
122  typedef typename F::mutable_result mutable_result;
123  typedef mlc_not_equal(mutable_result, void) is_mutable;
124 
125  public:
127  typedef F function_t;
128 
130  typedef mln_result(F) value;
131 
133  typedef mln_result(F) rvalue;
134 
136  typedef mlc_if(is_mutable, mutable_result, mln_result(F)) lvalue;
137 
139  void init_(const Function_v2v<F>& f, const Site_Set<S>& ps);
140 
142  const S& domain() const;
143 
145  F function() const;
146 
148  rvalue operator()(const mln_psite(S)& p) const;
149 
152  lvalue operator()(const mln_psite(S)& p);
153 
154  protected:
155  image_base();
156  image_base(const Function_v2v<F>& f, const Site_Set<S>& ps);
157  };
158 
159  } // end of namespace mln::pw::internal
160 
161  } // end of namespace mln::pw
162 
163 
164  // init_
165 
166  template <typename F, typename S, typename E>
167  void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model);
168 
169  template <typename F1, typename F2, typename S, typename E>
170  void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model);
171 
172 
173 # ifndef MLN_INCLUDE_ONLY
174 
175  // init_
176 
177  template <typename F, typename S, typename E>
178  void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model)
179  {
180  f = model.function();
181  }
182 
183  template <typename F1, typename F2, typename S, typename E>
184  void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model)
185  {
186  init_(tag::function, f, model.function());
187  }
188 
189 
190  namespace pw
191  {
192 
193  namespace internal
194  {
195 
196  template <typename F, typename S, typename E>
197  inline
198  image_base<F,S,E>::image_base()
199  {
200  }
201 
202  template <typename F, typename S, typename E>
203  inline
204  image_base<F,S,E>::image_base(const Function_v2v<F>& f, const Site_Set<S>& ps)
205  {
206  this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
207  }
208 
209  template <typename F, typename S, typename E>
210  inline
211  void
212  image_base<F,S,E>::init_(const Function_v2v<F>& f, const Site_Set<S>& ps)
213  {
214  this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
215  }
216 
217  template <typename F, typename S, typename E>
218  inline
219  const S&
220  image_base<F,S,E>::domain() const
221  {
222  return this->data_->domain_;
223  }
224 
225  template <typename F, typename S, typename E>
226  inline
227  F
228  image_base<F,S,E>:: function() const
229  {
230  return this->data_->f_;
231  }
232 
233 
234  template <typename F, typename S, typename E>
235  inline
236  typename image_base<F,S,E>::rvalue
237  image_base<F,S,E>::operator()(const mln_psite(S)& p) const
238  {
239  mln_precondition(this->data_->domain_.has(p));
240  return this->data_->f_(p);
241  }
242 
243  template <typename F, typename S, typename E>
244  inline
245  typename image_base<F,S,E>::lvalue
246  image_base<F,S,E>::operator()(const mln_psite(S)& p)
247  {
248  mln_precondition(this->data_->domain_.has(p));
249  return this->data_->f_(p);
250  }
251 
252  } // end of namespace mln::pw::internal
253 
254  } // end of namespace mln::pw
255 
256 # endif // ! MLN_INCLUDE_ONLY
257 
258 } // end of namespace mln
259 
260 
261 #endif // ! MLN_PW_INTERNAL_IMAGE_BASE_HH