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_FUN_IMAGE_HH
00028 # define MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH
00029
00034
00035 # include <mln/core/internal/image_value_morpher.hh>
00036 # include <mln/trait/images.hh>
00037 # include <mln/value/set.hh>
00038
00039 # include <mln/value/shell.hh>
00040
00041 # include <mln/metal/if.hh>
00042 # include <mln/metal/equal.hh>
00043
00044
00045 namespace mln
00046 {
00047
00048
00049 template <typename F, typename I> class fun_image;
00050
00051 namespace internal
00052 {
00054 template <typename F, typename I>
00055 struct data< fun_image<F,I> >
00056 {
00057 data(const F& f, const I& ima);
00058 F f_;
00059 const I ima_;
00060 };
00061
00062 }
00063
00064
00065
00066 namespace trait
00067 {
00068
00069 template <typename F, typename I>
00070 struct image_< fun_image<F,I> > : default_image_morpher< I, mln_result(F), fun_image<F,I> >
00071 {
00072
00073 typedef trait::image::category::primary category;
00074 typedef trait::image::value_io::read_only value_io;
00075 typedef trait::image::value_access::computed value_access;
00076 typedef trait::image::value_storage::disrupted value_storage;
00077 typedef
00078 mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::low),
00079
00080 trait::image::quant::low,
00081
00082 mlc_if(mlc_equal(typename value_<mln_result(F)>::quant, trait::value::quant::high),
00083
00084 trait::image::quant::high,
00085
00086 undef)
00087 )
00088 quant;
00089 };
00090
00091 }
00092
00093
00094
00095
00099
00100 template <typename F, typename I>
00101 struct fun_image :
00102 public internal::image_value_morpher< I, mln_result(F), fun_image<F,I> >
00103 {
00105 typedef mln_result(F) value;
00106
00108 typedef mln_result(F) rvalue;
00109
00111 typedef mln_result(F) lvalue;
00112
00113
00115 typedef fun_image< tag::value_<mln_result(F)>, tag::image_<I> > skeleton;
00116
00118 fun_image();
00119
00121 fun_image(const Function_v2v<F>& f, const Image<I>& ima);
00122
00124 fun_image(const Image<I>& ima);
00125
00127 void init_(const Function_v2v<F>& f, const Image<I>& ima);
00128
00130 mln_result(F) operator()(const mln_psite(I)& p) const;
00131
00133 mln_result(F) operator()(const mln_psite(I)& p);
00134
00135 };
00136
00137
00138
00139 template <typename F, typename I>
00140 fun_image<F, I>
00141 operator << (const Function_v2v<F>& f, const Image<I>& ima);
00142
00143
00144
00145 # ifndef MLN_INCLUDE_ONLY
00146
00147
00148 template <typename F, typename I>
00149 inline
00150 fun_image<F, I>
00151 operator << (const Function_v2v<F>& f, const Image<I>& ima)
00152 {
00153 fun_image<F, I> tmp(exact(f), exact(ima));
00154 return tmp;
00155 }
00156
00157
00158
00159
00160 namespace internal
00161 {
00162
00163 template <typename F, typename I>
00164 inline
00165 data< fun_image<F,I> >::data(const F& f, const I& ima)
00166 : f_(f),
00167 ima_(ima)
00168 {
00169 }
00170
00171 }
00172
00173
00174
00175 template <typename F, typename I>
00176 inline
00177 fun_image<F,I>::fun_image()
00178 {
00179 this->data_ = 0;
00180 }
00181
00182 template <typename F, typename I>
00183 inline
00184 fun_image<F,I>::fun_image(const Function_v2v<F>& f, const Image<I>& ima)
00185 {
00186 init_(f, ima);
00187 }
00188
00189 template <typename F, typename I>
00190 inline
00191 fun_image<F,I>::fun_image(const Image<I>& ima)
00192 {
00193 F f;
00194 init_(f, ima);
00195 }
00196
00197 template <typename F, typename I>
00198 inline
00199 void
00200 fun_image<F,I>::init_(const Function_v2v<F>& f, const Image<I>& ima)
00201 {
00202 mln_precondition(exact(ima).is_valid());
00203 this->data_ = new internal::data<fun_image<F,I> >(exact(f), exact(ima));
00204 }
00205
00206 template <typename F, typename I>
00207 inline
00208 mln_result(F)
00209 fun_image<F,I>::operator()(const mln_psite(I)& p) const
00210 {
00211 mln_precondition(this->data_->ima_.has(p));
00212 return this->data_->f_( this->data_->ima_(p) );
00213 }
00214
00215 template <typename F, typename I>
00216 inline
00217 mln_result(F)
00218 fun_image<F,I>::operator()(const mln_psite(I)& p)
00219 {
00220 mln_precondition(this->data_->ima_.has(p));
00221 return this->data_->f_( this->data_->ima_(p) );
00222
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 # endif // ! MLN_INCLUDE_ONLY
00234
00235 }
00236
00237
00238 #endif // ! MLN_CORE_IMAGE_VMORPH_FUN_IMAGE_HH