DGtal  1.5.beta
extract2DImagesFrom3DandVisu.cpp
Go to the documentation of this file.
1 
42 #include <iostream>
43 #include <sstream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/helpers/StdDefs.h"
46 #include "DGtal/images/ImageHelper.h"
47 #include "DGtal/io/readers/VolReader.h"
48 #include "DGtal/images/ImageSelector.h"
49 #include "DGtal/images/ConstImageAdapter.h"
50 #include "ConfigExamples.h"
51 #include "DGtal/io/viewers/Viewer3D.h"
52 #include "DGtal/kernel/BasicPointFunctors.h"
54 
55 using namespace std;
56 using namespace DGtal;
57 
58 
60 
61 int main( int argc, char** argv )
62 {
63 
64 
65  QApplication application(argc,argv);
66  Viewer3D<> viewer;
67  viewer.setWindowTitle("simpleViewer");
68  viewer.show();
69 
70 
74  Image3D::Value, DGtal::functors::Identity > SliceImageAdapter;
75 
77  Image3D::Value, DGtal::functors::Identity > ImageAdapterExtractor;
78 
80  // Importing a 3D image
81  std::string filename = examplesPath + "samples/lobster.vol";
82  Image3D image = VolReader<Image3D>::importVol( filename );
83 
84  DGtal::Z2i::Domain domain(invFunctor(image.domain().lowerBound()),
85  invFunctor(image.domain().upperBound()));
87 
88  trace.beginBlock ( "Example extract2DImagesFrom3D" );
89 
90  // Extracting 2D slices ... and visualisation on 3DViewer
91  unsigned int pos=0;
92  for (unsigned int i=0; i<30; i+=5){
93  DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctor(i); aSliceFunctor.initAddOneDim(2);
94  SliceImageAdapter sliceImageZ(image, domain, aSliceFunctor, idV);
95  viewer << sliceImageZ;
96  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(pos, Viewer3D<>::zDirection, i*20, i*20, i*20 );
97  pos++;
98  }
99 
100  // Visu extraction from points
101  const int IMAGE_PATCH_WIDTH = 40;
102 
103 
104  DGtal::Z3i::Point ptCenter(155, 155, 20);
105  DGtal::Z2i::Domain domainImage2D (DGtal::Z2i::Point(0,0),
107 
108 
109  DGtal::functors::Point2DEmbedderIn3D<DGtal::Z3i::Domain > embedder(image.domain(), ptCenter,
110  DGtal::Z3i::RealPoint(1,-1,1),
112 
113  ImageAdapterExtractor extractedImage(image, domainImage2D, embedder, idV);
114  viewer << extractedImage;
115  viewer << DGtal::UpdateImage3DEmbedding<Z3i::Space, Z3i::KSpace>(pos,
116  embedder(Z2i::Point(0,0)),
117  embedder(Z2i::Point(IMAGE_PATCH_WIDTH,0)),
118  embedder(domainImage2D.upperBound()),
119  embedder(Z2i::RealPoint(0, IMAGE_PATCH_WIDTH)));
120 
121 
122 
123  viewer << DGtal::Viewer3D<>::updateDisplay;
124 
125 
126  application.exec();
127  return 0;
128 }
129 // //
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
const Point & upperBound() const
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Aim: Functor that embeds a 2D point into a 3D space from two axis vectors and an origin point given i...
const int IMAGE_PATCH_WIDTH
int main(int argc, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
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)
Domain domain