VolumeIO
Input/Output for the structures describing 3D volumes, such as the
Geometry class, and voxels in 3D arrays such as
the Matrix class. Geometries can be read from
STL format,
both binary and ascii format.
Interface
template <typename T>
bool writeSTL(const Geometry<T> &geometry,
const std::string fileName,
const bool binary = true)
|
Write a Geometry to an STL-file in binary format (default), or,
if binary is false in ascii format. |
template <typename T>
bool readSTL(Geometry<T> &geometry,
const std::string fileName);
|
Read a Geometry from an STL-file. |
bool writeVoxels(const Array<T, N, Aux> &voxels,
const std::string fileName,
const bool compress = true);
|
Identical to writeArray in
ArrayIO, except that compression is enabled
by default.
|
bool readVoxels(Array<T, N, Aux> &voxels,
const std::string fileName);
|
Identical to readArray in ArrayIO.
|
Example
Facets to Voxels
Read a 3D Geometry in facet representation from an STL file, transform it to
voxels with the Voxelizer, then write the 3D array
of voxels to disk in compressed format:
#include <cvmlcpp/base/Matrix>
#include <cvmlcpp/volume/Geometry>
#include <cvmlcpp/volume/VolumeIO>
#include <cvmlcpp/volume/Voxelizer>
using namespace cvmlcpp;
Geometry<float> geometry;
readSTL(geometry, "cube.stl");
Matrix<char, 3> voxels;
// Use greater precision during calculations
Voxelizer<double>::voxelize(geometry, voxels, voxelSize, 1);
writeArray(voxels, "voxels.dat");
Voxels to Facets
Read voxels from a file, transform it to facet representation with the
SurfaceExtractor.
#include <cvmlcpp/base/Matrix>
#include <cvmlcpp/volume/Geometry>
#include <cvmlcpp/volume/SurfaceExtractor>
#include <cvmlcpp/volume/VolumeIO>
using namespace cvmlcpp;
Matrix<char, 3> voxels;
readArray(voxels, "voxels.dat");
Geometry<float> geometry;
// Use greater precision during calculations
SurfaceExtractor<double>::extract(voxels, geometry);
|