DGtal  1.5.beta
testSliceImageFromFunctor.cpp
Go to the documentation of this file.
1 
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 
57 {
58  unsigned int nbok = 0;
59  unsigned int nb = 0;
60  std::string filename = testPath + "samples/cat10.vol";
61  trace.beginBlock ( "Testing block ..." );
63 
65  Image3D::Value, DGtal::functors::Identity > MySliceImageAdapter;
66 
68  Image3D::Value, DGtal::functors::Identity > MyRotatorSliceImageAdapter;
69 
70  bool res= true;
71  Image3D image = VolReader<Image3D>::importVol( filename );
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 
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 
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 
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 // //
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
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()
std::ostream & info()
double endBlock()
Special Point Functor that adds one dimension to a 2D point and apply on it a rotation of angle alpha...
DGtal::int32_t Integer
Definition: StdDefs.h:143
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Export a 2D and a 3D Image using the Netpbm PGM formats (ASCII mode).
Definition: PGMWriter.h:89
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
Aim: Define a simple default functor that just returns its argument.
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
void initAddOneDim(const Dimension &newDim)
void initRemoveOneDim(const Dimension &dimRemoved)
int main(int argc, char **argv)
bool testSliceImageFromFunctor()