26 #ifndef MLN_CORE_IMAGE_IMORPH_LAZY_IMAGE_HH
27 # define MLN_CORE_IMAGE_IMORPH_LAZY_IMAGE_HH
36 # include <mln/core/internal/image_identity.hh>
37 # include <mln/core/alias/box2d.hh>
44 template <
typename I,
typename F,
typename B>
struct lazy_image;
50 template <
typename I,
typename F,
typename B>
51 struct data< lazy_image<I,F,B> >
53 data(
const F& fun_,
const B& box);
55 mutable mln_ch_value(I,mln_result(F)) ima_;
56 mutable mln_ch_value(I,
bool) is_known;
68 template <
typename I,
typename F,
typename B>
69 struct image_< lazy_image<I,F,B> > : default_image_morpher< I, mln_value(I),
72 typedef trait::image::category::domain_morpher category;
73 typedef trait::image::value_io::read_only value_io;
91 template <
typename I,
typename F,
typename B>
93 public mln::internal::image_identity< mln_ch_value(I, mln_result(F)),
94 mln_domain(I), lazy_image<I, F,B> >
96 typedef mln::internal::image_identity< mln_ch_value(I, mln_result(F)),
110 using super_::is_valid;
119 void init_(const F& fun, const B& box);
122 const box<mln_psite(I)>& domain() const;
125 bool has(const mln_psite(I)&) const;
128 mln_result(F) operator()(const typename F::input& x) const;
131 mln_result(F) operator()(const typename F::input& x);
134 rvalue operator()(const mln_psite(I)& p) const;
137 lvalue operator()(const mln_psite(I)& p);
143 # ifndef MLN_INCLUDE_ONLY
150 template <
typename I,
typename F,
typename B>
153 : ima_(box), is_known(box), fun(fun), bb_(box)
159 template <
typename I,
typename F,
typename B>
163 this->data_ =
new internal::data< lazy_image<I,F,B> >(fun, box);
166 template <
typename I,
typename F,
typename B>
170 this->data_ =
new internal::data< lazy_image<I,F,B> >(fun, box);
173 template <
typename I,
typename F,
typename B>
177 return this->data_->ima_.has(p);
180 template <
typename I,
typename F,
typename B>
183 lazy_image<I,F,B>::operator()(const typename F::input& p)
const
185 mln_assertion(this->has(p));
186 if (this->data_->is_known(p))
187 return this->data_->ima_(p);
188 this->data_->ima_(p) = this->data_->fun(p);
189 this->data_->is_known(p) =
true;
190 return this->data_->ima_(p);
194 template <
typename I,
typename F,
typename B>
199 mln_assertion(this->has(p));
200 if (this->data_->is_known(p))
201 return this->data_->ima_(p);
202 this->data_->ima_(p) = this->data_->fun(p);
203 this->data_->is_known(p) =
true;
204 return this->data_->ima_(p);
207 template <
typename I,
typename F,
typename B>
212 return (*this).operator()(convert::to< typename F::input >(p));
215 template <
typename I,
typename F,
typename B>
220 return (*this).operator()(convert::to< typename F::input >(p));
223 template <
typename I,
typename F,
typename B>
228 return this->data_->bb_;
231 # endif // ! MLN_INCLUDE_ONLY
236 #endif // ! MLN_CORE_IMAGE_IMORPH_LAZY_IMAGE_HH