Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
update.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_DATA_UPDATE_HH
27 # define MLN_DATA_UPDATE_HH
28 
32 
33 # include <mln/core/concept/accumulator.hh>
34 # include <mln/core/concept/image.hh>
35 
36 
37 
38 namespace mln
39 {
40 
41  namespace data
42  {
43 
50  template <typename A, typename I>
51  mln_result(A)
52  update(Accumulator<A>& a, const Image<I>& input);
53 
54 
55 
56 # ifndef MLN_INCLUDE_ONLY
57 
58 
59  // Tests.
60 
61  namespace internal
62  {
63 
64  template <typename A, typename I>
65  inline
66  void
67  update_tests(Accumulator<A>& a_, const Image<I>& input_)
68  {
69  A& a = exact(a_);
70  const I& input = exact(input_);
71  mln_precondition(input.is_valid());
72  // sizeof(a.take(mln_value(I)()));
73 
74  (void) a;
75  (void) input;
76  }
77 
78  } // end of namespace internal
79 
80 
81 
82  // Implementations.
83 
84  namespace impl
85  {
86 
87  namespace generic
88  {
89 
96  //
97  template <typename A, typename I>
98  inline
99  mln_result(A)
100  update(Accumulator<A>& a_, const Image<I>& input_)
101  {
102  trace::entering("data::impl::generic::update");
103 
104  A& a = exact(a_);
105  const I& input = exact(input_);
106  data::internal::update_tests(a, input);
107 
108  mln_piter(I) p(input.domain());
109  for_all(p)
110  a.take(input(p));
111 
112  trace::exiting("data::impl::generic::update");
113  return a.to_result();
114  }
115 
116  } // end of namespace mln::data::impl::generic
117 
118 
125  //
126  template <typename A, typename I>
127  inline
128  mln_result(A)
129  update_fastest(Accumulator<A>& a_, const Image<I>& input_)
130  {
131  trace::entering("data::impl::update_fastest");
132 
133  A& a = exact(a_);
134  const I& input = exact(input_);
135  data::internal::update_tests(a, input);
136 
137  mln_pixter(const I) pxl(input);
138  for_all(pxl)
139  a.take(pxl.val());
140 
141  trace::exiting("data::impl::update_fastest");
142  return a.to_result();
143  }
144 
145 
146  } // end of namespace mln::data::impl
147 
148 
149 
150  // Dispatch.
151 
152  namespace internal
153  {
154 
155  template <typename A, typename I>
156  inline
157  mln_result(A)
158  update_dispatch(trait::image::speed::any,
159  Accumulator<A>& a, const Image<I>& input)
160  {
161  return impl::generic::update(a, input);
162  }
163 
164  template <typename A, typename I>
165  inline
166  mln_result(A)
167  update_dispatch(trait::image::speed::fastest,
168  Accumulator<A>& a, const Image<I>& input)
169  {
170  return impl::update_fastest(a, input);
171  }
172 
173  template <typename A, typename I>
174  inline
175  mln_result(A)
176  update_dispatch(Accumulator<A>& a, const Image<I>& input)
177  {
178  return update_dispatch(mln_trait_image_speed(I)(),
179  a, input);
180  }
181 
182  } // end of namespace internal
183 
184 
185 
186  // Facades.
187 
188  template <typename A, typename I>
189  inline
190  mln_result(A)
191  update(Accumulator<A>& a, const Image<I>& input)
192  {
193  trace::entering("data::update");
194 
195  data::internal::update_tests(a, input);
196  mln_result(A) r = internal::update_dispatch(a, input);
197 
198  trace::exiting("data::update");
199  return r;
200  }
201 
202 # endif // ! MLN_INCLUDE_ONLY
203 
204  } // end of namespace mln::data
205 
206 } // end of namespace mln
207 
208 
209 #endif // ! MLN_DATA_UPDATE_HH