DGtal  0.9.2
exampleRigidtransformation2d.cpp
1 
30 #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 "ConfigExamples.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/base/Common.h"
39 #include "DGtal/io/readers/PGMReader.h"
40 #include "DGtal/io/writers/GenericWriter.h"
42 #include "DGtal/images/RigidTransformation2D.h"
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace functors;
49 using namespace Z2i;
50 
52 
53 int main( int , char** )
54 {
57  typedef ForwardRigidTransformation2D < Space > ForwardTrans;
58  typedef BackwardRigidTransformation2D < Space > BackwardTrans;
60  typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
61  typedef MyDomainTransformer::Bounds Bounds;
63  trace.beginBlock ( "Example rigidtransformation2d" );
65  ForwardTrans forwardTrans( RealPoint ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) );
66  BackwardTrans backwardTrans( RealPoint ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) );
69  MyDomainTransformer domainTransformer ( forwardTrans );
71  Identity idD;
72 
73  Image image = PGMReader<Image>::importPGM ( examplesPath + "samples/church.pgm" );
75  Bounds bounds = domainTransformer ( image.domain() );
76  Domain transformedDomain ( bounds.first, bounds.second );
78 
79  trace.beginBlock ( "Backward - Eulerian model" );
81  MyImageBackwardAdapter backwardImageAdapter ( image, transformedDomain , backwardTrans, idD );
83  backwardImageAdapter >> "backward_transform.pgm";
84  trace.endBlock();
85 
86  trace.beginBlock( "Forward - Lagrangian model" );
87  Image forwardTransformedImage ( transformedDomain );
89  for ( Domain::ConstIterator it = image.domain().begin(); it != image.domain().end(); ++it )
90  {
91  forwardTransformedImage.setValue ( forwardTrans ( *it ), image ( *it ) );
92  }
94  forwardTransformedImage >> "forward_transform.pgm";
95  trace.endBlock();
96  trace.endBlock();
97  return 0;
98 }
99 // //
void beginBlock(const std::string &keyword="")
Aim: Automatically defines an adequate image type according to the hints given by the user...
Definition: ImageSelector.h:66
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
STL namespace.
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
const Domain & domain() const
Definition: Image.h:192
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Space::RealVector RealVector
Definition: StdDefs.h:98