Milena (Olena)  User documentation 2.0a Id
fun_image.hh
00001 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH
00028 # define MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH
00029 
00034 
00035 # include <mln/core/internal/image_value_morpher.hh>
00036 # include <mln/trait/images.hh>
00037 # include <mln/value/set.hh>
00038 
00039 # include <mln/metal/if.hh>
00040 # include <mln/metal/equal.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   // Forward declaration.
00047   template <typename F, typename I> struct fun_image;
00048 
00049   namespace internal
00050   {
00052     template <typename F, typename I>
00053     struct data< fun_image<F,I> >
00054     {
00055       data(const F& f, const I& ima);
00056       F f_;
00057       const I ima_;
00058     };
00059 
00060   } // end of namespace mln::internal
00061 
00062 
00063 
00064   namespace trait
00065   {
00066 
00067     template <typename F, typename I>
00068     struct image_< fun_image<F,I> > : default_image_morpher< I, mln_result(F), fun_image<F,I> >
00069     {
00070       //      typedef trait::image::category::value_morpher   category;
00071       typedef trait::image::category::primary   category; // does not work either
00072       typedef trait::image::value_io::read_only      value_io;
00073       typedef trait::image::value_access::computed    value_access;
00074       typedef trait::image::value_storage::disrupted  value_storage;
00075       typedef
00076       mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::low),
00077         // Then
00078         trait::image::quant::low,
00079         // Else
00080              mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::high),
00081                     // Then
00082                     trait::image::quant::high,
00083                     // Else
00084                     undef)
00085             )
00086         quant;
00087     };
00088 
00089   } // end of namespace mln::trait
00090 
00091 
00092 
00093 
00097   //
00098   template <typename F, typename I>
00099   struct fun_image :
00100     public internal::image_value_morpher< I, mln_result(F), fun_image<F,I> >
00101   {
00103     typedef mln_result(F) value;
00104 
00106     typedef mln_result(F) rvalue;
00107 
00109     typedef mln_result(F) lvalue;
00110     // typedef mln::value::shell<F,I> lvalue;  De-activated for 1.0
00111 
00113     typedef fun_image< tag::value_<mln_result(F)>, tag::image_<I> > skeleton;
00114 
00116     fun_image();
00117 
00119     fun_image(const Function_v2v<F>& f, const Image<I>& ima);
00120 
00122     fun_image(const Image<I>& ima);
00123 
00125     void init_(const Function_v2v<F>& f, const Image<I>& ima);
00126 
00128     mln_result(F) operator()(const mln_psite(I)& p) const;
00129 
00131     mln_result(F) operator()(const mln_psite(I)& p);
00132     // lvalue operator()(const mln_psite(I)& p);  De-activated for 1.0
00133   };
00134 
00135 
00136 
00137   template <typename F, typename I>
00138   fun_image<F, I>
00139   operator << (const Function_v2v<F>& f, const Image<I>& ima);
00140 
00141 
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145 
00146   template <typename F, typename I>
00147   inline
00148   fun_image<F, I>
00149   operator << (const Function_v2v<F>& f, const Image<I>& ima)
00150   {
00151     fun_image<F, I> tmp(exact(f), exact(ima));
00152     return tmp;
00153   }
00154 
00155 
00156   // internal::data< fun_image<T,I> >
00157 
00158   namespace internal
00159   {
00160 
00161     template <typename F, typename I>
00162     inline
00163     data< fun_image<F,I> >::data(const F& f, const I& ima)
00164       : f_(f),
00165         ima_(ima)
00166     {
00167     }
00168 
00169   } // end of namespace mln::internal
00170 
00171   // fun_image<F,I>
00172 
00173   template <typename F, typename I>
00174   inline
00175   fun_image<F,I>::fun_image()
00176   {
00177     this->data_ = 0;
00178   }
00179 
00180   template <typename F, typename I>
00181   inline
00182   fun_image<F,I>::fun_image(const Function_v2v<F>& f, const Image<I>& ima)
00183   {
00184     init_(f, ima);
00185   }
00186 
00187   template <typename F, typename I>
00188   inline
00189   fun_image<F,I>::fun_image(const Image<I>& ima)
00190   {
00191     F f;
00192     init_(f, ima);
00193   }
00194 
00195   template <typename F, typename I>
00196   inline
00197   void
00198   fun_image<F,I>::init_(const Function_v2v<F>& f, const Image<I>& ima)
00199   {
00200     mln_precondition(exact(ima).is_valid());
00201     this->data_ = new internal::data<fun_image<F,I> >(exact(f), exact(ima));
00202   }
00203 
00204   template <typename F, typename I>
00205   inline
00206   mln_result(F)
00207   fun_image<F,I>::operator()(const mln_psite(I)& p) const
00208   {
00209     mln_precondition(this->data_->ima_.has(p));
00210     return this->data_->f_( this->data_->ima_(p) );
00211   }
00212 
00213   template <typename F, typename I>
00214   inline
00215   mln_result(F)
00216   fun_image<F,I>::operator()(const mln_psite(I)& p)
00217   {
00218     mln_precondition(this->data_->ima_.has(p));
00219     return this->data_->f_( this->data_->ima_(p) );
00220 //     return mln::value::shell<F, I>( this->data_->ima_, p );  De-activated for 1.0
00221   }
00222 
00223 
00224   //  template <typename F, typename I>
00225   //  fun_image<F, I> fun_image(Function<F> &f, Image<I> &i)
00226   //  {
00227   //    return fun_image<F, I> (f, i);
00228   //  }
00229 
00230 
00231 # endif // ! MLN_INCLUDE_ONLY
00232 
00233 } // end of namespace mln
00234 
00235 
00236 #endif // ! MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator