00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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 }
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 }
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
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 }
00172
00173
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 }
00212
00213
00214 #endif // ! MLN_CORE_IMAGE_VMORPH_CAST_IMAGE_HH