DGtalTools  1.3.beta
volFillInterior.cpp
1 
61 #include <iostream>
62 #include <DGtal/base/Common.h>
63 #include <DGtal/io/readers/VolReader.h>
64 #include <DGtal/io/writers/VolWriter.h>
65 #include <DGtal/helpers/StdDefs.h>
66 #include <DGtal/images/Image.h>
67 #include <DGtal/images/ImageContainerBySTLVector.h>
68 
69 #include "CLI11.hpp"
70 
71 using namespace std;
72 using namespace DGtal;
73 using namespace Z3i;
74 
80 void missingParam ( const std::string &param )
81 {
82  trace.error() <<" Parameter: "<<param<<" is required..";
83  trace.info() <<std::endl;
84  exit ( 1 );
85 }
86 
87 
88 int main(int argc, char**argv)
89 {
90  // parse command line using CLI ----------------------------------------------
91  CLI::App app;
92  std::string inputFileName;
93  std::string outputFileName {"result.vol"};
94 
95  app.description("Fill the interior of a voxel set by filling the exterior using the 6-adjacency.\nThe exterior is the set of voxels with value zero and the interior voxels have value 128\n Basic usage:\n\tvolFillInterior <volFileName> <volOutputFileName> ");
96 
97  app.add_option("-i,--input,1", inputFileName, "Input vol file." )
98  ->required()
99  ->check(CLI::ExistingFile);
100  app.add_option("-o,--output,2",outputFileName, "Output filename.", true);
101 
102  app.get_formatter()->column_width(40);
103  CLI11_PARSE(app, argc, argv);
104  // END parse command line using CLI ----------------------------------------------
105 
106 
107  trace.beginBlock("Loading");
109  MyImageC image = VolReader< MyImageC >::importVol ( inputFileName );
110  trace.info() << image << std::endl;
111  trace.endBlock();
112 
113  //Flag image
114  ImageContainerBySTLVector<Z3i::Domain, bool> imageFlag(image.domain());
115  for(auto &p: imageFlag.domain())
116  {
117  if (image(p) != 0)
118  imageFlag.setValue(p, true);
119  }
120 
121  std::stack<Z3i::Point> pstack;
122  pstack.push(*(image.domain().begin()));
123  FATAL_ERROR_MSG(image(pstack.top())==0, "Starting point of the domain must be equal to zero.");
124 
125  //6-Pencil for the exterior propagation
126  std::vector<Z3i::Point> pencil6= { {1,0,0}, {0,1,0}, {0,0,1},{-1,0,0}, {0,-1,0}, {0,0,-1} };
127 
128  trace.beginBlock("Filling");
129  while (!pstack.empty())
130  {
131  Z3i::Point p = pstack.top();
132  pstack.pop();
133  imageFlag.setValue(p, true);
134 
135  for(auto & delta: pencil6)
136  if ((image.domain().isInside(p + delta)) &&
137  (imageFlag( p + delta) == false))
138  pstack.push( p + delta);
139  }
140  trace.endBlock();
141 
142  trace.beginBlock("Complement");
143  for(auto &p : image.domain())
144  if ((image(p) == 0) && (!imageFlag(p)))
145  image.setValue(p,128);
146  trace.endBlock();
147 
148  trace.beginBlock("Saving");
149  bool res = VolWriter< MyImageC >::exportVol(outputFileName, image);
150  trace.endBlock();
151 
152  if (res) return 0; else return 1;
153 }
void beginBlock(const std::string &keyword="")
STL namespace.
double endBlock()
int main(int argc, char **argv)
Trace trace(traceWriterTerm)
std::ostream & info()
void setValue(const Point &aPoint, const Value &aValue)
std::ostream & error()