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>
72 using namespace DGtal;
80 void missingParam (
const std::string ¶m )
82 trace.error() <<
" Parameter: "<<param<<
" is required..";
83 trace.info() <<std::endl;
88 int main(
int argc,
char**argv)
92 std::string inputFileName;
93 std::string outputFileName {
"result.vol"};
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> ");
97 app.add_option(
"-i,--input,1", inputFileName,
"Input vol file." )
99 ->check(CLI::ExistingFile);
100 app.add_option(
"-o,--output,2",outputFileName,
"Output filename.",
true);
102 app.get_formatter()->column_width(40);
103 CLI11_PARSE(app, argc, argv);
107 trace.beginBlock(
"Loading");
108 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
109 MyImageC image = VolReader< MyImageC >::importVol ( inputFileName );
110 trace.info() << image << std::endl;
114 ImageContainerBySTLVector<Z3i::Domain, bool> imageFlag(image.domain());
115 for(
auto &p: imageFlag.domain())
118 imageFlag.setValue(p,
true);
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.");
126 std::vector<Z3i::Point> pencil6= { {1,0,0}, {0,1,0}, {0,0,1},{-1,0,0}, {0,-1,0}, {0,0,-1} };
128 trace.beginBlock(
"Filling");
129 while (!pstack.empty())
131 Z3i::Point p = pstack.top();
133 imageFlag.setValue(p,
true);
135 for(
auto & delta: pencil6)
136 if ((image.domain().isInside(p + delta)) &&
137 (imageFlag( p + delta) ==
false))
138 pstack.push( p + delta);
142 trace.beginBlock(
"Complement");
143 for(
auto &p : image.domain())
144 if ((image(p) == 0) && (!imageFlag(p)))
145 image.setValue(p,128);
148 trace.beginBlock(
"Saving");
149 bool res = VolWriter< MyImageC >::exportVol(outputFileName, image);
152 if (res)
return 0;
else return 1;