$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
update.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
2 // 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_UPDATE_HH
28 # define MLN_DATA_UPDATE_HH
29 
33 
34 # include <mln/core/concept/accumulator.hh>
35 # include <mln/core/concept/image.hh>
36 
37 
38 
39 namespace mln
40 {
41 
42  namespace data
43  {
44 
54  template <typename A, typename I>
55  mln_result(A)
56  update(Accumulator<A>& a, const Image<I>& input);
57 
58 
59 
60 # ifndef MLN_INCLUDE_ONLY
61 
62 
63  // Tests.
64 
65  namespace internal
66  {
67 
68  template <typename A, typename I>
69  inline
70  void
71  update_tests(Accumulator<A>& a_, const Image<I>& input_)
72  {
73  A& a = exact(a_);
74  const I& input = exact(input_);
75  mln_precondition(input.is_valid());
76  // sizeof(a.take(mln_value(I)()));
77 
78  (void) a;
79  (void) input;
80  }
81 
82  } // end of namespace internal
83 
84 
85 
86  // Implementations.
87 
88  namespace impl
89  {
90 
91  namespace generic
92  {
93 
100  //
101  template <typename A, typename I>
102  inline
103  mln_result(A)
104  update(Accumulator<A>& a_, const Image<I>& input_)
105  {
106  mln_trace("data::impl::generic::update");
107 
108  A& a = exact(a_);
109  const I& input = exact(input_);
110  data::internal::update_tests(a, input);
111 
112  mln_piter(I) p(input.domain());
113  for_all(p)
114  a.take(input(p));
115 
116  return a.to_result();
117  }
118 
119  } // end of namespace mln::data::impl::generic
120 
121 
128  //
129  template <typename A, typename I>
130  inline
131  mln_result(A)
132  update_fastest(Accumulator<A>& a_, const Image<I>& input_)
133  {
134  mln_trace("data::impl::update_fastest");
135 
136  A& a = exact(a_);
137  const I& input = exact(input_);
138  data::internal::update_tests(a, input);
139 
140  mln_pixter(const I) pxl(input);
141  for_all(pxl)
142  a.take(pxl.val());
143 
144  return a.to_result();
145  }
146 
147 
148  } // end of namespace mln::data::impl
149 
150 
151 
152  // Dispatch.
153 
154  namespace internal
155  {
156 
157  template <typename A, typename I>
158  inline
159  mln_result(A)
160  update_dispatch(trait::image::speed::any,
161  Accumulator<A>& a, const Image<I>& input)
162  {
163  return impl::generic::update(a, input);
164  }
165 
166  template <typename A, typename I>
167  inline
168  mln_result(A)
169  update_dispatch(trait::image::speed::fastest,
170  Accumulator<A>& a, const Image<I>& input)
171  {
172  return impl::update_fastest(a, input);
173  }
174 
175  template <typename A, typename I>
176  inline
177  mln_result(A)
178  update_dispatch(Accumulator<A>& a, const Image<I>& input)
179  {
180  return update_dispatch(mln_trait_image_speed(I)(),
181  a, input);
182  }
183 
184  } // end of namespace internal
185 
186 
187 
188  // Facades.
189 
190  template <typename A, typename I>
191  inline
192  mln_result(A)
193  update(Accumulator<A>& a, const Image<I>& input)
194  {
195  mln_trace("data::update");
196 
197  data::internal::update_tests(a, input);
198  mln_result(A) r = internal::update_dispatch(a, input);
199 
200  return r;
201  }
202 
203 # endif // ! MLN_INCLUDE_ONLY
204 
205  } // end of namespace mln::data
206 
207 } // end of namespace mln
208 
209 
210 #endif // ! MLN_DATA_UPDATE_HH