DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
3dVolViewer.cpp
1 
29 
30 #include <iostream>
31 #include <QtGui/qapplication.h>
32 
33 #include "DGtal/base/Common.h"
34 #include "DGtal/io/readers/VolReader.h"
35 #include "DGtal/io/viewers/Viewer3D.h"
36 #include "DGtal/io/DrawWithDisplay3DModifier.h"
37 
38 #include "DGtal/io/Color.h"
39 #include "DGtal/io/colormaps/GradientColorMap.h"
40 #include "DGtal/images/ImageSelector.h"
41 
42 
43 #include <boost/program_options/options_description.hpp>
44 #include <boost/program_options/parsers.hpp>
45 #include <boost/program_options/variables_map.hpp>
46 
47 using namespace std;
48 using namespace DGtal;
49 using namespace Z3i;
50 
52 namespace po = boost::program_options;
53 
54 int main( int argc, char** argv )
55 {
56  // parse command line ----------------------------------------------
57  po::options_description general_opt("Allowed options are: ");
58  general_opt.add_options()
59  ("help,h", "display this message")
60  ("input-file,i", po::value<std::string>(), "volume file" )
61  ("thresholdMin,m", po::value<int>()->default_value(0), "threshold min to define binary shape" )
62  ("thresholdMax,M", po::value<int>()->default_value(255), "threshold max to define binary shape" )
63  ("transparency,t", po::value<uint>()->default_value(255), "transparency") ;
64  po::variables_map vm;
65  po::store(po::parse_command_line(argc, argv, general_opt), vm);
66  po::notify(vm);
67  if(vm.count("help")||argc<=1)
68  {
69  std::cout << "Usage: " << argv[0] << " [input-file]\n"
70  << "Display volume file as a voxel set by using QGLviewer"
71  << general_opt << "\n";
72  return 0;
73  }
74 
75  if(! vm.count("input-file"))
76  {
77  trace.error() << " The file name was defined" << endl;
78  return 0;
79  }
80  string inputFilename = vm["input-file"].as<std::string>();
81  int thresholdMin = vm["thresholdMin"].as<int>();
82  int thresholdMax = vm["thresholdMax"].as<int>();
83  unsigned char transp = vm["transparency"].as<uint>();
84 
85  QApplication application(argc,argv);
86  Viewer3D viewer;
87  viewer.setWindowTitle("simple Volume Viewer");
88  viewer.show();
89 
91  Image image = VolReader<Image>::importVol( inputFilename );
92 
93  trace.info() << "Image loaded: "<<image<< std::endl;
94 
95  Domain domain = image.domain();
96  GradientColorMap<long> gradient( thresholdMin, thresholdMax);
97  gradient.addColor(Color::Blue);
98  gradient.addColor(Color::Green);
99  gradient.addColor(Color::Yellow);
100  gradient.addColor(Color::Red);
101  for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
102  unsigned char val= image( (*it) );
103 
104  Color c= gradient(val);
105  if(val<=thresholdMax && val >=thresholdMin){
106  viewer << CustomColors3D(Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp),
107  Color((float)(c.red()), (float)(c.green()),(float)(c.blue()), transp));
108  viewer << *it;
109  }
110  }
111  viewer << Viewer3D::updateDisplay;
112  return application.exec();
113 }