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