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_DATA_FILL_HH
00028 # define MLN_DATA_FILL_HH
00029
00035
00036 # include <mln/core/concept/function.hh>
00037 # include <mln/pw/image.hh>
00038 # include <mln/convert/to_fun.hh>
00039
00040 # include <mln/data/fill_with_image.hh>
00041 # include <mln/data/fill_with_value.hh>
00042
00043
00044 namespace mln
00045 {
00046
00047 namespace data
00048 {
00049
00057 template <typename I, typename D>
00058 void fill(Image<I>& ima, const D& data);
00059
00060
00061
00062 # ifndef MLN_INCLUDE_ONLY
00063
00064 namespace internal
00065 {
00066
00067
00068
00069 template <typename I, typename D>
00070 inline
00071 void fill_tests(Image<I>& ima, const D&)
00072 {
00073
00074
00075 (void) ima;
00076
00077 mlc_is(mln_trait_image_value_io(I), trait::image::value_io::read_write)::check();
00078 mln_precondition(exact(ima).is_valid());
00079
00080 }
00081
00082
00083
00084 template <typename I>
00085 void fill_dispatch_overload(I& ima, const mln_value(I)& v)
00086 {
00087 mln::data::fill_with_value(ima, v);
00088 }
00089
00090 template <typename I, typename J>
00091 void fill_dispatch_overload(I& ima, const Image<J>& data)
00092 {
00093 mln::data::fill_with_image(ima, data);
00094 }
00095
00096 template <typename I, typename F>
00097 void fill_dispatch_overload(I& ima, const Function<F>& f)
00098 {
00099 mlc_converts_to(mln_result(F), mln_value(I))::check();
00100 mln::data::fill_with_image(ima,
00101 exact(f) | ima.domain());
00102 }
00103
00104 template <typename I, typename R, typename A>
00105 void fill_dispatch_overload(I& ima, R (*f)(A))
00106 {
00107 mlc_converts_to(R, mln_value(I))::check();
00108 mln::data::fill_with_image(ima,
00109 convert::to_fun(f) | ima.domain());
00110 }
00111
00112 template <typename I, typename V, unsigned N>
00113 void fill_dispatch_overload(I& ima, V (&arr)[N])
00114 {
00115 mlc_converts_to(V, mln_value(I))::check();
00116 mln_precondition(N == ima.nsites());
00117 mln_fwd_piter(I) p(ima.domain());
00118 unsigned i = 0;
00119 for_all(p)
00120 ima(p) = arr[i++];
00121 }
00122
00123
00124
00125 template <typename I, typename D>
00126 void fill_dispatch(Image<I>& ima, const D& data)
00127 {
00128 fill_dispatch_overload(exact(ima), exact(data));
00129 }
00130
00131 }
00132
00133
00134
00135
00136 template <typename I, typename D>
00137 inline
00138 void fill(Image<I>& ima, const D& data)
00139 {
00140 trace::entering("data::fill");
00141
00142 internal::fill_tests(ima, data);
00143 internal::fill_dispatch(ima, data);
00144
00145 trace::exiting("data::fill");
00146 }
00147
00148
00149 # endif // ! MLN_INCLUDE_ONLY
00150
00151 }
00152
00153 }
00154
00155
00156 #endif // ! MLN_DATA_FILL_HH