DGtalTools  1.5.beta
volCrop.cpp
1 
2 
31 #include <iostream>
32 #include <DGtal/base/Common.h>
33 #include <DGtal/io/readers/VolReader.h>
34 #include <DGtal/io/writers/VolWriter.h>
35 #include <DGtal/helpers/StdDefs.h>
36 #include <DGtal/images/ImageContainerBySTLVector.h>
37 #include <DGtal/images/ConstImageAdapter.h>
38 
39 #include "CLI11.hpp"
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z3i;
44 
92 void missingParam ( std::string param )
93 {
94  trace.error() <<" Parameter: "<<param<<" is required..";
95  trace.info() <<std::endl;
96  exit ( 1 );
97 }
98 
99 int main(int argc, char**argv)
100 {
101 
102  // parse command line using CLI ----------------------------------------------
103  CLI::App app;
104  std::string inputFileName;
105  std::string outputFileName {"output.vol"};
106  int xMin {0};
107  int yMin {0};
108  int zMin {0};
109  int xMax;
110  int yMax;
111  int zMax;
112 
113  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");
114 
115  app.add_option("-i,--input,1", inputFileName, "Input vol file." )
116  ->required()
117  ->check(CLI::ExistingFile);
118  app.add_option("--output,-o,2", outputFileName, "Output filename.", true);
119 
120  app.add_option("--xMin",xMin, "x coordinate of lower point.", true);
121  app.add_option("--yMin",yMin, "y coordinate of lower point.", true);
122  app.add_option("--zMin",zMin, "z coordinate of lower point.", true);
123 
124  app.add_option("--xMax",xMax, "x coordinate of upper point.")
125  ->required();
126  app.add_option("--yMax",yMax, "y coordinate of upper point.")
127  ->required();
128  app.add_option("--zMax",zMax, "z coordinate of upper point.")
129  ->required();
130 
131  app.get_formatter()->column_width(40);
132  CLI11_PARSE(app, argc, argv);
133  // END parse command line using CLI ----------------------------------------------
134 
135  Z3i::Point ptLow( xMin, yMin, zMin);
136  Z3i::Point ptMax(xMax , yMax, zMax);
137 
138  trace.beginBlock("Loading file");
140  MyImageC imageC = VolReader< MyImageC >::importVol ( inputFileName );
141  functors::Identity df;
142 
144  Domain subDomain(ptLow, ptMax);
145  ConstImageAdapterForSubImage subImage(imageC, subDomain, df, df);
146  trace.endBlock();
147 
148  trace.beginBlock("Exporting...");
149  bool res = VolWriter< ConstImageAdapterForSubImage>::exportVol(outputFileName, subImage);
150  trace.endBlock();
151  if (res) return 0; else return 1;
152 }
int main(int argc, char **argv)
typename Self::Domain Domain
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
Trace trace(traceWriterTerm)