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>
39 using namespace DGtal;
80 template<
typename TInput>
82 unsigned char operator()(
const TInput& aInput)
const
87 return static_cast<unsigned char>(1+NumberTraits<TInput>::castToInt64_t(aInput) % 32);
97 LinearFunctor(
const DGtal::uint64_t vmax,
const DGtal::uint64_t vmin):
98 myMin(vmin), myMax(vmax) {}
100 inline unsigned char operator()(
const DGtal::int64_t& aInput)
const
102 return static_cast<unsigned char>( (NumberTraits<DGtal::uint64_t>::castToDouble(aInput - myMin)*255.0 /
103 (double) (myMax-myMin)));
106 DGtal::uint64_t myMin,myMax;
110 int main(
int argc,
char**argv)
116 std::string inputFileName;
117 std::string outputFileName {
"result.vol"};
118 unsigned int mode {0};
120 app.description(
"Converts a longvol (long int) to a vol file (unsigned char). \n Basic example:\n\t longvol2vol --input <LongvolFileName> --o <VolOutputFileName> ");
121 app.add_option(
"-i,--input,1", inputFileName,
"Input longvol filename ( .longvol)" )
123 ->check(CLI::ExistingFile);
124 app.add_option(
"-o,--output,2",outputFileName,
"Output vol filename." );
125 app.add_option(
"-m,--mode", mode,
"Conversion mode:\n\t 0 = cast (default)\n\t 1 = Linear Scaling\n\t 2 = Grayscale cycle (32 steps, except 0 values).")
126 -> check(CLI::IsMember({0, 1, 2}));
129 app.get_formatter()->column_width(40);
130 CLI11_PARSE(app, argc, argv);
135 typedef ImageContainerBySTLVector<Z3i::Domain, DGtal::uint64_t> MyImageC;
136 MyImageC imageC = LongvolReader< MyImageC >::importLongvol ( inputFileName );
140 res = VolWriter< MyImageC, functors::Cast<unsigned char> >::exportVol(outputFileName, imageC);
144 DGtal::uint64_t vmax, vmin;
145 vmax = *std::max_element(imageC.begin(), imageC.end());
146 vmin = *std::min_element(imageC.begin(), imageC.end());
147 trace.info() <<
"Max value = "<< vmax<<std::endl;
148 trace.info() <<
"Min value = "<< vmin<<std::endl;
149 res = VolWriter<MyImageC , LinearFunctor>::exportVol(outputFileName, imageC,
true, LinearFunctor(vmax,vmin));
152 res = VolWriter<MyImageC, CycleFunctor>::exportVol(outputFileName, imageC);
159 trace.error()<<
"Error while exporting the Vol.";
160 trace.info()<<std::endl;