DGtalTools  1.5.beta
volAddBorder.cpp
1 
27 #include <iostream>
28 #include <DGtal/base/Common.h>
29 #include <DGtal/io/readers/VolReader.h>
30 #include <DGtal/io/writers/VolWriter.h>
31 #include <DGtal/helpers/StdDefs.h>
32 #include <DGtal/images/Image.h>
33 #include <DGtal/images/ImageContainerBySTLVector.h>
34 
35 #include "CLI11.hpp"
36 
37 using namespace std;
38 using namespace DGtal;
39 using namespace Z3i;
40 
83 void missingParam ( std::string param )
84 {
85  trace.error() <<" Parameter: "<<param<<" is required..";
86  trace.info() <<std::endl;
87  exit ( 1 );
88 }
89 
90 
91 int main(int argc, char**argv)
92 {
93 
94  // parse command line using CLI ----------------------------------------------
95  CLI::App app;
96  std::string inputFileName;
97  std::string outputFileName {"result.vol"};
98  bool addInside {false};
99 
100  app.description("Add a border of one voxel with value 0 around a vol file.\n \tvolAddBorder --input <volFileName> --o <volOutputFileName>\n Example: \n \t volAddBorder -i $DGtal/examples/samples/Al.100.vol -o Al.100border.vol");
101 
102  app.add_option("-i,--input,1", inputFileName, "Input vol file." )
103  ->required()
104  ->check(CLI::ExistingFile);
105  app.add_flag("--inside", addInside , "Sets zero value to domain boundary voxels without changing the domain extent.");
106  app.add_option("--output,-o,2", outputFileName, "Output filename.");
107 
108  app.get_formatter()->column_width(40);
109  CLI11_PARSE(app, argc, argv);
110  // END parse command line using CLI ----------------------------------------------
111 
112 
114 
115  MyImageC imageC = VolReader< MyImageC >::importVol ( inputFileName );
116  Z3i::Domain rDom ( imageC.domain().lowerBound() - Vector().diagonal(addInside ? 0: 1),
117  imageC.domain().upperBound() + Vector().diagonal(addInside ? 0: 1));
118  MyImageC outputImage(rDom);
119  Z3i::Domain iDom ( imageC.domain().lowerBound() + Vector().diagonal( 1),
120  imageC.domain().upperBound() - Vector().diagonal( 1));
121 
122  //Fast Copy
123  for(MyImageC::Domain::ConstIterator it = imageC.domain().begin(),
124  itend = imageC.domain().end(); it != itend; ++it){
125  if(!addInside){
126  outputImage.setValue( *it , imageC(*it));
127  }
128  else
129  {
130  if (!iDom.isInside(*it)){
131  imageC.setValue( *it , 0);
132  }
133  }
134 
135  }
136  bool res = true;
137  if (!addInside) {
138  res= VolWriter< MyImageC>::exportVol(outputFileName, outputImage);
139  }
140  else{
141  res= VolWriter< MyImageC>::exportVol(outputFileName, imageC);
142  }
143  if (res) return 0; else return 1;
144 }
int main(int argc, char **argv)
std::ostream & error()
std::ostream & info()
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
Trace trace(traceWriterTerm)