DGtal  1.3.beta
io/viewers/viewer3D-8-2DSliceImages.cpp
Illustration of the 2D image slice visualization.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/ImageHelper.h"
#include "ConfigExamples.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/DrawWithViewer3DModifier.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/Color.h"
using namespace std;
using namespace DGtal;
struct hueFct{
inline
unsigned int operator() (unsigned char aVal) const
{
Color col = hueShade((unsigned char)aVal);
return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue());
}
};
int main( int argc, char** argv )
{
QApplication application(argc,argv);
MyViewer viewer;
viewer.show();
std::string inputFilename = examplesPath + "samples/lobster.vol";
Image3D imageVol = VolReader<Image3D>::importVol(inputFilename);
// Extracting the 2D images from the 3D one and from a given dimension.
// First image the teenth Z slice (dim=2)
Image3D::Value, DGtal::functors::Identity > MySliceImageAdapter;
// Define the functor to recover a 2D domain from the 3D one in the Z direction (2):
DGtal::functors::Projector<DGtal::Z2i::Space> transTo2DdomainFunctorZ; transTo2DdomainFunctorZ.initRemoveOneDim(2);
DGtal::Z2i::Domain domain2DZ(transTo2DdomainFunctorZ(imageVol.domain().lowerBound()),
transTo2DdomainFunctorZ(imageVol.domain().upperBound()));
// Define the functor to associate 2D coordinates to the 3D one by giving the direction Z (2) and the slide numnber (10):
DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctorZ(10); aSliceFunctorZ.initAddOneDim(2);
// We can now obtain the slice image (a ConstImageAdapter):
const auto identityFunctor = DGtal::functors::Identity();
MySliceImageAdapter aSliceImageZ(imageVol, domain2DZ, aSliceFunctorZ, identityFunctor );
// Second image the fiftieth Y slice (dim=1)
// Define the functor to recover a 2D domain from the 3D one in the Y direction (1):
DGtal::functors::Projector<DGtal::Z2i::Space> transTo2DdomainFunctorY; transTo2DdomainFunctorY.initRemoveOneDim(1);
DGtal::Z2i::Domain domain2DY(transTo2DdomainFunctorY(imageVol.domain().lowerBound()),
transTo2DdomainFunctorY(imageVol.domain().upperBound()));
// Define the functor to associate 2D coordinates to the 3D one by giving the direction Y (1) and the slide numnber (50):
DGtal::functors::Projector<DGtal::Z3i::Space> aSliceFunctorY(50); aSliceFunctorY.initAddOneDim(1);
// We can now obtain the slice image (a ConstImageAdapter):
MySliceImageAdapter aSliceImageY(imageVol, domain2DY, aSliceFunctorY, identityFunctor );
viewer << SetMode3D(aSliceImageZ.className(), "BoundingBox");
viewer << aSliceImageZ;
viewer << aSliceImageY;
viewer << SetMode3D(aSliceImageZ.className(), "");
viewer << AddTextureImage2DWithFunctor<MySliceImageAdapter, hueFct, Z3i::Space, Z3i::KSpace> (aSliceImageZ, hueFct(), Viewer3D<Z3i::Space, Z3i::KSpace>::RGBMode);
viewer << AddTextureImage2DWithFunctor<MySliceImageAdapter, hueFct, Z3i::Space, Z3i::KSpace> (aSliceImageY, hueFct(), Viewer3D<Z3i::Space, Z3i::KSpace>::RGBMode);
viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(1, MyViewer::yDirection, 0.0, 50.0, 0.0);
viewer << DGtal::UpdateImageData<MySliceImageAdapter>(0, aSliceImageZ, 0, 0, 10);
viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(3, MyViewer::yDirection, 500.0, 50.0, 0.0);
viewer << DGtal::UpdateImageData<MySliceImageAdapter, hueFct>(2, aSliceImageZ, 500, 0, 10, 0.0, MyViewer::zDirection, hueFct());
return application.exec();
}
// //
DGtal::functors::Projector
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Definition: BasicPointFunctors.h:106
DGtal::HyperRectDomain< Space >
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::functors::Projector::initRemoveOneDim
void initRemoveOneDim(const Dimension &dimRemoved)
DGtal::HueShadeColorMap< unsigned char >
DGtal::Display3D::updateDisplay
@ updateDisplay
Definition: Display3D.h:249
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition: BasicFunctors.h:287
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition: ConstImageAdapter.h:105
DGtal::Viewer3D< Space, KSpace >::yDirection
@ yDirection
Definition: Viewer3D.h:474
DGtal::Viewer3D< Space, KSpace >::zDirection
@ zDirection
Definition: Viewer3D.h:474
DGtal::Color::red
void red(const unsigned char aRedValue)
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Color::green
void green(const unsigned char aGreenValue)
DGtal::Color::blue
void blue(const unsigned char aBlueValue)
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38