30 #include <DGtal/base/Common.h>
31 #include <DGtal/io/readers/VolReader.h>
32 #include <DGtal/io/writers/VolWriter.h>
33 #include <DGtal/helpers/StdDefs.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 #include <DGtal/images/ConstImageAdapter.h>
40 using namespace DGtal;
90 void missingParam ( std::string param )
92 trace.error() <<
" Parameter: "<<param<<
" is required..";
93 trace.info() <<std::endl;
97 int main(
int argc,
char**argv)
102 std::string inputFileName;
103 std::string outputFileName {
"output.vol"};
111 app.description(
"Crops a 3D vol image from domain coordinates.\n Basic usage: \n \t volCrop --input <volFileName> --o <volOutputFileName> (both files can be independently in vol, pgm3D, p3d format)\nExample:\n volCrop --xMin 50 --yMin 50 --zMin 10 --xMax 150 --yMax 150 --zMax 50 -i ${DGtal}/examples/samples/lobster.vol -o croppedLobster.vol \n");
113 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file." )
115 ->check(CLI::ExistingFile);
116 app.add_option(
"--output,-o,2", outputFileName,
"Output filename.",
true);
118 app.add_option(
"--xMin",xMin,
"x coordinate of lower point.",
true);
119 app.add_option(
"--yMin",yMin,
"y coordinate of lower point.",
true);
120 app.add_option(
"--zMin",zMin,
"z coordinate of lower point.",
true);
122 app.add_option(
"--xMax",xMax,
"x coordinate of upper point.")
124 app.add_option(
"--yMax",yMax,
"y coordinate of upper point.")
126 app.add_option(
"--zMax",zMax,
"z coordinate of upper point.")
129 app.get_formatter()->column_width(40);
130 CLI11_PARSE(app, argc, argv);
133 Z3i::Point ptLow( xMin, yMin, zMin);
134 Z3i::Point ptMax(xMax , yMax, zMax);
136 trace.beginBlock(
"Loading file");
137 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
138 MyImageC imageC = VolReader< MyImageC >::importVol ( inputFileName );
139 functors::Identity df;
141 typedef ConstImageAdapter<MyImageC, Domain, functors::Identity, MyImageC::Value, functors::Identity > ConstImageAdapterForSubImage;
142 Domain subDomain(ptLow, ptMax);
143 ConstImageAdapterForSubImage subImage(imageC, subDomain, df, df);
146 trace.beginBlock(
"Exporting...");
147 bool res = VolWriter< ConstImageAdapterForSubImage>::exportVol(outputFileName, subImage);
149 if (res)
return 0;
else return 1;