Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
to_result.hh
1 // Copyright (C) 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_ACCU_IMAGE_TO_RESULT_HH
27 # define MLN_ACCU_IMAGE_TO_RESULT_HH
28 
32 
33 # include <mln/core/concept/accumulator.hh>
34 # include <mln/core/concept/image.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace accu
41  {
42 
43  namespace image
44  {
45 
46  template <typename I>
47  mln_ch_value(I, mln_deduce(I, value, result))
48  to_result(const Image<I>& input);
49 
50 
51 
52 # ifndef MLN_INCLUDE_ONLY
53 
54  namespace impl
55  {
56 
57  // Generic version.
58 
59  namespace generic
60  {
61 
62  template <typename I>
63  mln_ch_value(I, mln_deduce(I, value, result))
64  to_result(const Image<I>& input_)
65  {
66  trace::entering("accu::impl::image::generic::to_result");
67 
68  mlc_is_a(mln_value(I), Accumulator)::check();
69 
70  const I& input = exact(input_);
71  mln_precondition(input.is_valid());
72 
73  typedef mln_deduce(I, value, result) R;
74  mln_ch_value(I, R) output;
75  initialize(output, input);
76 
77  mln_piter(I) p(input.domain());
78  for_all(p)
79  output(p) = input(p).to_result();
80 
81  trace::exiting("accu::impl::image::generic::to_result");
82  return output;
83  }
84 
85  } // end of namespace mln::accu::image::impl::generic
86 
87 
88  // Fastest version.
89 
90  template <typename I>
91  mln_ch_value(I, mln_deduce(I, value, result))
92  to_result_fastest(const Image<I>& input_)
93  {
94  trace::entering("accu::impl::image::to_result_fastest");
95 
96  mlc_is_a(mln_value(I), Accumulator)::check();
97 
98  const I& input = exact(input_);
99  mln_precondition(input.is_valid());
100 
101  typedef mln_deduce(I, value, result) R;
102  typedef mln_ch_value(I, R) O;
103  O output;
104  initialize(output, input);
105 
106  mln_pixter(const I) p_in(input);
107  mln_pixter(O) p_out(output);
108  for_all_2(p_in, p_out)
109  p_out.val() = p_in.val().to_result();
110 
111  trace::exiting("accu::impl::image::to_result_fastest");
112  return output;
113  }
114 
115  } // end of namespace mln::accu::image::impl
116 
117 
118 
119  // Dispatch.
120 
121  namespace internal
122  {
123 
124  template <typename I>
125  mln_ch_value(I, mln_deduce(I, value, result))
126  to_result_dispatch(trait::image::speed::any,
127  const Image<I>& input)
128  {
129  return impl::generic::to_result(input);
130  }
131 
132  template <typename I>
133  mln_ch_value(I, mln_deduce(I, value, result))
134  to_result_dispatch(trait::image::speed::fastest,
135  const Image<I>& input)
136  {
137  return impl::to_result_fastest(input);
138  }
139 
140  template <typename I>
141  mln_ch_value(I, mln_deduce(I, value, result))
142  to_result_dispatch(const Image<I>& input)
143  {
144  return to_result_dispatch(mln_trait_image_speed(I)(),
145  input);
146  }
147 
148  } // end of namespace mln::accu::image::internal
149 
150 
151  // Facade.
152 
153  template <typename I>
154  mln_ch_value(I, mln_deduce(I, value, result))
155  to_result(const Image<I>& input)
156  {
157  trace::entering("accu::image::to_result");
158 
159  mlc_is_a(mln_value(I), Accumulator)::check();
160 
161  mln_precondition(exact(input).is_valid());
162 
163  typedef mln_deduce(I, value, result) R;
164  mln_ch_value(I, R) output;
165  output = internal::to_result_dispatch(input);
166 
167  trace::exiting("accu::image::to_result");
168  return output;
169  }
170 
171 # endif // ! MLN_INCLUDE_ONLY
172 
173  } // end of namespace mln::accu::image
174 
175  } // end of namespace mln::accu
176 
177 } // end of namespace mln
178 
179 
180 #endif // ! MLN_ACCU_IMAGE_TO_RESULT_HH