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_DMORPH_EXTENSION_VAL_HH
00027 # define MLN_CORE_IMAGE_DMORPH_EXTENSION_VAL_HH
00028
00035
00036 # include <mln/core/internal/image_identity.hh>
00037
00038
00039
00040 namespace mln
00041 {
00042
00043
00044 template <typename I> struct extension_val;
00045
00046
00047 namespace internal
00048 {
00049
00051 template <typename I>
00052 struct data< extension_val<I> >
00053 {
00054 data(I& ima, const mln_value(I)& val_);
00055
00056 I ima_;
00057 mln_value(I) val_;
00058 };
00059
00060 }
00061
00062
00063 namespace trait
00064 {
00065
00066 template <typename I>
00067 struct image_< extension_val<I> > : image_< I >
00068 {
00069
00070 typedef trait::image::category::identity_morpher category;
00071 typedef mln_internal_trait_image_speed_from(I) speed;
00072 typedef trait::image::value_access::indirect value_access;
00073
00074
00075 typedef trait::image::ext_domain::infinite ext_domain;
00076 typedef trait::image::ext_value::single ext_value;
00077 typedef trait::image::ext_io::read_write ext_io;
00078 };
00079
00080 template <typename I, typename V>
00081 struct ch_value< extension_val<I>, V >
00082 {
00083 typedef mlc_converts_to(mln_value(I), V) keep_ext;
00084 typedef mln_ch_value(I, V) Iv;
00085 typedef extension_val<Iv> Iv_ext;
00086 typedef mlc_if(keep_ext, Iv_ext, Iv) ret;
00087 };
00088
00089 }
00090
00091
00092
00096
00097 template <typename I>
00098 class extension_val :
00099 public internal::image_identity< I, mln_domain(I), extension_val<I> >
00100 {
00101 public:
00102
00104 typedef extension_val< tag::image_<I> > skeleton;
00105
00107 typedef mln_value(I) value;
00108
00110 typedef mln_value(I) rvalue;
00111
00112
00114 extension_val();
00115
00117 extension_val(I& ima, const mln_value(I)& val);
00118
00121 void init_(I& ima, const mln_value(I)& val);
00122
00123
00125
00126 template <typename P>
00127 bool has(const P& p) const;
00128
00129
00131 mln_value(I) operator()(const mln_psite(I)& p) const;
00132
00134 mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
00135
00136
00138 const mln_value(I)& extension() const;
00139
00141 void change_extension(const mln_value(I)& val);
00142 };
00143
00144
00145
00146
00147 template <typename I, typename J>
00148 void init_(tag::image_t, extension_val<I>& target, const J& model);
00149
00150 template <typename V, typename I>
00151 void init_(tag::extension_t, V& target, const extension_val<I>& model);
00152
00153
00154
00155 # ifndef MLN_INCLUDE_ONLY
00156
00157
00158
00159 namespace internal
00160 {
00161
00162 template <typename I>
00163 inline
00164 data< extension_val<I> >::data(I& ima, const mln_value(I)& val)
00165 : ima_(ima),
00166 val_(val)
00167 {
00168 }
00169
00170 }
00171
00172
00173
00174 template <typename I>
00175 inline
00176 extension_val<I>::extension_val()
00177 {
00178 }
00179
00180 template <typename I>
00181 inline
00182 extension_val<I>::extension_val(I& ima, const mln_value(I)& val)
00183 {
00184 init_(ima, val);
00185 }
00186
00187 template <typename I>
00188 inline
00189 void
00190 extension_val<I>::init_(I& ima, const mln_value(I)& val)
00191 {
00192 this->data_ = new internal::data< extension_val<I> >(ima, val);
00193 }
00194
00195 template <typename I>
00196 template <typename P>
00197 inline
00198 bool
00199 extension_val<I>::has(const P&) const
00200 {
00201 return true;
00202 }
00203
00204 template <typename I>
00205 inline
00206 mln_value(I)
00207 extension_val<I>::operator()(const mln_psite(I)& p) const
00208 {
00209 mln_precondition(this->is_valid());
00210
00211 if (this->data_->ima_.domain().has(p))
00212 return this->data_->ima_(p);
00213 else
00214 return this->data_->val_;
00215 }
00216
00217 template <typename I>
00218 inline
00219 mln_morpher_lvalue(I)
00220 extension_val<I>::operator()(const mln_psite(I)& p)
00221 {
00222 static mln_value(I) cpy;
00223 mln_precondition(this->is_valid());
00224
00225 if (this->data_->ima_.domain().has(p))
00226 return this->data_->ima_(p);
00227 else
00228 {
00229
00230 cpy = this->data_->val_;
00231 return cpy;
00232 }
00233 }
00234
00235 template <typename I>
00236 inline
00237 const mln_value(I)&
00238 extension_val<I>::extension() const
00239 {
00240 mln_precondition(this->is_valid());
00241 return this->data_->val_;
00242 }
00243
00244 template <typename I>
00245 inline
00246 void
00247 extension_val<I>::change_extension(const mln_value(I)& val)
00248 {
00249 mln_precondition(this->is_valid());
00250 this->data_->val_ = val;
00251 }
00252
00253
00254
00255
00256 template <typename I, typename J>
00257 void init_(tag::image_t, extension_val<I>& target, const J& model)
00258 {
00259 I ima;
00260 init_(tag::image, ima, model);
00261 mln_value(I) val;
00262 init_(tag::extension, val, model);
00263 target.init_(ima, val);
00264 }
00265
00266 template <typename V, typename I>
00267 void init_(tag::extension_t, V& target, const extension_val<I>& model)
00268 {
00269 mlc_converts_to(mln_value(I), V)::check();
00270 target = static_cast<V>(model.extension());
00271 }
00272
00273 # endif // ! MLN_INCLUDE_ONLY
00274
00275 }
00276
00277
00278 #endif // ! MLN_CORE_IMAGE_DMORPH_EXTENSION_VAL_HH