DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testSliceImageFromFunctor.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/helpers/StdDefs.h"
34
#include "DGtal/kernel/BasicPointFunctors.h"
35
#include "DGtal/io/readers/VolReader.h"
36
#include "DGtal/io/writers/PGMWriter.h"
37
#include "DGtal/images/ImageContainerBySTLVector.h"
38
#include "DGtal/images/ConstImageAdapter.h"
39
40
#include "ConfigTest.h"
41
42
44
45
using namespace
std
;
46
using namespace
DGtal
;
47
49
// Functions for testing class ImageHelper.
51
55
56
bool
testSliceImageFromFunctor
()
57
{
58
unsigned
int
nbok = 0;
59
unsigned
int
nb = 0;
60
std::string filename = testPath +
"samples/cat10.vol"
;
61
trace
.
beginBlock
(
"Testing block ..."
);
62
typedef
DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, unsigned char>
Image3D;
63
64
typedef
DGtal::ConstImageAdapter<Image3D, DGtal::Z2i::Domain, functors::Projector< DGtal::Z3i::Space>
,
65
Image3D::Value,
DGtal::functors::Identity
> MySliceImageAdapter;
66
67
typedef
DGtal::ConstImageAdapter<Image3D, DGtal::Z2i::Domain, functors::SliceRotator2D< HyperRectDomain< DGtal::Z3i::Space >
,
DGtal::Z3i::Integer
>,
68
Image3D::Value,
DGtal::functors::Identity
> MyRotatorSliceImageAdapter;
69
70
bool
res=
true
;
71
Image3D
image
=
VolReader<Image3D>::importVol
( filename );
72
DGtal::functors::Projector<DGtal::Z2i::Space>
projX(0); projX.
initRemoveOneDim
(0);
73
DGtal::Z2i::Domain
domainX(projX(
image
.
domain
().
lowerBound
()),
74
projX(
image
.
domain
().
upperBound
()));
75
76
77
DGtal::functors::Projector<DGtal::Z3i::Space>
aSliceFunctor(0); aSliceFunctor.
initAddOneDim
(0);
78
const
auto
identityFunctor =
DGtal::functors::Identity
();
79
MySliceImageAdapter sliceImageX(
image
, domainX, aSliceFunctor, identityFunctor);
80
res &=
PGMWriter<MySliceImageAdapter>::exportPGM
(
"exportedSlice2DDimX.pgm"
,sliceImageX);
81
82
DGtal::functors::Projector<DGtal::Z2i::Space>
projY(0); projY.
initRemoveOneDim
(1);
83
DGtal::Z2i::Domain
domainY(projY(
image
.
domain
().
lowerBound
()),
84
projY(
image
.
domain
().
upperBound
()));
85
86
DGtal::functors::Projector<DGtal::Z3i::Space>
aSliceFunctor2(0); aSliceFunctor2.
initAddOneDim
(1);
87
MySliceImageAdapter sliceImageY(
image
, domainY, aSliceFunctor2, identityFunctor);
88
res &=
PGMWriter<MySliceImageAdapter>::exportPGM
(
"exportedSlice2DDimY.pgm"
,sliceImageY);
89
90
91
DGtal::functors::Projector<DGtal::Z2i::Space>
projZ(0); projZ.
initRemoveOneDim
(2);
92
DGtal::Z2i::Domain
domainZ(projZ(
image
.
domain
().
lowerBound
()),
93
projZ(
image
.
domain
().
upperBound
()));
94
95
96
DGtal::functors::Projector<DGtal::Z3i::Space>
aSliceFunctor3(0); aSliceFunctor3.
initAddOneDim
(2);
97
MySliceImageAdapter sliceImageZ(
image
, domainZ, aSliceFunctor3, identityFunctor);
98
res &=
PGMWriter<MySliceImageAdapter>::exportPGM
(
"exportedSlice2DDimZ.pgm"
,sliceImageZ);
99
100
101
PointVector<3, DGtal::Z3i::Integer>
center(0,0,0);
102
DGtal::functors::SliceRotator2D< HyperRectDomain< DGtal::Z3i::Space >
,
DGtal::Z3i::Integer
> sliceRot(2,
image
.
domain
(), 0, 2, M_PI/4.0, center);
103
104
105
MyRotatorSliceImageAdapter sliceRotImageZ(
image
, domainZ, sliceRot, identityFunctor);
106
res &=
PGMWriter<MyRotatorSliceImageAdapter>::exportPGM
(
"exportedRotSliceZ.pgm"
,sliceRotImageZ);
107
108
109
110
111
112
nbok += res ? 1 : 0;
113
nb++;
114
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
115
<<
"true == true"
<< std::endl;
116
trace
.
endBlock
();
117
118
return
nbok == nb;
119
}
120
122
// Standard services - public :
123
124
int
main
(
int
argc,
char
** argv )
125
{
126
trace
.
beginBlock
(
"Testing class ImageHelper"
);
127
trace
.
info
() <<
"Args:"
;
128
for
(
int
i = 0; i < argc; ++i )
129
trace
.
info
() <<
" "
<< argv[ i ];
130
trace
.
info
() << endl;
131
132
bool
res =
testSliceImageFromFunctor
();
// && ... other tests
133
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
134
trace
.
endBlock
();
135
return
res ? 0 : 1;
136
}
137
// //
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::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
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::functors::SliceRotator2D
Special Point Functor that adds one dimension to a 2D point and apply on it a rotation of angle alpha...
Definition
BasicPointFunctors.h:201
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal::Z3i::Integer
DGtal::int32_t Integer
Definition
StdDefs.h:143
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::PGMWriter::exportPGM
static bool exportPGM(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool saveASCII=false, bool topbotomOrder=true)
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition
BasicFunctors.h:288
DGtal::functors::Projector
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Definition
BasicPointFunctors.h:107
DGtal::functors::Projector::initAddOneDim
void initAddOneDim(const Dimension &newDim)
DGtal::functors::Projector::initRemoveOneDim
void initRemoveOneDim(const Dimension &dimRemoved)
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
image
Image image(domain)
testSliceImageFromFunctor
bool testSliceImageFromFunctor()
Definition
testSliceImageFromFunctor.cpp:56
tests
images
testSliceImageFromFunctor.cpp
Generated on
for DGtal by
1.18.0