DGtal  0.9.2
extract2DImagesFrom3DandVisu.cpp
1 
30 #include <iostream>
32 #include <sstream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/images/ImageHelper.h"
36 #include "DGtal/io/readers/VolReader.h"
37 #include "DGtal/images/ImageSelector.h"
38 #include "DGtal/images/ConstImageAdapter.h"
39 #include "ConfigExamples.h"
40 #include "DGtal/io/viewers/Viewer3D.h"
41 #include "DGtal/kernel/BasicPointFunctors.h"
43 
44 using namespace std;
45 using namespace DGtal;
46 
47 
49 
50 int main( int argc, char** argv )
51 {
52 
53 
54  QApplication application(argc,argv);
55  Viewer3D<> viewer;
56  viewer.setWindowTitle("simpleViewer");
57  viewer.show();
58 
59 
63  Image3D::Value, DGtal::functors::Identity > SliceImageAdapter;
64 
66  Image3D::Value, DGtal::functors::Identity > ImageAdapterExtractor;
67 
69  // Importing a 3D image
70  std::string filename = examplesPath + "samples/lobster.vol";
71  Image3D image = VolReader<Image3D>::importVol( filename );
72 
73  DGtal::Z2i::Domain domain(invFunctor(image.domain().lowerBound()),
74  invFunctor(image.domain().upperBound()));
76 
77  trace.beginBlock ( "Example extract2DImagesFrom3D" );
78 
79  // Extracting 2D slices ... and visualisation on 3DViewer
80  unsigned int pos=0;
81  for (unsigned int i=0; i<30; i+=5){
82  DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor(i); aSliceFunctor.initAddOneDim(2);
83  SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
84  viewer << sliceImageZ;
85  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(pos, Viewer3D<>::zDirection, i*20, i*20, i*20 );
86  pos++;
87  }
88 
89  // Visu extraction from points
90  const int IMAGE_PATCH_WIDTH = 40;
91 
92 
93  DGtal::Z3i::Point ptCenter(155, 155, 20);
94  DGtal::Z2i::Domain domainImage2D (DGtal::Z2i::Point(0,0),
95  DGtal::Z2i::Point(IMAGE_PATCH_WIDTH, IMAGE_PATCH_WIDTH));
96 
97 
98  DGtal::functors::Point2DEmbedderIn3D<DGtal::Z3i::Domain > embedder(image.domain(), ptCenter,
99  DGtal::Z3i::RealPoint(1,-1,1),
100  IMAGE_PATCH_WIDTH);
101 
102  ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
103  viewer << extractedImage;
104  viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(pos,
105  embedder(Z2i::Point(0,0)),
106  embedder(Z2i::Point(IMAGE_PATCH_WIDTH,0)),
107  embedder(domainImage2D.upperBound()),
108  embedder(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH)));
109 
110 
111 
112  viewer << DGtal::Viewer3D<>::updateDisplay;
113 
114 
115  application.exec();
116  return 0;
117 }
118 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
STL namespace.
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Aim: Define a simple default functor that just returns its argument.
Aim: Functor that embeds a 2D point into a 3D space from two axis vectors and an origin point given i...
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Space::RealPoint RealPoint
Definition: StdDefs.h:170