DGtal  0.9.2
viewer3D-9-3Dimages.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/readers/GenericReader.h"
34 #include "DGtal/images/ImageHelper.h"
35 #include "DGtal/images/Image.h"
36 #include "ConfigExamples.h"
37 
38 #include "DGtal/helpers/StdDefs.h"
39 
40 #include "DGtal/io/viewers/Viewer3D.h"
41 #include "DGtal/io/DrawWithDisplay3DModifier.h"
42 #include "DGtal/io/colormaps/HueShadeColorMap.h"
43 #include "DGtal/io/Color.h"
44 
46 
47 using namespace std;
48 using namespace DGtal;
49 
50 
51 
52 struct hueFct{
53  inline
54  unsigned int operator() (unsigned int aVal) const
55  {
56  HueShadeColorMap<unsigned int> hueShade(0,255);
57  Color col = hueShade((unsigned int)aVal);
58  return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue());
59  }
60 };
61 
62 
64 
65 int main( int argc, char** argv )
66 {
67 
69  QApplication application(argc,argv);
70  typedef Viewer3D<> MyViewer ;
71  MyViewer viewer;
72 
73  viewer.show();
74  std::string inputFilename = examplesPath + "samples/lobster.vol";
75  Image3D imageVol = GenericReader<Image3D>::import(inputFilename);
76 
77  Z3i::Point ptLow (100, 100, 20);
78  Z3i::Point ptUpp (200, 200, 40);
79  Z3i::Domain subDomain(ptLow, ptUpp);
80 
81  Z3i::Point ptLow2 (220, 50, 10);
82  Z3i::Point ptUpp2 (260, 100, 20);
83  Z3i::Domain subDomain2(ptLow2, ptUpp2);
84 
85  Image3D imageCrop(subDomain);
86  Image3D imageCrop2(subDomain2);
87 
88  for(Z3i::Domain::ConstIterator it= imageVol.domain().begin(), itend = imageVol.domain().end(); it != itend; ++it){
89  if(imageVol(*it)>140)
90  viewer << *it;
91  Z3i::Point pt = *it;
92  if(pt[0]>=ptLow[0] && pt[1] >= ptLow[1] && pt[2] >= ptLow[2] &&
93  pt[0]<=ptUpp[0] && pt[1] <= ptUpp[1] && pt[2] <= ptUpp[2]){
94  imageCrop.setValue(*it, imageVol(*it));
95  }
96 
97  if(pt[0]>=ptLow2[0] && pt[1] >= ptLow2[1] && pt[2] >= ptLow2[2] &&
98  pt[0]<=ptUpp2[0] && pt[1] <= ptUpp2[1] && pt[2] <= ptUpp2[2]){
99  imageCrop2.setValue(*it, imageVol(*it));
100  }
101  }
102  viewer << imageCrop;
103  viewer << SetMode3D(imageCrop.className(), "BoundingBox");
105  viewer << AddTextureImage3DWithFunctor<Image3D, hueFct, Z3i::Space, Z3i::KSpace> (imageCrop2, hueFct(), MyViewer::RGBMode);
106  viewer << MyViewer::updateDisplay;
108 
109  return application.exec();
110 }
111 // //
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
STL namespace.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
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)
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)