$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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  mln_trace("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  return output;
82  }
83 
84  } // end of namespace mln::accu::image::impl::generic
85 
86 
87  // Fastest version.
88 
89  template <typename I>
90  mln_ch_value(I, mln_deduce(I, value, result))
91  to_result_fastest(const Image<I>& input_)
92  {
93  mln_trace("accu::impl::image::to_result_fastest");
94 
95  mlc_is_a(mln_value(I), Accumulator)::check();
96 
97  const I& input = exact(input_);
98  mln_precondition(input.is_valid());
99 
100  typedef mln_deduce(I, value, result) R;
101  typedef mln_ch_value(I, R) O;
102  O output;
103  initialize(output, input);
104 
105  mln_pixter(const I) p_in(input);
106  mln_pixter(O) p_out(output);
107  for_all_2(p_in, p_out)
108  p_out.val() = p_in.val().to_result();
109 
110  return output;
111  }
112 
113  } // end of namespace mln::accu::image::impl
114 
115 
116 
117  // Dispatch.
118 
119  namespace internal
120  {
121 
122  template <typename I>
123  mln_ch_value(I, mln_deduce(I, value, result))
124  to_result_dispatch(trait::image::speed::any,
125  const Image<I>& input)
126  {
127  return impl::generic::to_result(input);
128  }
129 
130  template <typename I>
131  mln_ch_value(I, mln_deduce(I, value, result))
132  to_result_dispatch(trait::image::speed::fastest,
133  const Image<I>& input)
134  {
135  return impl::to_result_fastest(input);
136  }
137 
138  template <typename I>
139  mln_ch_value(I, mln_deduce(I, value, result))
140  to_result_dispatch(const Image<I>& input)
141  {
142  return to_result_dispatch(mln_trait_image_speed(I)(),
143  input);
144  }
145 
146  } // end of namespace mln::accu::image::internal
147 
148 
149  // Facade.
150 
151  template <typename I>
152  mln_ch_value(I, mln_deduce(I, value, result))
153  to_result(const Image<I>& input)
154  {
155  mln_trace("accu::image::to_result");
156 
157  mlc_is_a(mln_value(I), Accumulator)::check();
158 
159  mln_precondition(exact(input).is_valid());
160 
161  typedef mln_deduce(I, value, result) R;
162  mln_ch_value(I, R) output;
163  output = internal::to_result_dispatch(input);
164 
165  return output;
166  }
167 
168 # endif // ! MLN_INCLUDE_ONLY
169 
170  } // end of namespace mln::accu::image
171 
172  } // end of namespace mln::accu
173 
174 } // end of namespace mln
175 
176 
177 #endif // ! MLN_ACCU_IMAGE_TO_RESULT_HH