$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compute_in_window.hh
1 // Copyright (C) 2011, 2012, 2013 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_COMPUTE_IN_WINDOW_HH
28 # define MLN_DATA_COMPUTE_IN_WINDOW_HH
29 
34 
35 # include <mln/accu/image/init.hh>
36 # include <mln/accu/image/to_result.hh>
37 # include <mln/core/concept/meta_accumulator.hh>
38 # include <mln/border/mirror.hh>
39 # include <mln/extension/adjust.hh>
40 
41 # include <mln/debug/println_with_border.hh>
42 
43 namespace mln
44 {
45 
46  namespace data
47  {
48 
60  template <typename A, typename I, typename W>
61  mln_ch_value(I, mln_result(A))
62  compute_in_window(const Accumulator<A>& a, const Image<I>& input,
63  const Window<W>& win);
64 
75  template <typename A, typename I, typename W>
76  mln_ch_value(I, mln_result(A))
77  compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input,
78  const Window<W>& win);
79 
80 
81 
82 # ifndef MLN_INCLUDE_ONLY
83 
84  namespace internal
85  {
86 
87  template <typename A, typename I, typename W>
88  void
89  compute_in_window_tests(const Accumulator<A>& a, const Image<I>& input_,
90  const Window<W>& win_)
91  {
92  const W& win = exact(win_);
93  const I& input = exact(input_);
94 
95  (void) a;
96  (void) win;
97  (void) input;
98 
99  mln_assertion(win.is_valid());
100  mln_assertion(input.is_valid());
101  }
102 
103  } // end of namespace mln::data::internal
104 
105 
106  namespace impl
107  {
108 
109  namespace generic
110  {
111 
112  template <typename A, typename I, typename W>
113  mln_ch_value(I, mln_result(A))
114  compute_in_window(const Accumulator<A>& a,
115  const Image<I>& input_,
116  const Window<W>& win_)
117  {
118  mln_trace("mln::impl::generic::compute_in_window");
119 
120  const I& input = exact(input_);
121  const W& win = exact(win_);
122 
123  internal::compute_in_window_tests(a, input, win);
124 
125  mln_ch_value(I, A) accu;
126  initialize(accu, input);
127 
128  accu::image::init(accu);
129 
130  mln_piter(I) p(accu.domain());
131  mln_qiter(W) q(win, p);
132 
133  for_all(p)
134  for_all(q)
135  if (input.domain().has(q))
136  accu(p).take(input(q));
137 
138  mln_ch_value(I, mln_result(A))
139  output = accu::image::to_result(accu);
140 
141  return output;
142  }
143 
144  } // end of namespace mln::impl::generic
145 
146 
147  template <typename A, typename I, typename W>
148  mln_ch_value(I, mln_result(A))
149  compute_in_window_fastest(const Accumulator<A>& a,
150  const Image<I>& input_,
151  const Window<W>& win_)
152  {
153  mln_trace("mln::impl::generic::compute_in_window_fastest");
154 
155  const W& win = exact(win_);
156  const I& input = exact(input_);
157 
158  internal::compute_in_window_tests(a, input, win);
159 
160  extension::adjust(input, win);
161  border::mirror(input);
162 
163  typedef mln_ch_value(I, A) J;
164  J accu;
165  initialize(accu, input);
166 
167  accu::image::init(accu);
168 
169  mln_pixter(J) p(accu);
170  mln_qixter(J, W) q(p, win);
171 
172  for_all(p)
173  for_all(q)
174  p.val().take(input.element(q.offset()));
175 
176  mln_ch_value(I, mln_result(A))
177  output = accu::image::to_result(accu);
178 
179  return output;
180  }
181 
182 
183  } // end of namespace mln::data::impl
184 
185 
186  // Dispatch
187 
188  namespace internal
189  {
190 
191  template <typename A, typename I, typename W>
192  mln_ch_value(I, mln_result(A))
193  compute_in_window_dispatch(const Accumulator<A>& a,
194  const Image<I>& input,
195  const Window<W>& win,
196  trait::image::speed::fastest)
197  {
198  return impl::compute_in_window_fastest(a, input, win);
199  }
200 
201  template <typename A, typename I, typename W>
202  mln_ch_value(I, mln_result(A))
203  compute_in_window_dispatch(const Accumulator<A>& a,
204  const Image<I>& input,
205  const Window<W>& win,
206  trait::image::speed::any)
207  {
208  return impl::generic::compute_in_window(a, input, win);
209  }
210 
211  template <typename A, typename I, typename W>
212  mln_ch_value(I, mln_result(A))
213  compute_in_window_dispatch(const Accumulator<A>& a,
214  const Image<I>& input,
215  const Window<W>& win)
216  {
217  return compute_in_window_dispatch(a, input, win,
218  mln_trait_image_speed(I)());
219  }
220 
221  } // end of namespace mln::data::internal
222 
223 
224 
225  // Facades.
226 
227  template <typename A, typename I, typename W>
228  mln_ch_value(I, mln_result(A))
229  compute_in_window(const Accumulator<A>& a, const Image<I>& input,
230  const Window<W>& win)
231  {
232  mln_trace("data::compute_in_window");
233 
234  internal::compute_in_window_tests(a, input, win);
235 
236  mln_ch_value(I, mln_result(A))
237  output = data::internal::compute_in_window_dispatch(a, input, win);
238 
239  return output;
240  }
241 
242 
243  template <typename A, typename I, typename W>
244  mln_ch_value(I, mln_result(A))
245  compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input,
246  const Window<W>& win)
247  {
248  typedef mln_accu_with(A, mln_value(I)) A_;
249  A_ a_ = accu::unmeta(exact(a), mln_value(I)());
250 
251  return data::compute_in_window(a_, input, win);
252  }
253 
254 # endif // ! MLN_INCLUDE_ONLY
255 
256  } // end of namespace mln::data
257 
258 } // end of namespace mln
259 
260 
261 #endif // ! MLN_DATA_COMPUTE_IN_WINDOW_HH