• 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 
00137 
00138 
00139   template <typename F, typename I>
00140   fun_image<F, I>
00141   operator << (const Function_v2v<F>& f, const Image<I>& ima);
00142 
00143 
00144 
00145 # ifndef MLN_INCLUDE_ONLY
00146 
00147 
00148   template <typename F, typename I>
00149   inline
00150   fun_image<F, I>
00151   operator << (const Function_v2v<F>& f, const Image<I>& ima)
00152   {
00153     fun_image<F, I> tmp(exact(f), exact(ima));
00154     return tmp;
00155   }
00156 
00157 
00158   // internal::data< fun_image<T,I> >
00159 
00160   namespace internal
00161   {
00162 
00163     template <typename F, typename I>
00164     inline
00165     data< fun_image<F,I> >::data(const F& f, const I& ima)
00166       : f_(f),
00167         ima_(ima)
00168     {
00169     }
00170 
00171   } // end of namespace mln::internal
00172 
00173   // fun_image<F,I>
00174 
00175   template <typename F, typename I>
00176   inline
00177   fun_image<F,I>::fun_image()
00178   {
00179     this->data_ = 0;
00180   }
00181 
00182   template <typename F, typename I>
00183   inline
00184   fun_image<F,I>::fun_image(const Function_v2v<F>& f, const Image<I>& ima)
00185   {
00186     init_(f, ima);
00187   }
00188 
00189   template <typename F, typename I>
00190   inline
00191   fun_image<F,I>::fun_image(const Image<I>& ima)
00192   {
00193     F f;
00194     init_(f, ima);
00195   }
00196 
00197   template <typename F, typename I>
00198   inline
00199   void
00200   fun_image<F,I>::init_(const Function_v2v<F>& f, const Image<I>& ima)
00201   {
00202     mln_precondition(exact(ima).is_valid());
00203     this->data_ = new internal::data<fun_image<F,I> >(exact(f), exact(ima));
00204   }
00205 
00206   template <typename F, typename I>
00207   inline
00208   mln_result(F)
00209   fun_image<F,I>::operator()(const mln_psite(I)& p) const
00210   {
00211     mln_precondition(this->data_->ima_.has(p));
00212     return this->data_->f_( this->data_->ima_(p) );
00213   }
00214 
00215   template <typename F, typename I>
00216   inline
00217   mln_result(F)
00218   fun_image<F,I>::operator()(const mln_psite(I)& p)
00219   {
00220     mln_precondition(this->data_->ima_.has(p));
00221     return this->data_->f_( this->data_->ima_(p) );
00222 //     return mln::value::shell<F, I>( this->data_->ima_, p );  De-activated for 1.0
00223   }
00224 
00225 
00226   //  template <typename F, typename I>
00227   //  fun_image<F, I> fun_image(Function<F> &f, Image<I> &i)
00228   //  {
00229   //    return fun_image<F, I> (f, i);
00230   //  }
00231 
00232 
00233 # endif // ! MLN_INCLUDE_ONLY
00234 
00235 } // end of namespace mln
00236 
00237 
00238 #endif // ! MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH

Generated on Tue Oct 4 2011 15:23:47 for Milena (Olena) by  doxygen 1.7.1