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