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_IMORPH_DECORATED_IMAGE_HH
00027 # define MLN_CORE_IMAGE_IMORPH_DECORATED_IMAGE_HH
00028
00029 # include <mln/core/internal/image_identity.hh>
00030
00031 # include <mln/value/proxy.hh>
00032
00036
00037
00038 namespace mln
00039 {
00040
00041
00042 template <typename I, typename D> struct decorated_image;
00043
00044
00045 namespace internal
00046 {
00047
00048 template <typename I, typename E>
00049 struct decorated_image_impl_
00050 {
00051 typedef mln::value::proxy<E> lvalue;
00053 void write_(const mln_psite(I)& p, const mln_value(I)& v);
00054 };
00055
00056 template <typename I, typename E>
00057 struct decorated_image_impl_< const I, E >
00058 {
00059 typedef mln::value::proxy<const E> lvalue;
00060 };
00061
00063 template <typename I, typename D>
00064 struct data< decorated_image<I,D> >
00065 {
00066 data(I& ima, const D& deco);
00067
00068 I ima_;
00069 D deco_;
00070 };
00071
00072 }
00073
00074
00075
00079
00080 template <typename I, typename D>
00081 struct decorated_image :
00082 public internal::decorated_image_impl_< I, decorated_image<I,D> >,
00083 public internal::image_identity< I, mln_domain(I), decorated_image<I,D> >
00084 {
00085 public:
00086 typedef decorated_image<I, D> self_;
00087 typedef internal::decorated_image_impl_< I, self_ > impl_;
00088
00090 typedef mln_psite(I) psite;
00091
00093 typedef mln_rvalue(I) rvalue;
00095 typedef typename impl_::lvalue lvalue;
00096
00098 decorated_image();
00099 decorated_image(I& ima, const D& deco);
00100
00102 void init_(I& ima, const D& deco);
00103
00105 ~decorated_image();
00106
00108 typedef decorated_image< tag::image_<I>, tag::data_<D> > skeleton;
00109
00111 rvalue operator()(const psite& p) const;
00112
00114 lvalue operator()(const psite& p);
00115
00117 rvalue read_(const mln_psite(I)& p) const;
00118
00120 operator decorated_image<const I, D>() const;
00121
00123 const D& decoration() const;
00124
00126 D& decoration();
00127 };
00128
00129
00130
00131 template <typename I, typename D>
00132 decorated_image<I,D> decorate(Image<I>& ima,
00133 const D& decoration);
00134
00135 template <typename I, typename D>
00136 decorated_image<const I, D> decorate(const Image<I>& ima,
00137 const D& decoration);
00138
00139
00140
00141 # ifndef MLN_INCLUDE_ONLY
00142
00143 namespace internal
00144 {
00145
00147 template <typename I, typename D>
00148 inline
00149 data< decorated_image<I,D> >::data(I& ima, const D& deco)
00150 : ima_(ima),
00151 deco_(deco)
00152 {
00153 }
00154
00155 }
00156
00157
00158
00159 template <typename I, typename D>
00160 inline
00161 decorated_image<I,D>::decorated_image()
00162 {
00163 }
00164
00165 template <typename I, typename D>
00166 inline
00167 decorated_image<I,D>::decorated_image(I& ima, const D& deco)
00168 {
00169 mln_precondition(exact(ima).is_valid());
00170 this->data_ = new internal::data< decorated_image<I,D> >(ima, deco);
00171 }
00172
00173 template <typename I, typename D>
00174 inline
00175 void
00176 decorated_image<I,D>::init_(I& ima, const D& deco)
00177 {
00178 mln_precondition(exact(ima).is_valid());
00179 this->data_ = new internal::data<decorated_image<I,D> >(ima, deco);
00180 }
00181
00182 template <typename I, typename D>
00183 inline
00184 decorated_image<I,D>::~decorated_image()
00185 {
00186 void (D::*mr)(const I&, const mln_psite(I)&) const = & D::reading;
00187 mr = 0;
00188 typedef mlc_unconst(I) I_;
00189 void (D::*mw)(I_&, const mln_psite(I_)&, const mln_value(I_)&) =
00190 & D::writing;
00191 mw = 0;
00192 }
00193
00194 template <typename I, typename D>
00195 inline
00196 typename decorated_image<I,D>::rvalue
00197 decorated_image<I,D>::operator()(const psite& p) const
00198 {
00199 mln_precondition(this->delegatee_() != 0);
00200 return read_(p);
00201 }
00202
00203 template <typename I, typename D>
00204 inline
00205 typename decorated_image<I,D>::lvalue
00206 decorated_image<I,D>::operator()(const psite& p)
00207 {
00208 mln_precondition(this->delegatee_() != 0);
00209
00210 return lvalue(*this, p);
00211 }
00212
00213 template <typename I, typename D>
00214 inline
00215 mln_rvalue(I)
00216 decorated_image<I,D>::read_(const mln_psite(I)& p) const
00217 {
00218 this->data_->deco_.reading(this->data_->ima_, p);
00219 return this->data_->ima_(p);
00220 }
00221
00222 namespace internal
00223 {
00224 template <typename I, typename E>
00225 inline
00226 void
00227 decorated_image_impl_<I,E>::write_(const mln_psite(I)& p,
00228 const mln_value(I)& v)
00229 {
00230 E& ima = internal::force_exact<E>(*this);
00231 ima.decoration().writing(*ima.delegatee_(), p, v);
00232 (*ima.delegatee_())(p) = v;
00233 }
00234
00235 }
00236
00237 template <typename I, typename D>
00238 inline
00239 decorated_image<I,D>::operator decorated_image<const I, D>() const
00240 {
00241 decorated_image<const I, D> tmp(this->data_->ima_, this->data_->deco_);
00242 return tmp;
00243 }
00244
00245
00246 template <typename I, typename D>
00247 inline
00248 const D&
00249 decorated_image<I,D>::decoration() const
00250 {
00251 return this->data_->deco_;
00252 }
00253
00254 template <typename I, typename D>
00255 inline
00256 D&
00257 decorated_image<I,D>::decoration()
00258 {
00259 return this->data_->deco_;
00260 }
00261
00262
00263
00264 template <typename I, typename D>
00265 inline
00266 decorated_image<I, D> decorate(Image<I>& ima,
00267 const D& decoration)
00268 {
00269 decorated_image<I, D> tmp(exact(ima), decoration);
00270 return tmp;
00271 }
00272
00273 template <typename I, typename D>
00274 inline
00275 decorated_image<const I, D> decorate(const Image<I>& ima,
00276 const D& decoration)
00277 {
00278 decorated_image<const I, D> tmp(exact(ima), decoration);
00279 return tmp;
00280 }
00281
00282 # endif // ! MLN_INCLUDE_ONLY
00283
00284 }
00285
00286
00287 #endif // ! MLN_CORE_IMAGE_IMORPH_DECORATED_IMAGE_HH