$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
center.hh
1
// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
2
// Laboratory (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 MLN_ACCU_CENTER_HH
28
# define MLN_ACCU_CENTER_HH
29
35
36
# include <mln/accu/internal/base.hh>
37
# include <mln/accu/shape/bbox.hh>
38
39
namespace
mln
40
{
41
42
namespace
accu
43
{
44
45
53
//
54
template
<
typename
P,
typename
V =
typename
P::vec>
55
struct
center
56
:
public
mln::accu::internal::base
<V, center<P,V> >
57
{
58
typedef
P
argument
;
59
typedef
V
result
;
60
61
center
();
62
65
void
init
();
66
void
take
(
const
argument
& t);
67
void
take
(
const
center<P,V>
& other);
69
71
V
to_result
()
const
;
72
operator
P()
const
;
73
75
bool
is_valid
()
const
;
76
78
unsigned
nsites
()
const
;
79
80
protected
:
81
algebra::vec<P::dim, mln_sum(mln_coord(P))>
center_
;
82
unsigned
nsites_
;
83
};
84
85
namespace
meta
86
{
87
89
struct
center
:
public
Meta_Accumulator
< center >
90
{
91
92
template
<
typename
P>
93
struct
with
94
{
95
typedef
accu::center<P>
ret
;
96
};
97
98
};
99
100
}
// end of namespace mln::accu::meta
101
102
103
104
# ifndef MLN_INCLUDE_ONLY
105
106
template
<
typename
P,
typename
V>
107
inline
108
center<P,V>::center
()
109
{
110
init();
111
}
112
113
template
<
typename
P,
typename
V>
114
inline
115
void
116
center<P,V>::init
()
117
{
118
center_ =
literal::zero
;
119
nsites_ = 0;
120
}
121
122
template
<
typename
P,
typename
V>
123
inline
124
void
center<P,V>::take
(
const
argument& t)
125
{
126
center_ += t.to_vec();
127
++nsites_;
128
}
129
130
template
<
typename
P,
typename
V>
131
inline
132
void
133
center<P,V>::take
(
const
center<P,V>& other)
134
{
135
center_ += other.center_;
136
nsites_ += other.nsites_;
137
}
138
139
template
<
typename
P,
typename
V>
140
inline
141
V
142
center<P,V>::to_result
()
const
143
{
144
// mln_precondition(is_valid());
145
if
(! is_valid())
146
return
V();
147
return
center_ / nsites_;
148
}
149
150
template
<
typename
P,
typename
V>
151
inline
152
center<P,V>::operator P()
const
153
{
154
return
P(
to_result
());
155
}
156
157
template
<
typename
P,
typename
V>
158
inline
159
bool
160
center<P,V>::is_valid
()
const
161
{
162
return
nsites_ > 0;
163
}
164
165
template
<
typename
P,
typename
V>
166
inline
167
unsigned
168
center<P,V>::nsites
()
const
169
{
170
return
nsites_;
171
}
172
173
# endif // ! MLN_INCLUDE_ONLY
174
175
176
}
// end of namespace mln::accu
177
178
}
// end of namespace mln
179
180
181
#endif // ! MLN_ACCU_CENTER_HH
mln
accu
center.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)