$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Milena
Getting started
API Reference Manual
All Classes
Examples
Demos
Publications
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
rms.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_RMS_HH
27
# define MLN_ACCU_RMS_HH
28
32
33
# include <mln/core/concept/meta_accumulator.hh>
34
# include <mln/accu/internal/base.hh>
35
# include <mln/math/sqrt.hh>
36
37
38
namespace
mln
39
{
40
41
namespace
accu
42
{
43
44
50
//
51
template
<
typename
T,
typename
V>
52
struct
rms
:
public
mln::accu::internal::base
<V, rms<T,V> >
53
{
54
typedef
T
argument
;
55
56
rms
();
57
60
void
init
();
61
void
take_as_init_
(
const
T
&
p
);
62
void
take
(
const
T
&
p
);
63
void
take
(
const
rms<T,V>
& other);
65
67
V
to_result
()
const
;
68
71
V
hook_value_
()
const
;
72
75
bool
is_valid
()
const
;
76
77
protected
:
78
79
V
v_
;
80
unsigned
count_
;
81
};
82
83
84
namespace
meta
85
{
86
88
struct
rms
:
public
Meta_Accumulator
< rms >
89
{
90
template
<
typename
T,
typename
V>
91
struct
with
92
{
93
typedef
accu::rms<T,V>
ret
;
94
};
95
};
96
97
}
// end of namespace mln::accu::meta
98
99
100
# ifndef MLN_INCLUDE_ONLY
101
102
template
<
typename
T,
typename
V>
103
inline
104
rms<T,V>::rms
()
105
{
106
init();
107
}
108
109
template
<
typename
T,
typename
V>
110
inline
111
void
112
rms<T,V>::init
()
113
{
114
v_ =
literal::zero
;
115
count_ = 0;
116
}
117
118
template
<
typename
T,
typename
V>
119
inline
120
void
121
rms<T,V>::take_as_init_
(
const
T
& t)
122
{
123
v_ += t * t;
124
++count_;
125
}
126
127
template
<
typename
T,
typename
V>
128
inline
129
void
130
rms<T,V>::take
(
const
T
& t)
131
{
132
v_ += t * t;
133
++count_;
134
}
135
136
template
<
typename
T,
typename
V>
137
inline
138
void
139
rms<T,V>::take
(
const
rms<T,V>& other)
140
{
141
v_ += other.v_;
142
count_ += other.count_;
143
}
144
145
template
<
typename
T,
typename
V>
146
inline
147
V
148
rms<T,V>::to_result
()
const
149
{
150
if
(count_ == 0)
151
return
V(0);
152
return
math::sqrt<V>(v_ / count_);
153
}
154
155
template
<
typename
T,
typename
V>
156
inline
157
V
158
rms<T,V>::hook_value_
()
const
159
{
160
return
v_;
161
}
162
163
template
<
typename
T,
typename
V>
164
inline
165
bool
166
rms<T,V>::is_valid
()
const
167
{
168
return
true
;
169
}
170
171
# endif // ! MLN_INCLUDE_ONLY
172
173
}
// end of namespace mln::accu
174
175
}
// end of namespace mln
176
177
178
#endif // ! MLN_ACCU_RMS_HH
mln
accu
rms.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)