$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
unproject_image.hh
1 // Copyright (C) 2009, 2012, 2013 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_DMORPH_UNPROJECT_IMAGE_HH
28 # define MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH
29 
34 
35 # include <mln/core/internal/image_domain_morpher.hh>
36 # include <mln/core/grids.hh>
37 # include <mln/core/site_set/box.hh>
38 
39 
40 namespace mln
41 {
42 
43 
44  // Forward declaration.
45  template <typename I, typename D, typename F> struct unproject_image;
46 
47 
48  namespace internal
49  {
50 
54  template <typename I, typename D, typename F>
55  struct data< unproject_image<I,D,F> >
56  {
57  data(I& ima, const D& dom, const F& f);
58 
59  I ima_;
60  D dom_;
61  F f_;
62  };
63 
64  } // end of namespace mln::internal
65 
66 
67  namespace trait
68  {
69 
70  template <typename I, typename D, typename F>
71  struct image_< unproject_image<I,D,F> > : default_image_morpher< I,
72  mln_value(I),
73  unproject_image<I,D,F> >
74  {
75  typedef trait::image::category::domain_morpher category;
76 
77  // FIXME:
78 // typedef trait::image::dimension::two_d dimension;
79 
80  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
81  typedef trait::image::ext_value::irrelevant ext_value;
82  typedef trait::image::ext_io::irrelevant ext_io;
83 
84  typedef trait::image::vw_io::none vw_io;
85  typedef trait::image::vw_set::none vw_set;
86  typedef trait::image::value_alignment::not_aligned value_alignment;
87  typedef trait::image::value_storage::disrupted value_storage;
88  };
89 
90  } // end of namespace mln::trait
91 
92 
93 
97  //
98  template <typename I, typename D, typename F>
100  D,
101  unproject_image<I,D,F> >
102  {
103  // FIXME:
104  typedef void skeleton;
105 // /// Skeleton.
106 // typedef unproject_image< tag::image_<I> > skeleton;
107 
108 
110  unproject_image();
111 
113  unproject_image(I& ima, const D& dom, const F& f);
114 
116  void init_(I& ima, const D& dom, const F& f);
118 
119 
121  const D& domain() const;
122 
124  mln_rvalue(I) operator()(const mln_psite(D)& p) const;
125 
127  mln_morpher_lvalue(I) operator()(const mln_psite(D)& p);
128 
129 
130 // /// Const promotion via conversion.
131 // operator unproject_image<const I, D, F>() const;
132  };
133 
134 
135 
136  template <typename I, typename D, typename F>
137  unproject_image<I, D, F>
138  unproject(Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f);
139 
140  template <typename I, typename D, typename F>
141  unproject_image<const I, D, F>
142  unproject(const Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f);
143 
144 
145 
146 
147 // namespace trait
148 // {
149 
150 // template <typename I, typename D, typename F,
151 // typename V>
152 // struct ch_value< unproject_image<I,D,F>, V >
153 // {
154 // // FIXME: Somthing like:
155 // typedef pw::image< pw::cst_<mln_value(I)>, D> I_;
156 // typedef mln_ch_value(I_,V) ret;
157 // };
158 
159 // } // end of namespace mln::trait
160 
161 
162 
163 # ifndef MLN_INCLUDE_ONLY
164 
165 
166  // internal::data< unproject_image<I,D,F> >
167 
168  namespace internal
169  {
170 
171  template <typename I, typename D, typename F>
172  inline
173  data< unproject_image<I,D,F> >::data(I& ima, const D& dom, const F& f)
174  : ima_(ima),
175  dom_(dom),
176  f_(f)
177  {
178  }
179 
180  }
181 
182 
183  // unproject_image<I,D,F>
184 
185  template <typename I, typename D, typename F>
186  inline
187  unproject_image<I,D,F>::unproject_image()
188  {
189  }
190 
191  template <typename I, typename D, typename F>
192  inline
193  unproject_image<I,D,F>::unproject_image(I& ima, const D& dom, const F& f)
194  {
195  init_(ima, dom, f);
196  }
197 
198  template <typename I, typename D, typename F>
199  inline
200  void
201  unproject_image<I,D,F>::init_(I& ima, const D& dom, const F& f)
202  {
203  mln_precondition(! this->is_valid());
204  this->data_ = new internal::data< unproject_image<I,D,F> >(ima, dom, f);
205  }
206 
207  template <typename I, typename D, typename F>
208  inline
209  const D&
210  unproject_image<I,D,F>::domain() const
211  {
212  mln_precondition(this->is_valid());
213  return this->data_->dom_;
214  }
215 
216  template <typename I, typename D, typename F>
217  inline
218  mln_rvalue(I)
219  unproject_image<I,D,F>::operator()(const mln_psite(D)& p) const
220  {
221  mln_precondition(this->has(p));
222  mln_result(F) p_ = this->data_->f_(p);
223  mln_precondition(this->data_->ima_.has(p_));
224  return this->data_->ima_(p_);
225  }
226 
227  template <typename I, typename D, typename F>
228  inline
229  mln_morpher_lvalue(I)
230  unproject_image<I,D,F>::operator()(const mln_psite(D)& p)
231  {
232  mln_precondition(this->has(p));
233  mln_result(F) p_ = this->data_->f_(p);
234  mln_precondition(this->data_->ima_.has(p_));
235  return this->data_->ima_(p_);
236  }
237 
238 
239  // Routines.
240 
241  template <typename I, typename D, typename F>
242  inline
243  unproject_image<I, D, F>
244  unproject(Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f)
245  {
246  mlc_converts_to(mln_psite(D), mln_argument(F))::check();
247  mlc_converts_to(mln_result(F), mln_psite(I))::check();
248 
249  I& ima = exact(ima_);
250  mln_precondition(ima.is_valid());
251 
252  unproject_image<I,D,F> tmp(ima, exact(dom), exact(f));
253  return tmp;
254  }
255 
256  template <typename I, typename D, typename F>
257  inline
258  unproject_image<const I, D, F>
259  unproject(const Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f)
260  {
261  mlc_converts_to(mln_psite(D), mln_argument(F))::check();
262  mlc_converts_to(mln_result(F), mln_psite(I))::check();
263 
264  const I& ima = exact(ima_);
265  mln_precondition(ima.is_valid());
266 
267  unproject_image<const I,D,F> tmp(ima, exact(dom), exact(f));
268  return tmp;
269  }
270 
271 
272 # endif // ! MLN_INCLUDE_ONLY
273 
274 } // end of namespace mln
275 
276 
277 
278 #endif // ! MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH