27 #ifndef MLN_CORE_IMAGE_DMORPH_EXTENSION_IMA_HH
28 # define MLN_CORE_IMAGE_DMORPH_EXTENSION_IMA_HH
35 # include <mln/core/internal/image_identity.hh>
43 template <
typename I,
typename J>
class extension_ima;
52 template <
typename I,
typename J>
53 struct data< extension_ima<I, J> >
55 data(I& ima,
const J& ext);
67 template <
typename I,
typename J>
68 struct image_< extension_ima<I, J> > : image_< I >
71 typedef trait::image::category::identity_morpher
category;
72 typedef mln_internal_trait_image_speed_from(I)
speed;
81 template <typename I, typename J, typename V>
84 typedef mlc_converts_to(mln_value(J), V)
keep_ext;
85 typedef mln_ch_value(I, V)
Iv;
87 typedef mlc_if(keep_ext, Iv_ext, Iv)
ret;
98 template <typename I, typename J>
101 : public internal::image_identity< I, mln_domain(I),
extension_ima<I, J> >,
102 private mlc_converts_to(mln_value(J), mln_value(I))::check_t
124 void init_(I& ima, const J& ext);
130 template <typename P>
131 bool has(const P&
p) const;
135 mln_value(I) operator()(const mln_psite(I)&
p) const;
138 mln_morpher_lvalue(I) operator()(const mln_psite(I)&
p);
142 const J& extension() const;
150 template <typename I, typename J, typename M>
153 template <typename J, typename I>
159 # ifndef MLN_INCLUDE_ONLY
166 template <
typename I,
typename J>
170 ext_(const_cast<J&>(ext))
178 template <
typename I,
typename J>
184 template <
typename I,
typename J>
186 extension_ima<I, J>::extension_ima(I& ima,
const J& ext)
191 template <
typename I,
typename J>
196 this->data_ =
new internal::data< extension_ima<I, J> >(ima, ext);
199 template <
typename I,
typename J>
200 template <
typename P>
203 extension_ima<I, J>::has(
const P& p)
const
205 mln_precondition(this->is_valid());
206 mln_precondition(this->data_->ext_.is_valid());
208 this->data_->ima_.domain().has(p)
209 || this->data_->ext_.has(p);
212 template <
typename I,
typename J>
215 extension_ima<I, J>::operator()(const mln_psite(I)& p)
const
217 mln_precondition(this->is_valid());
218 mln_precondition(
has(p));
221 if (this->data_->ima_.domain().has(p))
222 return this->data_->ima_(p);
224 return this->data_->ext_(p);
227 template <
typename I,
typename J>
229 mln_morpher_lvalue(I)
230 extension_ima<I, J>::operator()(const mln_psite(I)& p)
232 static mln_value(I) cpy;
233 mln_precondition(this->is_valid());
234 mln_precondition(has(p));
236 if (this->data_->ima_.domain().has(p))
237 return this->data_->ima_(p);
243 cpy = this->data_->ext_(p);
248 template <
typename I,
typename J>
251 extension_ima<I, J>::extension()
const
253 mln_precondition(this->is_valid());
254 return this->data_->ext_;
259 template <
typename I,
typename J,
typename M>
261 void init_(tag::image_t, extension_ima<I,J>& target,
const M& model)
267 target.init_(ima, ext);
270 template <
typename J,
typename I>
272 void init_(tag::extension_t, J& target,
const extension_ima<I,J>& model)
274 typedef mlc_unconst(J) J_;
275 J_& ext_ = const_cast<J_&>(model.extension());
276 J_& target_ = const_cast<J_&>(target);
280 # endif // ! MLN_INCLUDE_ONLY
285 #endif // ! MLN_CORE_IMAGE_DMORPH_EXTENSION_IMA_HH