Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
unproject_image.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH
27 # define MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH
28 
33 
34 # include <mln/core/internal/image_domain_morpher.hh>
35 # include <mln/core/grids.hh>
36 # include <mln/core/site_set/box.hh>
37 
38 
39 namespace mln
40 {
41 
42 
43  // Forward declaration.
44  template <typename I, typename D, typename F> struct unproject_image;
45 
46 
47  namespace internal
48  {
49 
51  template <typename I, typename D, typename F>
52  struct data< unproject_image<I,D,F> >
53  {
54  data(I& ima, const D& dom, const F& f);
55 
56  I ima_;
57  D dom_;
58  F f_;
59  };
60 
61  } // end of namespace mln::internal
62 
63 
64  namespace trait
65  {
66 
67  template <typename I, typename D, typename F>
68  struct image_< unproject_image<I,D,F> > : default_image_morpher< I,
69  mln_value(I),
70  unproject_image<I,D,F> >
71  {
72  typedef trait::image::category::domain_morpher category;
73 
74  // FIXME:
75 // typedef trait::image::dimension::two_d dimension;
76 
77  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
78  typedef trait::image::ext_value::irrelevant ext_value;
79  typedef trait::image::ext_io::irrelevant ext_io;
80 
81  typedef trait::image::vw_io::none vw_io;
82  typedef trait::image::vw_set::none vw_set;
83  typedef trait::image::value_alignment::not_aligned value_alignment;
84  typedef trait::image::value_storage::disrupted value_storage;
85  };
86 
87  } // end of namespace mln::trait
88 
89 
90 
94  //
95  template <typename I, typename D, typename F>
96  struct unproject_image : public internal::image_domain_morpher< I,
97  D,
98  unproject_image<I,D,F> >
99  {
100  // FIXME:
101  typedef void skeleton;
102 // /// Skeleton.
103 // typedef unproject_image< tag::image_<I> > skeleton;
104 
105 
107  unproject_image();
108 
110  unproject_image(I& ima, const D& dom, const F& f);
111 
112  void init_(I& ima, const D& dom, const F& f);
113 
114 
116  const D& domain() const;
117 
119  mln_rvalue(I) operator()(const mln_psite(D)& p) const;
120 
122  mln_morpher_lvalue(I) operator()(const mln_psite(D)& p);
123 
124 
125 // /// Const promotion via conversion.
126 // operator unproject_image<const I, D, F>() const;
127  };
128 
129 
130 
131  template <typename I, typename D, typename F>
133  unproject(Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f);
134 
135  template <typename I, typename D, typename F>
137  unproject(const Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f);
138 
139 
140 
141 
142 // namespace trait
143 // {
144 
145 // template <typename I, typename D, typename F,
146 // typename V>
147 // struct ch_value< unproject_image<I,D,F>, V >
148 // {
149 // // FIXME: Somthing like:
150 // typedef pw::image< pw::cst_<mln_value(I)>, D> I_;
151 // typedef mln_ch_value(I_,V) ret;
152 // };
153 
154 // } // end of namespace mln::trait
155 
156 
157 
158 # ifndef MLN_INCLUDE_ONLY
159 
160 
161  // internal::data< unproject_image<I,D,F> >
162 
163  namespace internal
164  {
165 
166  template <typename I, typename D, typename F>
167  inline
168  data< unproject_image<I,D,F> >::data(I& ima, const D& dom, const F& f)
169  : ima_(ima),
170  dom_(dom),
171  f_(f)
172  {
173  }
174 
175  }
176 
177 
178  // unproject_image<I,D,F>
179 
180  template <typename I, typename D, typename F>
181  inline
183  {
184  }
185 
186  template <typename I, typename D, typename F>
187  inline
188  unproject_image<I,D,F>::unproject_image(I& ima, const D& dom, const F& f)
189  {
190  init_(ima, dom, f);
191  }
192 
193  template <typename I, typename D, typename F>
194  inline
195  void
196  unproject_image<I,D,F>::init_(I& ima, const D& dom, const F& f)
197  {
198  mln_precondition(! this->is_valid());
199  this->data_ = new internal::data< unproject_image<I,D,F> >(ima, dom, f);
200  }
201 
202  template <typename I, typename D, typename F>
203  inline
204  const D&
206  {
207  mln_precondition(this->is_valid());
208  return this->data_->dom_;
209  }
210 
211  template <typename I, typename D, typename F>
212  inline
213  mln_rvalue(I)
214  unproject_image<I,D,F>::operator()(const mln_psite(D)& p) const
215  {
216  mln_precondition(this->has(p));
217  mln_result(F) p_ = this->data_->f_(p);
218  mln_precondition(this->data_->ima_.has(p_));
219  return this->data_->ima_(p_);
220  }
221 
222  template <typename I, typename D, typename F>
223  inline
224  mln_morpher_lvalue(I)
225  unproject_image<I,D,F>::operator()(const mln_psite(D)& p)
226  {
227  mln_precondition(this->has(p));
228  mln_result(F) p_ = this->data_->f_(p);
229  mln_precondition(this->data_->ima_.has(p_));
230  return this->data_->ima_(p_);
231  }
232 
233 
234  // Routines.
235 
236  template <typename I, typename D, typename F>
237  inline
239  unproject(Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f)
240  {
241  mlc_converts_to(mln_psite(D), mln_argument(F))::check();
242  mlc_converts_to(mln_result(F), mln_psite(I))::check();
243 
244  I& ima = exact(ima_);
245  mln_precondition(ima.is_valid());
246 
247  unproject_image<I,D,F> tmp(ima, exact(dom), exact(f));
248  return tmp;
249  }
250 
251  template <typename I, typename D, typename F>
252  inline
253  unproject_image<const I, D, F>
254  unproject(const Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f)
255  {
256  mlc_converts_to(mln_psite(D), mln_argument(F))::check();
257  mlc_converts_to(mln_result(F), mln_psite(I))::check();
258 
259  const I& ima = exact(ima_);
260  mln_precondition(ima.is_valid());
261 
262  unproject_image<const I,D,F> tmp(ima, exact(dom), exact(f));
263  return tmp;
264  }
265 
266 
267 # endif // ! MLN_INCLUDE_ONLY
268 
269 } // end of namespace mln
270 
271 
272 
273 #endif // ! MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH