66#include <DGtal/base/Common.h>
67#include <DGtal/io/readers/VolReader.h>
68#include <DGtal/io/writers/VolWriter.h>
69#include <DGtal/helpers/StdDefs.h>
70#include <DGtal/images/Image.h>
71#include <DGtal/images/ImageContainerBySTLVector.h>
84void missingParam (
const std::string ¶m )
86 trace.error() <<
" Parameter: "<<param<<
" is required..";
87 trace.info() <<std::endl;
92int main(
int argc,
char**argv)
94 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
98 std::string inputFileName;
99 std::string outputFileName {
"result.vol"};
100 MyImageC::Value fillValue = 128;
102 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> ");
104 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file." )
106 ->check(CLI::ExistingFile);
107 app.add_option(
"-o,--output,2",outputFileName,
"Output filename.");
108 app.add_option(
"-v,--fillValue,3", fillValue,
"Set the filling value other than the default value of 128.");
110 app.get_formatter()->column_width(40);
111 CLI11_PARSE(app, argc, argv);
115 trace.beginBlock(
"Loading");
117 MyImageC image = VolReader< MyImageC >::importVol ( inputFileName );
118 trace.info() << image << std::endl;
122 ImageContainerBySTLVector<Z3i::Domain, bool> imageFlag(image.domain());
123 for(
auto &p: imageFlag.domain())
126 imageFlag.setValue(p,
true);
129 std::stack<Z3i::Point> pstack;
130 pstack.push(*(image.domain().begin()));
131 FATAL_ERROR_MSG(image(pstack.top())==0,
"Starting point of the domain must be equal to zero.");
134 std::vector<Z3i::Point> pencil6= { {1,0,0}, {0,1,0}, {0,0,1},{-1,0,0}, {0,-1,0}, {0,0,-1} };
136 trace.beginBlock(
"Filling");
137 while (!pstack.empty())
139 Z3i::Point p = pstack.top();
141 imageFlag.setValue(p,
true);
143 for(
auto & delta: pencil6)
144 if ((image.domain().isInside(p + delta)) &&
145 (imageFlag( p + delta) == false))
146 pstack.push( p + delta);
150 trace.beginBlock(
"Complement");
151 for(
auto &p : image.domain())
152 if ((image(p) == 0) && (!imageFlag(p)))
153 image.setValue(p, fillValue);
156 trace.beginBlock(
"Saving");
157 bool res = VolWriter< MyImageC >::exportVol(outputFileName, image);
160 if (res)
return 0;
else return 1;