DGtal  1.4.beta
testRigidTransformation2D.cpp
Go to the documentation of this file.
1 
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 
45 using namespace std;
46 using namespace DGtal;
47 using namespace functors;
48 using namespace Z2i;
49 
51 // Functions for testing class testRigidTransformation2D.
53 
58 class testRigidTransformation2D
59 {
61  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
62  typedef BackwardRigidTransformation2D < Space > BackwardTrans;
65  typedef DomainTrans::Bounds Bounds;
66 private:
67  Image binary;
68  Image gray;
69  ForwardTrans forwardTrans;
70  BackwardTrans backwardTrans;
71  Identity idD;
72  DomainTrans domainForwardTrans;
73 public:
74  // Setup part
75  testRigidTransformation2D() :
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 ) ),
80  domainForwardTrans ( forwardTrans )
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 
91  bool forwardTransformationBinary ()
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 
104  bool backwardTransformationBinary ()
105  {
106  Bounds bounds = domainForwardTrans ( binary.domain() );
107  Domain d ( bounds.first, bounds.second );
108  MyImageBackwardAdapter adapter ( binary, d, backwardTrans, idD );
109  adapter >> "binary_after_backward.pgm";
110  return true;
111  }
112 
113  bool backwardTransformationGray ()
114  {
115  Bounds bounds = domainForwardTrans ( gray.domain() );
116  Domain d ( bounds.first, bounds.second );
117  MyImageBackwardAdapter adapter ( gray, d, backwardTrans, idD );
118  adapter >> "gray_after_backward.pgm";
119  return true;
120  }
121 
122  bool forwardTransformationGray ()
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 
139 int main( int, char** )
140 {
141  bool res = true;
142  testRigidTransformation2D rigidTest;
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...
Iterator for HyperRectDomain.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
const Domain & domain() const
Definition: Image.h:192
void setValue(const Point &aPoint, const Value &aValue)
Definition: Image.h:247
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Automatically defines an adequate image type according to the hints given by the user.
Definition: ImageSelector.h:70
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(int, char **)
ImageContainerBySTLVector< Domain, Value > Image