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

fun_image.hh

00001 // Copyright (C) 2007, 2008, 2009 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 //<<lrde
00039 # include <mln/value/shell.hh>
00040 //>>
00041 # include <mln/metal/if.hh>
00042 # include <mln/metal/equal.hh>
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   // Forward declaration.
00049   template <typename F, typename I> class fun_image;
00050 
00051   namespace internal
00052   {
00054     template <typename F, typename I>
00055     struct data< fun_image<F,I> >
00056     {
00057       data(const F& f, const I& ima);
00058       F f_;
00059       const I ima_;
00060     };
00061 
00062   } // end of namespace mln::internal
00063 
00064 
00065 
00066   namespace trait
00067   {
00068 
00069     template <typename F, typename I>
00070     struct image_< fun_image<F,I> > : default_image_morpher< I, mln_result(F), fun_image<F,I> >
00071     {
00072       //      typedef trait::image::category::value_morpher   category;
00073       typedef trait::image::category::primary   category; // does not work either
00074       typedef trait::image::value_io::read_only      value_io;
00075       typedef trait::image::value_access::computed    value_access;
00076       typedef trait::image::value_storage::disrupted  value_storage;
00077       typedef
00078       mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::low),
00079         // Then
00080         trait::image::quant::low,
00081         // Else
00082              mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::high),
00083                     // Then
00084                     trait::image::quant::high,
00085                     // Else
00086                     undef)
00087             )
00088         quant;
00089     };
00090 
00091   } // end of namespace mln::trait
00092 
00093 
00094 
00095 
00099   //
00100   template <typename F, typename I>
00101   struct fun_image :
00102     public internal::image_value_morpher< I, mln_result(F), fun_image<F,I> >
00103   {
00105     typedef mln_result(F) value;
00106 
00108     typedef mln_result(F) rvalue;
00109 
00111     typedef mln_result(F) lvalue;
00112     // typedef mln::value::shell<F,I> lvalue;  De-activated for 1.0
00113 
00115     typedef fun_image< tag::value_<mln_result(F)>, tag::image_<I> > skeleton;
00116 
00118     fun_image();
00119 
00121     fun_image(const Function_v2v<F>& f, const Image<I>& ima);
00122 
00124     fun_image(const Image<I>& ima);
00125 
00127     void init_(const Function_v2v<F>& f, const Image<I>& ima);
00128 
00130     mln_result(F) operator()(const mln_psite(I)& p) const;
00131 
00133     mln_result(F) operator()(const mln_psite(I)& p);
00134     // lvalue operator()(const mln_psite(I)& p);  De-activated for 1.0
00135 
00136     F f;
00137   };
00138 
00139 
00140 
00141   template <typename F, typename I>
00142   fun_image<F, I>
00143   operator << (const Function_v2v<F>& f, const Image<I>& ima);
00144 
00145 
00146 
00147 # ifndef MLN_INCLUDE_ONLY
00148 
00149 
00150   template <typename F, typename I>
00151   inline
00152   fun_image<F, I>
00153   operator << (const Function_v2v<F>& f, const Image<I>& ima)
00154   {
00155     fun_image<F, I> tmp(exact(f), exact(ima));
00156     return tmp;
00157   }
00158 
00159 
00160   // internal::data< fun_image<T,I> >
00161 
00162   namespace internal
00163   {
00164 
00165     template <typename F, typename I>
00166     inline
00167     data< fun_image<F,I> >::data(const F& f, const I& ima)
00168       : f_(f),
00169         ima_(ima)
00170     {
00171     }
00172 
00173   } // end of namespace mln::internal
00174 
00175   // fun_image<F,I>
00176 
00177   template <typename F, typename I>
00178   inline
00179   fun_image<F,I>::fun_image()
00180   {
00181     this->data_ = 0;
00182   }
00183 
00184   template <typename F, typename I>
00185   inline
00186   fun_image<F,I>::fun_image(const Function_v2v<F>& f, const Image<I>& ima)
00187   {
00188     init_(f, ima);
00189   }
00190 
00191   template <typename F, typename I>
00192   inline
00193   fun_image<F,I>::fun_image(const Image<I>& ima)
00194   {
00195     F f;
00196     init_(f, ima);
00197   }
00198 
00199   template <typename F, typename I>
00200   inline
00201   void
00202   fun_image<F,I>::init_(const Function_v2v<F>& f, const Image<I>& ima)
00203   {
00204     mln_precondition(exact(ima).is_valid());
00205     this->data_ = new internal::data<fun_image<F,I> >(exact(f), exact(ima));
00206   }
00207 
00208   template <typename F, typename I>
00209   inline
00210   mln_result(F)
00211   fun_image<F,I>::operator()(const mln_psite(I)& p) const
00212   {
00213     mln_precondition(this->data_->ima_.has(p));
00214     return f( this->data_->ima_(p) );
00215   }
00216 
00217   template <typename F, typename I>
00218   inline
00219   mln_result(F)
00220   fun_image<F,I>::operator()(const mln_psite(I)& p)
00221   {
00222     mln_precondition(this->data_->ima_.has(p));
00223     return f( this->data_->ima_(p) );
00224 //     return mln::value::shell<F, I>( this->data_->ima_, p );  De-activated for 1.0
00225   }
00226 
00227 
00228   //  template <typename F, typename I>
00229   //  fun_image<F, I> fun_image(Function<F> &f, Image<I> &i)
00230   //  {
00231   //    return fun_image<F, I> (f, i);
00232   //  }
00233 
00234 
00235 # endif // ! MLN_INCLUDE_ONLY
00236 
00237 } // end of namespace mln
00238 
00239 
00240 #endif // ! MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH

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