$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
integral_sum_sum2_global_min_functor.hh
1 // Copyright (C) 2012, 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_GLOBAL_MIN_FUNCTOR_HH
28 # define SCRIBO_UTIL_INTEGRAL_SUM_SUM2_GLOBAL_MIN_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  const V& global_min() const;
63 
64  private:
65  S h_sum_;
66  S h_sum_2_;
67 
68  V global_min_;
69  };
70 
71 
72 # ifndef MLN_INCLUDE_ONLY
73 
74  template <typename V, typename S>
75  inline
76  void
78  {
79  h_sum_ = 0;
80  h_sum_2_ = 0;
81  global_min_ = 0;
82  }
83 
84  template <typename V, typename S>
85  inline
86  void
87  integral_sum_sum2_global_min_functor<V,S>::begin_of_row()
88  {
89  h_sum_ = 0;
90  h_sum_2_ = 0;
91  }
92 
93  template <typename V, typename S>
94  inline
95  void
96  integral_sum_sum2_global_min_functor<V,S>::take(const V& v)
97  {
98  if (global_min_ > v)
99  global_min_ = v;
100 
101  h_sum_ += v;
102  h_sum_2_ += v * v;
103  }
104 
105  template <typename V, typename S>
106  inline
107  typename integral_sum_sum2_global_min_functor<V,S>::result
108  integral_sum_sum2_global_min_functor<V,S>::to_result_first_row() const
109  {
110  return result(h_sum_, h_sum_2_);
111  }
112 
113  template <typename V, typename S>
114  inline
115  typename integral_sum_sum2_global_min_functor<V,S>::result
116  integral_sum_sum2_global_min_functor<V,S>::to_result(const result& up_result) const
117  {
118  return result(h_sum_ + up_result.first(),
119  h_sum_2_ + up_result.second());
120  }
121 
122  template <typename V, typename S>
123  inline
124  const V&
125  integral_sum_sum2_global_min_functor<V,S>::global_min() const
126  {
127  return global_min_;
128  }
129 
130  template <typename V, typename S>
131  inline
132  void
133  integral_sum_sum2_global_min_functor<V,S>::begin_of_col()
134  {
135  }
136 
137  template <typename V, typename S>
138  inline
139  void
140  integral_sum_sum2_global_min_functor<V,S>::end_of_col()
141  {
142  }
143 
144 
145  template <typename V, typename S>
146  inline
147  void
148  integral_sum_sum2_global_min_functor<V,S>::end_of_row()
149  {
150  }
151 
152 #endif // ! MLN_INCLUDE_ONLY
153 
154  } // end of namespace scribo::util
155 
156 } // end of namespace scribo
157 
158 #endif // ! SCRIBO_UTIL_INTEGRAL_SUM_SUM2_GLOBAL_MIN_FUNCTOR_HH