Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testRigidTransformation2D.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include <cmath>
33#include <DGtal/images/ImageSelector.h>
34#include <DGtal/images/ImageContainerBySTLVector.h>
35#include "DGtal/images/ConstImageAdapter.h"
36#include "DGtal/base/Common.h"
37#include "ConfigTest.h"
38#include "DGtal/helpers/StdDefs.h"
39#include "DGtal/images/RigidTransformation2D.h"
40#include "DGtal/io/readers/PGMReader.h"
41#include "DGtal/io/writers/GenericWriter.h"
42
44
45using namespace std;
46using namespace DGtal;
47using namespace functors;
48using namespace Z2i;
49
51// Functions for testing class testRigidTransformation2D.
53
57
59{
61 typedef ForwardRigidTransformation2D < Space > ForwardTrans;
62 typedef BackwardRigidTransformation2D < Space > BackwardTrans;
64 typedef DomainRigidTransformation2D < Domain, ForwardTrans > DomainTrans;
66private:
73public:
74 // Setup part
76 binary ( Domain ( Point ( 0,0 ), Point ( 10, 10 ) ) ),
77 gray ( PGMReader<Image>::importPGM ( testPath + "samples/church-small.pgm" ) ),
78 forwardTrans ( Point ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) ),
79 backwardTrans ( Point ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) ),
81 {
82 binary.setValue ( Point ( 3,3 ), 255 );
83 binary.setValue ( Point ( 3,4 ), 255 );
84 binary.setValue ( Point ( 4,3 ), 255 );
85 binary.setValue ( Point ( 4,4 ), 255 );
86
87 binary >> "binary.pgm";
88 gray >> "gray.pgm";
89 }
90
92 {
93 Bounds bounds = domainForwardTrans ( binary.domain() );
94 Domain d ( bounds.first, bounds.second );
95 Image transformed ( d );
96 for ( Domain::ConstIterator it = binary.domain().begin(); it != binary.domain().end(); ++it )
97 {
98 transformed.setValue ( forwardTrans ( *it ), binary ( *it ) );
99 }
100 transformed >> "binary_after_forward.pgm";
101 return true;
102 }
103
105 {
106 Bounds bounds = domainForwardTrans ( binary.domain() );
107 Domain d ( bounds.first, bounds.second );
109 adapter >> "binary_after_backward.pgm";
110 return true;
111 }
112
114 {
115 Bounds bounds = domainForwardTrans ( gray.domain() );
116 Domain d ( bounds.first, bounds.second );
118 adapter >> "gray_after_backward.pgm";
119 return true;
120 }
121
123 {
124 Bounds bounds = domainForwardTrans ( gray.domain() );
125 Domain d ( bounds.first, bounds.second );
126 Image transformed ( d );
127 for ( Domain::ConstIterator it = gray.domain().begin(); it != gray.domain().end(); ++it )
128 {
129 transformed.setValue ( forwardTrans ( *it ), gray ( *it ) );
130 }
131 transformed >> "gray_after_forward.pgm";
132 return true;
133 }
134};
135
137// Standard services - public :
138
139int main( int, char** )
140{
141 bool res = true;
143 trace.beginBlock ( "Testing RigidTransformation2D" );
144 res &= rigidTest.forwardTransformationBinary();
145 res &= rigidTest.backwardTransformationBinary();
146 res &= rigidTest.backwardTransformationGray();
147 res &= rigidTest.forwardTransformationGray();
148 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
149 trace.endBlock();
150 return res ? 0 : 1;
151}
152// //
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
void setValue(const Point &aPoint, const Value &aValue)
std::pair< typename Domain::Space::Point, typename Domain::Space::Point > Bounds
ImageSelector< Domain, unsignedchar >::Type Image
ConstImageAdapter< Image, Domain, BackwardTrans, Image::Value, Identity > MyImageBackwardAdapter
ForwardRigidTransformation2D< Space > ForwardTrans
BackwardRigidTransformation2D< Space > BackwardTrans
DomainRigidTransformation2D< Domain, ForwardTrans > DomainTrans
Z2i this namespace gathers the standard of types for 2D imagery.
Space::RealVector RealVector
Definition StdDefs.h:98
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition PGMReader.h:98
Aim: Define a simple default functor that just returns its argument.
int main()
Definition testBits.cpp:56