27 #ifndef MLN_CORE_IMAGE_DMORPH_EXTENSION_FUN_HH
28 # define MLN_CORE_IMAGE_DMORPH_EXTENSION_FUN_HH
38 # include <mln/core/internal/image_identity.hh>
46 template <
typename I,
typename F>
class extension_fun;
55 template <
typename I,
typename F>
56 struct data< extension_fun<I, F> >
58 data(I& ima,
const F& fun);
70 template <
typename I,
typename F>
71 struct image_< extension_fun<I, F> > : image_< I >
74 typedef trait::image::category::identity_morpher
category;
75 typedef mln_internal_trait_image_speed_from(I)
speed;
84 template <typename I, typename F, typename V>
87 typedef mlc_converts_to(mln_result(F), V)
keep_ext;
88 typedef mln_ch_value(I, V)
Iv;
90 typedef mlc_if(keep_ext, Iv_ext, Iv)
ret;
101 template <typename I, typename F>
103 : public internal::image_identity< I, mln_domain(I),
extension_fun<I, F> >,
104 private mlc_converts_to(mln_result(F), mln_value(I))::check_t
127 void init_(I& ima, const F& fun);
134 template <typename P>
135 bool has(const P&
p) const;
139 mln_value(I) operator()(const mln_psite(I)&
p) const;
142 mln_morpher_lvalue(I) operator()(const mln_psite(I)&
p);
146 const F& extension() const;
154 template <typename I, typename F, typename J>
157 template <typename F, typename I>
163 # ifndef MLN_INCLUDE_ONLY
170 template <
typename I,
typename F>
183 template <
typename I,
typename F>
189 template <
typename I,
typename F>
191 extension_fun<I, F>::extension_fun(I& ima,
const F& fun)
196 template <
typename I,
typename F>
201 this->data_ =
new internal::data< extension_fun<I, F> >(ima, fun);
204 template <
typename I,
typename F>
205 template <
typename P>
208 extension_fun<I, F>::has(
const P&)
const
213 template <
typename I,
typename F>
216 extension_fun<I, F>::operator()(const mln_psite(I)& p)
const
218 mln_precondition(this->is_valid());
221 if (this->data_->ima_.domain().has(p))
222 return this->data_->ima_(p);
224 return this->data_->fun_(p);
227 template <
typename I,
typename F>
229 mln_morpher_lvalue(I)
230 extension_fun<I, F>::operator()(const mln_psite(I)& p)
232 static mln_value(I) cpy;
233 mln_precondition(this->is_valid());
235 if (this->data_->ima_.domain().has(p))
236 return this->data_->ima_(p);
242 cpy = this->data_->fun_(p);
247 template <
typename I,
typename F>
250 extension_fun<I, F>::extension()
const
252 mln_precondition(this->is_valid());
253 return this->data_->fun_;
259 template <
typename I,
typename F,
typename J>
260 void init_(tag::image_t, extension_fun<I,F>& target,
const J& model)
266 target.init_(ima, fun);
269 template <
typename F,
typename I>
270 void init_(tag::extension_t, F& target,
const extension_fun<I,F>& model)
272 target = model.extension();
275 # endif // ! MLN_INCLUDE_ONLY
280 #endif // ! MLN_CORE_IMAGE_DMORPH_EXTENSION_FUN_HH