$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
interpolated.hh
1 // Copyright (C) 2007, 2008, 2009, 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_IMORPH_INTERPOLATED_HH
28 # define MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH
29 
36 
37 
38 # include <cmath>
39 
40 # include <mln/core/internal/image_identity.hh>
41 # include <mln/algebra/vec.hh>
42 # include <mln/value/set.hh>
43 
44 namespace mln
45 {
46 
47  // Forward declaration.
48  template <typename I, template <class> class F> struct interpolated;
49 
50  namespace internal
51  {
52 
56  template <typename I, template <class> class F>
57  struct data< interpolated<I,F> >
58  {
59  data(I& ima);
60 
61  I& ima_;
62  };
63 
64  } // end of namespace mln::internal
65 
66 
67  namespace trait
68  {
69 
70  template <typename I, template <class> class F>
71  struct image_< interpolated<I,F> >
72  : public image_<I> // Same as I except...
73  {
74  // ...these changes.
75  typedef trait::image::value_io::read_only value_io;
76  };
77 
78  } // end of namespace mln::trait
79 
80 
84  //
85  template <typename I, template <class> class F>
86  struct interpolated :
87  public mln::internal::image_identity< I, mln_domain(I), interpolated<I,F> >
88  {
89 
90  typedef mln::internal::image_identity< I, mln_domain(I),
91  interpolated<I,F> > super_;
92 
94  typedef mln_psite(I) psite;
95 
97  typedef mln_value(I) value;
98 
100  typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I.
101 
103  typedef mln_rvalue(I) rvalue;
104 
106  typedef interpolated< tag::image_<I>, F > skeleton;
107 
108 
111  interpolated(I& ima);
112  interpolated();
113 
116  void init_(I& ima);
118 
119 
121  bool is_valid() const;
122 
124  using super_::has;
125 
127  template <typename C>
128  bool has(const mln::algebra::vec<I::psite::dim, C>& v) const;
129 
132  using super_::operator();
133 
134  mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v) const;
135  mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v);
136 
137  const F<I> fun_;
138  };
139 
140 
153  template <template <class> class F, typename I>
154  interpolated<I, F> interpolate(Image<I>& ima);
155 
156 
157 
158 # ifndef MLN_INCLUDE_ONLY
159 
160  namespace internal
161  {
162 
163  // internal::data< interpolated<I,S> >
164 
165  template <typename I, template <class> class F>
166  inline
168  : ima_(ima)
169  {
170  }
171 
172  } // end of namespace mln::internal
173 
174  template <typename I, template <class> class F>
175  inline
176  interpolated<I,F>::interpolated(I& ima)
177  : fun_(ima)
178  {
179  mln_precondition(ima.is_valid());
180  init_(ima);
181  }
182 
183  template <typename I, template <class> class F>
184  inline
185  interpolated<I,F>::interpolated()
186  {
187  }
188 
189  template <typename I, template <class> class F>
190  inline
191  void
193  {
194  mln_precondition(ima.is_valid());
195  this->data_ = new internal::data< interpolated<I,F> >(ima);
196  }
197 
198  template <typename I, template <class> class F>
199  inline
200  bool interpolated<I,F>::is_valid() const
201  {
202  mln_invariant(this->data_->ima_.is_valid());
203  return true;
204  }
205 
206  template <typename I, template <class> class F>
207  template <typename C>
208  inline
209  bool interpolated<I,F>::has(const mln::algebra::vec<I::psite::dim, C>& v) const
210  {
211  mln_psite(I) p;
212  for (unsigned i = 0; i < I::psite::dim; ++i)
213  p[i] = static_cast<int>(round(v[i]));
214  return this->data_->ima_.has(p);
215  }
216 
217 
218  template <typename I, template <class> class F>
219  inline
220  mln_value(I)
221  interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) const
222  {
223  return fun_(v);
224  }
225 
226  template <typename I, template <class> class F>
227  inline
228  mln_value(I)
229  interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v)
230  {
231  return fun_(v);
232  }
233 
234 
235  // interpolate.
236 
237  template <template <class> class F, typename I>
238  interpolated<I, F> interpolate(Image<I>& ima)
239  {
240  interpolated<I, F> tmp(exact(ima));
241  return tmp;
242  }
243 
244 # endif // ! MLN_INCLUDE_ONLY
245 
246 } // end of namespace mln
247 
248 
249 #endif // ! MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH