DGtal  1.5.beta
viewer3D-9-3Dimages.cpp
Go to the documentation of this file.
1 
41 #include <iostream>
42 #include "DGtal/base/Common.h"
43 #include "DGtal/io/readers/GenericReader.h"
44 #include "DGtal/images/ImageHelper.h"
45 #include "DGtal/images/Image.h"
46 #include "ConfigExamples.h"
47 
48 #include "DGtal/helpers/StdDefs.h"
49 
50 #include "DGtal/io/viewers/Viewer3D.h"
51 #include "DGtal/io/DrawWithDisplay3DModifier.h"
52 #include "DGtal/io/colormaps/HueShadeColorMap.h"
53 #include "DGtal/io/Color.h"
54 
56 
57 using namespace std;
58 using namespace DGtal;
59 
60 
61 
62 struct hueFct{
63  inline
64  unsigned int operator() (unsigned int aVal) const
65  {
66  HueShadeColorMap<unsigned int> hueShade(0,255);
67  Color col = hueShade((unsigned int)aVal);
68  return (((unsigned int) col.red()) << 16)| (((unsigned int) col.green()) << 8)|((unsigned int) col.blue());
69  }
70 };
71 
72 
74 
75 int main( int argc, char** argv )
76 {
77 
79  QApplication application(argc,argv);
80  typedef Viewer3D<> MyViewer ;
81  MyViewer viewer;
82 
83  viewer.show();
84  std::string inputFilename = examplesPath + "samples/lobster.vol";
85  Image3D imageVol = GenericReader<Image3D>::import(inputFilename);
86 
87  Z3i::Point ptLow (100, 100, 20);
88  Z3i::Point ptUpp (200, 200, 40);
89  Z3i::Domain subDomain(ptLow, ptUpp);
90 
91  Z3i::Point ptLow2 (220, 50, 10);
92  Z3i::Point ptUpp2 (260, 100, 20);
93  Z3i::Domain subDomain2(ptLow2, ptUpp2);
94 
95  Image3D imageCrop(subDomain);
96  Image3D imageCrop2(subDomain2);
97 
98  for(Z3i::Domain::ConstIterator it= imageVol.domain().begin(), itend = imageVol.domain().end(); it != itend; ++it){
99  if(imageVol(*it)>140)
100  viewer << *it;
101  Z3i::Point pt = *it;
102  if(pt[0]>=ptLow[0] && pt[1] >= ptLow[1] && pt[2] >= ptLow[2] &&
103  pt[0]<=ptUpp[0] && pt[1] <= ptUpp[1] && pt[2] <= ptUpp[2]){
104  imageCrop.setValue(*it, imageVol(*it));
105  }
106 
107  if(pt[0]>=ptLow2[0] && pt[1] >= ptLow2[1] && pt[2] >= ptLow2[2] &&
108  pt[0]<=ptUpp2[0] && pt[1] <= ptUpp2[1] && pt[2] <= ptUpp2[2]){
109  imageCrop2.setValue(*it, imageVol(*it));
110  }
111  }
112  viewer << imageCrop;
113  viewer << SetMode3D(imageCrop.className(), "BoundingBox");
115  viewer << AddTextureImage3DWithFunctor<Image3D, hueFct, Z3i::Space, Z3i::KSpace> (imageCrop2, hueFct(), MyViewer::RGBMode);
116  viewer << MyViewer::updateDisplay;
118 
119  return application.exec();
120 }
121 // //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Iterator for HyperRectDomain.
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
int main(int argc, char **argv)