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

cast_image.hh

00001 // Copyright (C) 2007, 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_VMORPH_CAST_IMAGE_HH
00027 # define MLN_CORE_IMAGE_VMORPH_CAST_IMAGE_HH
00028 
00035 
00036 # include <mln/core/internal/image_value_morpher.hh>
00037 # include <mln/value/set.hh>
00038 # include <mln/value/cast.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   // Fwd decl.
00045   template <typename T, typename I> class cast_image_;
00046 
00047 
00048   namespace internal
00049   {
00051     template <typename T, typename I>
00052     struct data< cast_image_<T,I> >
00053     {
00054       data(const I& ima);
00055       const I& ima_;
00056     };
00057 
00058   } // end of namespace mln::internal
00059 
00060 
00061 
00062   namespace trait
00063   {
00064 
00065     template <typename T, typename I, typename value_io>
00066     struct cast_image_trait_selector :
00067       default_image_morpher< I, T, cast_image_<T,I> >
00068     {
00069       typedef trait::image::vw_io::none vw_io;
00070       typedef trait::image::vw_set::none vw_set;
00071     };
00072 
00073     template <typename T, typename I>
00074     struct cast_image_trait_selector<T, I, trait::image::vw_io::read> :
00075       default_image_morpher< I, T, cast_image_<T,I> >
00076     {
00077       typedef trait::image::vw_io::read vw_io;
00078     };
00079 
00080     template <typename T, typename I>
00081     struct cast_image_trait_selector<T, I, trait::image::vw_io::read_write> :
00082       default_image_morpher< I, T, cast_image_<T,I> >
00083     {
00084       typedef trait::image::vw_io::read vw_io;
00085     };
00086 
00087     template <typename T, typename I>
00088     struct image_< cast_image_<T,I> > :
00089       cast_image_trait_selector<T, I, mln_trait_image_vw_io(I)>
00090     {
00091     private:
00092       typedef mlc_equal(mln_trait_value_quant(T),
00093                         trait::value::quant::high) is_high_quant_;
00094     public:
00095       typedef mlc_if(is_high_quant_,
00096                      trait::image::quant::high,
00097                      trait::image::quant::low) quant;
00098 
00099       typedef trait::image::category::value_morpher category;
00100       typedef trait::image::value_io::read_only value_io;
00101       typedef trait::image::pw_io::read pw_io;
00102       typedef trait::image::value_access::indirect value_access;
00103 
00105       typedef trait::image::ext_domain::none ext_domain;
00106     };
00107 
00108   } // end of namespace mln::trait
00109 
00110 
00111 
00116   template <typename T, typename I>
00117   struct cast_image_ :
00118     public internal::image_value_morpher< I, T, cast_image_<T,I> >
00119   {
00121     typedef T value;
00122 
00124     typedef T rvalue;
00125 
00127     typedef T lvalue;
00128 
00130     typedef cast_image_< tag::value_<T>, tag::image_<I> > skeleton;
00131 
00133     cast_image_(const Image<I>& ima);
00134 
00136     void init_(const Image<I>& ima);
00137 
00139     T operator()(const mln_psite(I)& p) const;
00140 
00142     T operator()(const mln_psite(I)& p);
00143   };
00144 
00145 
00146   template <typename T, typename I>
00147   cast_image_<T,I>
00148   cast_image(const Image<I>& ima)
00149   {
00150     mln_precondition(exact(ima).is_valid());
00151     cast_image_<T,I> tmp(ima);
00152     return tmp;
00153   }
00154 
00155 
00156 # ifndef MLN_INCLUDE_ONLY
00157 
00158 
00159   // internal::data< cast_image_<T,I> >
00160 
00161   namespace internal
00162   {
00163 
00164     template <typename T, typename I>
00165     inline
00166     data< cast_image_<T,I> >::data(const I& ima)
00167       : ima_(ima)
00168     {
00169     }
00170 
00171   } // end of namespace mln::internal
00172 
00173   // cast_image_<T,I>
00174 
00175   template <typename T, typename I>
00176   inline
00177   cast_image_<T,I>::cast_image_(const Image<I>& ima)
00178   {
00179     mln_precondition(exact(ima).is_valid());
00180     this->data_ = new internal::data< cast_image_<T,I> >(exact(ima));
00181   }
00182 
00183   template <typename T, typename I>
00184   inline
00185   void
00186   cast_image_<T,I>::init_(const Image<I>& ima)
00187   {
00188     mln_precondition(exact(ima).is_valid());
00189     this->data_ = new internal::data<cast_image_<T,I> >(exact(ima));
00190   }
00191 
00192   template <typename T, typename I>
00193   inline
00194   T
00195   cast_image_<T,I>::operator()(const mln_psite(I)& p) const
00196   {
00197     mln_precondition(this->data_->ima_.has(p));
00198     return mln::value::cast<T>( this->data_->ima_(p) );
00199   }
00200 
00201   template <typename T, typename I>
00202   inline
00203   T
00204   cast_image_<T,I>::operator()(const mln_psite(I)& p)
00205   {
00206     return mln::value::cast<T>( this->data_->ima_(p) );
00207   }
00208 
00209 # endif // ! MLN_INCLUDE_ONLY
00210 
00211 } // end of namespace mln
00212 
00213 
00214 #endif // ! MLN_CORE_IMAGE_VMORPH_CAST_IMAGE_HH

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