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_THRUBIN_IMAGE_HH
00028 # define MLN_CORE_IMAGE_VMORPH_THRUBIN_IMAGE_HH
00029
00034
00035 # include <mln/core/internal/image_value_morpher.hh>
00036 # include <mln/core/concept/meta_function.hh>
00037 # include <mln/metal/bexpr.hh>
00038 # include <mln/trait/functions.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044
00045 template <typename I1, typename I2, typename F> struct thrubin_image;
00046
00047 namespace internal
00048 {
00050 template <typename I1, typename I2, typename F>
00051 struct data< thrubin_image<I1, I2, F> >
00052 {
00053 data(I1& ima1, I2& ima2, const F& f);
00054
00055 I1 ima_;
00056 I2 ima2_;
00057 F f_;
00058 };
00059
00060 }
00061
00062
00063 namespace trait
00064 {
00065
00066 template <typename I1, typename I2, typename F>
00067 struct image_< thrubin_image<I1, I2, F> > : image_< I1 >
00068 {
00069
00070 typedef trait::image::category::value_morpher category;
00071 typedef mln_internal_trait_image_speed_from(I1) speed;
00072 typedef trait::image::value_access::computed value_access;
00073 typedef trait::image::vw_io::read vw_io;
00074 };
00075
00076 }
00077
00081 template <typename I1, typename I2, typename F>
00082 class thrubin_image : public internal::image_value_morpher< I1, typename F::result, thrubin_image<I1,I2,F> >
00083 {
00084 public:
00085
00086 thrubin_image();
00087 thrubin_image(I1& ima1, I2& ima2);
00088 thrubin_image(I1& ima1, I2& ima2, const F& f);
00089
00091 typedef thrubin_image<tag::image_<I1>, tag::image_<I2>, F> skeleton;
00092
00094 typedef mln_psite(I1) psite;
00095
00097 typedef mln_result(F) value;
00098
00100 typedef value rvalue;
00101 typedef value lvalue;
00102
00103 rvalue operator()(const mln_psite(I1)& p) const;
00104 rvalue operator()(const mln_psite(I1)& p);
00105
00106 void init_(I1& ima1, I2& ima2, const F& f);
00107
00109 operator thrubin_image<const I1, const I2, F>() const;
00110 };
00111
00112 template <typename I1, typename I2, typename F>
00113 thrubin_image<I1, I2, F>
00114 thru(const mln::Function<F>& f,
00115 Image<I1>& ima1, Image<I2>& ima2);
00116
00117 template <typename I1, typename I2, typename F>
00118 const thrubin_image<const I1, const I2, F>
00119 thru(const mln::Function<F>& f,
00120 const Image<I1>& ima1, const Image<I2>& ima2);
00121
00122 template <typename I1, typename I2, typename M>
00123 thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
00124 thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I1>& ima2);
00125
00126 template <typename I1, typename I2, typename M>
00127 const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
00128 thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2);
00129
00130 # ifndef MLN_INCLUDE_ONLY
00131
00132
00133
00134 namespace internal
00135 {
00136
00137 template <typename I1, typename I2, typename F>
00138 inline
00139 data< thrubin_image<I1, I2, F> >::data(I1& ima1, I2& ima2, const F& f)
00140 : ima_(ima1), ima2_(ima2),
00141 f_(f)
00142 {
00143 }
00144
00145 }
00146
00147
00148
00149 template <typename I1, typename I2, typename F>
00150 inline
00151 thrubin_image<I1, I2, F>::thrubin_image()
00152 {
00153 }
00154
00155 template <typename I1, typename I2, typename F>
00156 inline
00157 thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2, const F& f)
00158 {
00159 mln_precondition(ima1.is_valid());
00160 mln_precondition(ima2.is_valid());
00161 init_(ima1, ima2, f);
00162 }
00163
00164 template <typename I1, typename I2, typename F>
00165 inline
00166 thrubin_image<I1, I2, F>::thrubin_image(I1& ima1, I2& ima2)
00167 {
00168 mln_precondition(ima1.is_valid());
00169 mln_precondition(ima2.is_valid());
00170 init_(ima1, ima2, F());
00171 }
00172
00173 template <typename I1, typename I2, typename F>
00174 inline
00175 void
00176 thrubin_image<I1, I2, F>::init_(I1& ima1, I2& ima2, const F& f)
00177 {
00178 mln_precondition(! this->is_valid());
00179 mln_precondition(ima1.is_valid());
00180 mln_precondition(ima2.is_valid());
00181 this->data_ = new internal::data< thrubin_image<I1, I2, F> >(ima1, ima2, f);
00182 }
00183
00184 template <typename I1, typename I2, typename F>
00185 inline
00186 thrubin_image<I1, I2, F>::operator thrubin_image<const I1, const I2, F>() const
00187 {
00188 thrubin_image<const I1, const I2, F> tmp(this->data_->ima_, this->data_->ima2_, this->data_->f_);
00189 return tmp;
00190 }
00191
00192 template <typename I1, typename I2, typename F>
00193 inline
00194 typename thrubin_image<I1, I2, F>::rvalue
00195 thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p) const
00196 {
00197 mln_precondition(this->is_valid());
00198 return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p));
00199 }
00200
00201 template <typename I1, typename I2, typename F>
00202 inline
00203 typename thrubin_image<I1, I2, F>::rvalue
00204 thrubin_image<I1, I2, F>::operator()(const mln_psite(I1)& p)
00205 {
00206 mln_precondition(this->is_valid());
00207 return this->data_->f_(this->data_->ima_(p), this->data_->ima2_(p));
00208 }
00209
00210
00211 template <typename I1, typename I2, typename F>
00212 thrubin_image<I1, I2, F>
00213 thru(const mln::Function<F>& f,
00214 Image<I1>& ima1, Image<I2>& ima2)
00215 {
00216 thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), exact(f).state());
00217 return tmp;
00218 }
00219
00220 template <typename I1, typename I2, typename F>
00221 const thrubin_image<const I1, const I2, F>
00222 thru(const mln::Function<F>& f,
00223 const Image<I1>& ima1, const Image<I2>& ima2)
00224 {
00225 thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), exact(f).state());
00226 return tmp;
00227 }
00228
00229 template <typename I1, typename I2, typename M>
00230 thrubin_image<I1, I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
00231 thru(const mln::Meta_Function<M>& f, Image<I1>& ima1, Image<I2>& ima2)
00232 {
00233 typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F;
00234 thrubin_image<I1, I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state()));
00235
00236 return tmp;
00237 }
00238
00239 template <typename I1, typename I2, typename M>
00240 const thrubin_image<const I1, const I2, mln_fun_withbin(M, mln_value(I1), mln_value(I2))>
00241 thru(const mln::Meta_Function<M>& f, const Image<I1>& ima1, const Image<I2>& ima2)
00242 {
00243 typedef mln_fun_withbin(M, mln_value(I1), mln_value(I2)) F;
00244 thrubin_image<const I1, const I2, F> tmp(exact(ima1), exact(ima2), F(exact(f).state()));
00245
00246 return tmp;
00247 }
00248
00249 # endif // ! MLN_INCLUDE_ONLY
00250
00251 }
00252
00253
00254 #endif // ! MLN_CORE_IMAGE_VMORPH_THRUBIN_IMAGE_HH