$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
integral_sum_sum2_functor.hh
1 // Copyright (C) 2011, 2013 EPITA Research and Development Laboratory
2 // (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 SCRIBO_UTIL_INTEGRAL_SUM_SUM2_FUNCTOR_HH
28 # define SCRIBO_UTIL_INTEGRAL_SUM_SUM2_FUNCTOR_HH
29 
33 
34 # include <mln/util/couple.hh>
35 # include <mln/trait/value_.hh>
36 
37 namespace scribo
38 {
39 
40  namespace util
41  {
42 
43  template <typename V, typename S = mln_sum(V)>
45  {
46  public:
48 
49  void begin_of_first_row();
50  void begin_of_row();
51  void end_of_row();
52 
53  void begin_of_col();
54  void end_of_col();
55 
56 
57  void take(const V& v);
58 
59  result to_result_first_row() const;
60  result to_result(const result& up_result) const;
61 
62  private:
63  S h_sum;
64  S h_sum_2;
65  };
66 
67 
68 # ifndef MLN_INCLUDE_ONLY
69 
70  template <typename V, typename S>
71  inline
72  void
74  {
75  h_sum = 0;
76  h_sum_2 = 0;
77  }
78 
79  template <typename V, typename S>
80  inline
81  void
82  integral_sum_sum2_functor<V,S>::begin_of_row()
83  {
84  h_sum = 0;
85  h_sum_2 = 0;
86  }
87 
88  template <typename V, typename S>
89  inline
90  void
91  integral_sum_sum2_functor<V,S>::take(const V& v)
92  {
93  h_sum += v;
94  h_sum_2 += v * v;
95  }
96 
97  template <typename V, typename S>
98  inline
99  typename integral_sum_sum2_functor<V,S>::result
100  integral_sum_sum2_functor<V,S>::to_result_first_row() const
101  {
102  return result(h_sum, h_sum_2);
103  }
104 
105  template <typename V, typename S>
106  inline
107  typename integral_sum_sum2_functor<V,S>::result
108  integral_sum_sum2_functor<V,S>::to_result(const result& up_result) const
109  {
110  return result(h_sum + up_result.first(),
111  h_sum_2 + up_result.second());
112  }
113 
114  template <typename V, typename S>
115  inline
116  void
117  integral_sum_sum2_functor<V,S>::begin_of_col()
118  {
119  }
120 
121  template <typename V, typename S>
122  inline
123  void
124  integral_sum_sum2_functor<V,S>::end_of_col()
125  {
126  }
127 
128 
129  template <typename V, typename S>
130  inline
131  void
132  integral_sum_sum2_functor<V,S>::end_of_row()
133  {
134  }
135 
136 #endif // ! MLN_INCLUDE_ONLY
137 
138  } // end of namespace scribo::util
139 
140 } // end of namespace scribo
141 
142 #endif // ! SCRIBO_UTIL_INTEGRAL_SUM_SUM2_FUNCTOR_HH