DGtal  1.5.beta
testRigidTransformation3D.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <boost/graph/graph_concepts.hpp>
33 #include "DGtal/base/Common.h"
34 #include "ConfigTest.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include <DGtal/images/ImageSelector.h>
37 #include <DGtal/images/ImageContainerBySTLVector.h>
38 #include "DGtal/images/ConstImageAdapter.h"
39 #include "DGtal/images/RigidTransformation3D.h"
40 #include "DGtal/io/readers/PGMReader.h"
41 #include "DGtal/io/readers/VolReader.h"
42 #include "DGtal/io/writers/GenericWriter.h"
43 
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace Z3i;
49 using namespace functors;
50 
52 // Functions for testing class RigidTransformation3D.
54 
58 class testRigidTransformation3D
59 {
61  typedef ForwardRigidTransformation3D < Space > ForwardTrans;
62  typedef BackwardRigidTransformation3D < Space > BackwardTrans;
65  typedef DomainTrans::Bounds Bounds;
66 private:
67  Image binary;
68  ForwardTrans forwardTrans;
69  BackwardTrans backwardTrans;
70  Identity idD;
71  DomainTrans domainForwardTrans;
72 public:
73  // Setup part
74  testRigidTransformation3D() :
75  binary ( PGMReader<Image>::importPGM3D ( testPath + "samples/cat10.pgm3d" ) ),
76  forwardTrans ( RealPoint ( 5, 5, 5 ), RealVector ( 1, 0, 1 ), M_PI_4, RealVector( 3, -3, 3 ) ),
77  backwardTrans( RealPoint ( 5, 5, 5 ), RealVector ( 1, 0, 1 ), M_PI_4, RealVector( 3, -3, 3 ) ),
78  domainForwardTrans(forwardTrans)
79  {}
80 
81  bool forwardTransformation ()
82  {
83  Bounds bounds = domainForwardTrans ( binary.domain() );
84  Domain d ( bounds.first, bounds.second );
85  Image transformed ( d );
86  for ( Domain::ConstIterator it = binary.domain().begin(); it != binary.domain().end(); ++it )
87  {
88  transformed.setValue ( forwardTrans ( *it ), binary ( *it ) );
89  }
90  transformed >> "binary_after_forward.pgm3d";
91  return true;
92  }
93  bool backwardTransformation ()
94  {
95  Bounds bounds = domainForwardTrans ( binary.domain() );
96  Domain d ( bounds.first, bounds.second );
97  MyImageBackwardAdapter adapter ( binary, d, backwardTrans, idD );
98  adapter >> "binary_after_backward.pgm3d";
99  return true;
100  }
101 };
102 
104 // Standard services - public :
105 
106 int main( int, char** )
107 {
108  bool res = true;
109  testRigidTransformation3D rigidTest;
110  trace.beginBlock ( "Testing RigidTransformation3D" );
111  res &= rigidTest.forwardTransformation();
112  res &= rigidTest.backwardTransformation();
113  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
114  trace.endBlock();
115  return res ? 0 : 1;
116 }
117 // //
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
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
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