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 84 return static_cast<unsigned char>(1+NumberTraits<TInput>::castToInt64_t(aInput) % 32);
94 LinearFunctor(
const DGtal::uint64_t vmax,
const DGtal::uint64_t vmin):
95 myMin(vmin), myMax(vmax) {}
97 inline unsigned char operator()(
const DGtal::int64_t& aInput)
const 99 return static_cast<unsigned char>( (NumberTraits<DGtal::uint64_t>::castToDouble(aInput - myMin)*255.0 /
100 (double) (myMax-myMin)));
103 DGtal::uint64_t myMin,myMax;
113 void missingParam ( std::string param )
115 trace.error() <<
" Parameter: "<<param<<
" is required..";
116 trace.info() <<std::endl;
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>();
158 typedef ImageContainerBySTLVector<Z3i::Domain, DGtal::uint64_t> MyImageC;
159 MyImageC imageC = LongvolReader< MyImageC >::importLongvol ( filename );
163 res = VolWriter< MyImageC, functors::Cast<unsigned char> >::exportVol(outputFileName, imageC);
167 DGtal::uint64_t vmax, vmin;
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;
172 res = VolWriter<MyImageC , LinearFunctor>::exportVol(outputFileName, imageC, LinearFunctor(vmax,vmin));
175 res = VolWriter<MyImageC, CycleFunctor>::exportVol(outputFileName, imageC);
181 trace.error()<<
"Error while exporting the Vol.";
182 trace.info()<<std::endl;