DGtal  0.9.2
viewer3D-8-2DSliceImages.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/readers/VolReader.h"
34 #include "DGtal/images/ImageHelper.h"
35 #include "ConfigExamples.h"
36 #include "DGtal/io/viewers/Viewer3D.h"
37 
39 #include "DGtal/io/DrawWithDisplay3DModifier.h"
40 #include "DGtal/io/viewers/DrawWithViewer3DModifier.h"
41 #include "DGtal/io/colormaps/HueShadeColorMap.h"
42 #include "DGtal/io/Color.h"
44 
46 
47 using namespace std;
48 using namespace DGtal;
49 
51 struct hueFct{
52  inline
53  unsigned int operator() (unsigned char aVal) const
54  {
55  HueShadeColorMap<unsigned char> hueShade(0,255);
56  Color col = hueShade((unsigned char)aVal);
57  return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue());
58  }
59 };
62 
63 int main( int argc, char** argv )
64 {
65 
67  QApplication application(argc,argv);
68  typedef Viewer3D<> MyViewer;
69  MyViewer viewer;
70  viewer.show();
71  std::string inputFilename = examplesPath + "samples/lobster.vol";
72  Image3D imageVol = VolReader<Image3D>::importVol(inputFilename);
73 
74 
76  // Extracting the 2D images from the 3D one and from a given dimension.
77  // First image the teenth Z slice (dim=2)
79  Image3D::Value, DGtal::functors::Identity > MySliceImageAdapter;
80 
81  // Define the functor to recover a 2D domain from the 3D one in the Z direction (2):
82  DGtal::functors::Projector<DGtal::Z2i::Space> transTo2DdomainFunctorZ; transTo2DdomainFunctorZ.initRemoveOneDim(2);
83  DGtal::Z2i::Domain domain2DZ(transTo2DdomainFunctorZ(imageVol.domain().lowerBound()),
84  transTo2DdomainFunctorZ(imageVol.domain().upperBound()));
85 
86  // Define the functor to associate 2D coordinates to the 3D one by giving the direction Z (2) and the slide numnber (10):
87  DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctorZ(10); aSliceFunctorZ.initAddOneDim(2);
88 
89  // We can now obtain the slice image (a ConstImageAdapter):
90  const auto identityFunctor = DGtal::functors::Identity();
91  MySliceImageAdapter aSliceImageZ(imageVol, domain2DZ, aSliceFunctorZ, identityFunctor );
92 
93  // Second image the fiftieth Y slice (dim=1)
94  // Define the functor to recover a 2D domain from the 3D one in the Y direction (1):
95  DGtal::functors::Projector<DGtal::Z2i::Space> transTo2DdomainFunctorY; transTo2DdomainFunctorY.initRemoveOneDim(1);
96  DGtal::Z2i::Domain domain2DY(transTo2DdomainFunctorY(imageVol.domain().lowerBound()),
97  transTo2DdomainFunctorY(imageVol.domain().upperBound()));
98 
99  // Define the functor to associate 2D coordinates to the 3D one by giving the direction Y (1) and the slide numnber (50):
100  DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctorY(50); aSliceFunctorY.initAddOneDim(1);
101 
102  // We can now obtain the slice image (a ConstImageAdapter):
103  MySliceImageAdapter aSliceImageY(imageVol, domain2DY, aSliceFunctorY, identityFunctor );
105 
107  viewer << SetMode3D(aSliceImageZ.className(), "BoundingBox");
108  viewer << MyViewer::updateDisplay;
110 
112  viewer << aSliceImageZ;
113  viewer << aSliceImageY;
115 
116  viewer << SetMode3D(aSliceImageZ.className(), "");
118  viewer << AddTextureImage2DWithFunctor<MySliceImageAdapter, hueFct, Z3i::Space, Z3i::KSpace> (aSliceImageZ, hueFct(), Viewer3D<Z3i::Space, Z3i::KSpace>::RGBMode);
119  viewer << AddTextureImage2DWithFunctor<MySliceImageAdapter, hueFct, Z3i::Space, Z3i::KSpace> (aSliceImageY, hueFct(), Viewer3D<Z3i::Space, Z3i::KSpace>::RGBMode);
121 
122 
124  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(1, MyViewer::yDirection, 0.0, 50.0, 0.0);
125  viewer << DGtal::UpdateImageData<MySliceImageAdapter>(0, aSliceImageZ, 0, 0, 10);
126  viewer << MyViewer::updateDisplay;
128 
129 
131  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(3, MyViewer::yDirection, 500.0, 50.0, 0.0);
132  viewer << DGtal::UpdateImageData<MySliceImageAdapter, hueFct>(2, aSliceImageZ, 500, 0, 10, 0.0, MyViewer::zDirection, hueFct());
133  viewer << MyViewer::updateDisplay;
135 
136 return application.exec();
137 
138  trace.endBlock();
139  return 0;
140 }
141 // //
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.
double endBlock()
void initRemoveOneDim(const Dimension &dimRemoved)
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: 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.
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void green(const unsigned char aGreenValue)
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
void red(const unsigned char aRedValue)
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.
void blue(const unsigned char aBlueValue)