DGtal  0.9.2
test3DImageView.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/viewers/Viewer3D.h"
34 #include "DGtal/io/viewers/DrawWithViewer3DModifier.h"
35 #include "DGtal/io/Color.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/shapes/Shapes.h"
38 #include "DGtal/io/readers/PGMReader.h"
39 #include "DGtal/io/readers/GenericReader.h"
40 #include "DGtal/io/writers/GenericWriter.h"
41 #include "DGtal/io/colormaps/BasicColorToScalarFunctors.h"
42 #include "DGtal/math/BasicMathFunctions.h"
43 #include "DGtal/io/colormaps/HueShadeColorMap.h"
44 
45 #include "ConfigTest.h"
46 
47 #include <limits>
49 
50 using namespace std;
51 using namespace DGtal;
52 using namespace Z3i;
53 
54 
55 
56 
58 // Functions for testing class Viewer3D.
60 
64 bool testViewer3D()
65 {
66  unsigned int nbok = 0;
67  unsigned int nb = 0;
68  trace.beginBlock ( "Testing block ..." );
69  nbok += true ? 1 : 0;
70  nb++;
71  trace.info() << "(" << nbok << "/" << nb << ") "
72  << "true == true" << std::endl;
73  trace.endBlock();
74 
75  return nbok == nb;
76 }
77 
78 struct hueFct{
79  inline
80  unsigned int operator() (unsigned char aVal) const
81  {
82  HueShadeColorMap<unsigned int> hueShade(0,255);
83  Color col = hueShade((unsigned int)aVal);
84  return col.getRGB();
85  }
86 };
87 
89 // Standard services - public :
90 
91 int main( int argc, char** argv )
92 {
95 
96  QApplication application(argc,argv);
97  Viewer3D<> viewer;
98  viewer.setWindowTitle("simpleViewer");
99  viewer.show();
100  trace.beginBlock("Testing Viewer with 3D Image View ");
101 
102  Point p1( 0, 0, 0 );
103  Point p2( 125, 188, 0 );
104  Point p3( 30, 30, 30 );
105 
106  std::string filename = testPath + "samples/church-small.pgm";
107  std::string filename3 = testPath + "samples/color64.ppm";
108 
109  imageNG image = DGtal::PGMReader<imageNG>::importPGM(filename);
110  imageNG image2 = DGtal::GenericReader<imageNG>::import(filename);
111  imageCol image3 = DGtal::GenericReader<imageCol>::import(filename3);
112  hueFct huefct;
113  functors::Identity defaultfunctor;
114 
115  viewer << DGtal::AddTextureImage2DWithFunctor<imageNG, hueFct , Z3i::Space, Z3i::KSpace>(image2, huefct, Viewer3D<>::RGBMode );
116  viewer << image;
117  viewer << DGtal::AddTextureImage2DWithFunctor<imageCol, functors::Identity, Z3i::Space, Z3i::KSpace>(image3, defaultfunctor, Viewer3D<>::RGBMode );
118  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(0, Viewer3D<>::xDirection, 50, 50, 50 );
119  viewer << DGtal::UpdateImagePosition<Z3i::Space, Z3i::KSpace>(2, Viewer3D<>::yDirection, 0, 0, 0);
120 
121  viewer << SetMode3D( image.domain().className(), "BoundingBox" );
122  viewer << image.domain();
123  viewer << DGtal::Update2DDomainPosition<Z3i::Space, Z3i::KSpace>(0, Viewer3D<>::xDirection, 0, 0, 0);
124  for(unsigned int i= 0; i< 10; i++){
125  if(i%4==0){
126  viewer << SetMode3D( image.className(), "" );
127  }else if(i%4==1){
128  viewer << SetMode3D( image.className(), "BoundingBox" );
129  }else if(i%4==2){
130  viewer << SetMode3D( image.className(), "Grid" );
131  }else if(i%4==3){
132  viewer << SetMode3D( image.className(), "InterGrid" );
133  }
134  viewer << image;
135  viewer << DGtal::UpdateImageData<imageNG>(i+3, image, i*50, i*50, i*50);
136  }
137 
138 
139  viewer << p1 << p2 << p3;
140  viewer << Viewer3D<>::updateDisplay;
141 
142 
143  bool res = application.exec();
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  trace.endBlock();
146  return res ? 0 : 1;
147 
148 
149 }
150 // //
152 
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.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
Aim: Define a simple default functor that just returns its argument.
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
std::ostream & emphase()
DGtal::uint32_t getRGB() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.