32 #include "DGtal/base/Common.h"    33 #include "DGtal/base/BasicFunctors.h"    34 #include "DGtal/helpers/StdDefs.h"    35 #include "DGtal/io/readers/GenericReader.h"    37 #include "DGtal/io/readers/DicomReader.h"    39 #include "DGtal/io/viewers/Viewer3D.h"    40 #include "DGtal/io/DrawWithDisplay3DModifier.h"    41 #include "DGtal/io/readers/PointListReader.h"    43 #include "DGtal/io/Color.h"    44 #include "DGtal/io/colormaps/GradientColorMap.h"    45 #include "DGtal/images/ImageSelector.h"    47 #include <boost/program_options/options_description.hpp>    48 #include <boost/program_options/parsers.hpp>    49 #include <boost/program_options/variables_map.hpp>    52 using namespace DGtal;
   104 namespace po = boost::program_options;
   107 int main( 
int argc, 
char** argv )
   110   po::options_description general_opt(
"Allowed options are: ");
   111   general_opt.add_options()
   112     (
"help,h", 
"display this message")
   113     (
"input,i", po::value<std::string>(), 
"vol file (.vol) , pgm3d (.p3d or .pgm3d, pgm (with 3 dims)) file or sdp (sequence of discrete points)" )
   114     (
"thresholdMin,m",  po::value<int>()->default_value(0), 
"threshold min to define binary shape" )
   115     (
"thresholdMax,M",  po::value<int>()->default_value(255), 
"threshold max to define binary shape" )
   116     (
"numMaxVoxel,n",  po::value<int>()->default_value(500000), 
"set the maximal voxel number to be displayed." )
   118     (
"dicomMin", po::value<int>()->default_value(-1000), 
"set minimum density threshold on Hounsfield scale")
   119     (
"dicomMax", po::value<int>()->default_value(3000), 
"set maximum density threshold on Hounsfield scale")
   121     (
"transparency,t",  po::value<uint>()->default_value(255), 
"transparency") ;
   124   po::variables_map vm;
   126     po::store(po::parse_command_line(argc, argv, general_opt), vm);
   127   }
catch(
const std::exception& ex){
   129     trace.info()<< 
"Error checking program options: "<< ex.what()<< endl;
   132   if( !parseOK || vm.count(
"help")||argc<=1)
   134       std::cout << 
"Usage: " << argv[0] << 
" [input]\n"   135                 << 
"Display volume file as a voxel set by using QGLviewer"<< endl
   136                 << general_opt << 
"\n"   137                 << 
"Example: "<< std::endl
   138                 << 
"    \t 3dVolViewer -i $DGtal/examples/samples/lobster.vol -m 60 -t 10" << endl;
   142   if(! vm.count(
"input"))
   144       trace.error() << 
" The file name was defined" << endl;
   147   string inputFilename = vm[
"input"].as<std::string>();
   148   int thresholdMin = vm[
"thresholdMin"].as<
int>();
   149   int thresholdMax = vm[
"thresholdMax"].as<
int>();
   150   unsigned char transp = vm[
"transparency"].as<uint>();
   152   bool limitDisplay=
false;
   153   if(vm.count(
"numMaxVoxel")){
   156   unsigned int numDisplayedMax = vm[
"numMaxVoxel"].as<
int>();
   159   QApplication application(argc,argv);
   161   viewer.setWindowTitle(
"simple Volume Viewer");
   164   typedef ImageSelector<Domain, unsigned char>::Type Image;
   165   string extension = inputFilename.substr(inputFilename.find_last_of(
".") + 1);
   166   if(extension!=
"vol" && extension != 
"p3d" && extension != 
"pgm3D" && extension != 
"pgm3d" && extension != 
"sdp" && extension != 
"pgm"   171     trace.info() << 
"File extension not recognized: "<< extension << std::endl;
   175   if(extension==
"vol" || extension==
"pgm3d" || extension==
"pgm3D"   180     unsigned int numDisplayed=0;
   183    int dicomMin = vm[
"dicomMin"].as<
int>();
   184    int dicomMax = vm[
"dicomMax"].as<
int>();
   185    typedef DGtal::functors::Rescaling<int ,unsigned char > RescalFCT;
   186    Image image = extension == 
"dcm" ? DicomReader< Image,  RescalFCT  >::importDicom( inputFilename,
   190      GenericReader<Image>::import( inputFilename );
   192    Image image = GenericReader<Image>::import (inputFilename );
   195     trace.info() << 
"Image loaded: "<<image<< std::endl;
   196     Domain domain = image.domain();
   197     GradientColorMap<long> gradient( thresholdMin, thresholdMax);
   198     gradient.addColor(Color::Blue);
   199     gradient.addColor(Color::Green);
   200     gradient.addColor(Color::Yellow);
   201     gradient.addColor(Color::Red);
   202     for(Domain::ConstIterator it = domain.begin(), itend=domain.end(); it!=itend; ++it){
   203       unsigned char  val= image( (*it) );
   204       if(limitDisplay && numDisplayed > numDisplayedMax)
   206       Color c= gradient(val);
   207       if(val<=thresholdMax && val >=thresholdMin){
   208   viewer <<  CustomColors3D(Color((
float)(c.red()), (
float)(c.green()),(
float)(c.blue()), transp),
   209           Color((
float)(c.red()), (
float)(c.green()),(
float)(c.blue()), transp));
   214   }
else if(extension==
"sdp"){
   215     vector<Z3i::RealPoint> vectVoxels = PointListReader<Z3i::RealPoint>::getPointsFromFile(inputFilename);
   216     for(
unsigned int i=0;i< vectVoxels.size(); i++){
   217       viewer << vectVoxels.at(i);
   220   viewer << Viewer3D<>::updateDisplay;
   221   return application.exec();