Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
accu/compute.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_ACCU_COMPUTE_HH
27 # define MLN_ACCU_COMPUTE_HH
28 
35 
36 # include <mln/core/concept/meta_accumulator.hh>
37 # include <mln/core/concept/image.hh>
38 # include <mln/util/pix.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace accu
45  {
46 
58  template <typename A, typename I>
59  mln_result(A)
60  compute(const Accumulator<A>& a, const Image<I>& input);
61 
62 
74  template <typename A, typename I>
75  mln_meta_accu_result(A, util::pix<I>)
76  compute(const Meta_Accumulator<A>& a, const Image<I>& input);
77 
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82 
83  namespace impl
84  {
85 
86  namespace generic
87  {
88 
89  template <typename A, typename I>
90  mln_result(A)
91  compute(const Accumulator<A>&, const Image<I>& input_)
92  {
93  trace::entering("accu::impl::generic::compute");
94 
95  const I& input = exact(input_);
96  mln_precondition(input.is_valid());
97 
98  A a;
99  mln_piter(I) p(input.domain());
100  for_all(p)
101  a.take(make::pix(input, p));
102 
103  trace::exiting("accu::impl::generic::compute");
104  return a.to_result();
105  }
106 
107  } // end of namespace mln::accu::impl::generic
108 
109  } // end of namespace mln::accu::impl
110 
111 
112  namespace internal
113  {
114 
115  template <typename A, typename I>
116  inline
117  mln_result(A)
118  compute_dispatch(const Accumulator<A>& a, const Image<I>& input)
119  {
120  return impl::generic::compute(a, input);
121  }
122 
123  } // end of namespace mln::accu::internal
124 
125 
126 
127  template <typename A, typename I>
128  inline
129  mln_result(A)
130  compute(const Accumulator<A>& a, const Image<I>& input)
131  {
132  trace::entering("accu::compute");
133 
134  mln_precondition(exact(input).is_valid());
135  mln_result(A) output = internal::compute_dispatch(a, input);
136 
137  trace::exiting("accu::compute");
138  return output;
139  }
140 
141  template <typename A, typename I>
142  inline
144  compute(const Meta_Accumulator<A>& a, const Image<I>& input)
145  {
146  trace::entering("accu::compute");
147 
148  mln_precondition(exact(input).is_valid());
149 
150  typedef mln_accu_with(A, util::pix<I>) A_;
151  util::pix<I> pix_(exact(input), mln_psite(I)());
152  A_ a_ = accu::unmeta(exact(a), pix_);
153 
154  mln_result(A_) output = internal::compute_dispatch(a_, input);
155 
156  trace::exiting("accu::compute");
157  return output;
158  }
159 
160 # endif // ! MLN_INCLUDE_ONLY
161 
162  } // end of namespace mln::accu
163 
164 } // end of namespace mln
165 
166 
167 #endif // ! MLN_ACCU_COMPUTE_HH