DGtal  0.9.3
test3DImage3DView.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/viewers/Viewer3D.h"
34 #include "DGtal/io/DrawWithDisplay3DModifier.h"
35 #include "DGtal/io/Color.h"
36 #include "DGtal/io/readers/VolReader.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/shapes/Shapes.h"
39 #include "DGtal/math/BasicMathFunctions.h"
40 #include "ConfigTest.h"
41 #include "DGtal/io/colormaps/HueShadeColorMap.h"
42 
43 
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace Z3i;
49 
50 
51 
53 // Functions for testing class Viewer3D.
55 
60 {
61  unsigned int nbok = 0;
62  unsigned int nb = 0;
63  trace.beginBlock ( "Testing block ..." );
64  nbok += true ? 1 : 0;
65  nb++;
66  trace.info() << "(" << nbok << "/" << nb << ") "
67  << "true == true" << std::endl;
68  trace.endBlock();
69 
70  return nbok == nb;
71 }
72 
73 struct hueFct{
74 inline
75  unsigned int operator() (unsigned int aVal) const
76  {
77  HueShadeColorMap<unsigned int> hueShade(0,255);
78  DGtal::Color col = hueShade(aVal);
79  return col.getRGB();
80  }
81 };
83 // Standard services - public :
84 
85 int main( int argc, char** argv )
86 {
88 
89  QApplication application(argc,argv);
90  Viewer3D<> viewer;
91  viewer.setWindowTitle("simpleViewer");
92  viewer.show();
93  trace.beginBlock("Testing Viewer with display of 3D Image ");
94 
95  Point p1( 0, 0, 0 );
96  Point p2( 125, 188, 0 );
97  Point p3( 30, 30, 30 );
98 
99  std::string filename = testPath + "samples/lobsterCroped.vol";
100  hueFct huefct;
101 
102  viewer.setFillTransparency(150);
103  Image3D image3d = VolReader<Image3D>::importVol(filename);
104  viewer << SetMode3D(image3d.className(), "BoundingBox");
105 
106  viewer << DGtal::AddTextureImage3DWithFunctor<Image3D, hueFct , Space, KSpace>(image3d, huefct, Viewer3D<>::RGBMode );
107  viewer.setFillTransparency(255);
108  // Extract some slice images:
109  // Get the 2D domain of the slice:
111  DGtal::Z2i::Domain domain2D(invFunctor(image3d.domain().lowerBound()),
112  invFunctor(image3d.domain().upperBound()));
113 
115  Image3D::Value, functors::Identity > SliceImageAdapter;
116  functors::Identity idV;
117  functors::Projector<DGtal::Z3i::Space> aSliceFunctorZ(5); aSliceFunctorZ.initAddOneDim(2);
118 
119  SliceImageAdapter sliceImageZ(image3d, domain2D, aSliceFunctorZ, idV);
120 
121  viewer << sliceImageZ;
122  viewer << DGtal::UpdateImagePosition<Space, KSpace>(6, Viewer3D<>::zDirection, 0.0, 0.0, -10.0);
123 
124  viewer << p1 << p2 << p3;
125  viewer << Viewer3D<>::updateDisplay;
126 
127 
128  bool res = application.exec();
129  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
130  trace.endBlock();
131  return res ? 0 : 1;
132 
133 
134 }
135 // //
137 
void beginBlock(const std::string &keyword="")
virtual void setFillTransparency(unsigned char alpha)
Trace trace
Definition: Common.h:137
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()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
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.
bool testViewer3D()
std::ostream & emphase()
DGtal::uint32_t getRGB() const
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
void initAddOneDim(const Dimension &newDim)
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
int main(int argc, char **argv)
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.