DGtalTools 2.0.0
Loading...
Searching...
No Matches
volFillInterior.cpp
1
65#include <iostream>
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>
72
73#include "CLI11.hpp"
74
75using namespace std;
76using namespace DGtal;
77using namespace Z3i;
78
84void missingParam ( const std::string &param )
85{
86 trace.error() <<" Parameter: "<<param<<" is required..";
87 trace.info() <<std::endl;
88 exit ( 1 );
89}
90
91
92int main(int argc, char**argv)
93{
94 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
95
96 // parse command line using CLI ----------------------------------------------
97 CLI::App app;
98 std::string inputFileName;
99 std::string outputFileName {"result.vol"};
100 MyImageC::Value fillValue = 128;
101
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> ");
103
104 app.add_option("-i,--input,1", inputFileName, "Input vol file." )
105 ->required()
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.");
109
110 app.get_formatter()->column_width(40);
111 CLI11_PARSE(app, argc, argv);
112 // END parse command line using CLI ----------------------------------------------
113
114
115 trace.beginBlock("Loading");
116
117 MyImageC image = VolReader< MyImageC >::importVol ( inputFileName );
118 trace.info() << image << std::endl;
119 trace.endBlock();
120
121 //Flag image
122 ImageContainerBySTLVector<Z3i::Domain, bool> imageFlag(image.domain());
123 for(auto &p: imageFlag.domain())
124 {
125 if (image(p) != 0)
126 imageFlag.setValue(p, true);
127 }
128
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.");
132
133 //6-Pencil for the exterior propagation
134 std::vector<Z3i::Point> pencil6= { {1,0,0}, {0,1,0}, {0,0,1},{-1,0,0}, {0,-1,0}, {0,0,-1} };
135
136 trace.beginBlock("Filling");
137 while (!pstack.empty())
138 {
139 Z3i::Point p = pstack.top();
140 pstack.pop();
141 imageFlag.setValue(p, true);
142
143 for(auto & delta: pencil6)
144 if ((image.domain().isInside(p + delta)) &&
145 (imageFlag( p + delta) == false))
146 pstack.push( p + delta);
147 }
148 trace.endBlock();
149
150 trace.beginBlock("Complement");
151 for(auto &p : image.domain())
152 if ((image(p) == 0) && (!imageFlag(p)))
153 image.setValue(p, fillValue);
154 trace.endBlock();
155
156 trace.beginBlock("Saving");
157 bool res = VolWriter< MyImageC >::exportVol(outputFileName, image);
158 trace.endBlock();
159
160 if (res) return 0; else return 1;
161}
Definition ATu0v1.h:57