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
00027 #ifndef MLN_CORE_CONCEPT_IMAGE_HH
00028 # define MLN_CORE_CONCEPT_IMAGE_HH
00029
00033
00034 # include <mln/core/concept/site_set.hh>
00035 # include <mln/core/concept/mesh.hh>
00036
00037 # include <mln/core/trait/all.hh>
00038 # include <mln/core/macros.hh>
00039 # include <mln/core/site_set/box.hh>
00040
00041 # include <mln/trait/concrete.hh>
00042 # include <mln/trait/images.hh>
00043
00044 # include <mln/metal/abort.hh>
00045 # include <mln/metal/is_a.hh>
00046 # include <mln/metal/equal.hh>
00047
00048 # include <mln/tag/init.hh>
00049
00050
00051 namespace mln
00052 {
00053
00054
00055
00056 template <typename E> struct Image;
00057 template <typename E> struct Literal;
00058
00059
00060
00061 template <>
00062 struct Image<void>
00063 {
00064 typedef Object<void> super;
00065 };
00066
00067
00072 template <typename E>
00073 struct Image : public Object<E>
00074 {
00075 typedef Image<void> category;
00076
00077 template <typename J>
00078 Image<E>& operator=(const J& rhs);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 protected:
00120 Image();
00121 };
00122
00123
00124 namespace convert
00125 {
00126
00127 namespace over_load
00128 {
00129
00130 template <typename V, unsigned S, typename I>
00131 void
00132 from_to_(const V (&values)[S], Image<I>& to);
00133
00134 }
00135
00136 }
00137
00138
00139
00140 # ifndef MLN_INCLUDE_ONLY
00141
00142
00143 namespace internal
00144 {
00145
00146 template <typename values_browsing_trait, typename E>
00147 struct image_values_interface_check
00148 {
00149 static void run() { }
00150 };
00151
00152 template <typename E>
00153 struct image_values_interface_check<
00154 mln::trait::image::value_browsing::value_wise,
00155 E>
00156 {
00157 static void run()
00158 {
00159 }
00160 };
00161
00162
00163
00164
00165 template < typename E,
00166 typename A >
00167 int check_init(void (E::*)(A))
00168 {
00169 return 0;
00170 }
00171
00172 template < typename E,
00173 typename A1, typename A2 >
00174 int check_init(void (E::*)(A1, A2))
00175 {
00176 return 0;
00177 }
00178
00179 template < typename E,
00180 typename A1, typename A2, typename A3 >
00181 int check_init(void (E::*)(A1, A2, A3))
00182 {
00183 return 0;
00184 }
00185
00186 }
00187
00188
00189 template <typename E>
00190 template <typename J>
00191 inline
00192 Image<E>&
00193 Image<E>::operator=(const J&)
00194 {
00199 mlc_abort(E)::check();
00200 return *this;
00201 }
00202
00203
00204 template <typename E>
00205 inline
00206 Image<E>::Image()
00207 {
00208
00209
00210 typedef mln_domain(E) domain_t;
00211 typedef mln_site(E) site;
00212 typedef mln_psite(E) psite;
00213
00214 typedef mln_piter(E) piter;
00215 typedef mln_fwd_piter(E) fwd_piter;
00216 typedef mln_bkd_piter(E) bkd_piter;
00217
00218 bool (E::*m1)(const psite& p) const = & E::has;
00219 m1 = 0;
00220
00221
00222
00223
00224
00225 bool (E::*m3)() const = & E::is_valid;
00226 m3 = 0;
00227
00228 typedef typename E::t_eligible_values_set t_eligible_values_set;
00229
00230 const t_eligible_values_set& (E::*m4)() const = & E::values_eligible;
00231 m4 = 0;
00232
00233 typedef typename E::t_values_space t_values_space;
00234
00235 const t_values_space& (E::*m5)() const = & E::values_space;
00236 m5 = 0;
00237
00238
00239
00240 typedef mln_value(E) value;
00241 typedef mln_rvalue(E) rvalue;
00242 typedef mln_lvalue(E) lvalue;
00243
00244 mlc_is_not_a(value, Literal)::check();
00245
00246
00247
00248
00249
00250
00251 rvalue (E::*m6)(const psite& p) const = & E::operator();
00252 m6 = 0;
00253 lvalue (E::*m7)(const psite& p) = & E::operator();
00254 m7 = 0;
00255
00256 const domain_t& (E::*m8)() const = & E::domain;
00257 m8 = 0;
00258
00259 typedef typename E::skeleton skeleton;
00260
00261
00262
00263 internal::check_init(& E::init_);
00264
00266 internal::image_values_interface_check<mln_trait_image_value_browsing(E),
00267 E>::run();
00268 }
00269
00270
00271 namespace convert
00272 {
00273
00274 namespace over_load
00275 {
00276
00277 template <typename V, unsigned S, typename I>
00278 void
00279 from_to_(const V (&values)[S], Image<I>& to_)
00280 {
00281 mlc_bool(S != 0)::check();
00282 mlc_converts_to(V, mln_value(I))::check();
00283 typedef mln_site(I) P;
00284 enum { d = P::dim,
00285 s = mlc_root(d, S)::value };
00286 metal::bool_<(mlc_pow_int(s, d) == S)>::check();
00287
00288 I& to = exact(to_);
00289 mln_precondition(! to.is_valid());
00290
00291 box<P> b(all_to(0), all_to(s - 1));
00292 to.init_(b);
00293 mln_fwd_piter(box<P>) p(b);
00294 unsigned i = 0;
00295 for_all(p)
00296 to(p) = values[i++];
00297 }
00298
00299 }
00300
00301 }
00302
00303 # endif // ! MLN_INCLUDE_ONLY
00304
00305 }
00306
00307
00308 # include <mln/core/routine/initialize.hh>
00309
00310
00311 #endif // ! MLN_CORE_CONCEPT_IMAGE_HH