DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testImage.cpp
Go to the documentation of this file.
1
16
31
32
33
34
#include <cstdio>
35
#include <cmath>
36
#include <iostream>
37
38
#include "DGtal/base/Common.h"
39
#include "DGtal/kernel/SpaceND.h"
40
#include "DGtal/kernel/domains/HyperRectDomain.h"
41
#include "DGtal/images/CImage.h"
42
#include "DGtal/images/ImageContainerBySTLVector.h"
43
#include "DGtal/images/ImageContainerBySTLMap.h"
44
#include "DGtal/images/ImageContainerByHashTree.h"
45
#include "DGtal/images/Image.h"
46
47
48
using namespace
DGtal
;
49
using namespace
std
;
50
51
56
template
<
typename
Image>
57
bool
testImage
(
const
Image
& aImage)
58
{
59
60
BOOST_CONCEPT_ASSERT((
concepts::CImage<Image>
));
61
62
int
nb = 0;
63
int
nbok = 0;
64
66
trace
.
beginBlock
(
"Main services, range"
);
67
68
Image
img(aImage);
69
Image
img2 = img;
//copy
70
71
//fill
72
typename
Image::Domain::ConstIterator
dit = img.
domain
().
begin
();
73
typename
Image::Domain::ConstIterator
ditEnd = img.
domain
().
end
();
74
for
(
int
i = 0; ( (dit != ditEnd)&&(i < 5) ); ++dit, ++i)
75
{
76
img.
setValue
(*dit, i);
77
}
78
Image
img3(img2);
79
img3 = img;
//assignment
80
81
//ranges comparison
82
typename
Image::ConstRange
rimg = img.
constRange
();
83
typename
Image::ConstRange
rimg2 = img2.
constRange
();
84
typename
Image::ConstRange
rimg3 = img3.
constRange
();
85
86
bool
flag2 = std::equal(rimg.
begin
(), rimg.
end
(), rimg2.
begin
());
87
bool
flag3 = std::equal(rimg.
begin
(), rimg.
end
(), rimg3.
begin
());
88
bool
flag23 = std::equal(rimg2.
begin
(), rimg2.
end
(), rimg3.
begin
());
89
90
nbok += ( (!flag2) && flag3 && (!flag23) )?1:0;
91
nb++;
92
trace
.
info
() <<
"("
<<nbok <<
"/"
<< nb <<
")"
<< std::endl;
93
trace
.
endBlock
();
94
96
trace
.
beginBlock
(
"Output iterator"
);
97
std::copy(rimg.
begin
(), rimg.
end
(), img2.
range
().
outputIterator
());
98
99
//rimg2 is invalid if Image is a proxy image
100
//because its iterators point to the data of aImage
101
//instead of pointing to the data of img2
102
rimg2 = img2.
constRange
();
103
flag2 = std::equal(rimg.
begin
(), rimg.
end
(), rimg2.
begin
());
104
nbok += (flag2)?1:0;
105
nb++;
106
trace
.
info
() <<
"("
<<nbok <<
"/"
<< nb <<
")"
<< std::endl;
107
trace
.
endBlock
();
108
110
trace
.
beginBlock
(
" Getters / setters "
);
111
typename
Image::Domain::Point
p = img.
domain
().
upperBound
();
112
113
//local comparison
114
img.
setValue
( p, 128 );
115
bool
flag4 = ( img(p) == 128 );
116
117
//range comparison
118
rimg = img.
constRange
();
119
rimg2 = img2.
constRange
();
120
rimg3 = img3.
constRange
();
121
std::copy( rimg.
begin
(), rimg.
end
(), std::ostream_iterator<int>(cout,
", "
) );
122
cout << endl;
123
flag2 = std::equal(rimg.
begin
(), rimg.
end
(), rimg2.
begin
());
124
std::copy( rimg2.
begin
(), rimg2.
end
(), std::ostream_iterator<int>(cout,
", "
) );
125
cout << endl;
126
flag3 = std::equal(rimg.
begin
(), rimg.
end
(), rimg3.
begin
());
127
std::copy( rimg3.
begin
(), rimg3.
end
(), std::ostream_iterator<int>(cout,
", "
) );
128
cout << endl;
129
130
nbok += ( flag4 && (!flag2) && (!flag3) )?1:0;
131
nb++;
132
trace
.
info
() <<
"("
<<nbok <<
"/"
<< nb <<
")"
<< std::endl;
133
trace
.
endBlock
();
134
136
trace
.
beginBlock
(
" Display "
);
137
trace
.
info
() << img << std::endl;
138
trace
.
info
() << img2 << std::endl;
139
trace
.
info
() << img3 << std::endl;
140
trace
.
endBlock
();
141
142
return
( img.
isValid
() && img2.
isValid
() && img3.
isValid
() && (nbok == nb) );
143
}
144
145
int
main
(
int
argc,
char
** argv )
146
{
147
148
trace
.
beginBlock
(
"Testing image classes"
);
149
trace
.
info
() <<
"Args:"
;
150
for
(
int
i = 0; i < argc; ++i )
151
trace
.
info
() <<
" "
<< argv[ i ];
152
trace
.
info
() << endl;
153
155
typedef
DGtal::int64_t
Integer
;
156
typedef
SpaceND<2,Integer>
Space
;
157
typedef
Space::Point
Point
;
158
typedef
HyperRectDomain<Space>
Domain
;
159
160
const
Integer
size = 5;
161
Point
p = Point::diagonal(0);
162
Point
q = Point::diagonal(size-1);
163
Domain
d(p,q);
164
166
typedef
short
Value
;
167
typedef
ImageContainerBySTLVector<Domain,Value>
VImage;
168
typedef
ImageContainerBySTLMap<Domain,Value>
MImage;
169
// TODO typedef experimental::ImageContainerByHashTree<Domain,Value> HImage;
170
// TODO typedef Image<VImage > LImage;
171
173
VImage vi(d);
174
bool
res =
testImage
(vi);
175
176
MImage mi(d);
177
res = res &&
testImage
(mi);
178
179
// TODO
180
// HImage hi(3, p, q, 0);
181
// res = res && testImage(hi);
182
183
// LImage li( new VImage(d) );
184
// res = res && testImage(li);
185
186
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
187
trace
.
endBlock
();
188
return
res ? 0 : 1;
189
}
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition
HyperRectDomain.h:176
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition
HyperRectDomain.h:201
DGtal::ImageContainerBySTLMap
Definition
ImageContainerBySTLMap.h:98
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition
ImageContainerBySTLVector.h:274
DGtal::ImageContainerBySTLVector< Domain, Value >::Point
Domain::Point Point
Definition
ImageContainerBySTLVector.h:138
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::Image::range
Range range()
Definition
Image.h:214
DGtal::Image::constRange
ConstRange constRange() const
Definition
Image.h:203
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition
Image.h:247
DGtal::Image::isValid
bool isValid() const
Definition
Image.h:266
DGtal::SimpleRandomAccessConstRangeFromPoint::begin
ConstIterator begin() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:192
DGtal::SimpleRandomAccessConstRangeFromPoint::end
ConstIterator end() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:212
DGtal::SimpleRandomAccessRangeFromPoint::outputIterator
OutputIterator outputIterator()
Definition
SimpleRandomAccessRangeFromPoint.h:262
DGtal::SpaceND
Definition
SpaceND.h:96
DGtal::SpaceND< 3, Integer >::Point
PointVector< dim, Integer > Point
Definition
SpaceND.h:110
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::int64_t
std::int64_t int64_t
signed 94-bit integer.
Definition
BasicTypes.h:73
DGtal::trace
Trace trace
std
STL namespace.
DGtal::Space
DGtal::Value
DGtal::concepts::CImage
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition
CImage.h:103
testImage
bool testImage(const Image &aImage)
Definition
testImage.cpp:57
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
tests
images
testImage.cpp
Generated on
for DGtal by
1.18.0