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