Milena (Olena)
User documentation 2.0a Id
Main Page
Related Pages
Modules
Namespaces
Classes
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerator
Groups
Pages
accu/shape/volume.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_SHAPE_VOLUME_HH
27
# define MLN_ACCU_SHAPE_VOLUME_HH
28
32
43
# include <mln/accu/internal/base.hh>
44
# include <mln/core/concept/meta_accumulator.hh>
45
# include <mln/math/diff_abs.hh>
46
47
# include <mln/util/pix.hh>
48
# include <mln/literal/zero.hh>
49
50
namespace
mln
51
{
52
53
namespace
accu
54
{
55
56
namespace
shape
57
{
58
65
template
<
typename
I>
66
struct
volume
67
:
public
mln::accu::internal::base< unsigned , volume<I> >
68
{
76
typedef
util::pix<I>
argument
;
78
typedef
typename
argument::value
value
;
79
80
volume
();
81
84
void
init
();
85
void
take(
const
argument
&
pixel
);
86
void
take(
const
volume<I>
& other);
87
89
void
set_value
(
unsigned
v);
91
93
unsigned
to_result
()
const
;
94
97
bool
is_valid
()
const
;
98
99
protected
:
101
value
ref_level__;
103
unsigned
area__;
105
unsigned
volume_;
106
};
107
108
109
}
// end of mln::accu::shape
110
111
112
namespace
meta
113
{
114
115
namespace
shape
116
{
117
119
120
struct
volume
:
public
Meta_Accumulator
< volume >
121
{
122
template
<
typename
I>
123
struct
with
124
{
125
typedef
accu::shape::volume<I>
ret;
126
};
127
};
128
129
}
// end of namespace mln::accu::meta::shape
130
131
}
// end of namespace mln::accu::meta
132
133
# ifndef MLN_INCLUDE_ONLY
134
135
namespace
shape
136
{
137
138
template
<
typename
I>
139
inline
140
volume<I>::volume()
141
{
142
init();
143
}
144
145
template
<
typename
I>
146
inline
147
void
148
volume<I>::init
()
149
{
150
ref_level__ =
literal::zero
;
151
volume_ = 0;
152
area__ = 0;
153
}
154
155
template
<
typename
I>
156
inline
157
void
158
volume<I>::take
(
const
argument&
pixel
)
159
{
160
/* FIXME: Growing a component using this particular `take'
161
routine won't work, since the update does not take care of
162
the reference level to compute the new volume. Maybe we
163
could distinguish two cases:
164
165
1. the empty accumulator case (which corresponds to the
166
following code);
167
2. the non-empty accumulator case (which sohuld act as in
168
`take(const volume<I>& other)').
169
170
Currently, the implementation is only valid if the
171
accumulator was initialy empty before the call to
172
`take(const argument&)'. */
173
ref_level__ = pixel.v();
174
++area__;
175
++volume_;
176
}
177
178
template
<
typename
I>
179
inline
180
void
181
volume<I>::take(
const
volume<I>& other)
182
{
183
area__ += other.area__;
184
/* FIXME: Is it `t.area__' or `area__' ? Théo said it was
185
the latter, but both the ISMM 2005 paper and Olena 0.11 use
186
the former. */
187
volume_ +=
188
other.volume_ +
189
other.area__ * mln::math::diff_abs(other.ref_level__, ref_level__);
190
// Member ref_level__ is not touched.
191
}
192
193
template
<
typename
I>
194
inline
195
unsigned
196
volume<I>::to_result
()
const
197
{
198
return
volume_;
199
}
200
201
template
<
typename
I>
202
inline
203
void
204
volume<I>::set_value
(
unsigned
v)
205
{
206
volume_ = v;
207
// Reset the other members.
208
ref_level__ =
literal::zero
;
209
area__ = 0;
210
}
211
212
template
<
typename
I>
213
inline
214
bool
215
volume<I>::is_valid
()
const
216
{
217
return
true
;
218
}
219
220
}
// end of namespace mln::accu::shape
221
222
# endif // ! MLN_INCLUDE_ONLY
223
224
}
// end of namespace mln::accu
225
226
}
// end of namespace mln
227
228
229
#endif // ! MLN_ACCU_SHAPE_VOLUME_HH
mln
accu
shape
volume.hh
Generated on Thu Nov 8 2012 10:58:26 for Milena (Olena) by
1.8.2-20120930