$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
revert_full.cc
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
#include <mln/core/image/image1d.hh>
27
#include <mln/core/image/image2d.hh>
28
#include <mln/core/image/image3d.hh>
29
#include <mln/core/image/dmorph/sub_image.hh>
30
#include <mln/core/image/dmorph/image_if.hh>
31
32
#include <mln/fun/p2b/chess.hh>
33
#include <mln/literal/origin.hh>
34
#include <mln/value/int_u8.hh>
35
#include <mln/value/int_s8.hh>
36
#include <mln/value/int_s16.hh>
37
38
#include <mln/debug/iota.hh>
39
#include <mln/arith/revert.hh>
40
41
42
43
44
struct
f_box1d_t :
mln::Function_v2b
< f_box1d_t >
45
{
46
f_box1d_t(
const
mln::box1d
& b)
47
: b_(b)
48
{
49
}
50
mln::box1d
b_;
51
bool
operator()(
const
mln::point1d
& p)
const
52
{
53
return
b_.
has
(p);
54
}
55
};
56
57
struct
f_box2d_t :
mln::Function_v2b
< f_box2d_t >
58
{
59
f_box2d_t(
const
mln::box2d
& b)
60
: b_(b)
61
{
62
}
63
mln::box2d
b_;
64
bool
operator()(
const
mln::point2d
& p)
const
65
{
66
return
b_.
has
(p);
67
}
68
};
69
70
struct
f_box3d_t :
mln::Function_v2b
< f_box3d_t >
71
{
72
f_box3d_t(
const
mln::box3d
& b)
73
: b_(b)
74
{
75
}
76
mln::box3d
b_;
77
bool
operator()(
const
mln::point3d
& p)
const
78
{
79
return
b_.
has
(p);
80
}
81
};
82
83
84
85
namespace
mln
86
{
87
template
<
typename
I,
typename
J>
88
void
89
chck
(
const
Image<I>
& ref_,
const
Image<J>
& ima_)
90
{
91
typedef
mln_value(I) V;
92
const
I& ref =
exact
(ref_);
93
const
J& ima =
exact
(ima_);
94
95
mln_piter(I)
p
(ima.domain ());
96
for_all(
p
)
97
mln_assertion (ima(
p
) == mln_value(J)(mln_min(V) + mln_max(V) - ref(
p
)));
98
}
99
100
template
<
typename
V>
101
void
102
chk
()
103
{
104
box1d
b1(
literal::origin
,
point1d
(1));
105
box2d
b2(
literal::origin
,
point2d
(1,1));
106
box3d
b3(
literal::origin
,
point3d
(1,1,1));
107
f_box1d_t f_b1(b1);
108
f_box2d_t f_b2(b2);
109
f_box3d_t f_b3(b3);
110
unsigned
sli = 5;
111
unsigned
row = 10;
112
unsigned
col = 100;
113
114
115
{
116
typedef
image1d<V>
I;
117
118
119
for
(
unsigned
i = 1; i < col; ++i)
120
{
121
I ref(i);
122
debug::iota
(ref);
123
I ima(i);
124
debug::iota
(ima);
125
arith::revert_inplace
(ima);
126
chck
(ref, ima);
127
}
128
}
129
{
130
typedef
image2d<V>
I;
131
132
133
for
(
unsigned
i = 1; i < col; ++i)
134
for
(
unsigned
j = 1; j < row; ++j)
135
{
136
I ref(j, i);
137
debug::iota
(ref);
138
I ima(j, i);
139
debug::iota
(ima);
140
arith::revert_inplace
(ima);
141
chck
(ref, ima);
142
}
143
}
144
{
145
typedef
image3d<V>
I;
146
147
148
for
(
unsigned
i = 1; i < col; ++i)
149
for
(
unsigned
j = 1; j < row; ++j)
150
for
(
unsigned
k = 1; k < sli; ++k)
151
{
152
I ref(k, j, i);
153
debug::iota
(ref);
154
I ima(k, j, i);
155
debug::iota
(ima);
156
arith::revert_inplace
(ima);
157
chck
(ref, ima);
158
}
159
}
160
{
161
typedef
image1d<V>
I;
162
typedef
sub_image<I, box1d>
J;
163
164
165
166
for
(
unsigned
i = 1; i < col; ++i)
167
{
168
I refima(i);
169
J ref(refima, b1);
170
debug::iota
(ref);
171
172
I image(i);
173
J ima(image, b1);
174
debug::iota
(ima);
175
arith::revert_inplace
(ima);
176
chck
(ref, ima);
177
}
178
}
179
{
180
typedef
image2d<V>
I;
181
typedef
sub_image<I, box2d>
J;
182
183
184
for
(
unsigned
i = 1; i < col; ++i)
185
for
(
unsigned
j = 1; j < row; ++j)
186
{
187
I refima(j, i);
188
J ref(refima, b2);
189
debug::iota
(ref);
190
191
I image(j, i);
192
J ima(image, b2);
193
debug::iota
(ima);
194
arith::revert_inplace
(ima);
195
chck
(ref, ima);
196
}
197
}
198
{
199
typedef
image3d<V>
I;
200
typedef
sub_image<I, box3d>
J;
201
202
203
for
(
unsigned
i = 1; i < col; ++i)
204
for
(
unsigned
j = 1; j < row; ++j)
205
for
(
unsigned
k = 1; k < sli; ++k)
206
{
207
I refima(k, j, i);
208
J ref(refima, b3);
209
debug::iota
(ref);
210
211
I image(k, j, i);
212
J ima(image, b3);
213
debug::iota
(ima);
214
arith::revert_inplace
(ima);
215
chck
(ref, ima);
216
}
217
}
218
}
219
220
}
221
222
223
224
225
226
int
main()
227
{
228
using namespace
mln;
229
230
chk<int>();
231
chk<value::int_s8>();
232
chk<value::int_s16>();
233
chk<value::int_u8>();
234
chk<unsigned>();
235
}
tests
arith
revert_full.cc
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)