$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
set/compute.hh
1 // Copyright (C) 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_SET_COMPUTE_HH
27 # define MLN_SET_COMPUTE_HH
28 
32 
33 # include <mln/core/concept/meta_accumulator.hh>
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/site_set.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace set
42  {
43 
49  //
50  template <typename A, typename S>
51  mln_result(A)
52  compute(const Accumulator<A>& a, const Site_Set<S>& s);
53 
54 
59  // \return The accumulator result.
60  //
61  template <typename A, typename S>
62  mln_meta_accu_result(A, mln_site(S))
63  compute(const Meta_Accumulator<A>& a, const Site_Set<S>& s);
64 
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69 
70  // Implementation.
71 
72 
73  namespace impl
74  {
75 
76  namespace generic
77  {
78 
79  template <typename A, typename S>
80  inline
81  mln_result(A)
82  compute(const Accumulator<A>& a_, const Site_Set<S>& s_)
83  {
84  mln_trace("set::impl::generic::compute");
85 
86  mlc_converts_to(mln_site(S), mln_argument(A))::check();
87 
88  A a = exact(a_);
89  const S& s = exact(s_);
90 
91  a.init();
92  mln_piter(S) p(s);
93  for_all(p)
94  a.take(p);
95 
96  return a.to_result();
97  }
98 
99  } // end of namespace mln::set::impl::generic
100 
101  } // end of namespace mln::set::impl
102 
103 
104 
105  // Facades.
106 
107 
108  template <typename A, typename S>
109  inline
110  mln_result(A)
111  compute(const Accumulator<A>& a, const Site_Set<S>& s)
112  {
113  mln_trace("set::compute");
114 
115  mlc_converts_to(mln_site(S), mln_argument(A))::check();
116 
117  mln_result(A) r = impl::generic::compute(a, s);
118 
119  return r;
120  }
121 
122 
123  template <typename A, typename S>
124  mln_meta_accu_result(A, mln_site(S))
125  compute(const Meta_Accumulator<A>& a, const Site_Set<S>& s)
126  {
127  mln_trace("set::compute");
128 
129  typedef mln_accu_with(A, mln_site(S)) A_;
130  A_ a_ = accu::unmeta(exact(a), mln_site(S)());
131 
132  mln_result(A_) r = impl::generic::compute(a_, s);
133 
134  return r;
135  }
136 
137 # endif // ! MLN_INCLUDE_ONLY
138 
139  } // end of namespace mln::set
140 
141 } // end of namespace mln
142 
143 
144 #endif // ! MLN_SET_COMPUTE_HH