$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
data/fill.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_DATA_FILL_HH
28 # define MLN_DATA_FILL_HH
29 
35 
36 # include <mln/core/concept/function.hh>
37 # include <mln/pw/image.hh>
38 # include <mln/convert/to_fun.hh>
39 
40 # include <mln/data/fill_with_image.hh>
41 # include <mln/data/fill_with_value.hh>
42 
43 
44 namespace mln
45 {
46 
47  namespace data
48  {
49 
60  template <typename I, typename D>
61  void fill(Image<I>& ima, const D& data);
62 
63 
64 
65 # ifndef MLN_INCLUDE_ONLY
66 
67  namespace internal
68  {
69 
70  // tests
71 
72  template <typename I, typename D>
73  inline
74  void fill_tests(Image<I>& ima, const D&)
75  {
76  // Avoid a warning about an undefined variable when NDEBUG
77  // is not defined.
78  (void) ima;
79 
80  mlc_is(mln_trait_image_value_io(I),
81  trait::image::value_io::read_write)::check();
82  mln_precondition(exact(ima).is_valid());
83  // FIXME: check for ambiguities...
84  }
85 
86  // dispatch_overload
87 
88  template <typename I>
89  void fill_dispatch_overload(I& ima, const mln_value(I)& v)
90  {
92  }
93 
94  template <typename I, typename J>
95  void fill_dispatch_overload(I& ima, const Image<J>& data)
96  {
97  mln::data::fill_with_image(ima, data);
98  }
99 
100  template <typename I, typename F>
101  void fill_dispatch_overload(I& ima, const Function<F>& f)
102  {
103  mlc_converts_to(mln_result(F), mln_value(I))::check();
105  exact(f) | ima.domain());
106  }
107 
108  template <typename I, typename R, typename A>
109  void fill_dispatch_overload(I& ima, R (*f)(A))
110  {
111  mlc_converts_to(R, mln_value(I))::check();
113  convert::to_fun(f) | ima.domain());
114  }
115 
116  template <typename I, typename V, unsigned N>
117  void fill_dispatch_overload(I& ima, V (&arr)[N])
118  {
119  mlc_converts_to(V, mln_value(I))::check();
120  mln_precondition(N == ima.nsites());
121  mln_fwd_piter(I) p(ima.domain());
122  unsigned i = 0;
123  for_all(p)
124  ima(p) = arr[i++];
125  }
126 
127  // dispatch
128 
129  template <typename I, typename D>
130  void fill_dispatch(Image<I>& ima, const D& data)
131  {
132  fill_dispatch_overload(exact(ima), exact(data));
133  }
134 
135  } // end of namespace mln::data::internal
136 
137 
138  // Facade.
139 
140  template <typename I, typename D>
141  inline
142  void fill(Image<I>& ima, const D& data)
143  {
144  mln_trace("data::fill");
145 
146  internal::fill_tests(ima, data);
147  internal::fill_dispatch(ima, data);
148 
149  }
150 
151 
152 # endif // ! MLN_INCLUDE_ONLY
153 
154  } // end of namespace mln::data
155 
156 } // end of namespace mln
157 
158 
159 #endif // ! MLN_DATA_FILL_HH