00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH
00028 # define MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH
00029 
00036 
00037 
00038 # include <cmath>
00039 
00040 # include <mln/core/internal/image_identity.hh>
00041 # include <mln/algebra/vec.hh>
00042 # include <mln/value/set.hh>
00043 
00044 namespace mln
00045 {
00046 
00047   
00048   template <typename I, template <class> class F> struct interpolated;
00049 
00050   namespace internal
00051   {
00052 
00054     template <typename I, template <class> class F>
00055     struct data< interpolated<I,F> >
00056     {
00057       data(I& ima);
00058 
00059       I& ima_;
00060     };
00061 
00062   } 
00063 
00064 
00065   namespace trait
00066   {
00067 
00068     template <typename I, template <class> class F>
00069     struct image_< interpolated<I,F> >
00070       : public image_<I> 
00071     {
00072       
00073       typedef trait::image::value_io::read_only value_io;
00074     };
00075 
00076   } 
00077 
00078 
00082   
00083   template <typename I, template <class> class F>
00084   struct interpolated :
00085     public mln::internal::image_identity< I, mln_domain(I), interpolated<I,F> >
00086   {
00087 
00088     typedef mln::internal::image_identity< I, mln_domain(I),
00089                                            interpolated<I,F> > super_;
00090 
00092     typedef mln_psite(I) psite;
00093 
00095     typedef mln_value(I) value;
00096 
00098     typedef mln_lvalue(I) lvalue; 
00099 
00101     typedef mln_rvalue(I) rvalue;
00102 
00104     typedef interpolated< tag::image_<I>, F > skeleton;
00105 
00106 
00109     interpolated(I& ima);
00110     interpolated();
00111 
00113     void init_(I& ima);
00114 
00115 
00117     bool is_valid() const;
00118 
00120     using super_::has;
00121 
00123     template <typename C>
00124     bool has(const mln::algebra::vec<I::psite::dim, C>& v) const;
00125 
00128     using super_::operator();
00129 
00130     mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v) const;
00131     mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v);
00132 
00133     const F<I> fun_;
00134   };
00135 
00136 
00137 
00138 # ifndef MLN_INCLUDE_ONLY
00139 
00140   namespace internal
00141   {
00142 
00143     
00144 
00145     template <typename I, template <class> class F>
00146     inline
00147     data< interpolated<I,F> >::data(I& ima)
00148       : ima_(ima)
00149     {
00150     }
00151 
00152   } 
00153 
00154   template <typename I, template <class> class F>
00155   inline
00156   interpolated<I,F>::interpolated(I& ima)
00157     : fun_(ima)
00158   {
00159     mln_precondition(ima.is_valid());
00160     init_(ima);
00161   }
00162 
00163   template <typename I, template <class> class F>
00164   inline
00165   interpolated<I,F>::interpolated()
00166   {
00167   }
00168 
00169   template <typename I, template <class> class F>
00170   inline
00171   void
00172   interpolated<I, F >::init_(I& ima)
00173   {
00174     mln_precondition(ima.is_valid());
00175     this->data_ = new internal::data< interpolated<I,F> >(ima);
00176   }
00177 
00178   template <typename I, template <class> class F>
00179   inline
00180   bool interpolated<I,F>::is_valid() const
00181   {
00182     mln_invariant(this->data_->ima_.is_valid());
00183     return true;
00184   }
00185 
00186   template <typename I, template <class> class F>
00187   template <typename C>
00188   inline
00189   bool interpolated<I,F>::has(const mln::algebra::vec<I::psite::dim, C>& v) const
00190   {
00191     mln_psite(I) p;
00192     for (unsigned i = 0; i < I::psite::dim; ++i)
00193       p[i] = static_cast<int>(round(v[i]));
00194     return this->data_->ima_.has(p);
00195   }
00196 
00197 
00198   template <typename I, template <class> class F>
00199   inline
00200   mln_value(I)
00201   interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) const
00202   {
00203     return fun_(v);
00204   }
00205 
00206   template <typename I, template <class> class F>
00207   inline
00208   mln_value(I)
00209   interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v)
00210   {
00211     return fun_(v);
00212   }
00213 
00214 
00215 # endif // ! MLN_INCLUDE_ONLY
00216 
00217 } 
00218 
00219 
00220 #endif // ! MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH