Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
interpolated.hh
1 // Copyright (C) 2007, 2008, 2009 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_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 
54  template <typename I, template <class> class F>
55  struct data< interpolated<I,F> >
56  {
57  data(I& ima);
58 
59  I& ima_;
60  };
61 
62  } // end of namespace mln::internal
63 
64 
65  namespace trait
66  {
67 
68  template <typename I, template <class> class F>
69  struct image_< interpolated<I,F> >
70  : public image_<I> // Same as I except...
71  {
72  // ...these changes.
73  typedef trait::image::value_io::read_only value_io;
74  };
75 
76  } // end of namespace mln::trait
77 
78 
82  //
83  template <typename I, template <class> class F>
84  struct interpolated :
85  public mln::internal::image_identity< I, mln_domain(I), interpolated<I,F> >
86  {
87 
88  typedef mln::internal::image_identity< I, mln_domain(I),
89  interpolated<I,F> > super_;
90 
92  typedef mln_psite(I) psite;
93 
95  typedef mln_value(I) value;
96 
98  typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I.
99 
101  typedef mln_rvalue(I) rvalue;
102 
104  typedef interpolated< tag::image_<I>, F > skeleton;
105 
106 
109  interpolated(I& ima);
110  interpolated();
111 
113  void init_(I& ima);
114 
115 
117  bool is_valid() const;
118 
120  using super_::has;
121 
123  template <typename C>
124  bool has(const mln::algebra::vec<I::psite::dim, C>& v) const;
125 
128  using super_::operator();
129 
130  mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v) const;
131  mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v);
132 
133  const F<I> fun_;
134  };
135 
136 
137 
138 # ifndef MLN_INCLUDE_ONLY
139 
140  namespace internal
141  {
142 
143  // internal::data< interpolated<I,S> >
144 
145  template <typename I, template <class> class F>
146  inline
148  : ima_(ima)
149  {
150  }
151 
152  } // end of namespace mln::internal
153 
154  template <typename I, template <class> class F>
155  inline
157  : fun_(ima)
158  {
159  mln_precondition(ima.is_valid());
160  init_(ima);
161  }
162 
163  template <typename I, template <class> class F>
164  inline
166  {
167  }
168 
169  template <typename I, template <class> class F>
170  inline
171  void
172  interpolated<I, F >::init_(I& ima)
173  {
174  mln_precondition(ima.is_valid());
175  this->data_ = new internal::data< interpolated<I,F> >(ima);
176  }
177 
178  template <typename I, template <class> class F>
179  inline
181  {
182  mln_invariant(this->data_->ima_.is_valid());
183  return true;
184  }
185 
186  template <typename I, template <class> class F>
187  template <typename C>
188  inline
189  bool interpolated<I,F>::has(const mln::algebra::vec<I::psite::dim, C>& v) const
190  {
191  mln_psite(I) p;
192  for (unsigned i = 0; i < I::psite::dim; ++i)
193  p[i] = static_cast<int>(round(v[i]));
194  return this->data_->ima_.has(p);
195  }
196 
197 
198  template <typename I, template <class> class F>
199  inline
200  mln_value(I)
201  interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) const
202  {
203  return fun_(v);
204  }
205 
206  template <typename I, template <class> class F>
207  inline
208  mln_value(I)
209  interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v)
210  {
211  return fun_(v);
212  }
213 
214 
215 # endif // ! MLN_INCLUDE_ONLY
216 
217 } // end of namespace mln
218 
219 
220 #endif // ! MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH