31 #include "DGtal/helpers/StdDefs.h"
32 #include "DGtal/shapes/MeshVoxelizer.h"
33 #include "DGtal/kernel/sets/CDigitalSet.h"
34 #include "DGtal/kernel/domains/HyperRectDomain.h"
35 #include "DGtal/io/readers/MeshReader.h"
36 #include "DGtal/io/Display3D.h"
37 #include "DGtal/io/writers/GenericWriter.h"
38 #include "DGtal/images/ImageContainerBySTLVector.h"
44 using namespace DGtal;
80 template<
unsigned int SEP >
81 void voxelizeAndExport(
const std::string& inputFilename,
82 const std::string& outputFilename,
83 const unsigned int resolution,
84 const unsigned int margin,
85 const unsigned char fillVal)
92 trace.
info() <<
"Reading input file: " << inputFilename;
94 inputMesh << inputFilename.c_str();
96 const std::pair<PointR3, PointR3> bbox = inputMesh.
getBoundingBox();
97 trace.
info()<<
"Mesh bounding box: "<<bbox.first <<
" "<<bbox.second<<std::endl;
99 const double smax = (bbox.second - bbox.first).max();
102 const double factor = resolution / smax;
103 const PointR3 translate = -bbox.first;
104 trace.
info() <<
"Scale = "<<factor<<
" translate = "<<translate<<std::endl;
115 trace.
info() <<
"Voxelization " << SEP <<
"-separated ; " << resolution <<
"^3 ";
119 aDomain =
Domain(bbox.first, bbox.second);
124 MeshVoxelizer<Z3i::DigitalSet, SEP> aVoxelizer;
125 aVoxelizer.voxelize(mySet, inputMesh, 1.0);
134 image.setValue(p, fillVal);
135 image >> outputFilename.c_str();
139 int main(
int argc,
char** argv )
144 std::string inputFileName;
145 std::string outputFileName {
"result.vol"};
146 unsigned int margin {0};
147 unsigned int separation {6};
148 unsigned int resolution {128};
149 unsigned char fillValue {128};
150 bool unitScale {
false};
152 app.description(
"Convert a mesh file into a 26-separated or 6-separated volumetric voxelization in a given resolution grid. \n Example:\n mesh2vol ${DGtal}/examples/samples/tref.off output.vol --separation 26 --resolution 256 ");
154 app.add_option(
"-i,--input,1", inputFileName,
"mesh file (.off)." )
156 ->check(CLI::ExistingFile);
157 app.add_option(
"-o,--output,2", outputFileName,
"filename of ouput volumetric file (vol, pgm3d, ...).",
true);
158 app.add_option(
"-m,--margin", margin,
"add volume margin around the mesh bounding box.");
159 app.add_flag(
"-d,--objectDomainBB", unitScale,
"use the digitization space defined from bounding box of input mesh. If seleted, the option --resolution will have no effect.");
160 app.add_option(
"-f,--fillValue", fillValue,
"change the default output volumetric image value in [1...255].")
162 app.add_option(
"-s,--separation", separation,
"voxelization 6-separated or 26-separated.",
true)
163 -> check(CLI::IsMember({6, 26}));
164 app.add_option(
"-r,--resolution", resolution,
"digitization domain size (e.g. 128). The mesh will be scaled such that its bounding box maps to [0,resolution)^3.",
true);
167 app.get_formatter()->column_width(40);
168 CLI11_PARSE(app, argc, argv);
172 voxelizeAndExport<6>(inputFileName, outputFileName, unitScale ? 0 : resolution, margin, fillValue);
174 voxelizeAndExport<26>(inputFileName, outputFileName, unitScale ? 0 : resolution, margin, fillValue);
int main(int argc, char **argv)
typename Self::Domain Domain
std::pair< TPoint, TPoint > getBoundingBox() const
ConstIterator vertexBegin() const
ConstIterator vertexEnd() const
void beginBlock(const std::string &keyword="")
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
Trace trace(traceWriterTerm)