• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

interpolated.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH
00027 # define MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH
00028 
00035 
00036 
00037 # include <cmath>
00038 
00039 # include <mln/core/internal/image_identity.hh>
00040 # include <mln/algebra/vec.hh>
00041 # include <mln/value/set.hh>
00042 
00043 namespace mln
00044 {
00045 
00046   // Forward declaration.
00047   template <typename I, template <class> class F> struct interpolated;
00048 
00049   namespace internal
00050   {
00051 
00053     template <typename I, template <class> class F>
00054     struct data< interpolated<I,F> >
00055     {
00056       data(I& ima);
00057 
00058       I& ima_;
00059     };
00060 
00061   } // end of namespace mln::internal
00062 
00063 
00064   namespace trait
00065   {
00066 
00067     template <typename I, template <class> class F>
00068     struct image_< interpolated<I,F> >
00069       : public image_<I> // Same as I except...
00070     {
00071       // ...these changes.
00072       typedef trait::image::value_io::read_only value_io;
00073     };
00074 
00075   } // end of namespace mln::trait
00076 
00077 
00081   //
00082   template <typename I, template <class> class F>
00083   struct interpolated :
00084     public mln::internal::image_identity< I, mln_domain(I), interpolated<I,F> >
00085   {
00086     
00087     typedef mln::internal::image_identity< I, mln_domain(I),
00088                                            interpolated<I,F> > super_;
00089 
00091     typedef mln_psite(I) psite;
00092 
00094     typedef mln_value(I) value;
00095 
00097     typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I.
00098 
00100     typedef mln_rvalue(I) rvalue;
00101 
00103     typedef interpolated< tag::image_<I>, F > skeleton;
00104 
00105 
00108     interpolated(I& ima);
00109     interpolated();
00110 
00112     void init_(I& ima);
00113 
00114 
00116     bool is_valid() const;
00117 
00119     using super_::has;
00120 
00122     bool has(const mln::algebra::vec<I::psite::dim, float>& v) const;
00123 
00126     using super_::operator();
00127 
00128     mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v) const;
00129     mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v);
00130 
00131     const F<I> fun_;
00132   };
00133 
00134 
00135 
00136 # ifndef MLN_INCLUDE_ONLY
00137 
00138   namespace internal
00139   {
00140 
00141     // internal::data< interpolated<I,S> >
00142 
00143     template <typename I, template <class> class F>
00144     inline
00145     data< interpolated<I,F> >::data(I& ima)
00146       : ima_(ima)
00147     {
00148     }
00149 
00150   } // end of namespace mln::internal
00151 
00152   template <typename I, template <class> class F>
00153   inline
00154   interpolated<I,F>::interpolated(I& ima)
00155     : fun_(ima)
00156   {
00157     mln_precondition(ima.is_valid());
00158     init_(ima);
00159   }
00160 
00161   template <typename I, template <class> class F>
00162   inline
00163   interpolated<I,F>::interpolated()
00164   {
00165   }
00166 
00167   template <typename I, template <class> class F>
00168   inline
00169   void
00170   interpolated<I, F >::init_(I& ima)
00171   {
00172     mln_precondition(ima.is_valid());
00173     this->data_ = new internal::data< interpolated<I,F> >(ima);
00174   }
00175 
00176   template <typename I, template <class> class F>
00177   inline
00178   bool interpolated<I,F>::is_valid() const
00179   {
00180     mln_invariant(this->data_->ima_.is_valid());
00181     return true;
00182   }
00183 
00184   template <typename I, template <class> class F>
00185   inline
00186   bool interpolated<I,F>::has(const mln::algebra::vec<I::psite::dim, float>& v) const
00187   {
00188     mln_psite(I) p;
00189     for (unsigned i = 0; i < I::psite::dim; ++i)
00190       p[i] = static_cast<int>(round(v[i]));
00191     return this->data_->ima_.has(p);
00192   }
00193 
00194   template <typename I, template <class> class F>
00195   inline
00196   mln_value(I)
00197   interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) const
00198   {
00199     return fun_(v);
00200   }
00201 
00202   template <typename I, template <class> class F>
00203   inline
00204   mln_value(I)
00205   interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v)
00206   {
00207     return fun_(v);
00208   }
00209 
00210 # endif // ! MLN_INCLUDE_ONLY
00211 
00212 } // end of namespace mln
00213 
00214 
00215 #endif // ! MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH

Generated on Thu Sep 8 2011 18:32:02 for Milena (Olena) by  doxygen 1.7.1