29 #include <DGtal/base/Common.h>
30 #include <DGtal/helpers/StdDefs.h>
31 #include <DGtal/io/readers/LongvolReader.h>
32 #include <DGtal/io/writers/VolWriter.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 #include <DGtal/base/BasicFunctors.h>
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
40 using namespace DGtal;
43 namespace po = boost::program_options;
77 template<
typename TInput>
79 unsigned char operator()(
const TInput& aInput)
const
95 myMin(vmin), myMax(vmax) {}
97 inline unsigned char operator()(
const DGtal::int64_t& aInput)
const
100 (double) (myMax-myMin)));
113 void missingParam ( std::string param )
115 trace.
error() <<
" Parameter: "<<param<<
" is required..";
120 int main(
int argc,
char**argv)
124 po::options_description general_opt (
"Allowed options are: " );
125 general_opt.add_options()
126 (
"help,h",
"display this message." )
127 (
"input,i", po::value<std::string>(),
"Input longvol filename." )
128 (
"output,o", po::value<std::string>(),
"Output vole filename." )
129 (
"mode,m", po::value<unsigned int>()->default_value(0),
"Conversion mode:\n\t 0 = cast (default)\n\t 1 = Linear Scaling\n\t 2 = Grayscale cycle (32 steps, except 0 values)." )
132 po::variables_map vm;
134 po::store(po::parse_command_line(argc, argv, general_opt), vm);
135 }
catch(
const std::exception& ex){
137 trace.
info()<<
"Error checking program options: "<< ex.what()<< std::endl;
140 if (!parseOK || vm.count (
"help" ) ||argc<=1 )
142 trace.
info() <<
"Converts a longvol (long int) to a vol file (unsigned char)."<<std::endl
143 << std::endl <<
"Basic usage: "<<std::endl
144 <<
"\tlongvol2vol --input <LongvolFileName> --o <VolOutputFileName> "<<std::endl
145 << general_opt <<
"\n";
150 if ( ! ( vm.count (
"input" ) ) ) missingParam (
"--input" );
151 std::string filename = vm[
"input"].as<std::string>();
152 if ( ! ( vm.count (
"output" ) ) ) missingParam (
"--output" );
153 std::string outputFileName = vm[
"output"].as<std::string>();
154 unsigned int mode = vm[
"mode"].as<
unsigned int>();
168 vmax = *std::max_element(imageC.begin(), imageC.end());
169 vmin = *std::min_element(imageC.begin(), imageC.end());
170 trace.
info() <<
"Max value = "<< vmax<<std::endl;
171 trace.
info() <<
"Min value = "<< vmin<<std::endl;
181 trace.
error()<<
"Error while exporting the Vol.";
static double castToDouble(const T &aT)
static DGtal::int64_t castToInt64_t(const T &aT)
static ImageContainer importLongvol(const std::string &filename, const Functor &aFunctor=Functor())
Trace trace(traceWriterTerm)
static bool exportVol(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor())