$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
maj_h.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_MAJ_H_HH
27
# define MLN_ACCU_MAJ_H_HH
28
32
33
34
# include <mln/core/concept/meta_accumulator.hh>
35
# include <mln/accu/internal/base.hh>
36
# include <mln/trait/value_.hh>
37
# include <mln/util/pix.hh>
38
# include <mln/accu/histo.hh>
39
# include <vector>
40
41
42
namespace
mln
43
{
44
45
namespace
accu
46
{
47
48
50
56
template
<
typename
T>
57
struct
maj_h
:
public
mln::accu::internal::base
< const T& , maj_h<T> >
58
{
59
typedef
T
argument
;
60
61
maj_h
();
62
65
void
init
();
66
void
take
(
const
argument
& t);
67
void
untake
(
const
argument
& t);
68
void
take
(
const
maj_h<T>
& other);
70
72
const
T&
to_result
()
const
;
73
74
//operator T () const;
75
78
bool
is_valid
()
const
;
79
80
void
update_
()
const
;
81
82
mutable
bool
valid_
;
83
84
const
accu::histo<T>
&
histo
()
const
;
85
86
protected
:
87
88
mutable
argument
t_
;
89
mutable
accu::histo<T>
h_
;
90
};
91
92
93
template
<
typename
I>
struct
maj_h
< util::pix<I> >;
94
95
96
namespace meta
97
{
98
100
101
struct
maj_h
:
public
Meta_Accumulator
< maj_h >
102
{
103
template
<
typename
T>
104
struct
with
105
{
106
typedef
accu::maj_h<T>
ret
;
107
};
108
};
109
110
}
// end of namespace mln::accu::meta
111
112
113
114
# ifndef MLN_INCLUDE_ONLY
115
116
template
<
typename
T>
117
inline
118
maj_h<T>::maj_h
()
119
{
120
init();
121
valid_ =
true
;
122
//FIXME: Not generic
123
t_ =
literal::zero
;
124
}
125
126
template
<
typename
T>
127
inline
128
void
129
maj_h<T>::init
()
130
{
131
h_.init();
132
}
133
134
template
<
typename
T>
135
inline
136
void
137
maj_h<T>::take
(
const
argument& t)
138
{
139
h_.take(t);
140
141
//update return value
142
if
(h_(t) > h_(t_))
143
t_ = t;
144
}
145
146
template
<
typename
T>
147
inline
148
void
149
maj_h<T>::untake
(
const
argument& t)
150
{
151
h_.untake(t);
152
153
if
(valid_)
154
valid_ =
false
;
155
}
156
157
template
<
typename
T>
158
inline
159
void
160
maj_h<T>::take
(
const
maj_h<T>& other)
161
{
162
h_.take(other.h_);
163
164
if
(valid_)
165
valid_ =
false
;
166
}
167
168
template
<
typename
T>
169
inline
170
void
171
maj_h<T>::update_
()
const
172
{
173
const
std::vector<unsigned>& v = h_.vect();
174
175
for
(
unsigned
i = 0; i != v.size(); i++)
176
{
177
// if nb referents of occurrence i > nb referents of t_
178
if
(v[i] > h_(t_))
179
t_ = h_.vset()[i];
// t_ <- current
180
}
181
valid_ =
true
;
182
}
183
184
template
<
typename
T>
185
inline
186
const
T
&
187
maj_h<T>::to_result
()
const
188
{
189
if
(not valid_)
190
update_();
191
return
t_;
192
}
193
194
template
<
typename
T>
195
inline
196
bool
197
maj_h<T>::is_valid
()
const
198
{
199
return
true
;
200
}
201
202
template
<
typename
V>
203
inline
204
const
accu::histo<V>&
205
maj_h<V>::histo
()
const
206
{
207
return
h_;
208
}
209
210
# endif // ! MLN_INCLUDE_ONLY
211
212
}
// end of namespace mln::accu
213
214
}
// end of namespace mln
215
216
217
#endif // ! MLN_ACCU_MAJ_H_HH
mln
accu
maj_h.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)