DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testConstImageAdapter.cpp
Go to the documentation of this file.
1
16
34
36
#include <iostream>
37
38
#include "DGtal/base/Common.h"
39
#include "DGtal/helpers/StdDefs.h"
40
#include "ConfigTest.h"
41
42
#include "DGtal/base/BasicFunctors.h"
43
#include "DGtal/images/ImageSelector.h"
44
#include "DGtal/images/ConstImageAdapter.h"
45
47
48
using namespace
std
;
49
using namespace
DGtal
;
50
51
template
<
typename
R>
52
void
displayRange
(
const
R& r)
53
{
54
typedef
typename
R::ConstIterator I;
55
for
(I it = r.begin(), itEnd = r.end();
56
it != itEnd; ++it)
57
{
58
trace
.
info
() << *it <<
" "
;
59
}
60
trace
.
info
() << std::endl;
61
}
62
64
int
main
(
int
argc,
char
** argv )
65
{
66
unsigned
int
nbok = 0;
67
unsigned
int
nb = 0;
68
69
trace
.
beginBlock
(
"Test for ConstImageAdapter"
);
70
trace
.
info
() <<
"Args:"
;
71
for
(
int
i = 0; i < argc; ++i )
72
trace
.
info
() <<
" "
<< argv[ i ];
73
trace
.
info
() << endl;
74
75
using namespace
Z2i
;
76
77
trace
.
beginBlock
(
"Image creation"
);
78
79
//domain
80
const
Integer
size = 5;
81
Point
p = Point::diagonal(0);
82
Point
q = Point::diagonal(size-1);
83
Domain
d(p,q);
84
85
//image
86
typedef
ImageSelector<Domain, int >::Type
Image
;
87
Image
img(d);
88
89
//fill
90
const
int
maximalValue = size*size;
91
Image::Range::OutputIterator
it = img.
range
().
outputIterator
();
92
for
(
int
i = 0; i < maximalValue; ++i)
93
*it++ = i;
94
95
//display values
96
Image::ConstRange
r = img.
constRange
();
97
std::copy( r.
begin
(), r.
end
(), std::ostream_iterator<int>(cout,
", "
) );
98
cout << endl;
99
trace
.
endBlock
();
100
101
102
const
int
thresholdValue = maximalValue/2;
103
trace
.
beginBlock
(
"Implicit thresholding"
);
104
106
functors::Identity
g
;
107
DGtal::functors::Thresholder<Image::Value>
t( thresholdValue );
108
typedef
ConstImageAdapter<Image, Domain, functors::Identity, bool, DGtal::functors::Thresholder<Image::Value>
> MyConstImageAdapter;
109
BOOST_CONCEPT_ASSERT((
concepts::CConstImage< MyConstImageAdapter >
));
110
MyConstImageAdapter a(img, d,
g
, t);
112
113
//display values
115
ConstImageAdapter<Image, Domain, functors::Identity, bool, DGtal::functors::Thresholder<Image::Value>
>
::ConstRange
116
ra = a.
constRange
();
117
std::copy( ra.begin(), ra.end(), std::ostream_iterator<int>(cout,
", "
) );
118
cout << endl;
119
120
std::vector<int> to_vector(25);
121
std::copy(ra.begin(), ra.end(), to_vector.begin());
122
for
(
int
i = 0; i < 25; i++)
123
{
124
if
(i<=12)
125
{
126
if
(to_vector[i]==1)
127
{
128
cout <<
"ok, "
;
129
nbok += 1 ; nb++;
130
}
131
else
132
{
133
cout <<
"!ok, "
;
134
nb++;
135
}
136
}
137
else
138
{
139
if
(to_vector[i]==0)
140
{
141
cout <<
"ok, "
;
142
nbok += 1 ; nb++;
143
}
144
else
145
{
146
cout <<
"!ok, "
;
147
nb++;
148
}
149
}
150
}
152
153
cout << endl;
154
155
trace
.
endBlock
();
156
157
bool
res = (nbok == nb);
158
159
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
160
trace
.
endBlock
();
161
return
res ? 0 : 1;
162
}
163
// //
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition
ConstImageAdapter.h:106
DGtal::ConstImageAdapter::constRange
ConstRange constRange() const
Definition
ConstImageAdapter.h:203
DGtal::ImageContainerBySTLVector< Domain, Value >::OutputIterator
std::vector< Value >::iterator OutputIterator
Definition
ImageContainerBySTLVector.h:270
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition
ImageContainerBySTLVector.h:274
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::range
Range range()
Definition
Image.h:214
DGtal::Image::constRange
ConstRange constRange() const
Definition
Image.h:203
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::Point
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
DGtal::functors::Thresholder
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
Definition
BasicFunctors.h:501
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
DGtal::concepts::CConstImage
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
Definition
CConstImage.h:95
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition
BasicFunctors.h:288
g
std::mt19937 g(rd())
displayRange
void displayRange(const R &r)
Definition
testConstImageAdapter.cpp:52
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
ConstRange
Image::ConstRange ConstRange
Definition
testSimpleRandomAccessRangeFromPoint.cpp:47
tests
images
testConstImageAdapter.cpp
Generated on
for DGtal by
1.18.0