Developer Documentation
Loading...
Searching...
No Matches
Tutorial 04: Using File I/O

The OpenVolumeMesh library defines and implements two file formats, the classic text-based *.ovm format (cf. Text-based File Format ) as well as a newer binary format, *.ovmb. (cf. Binary File Format )

We recommend saving files in the *.ovmb file format, it is more space efficient, faster to read and write and has better support for custom property types.

The OpenVolumeMesh library is equipped with a file manager class that allows reading polyhedral meshes from file as well as writing mesh objects to files. The format for these files is specified in Section File formats.

In this tutorial, we will learn how to use the file manager in order to permanently store mesh objects and read them.

Consider the following code for an example on how to write a polyhedral mesh to a file:

// Include the file manager header
#include <OpenVolumeMesh/FileManager/FileManager.hh>
// Include the polyhedral mesh header
#include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
...
void someFunction() {
// Create mesh object
// Fill mesh with geometry
...
// Create file manager object
// Store mesh to file "myMesh.ovm" in the current directory
fileManager.writeFile("myMesh.ovm", myMesh);
}
Read/Write mesh data from/to files.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.

This works analogously for reading files into mesh objects. See the following code for an example.

// Include the file manager header
#include <OpenVolumeMesh/FileManager/FileManager.hh>
// Include the polyhedral mesh header
#include <OpenVolumeMesh/Mesh/PolyhedralMesh.hh>
...
void someFunction() {
// Create an empty mesh object
// Create file manager object
// Read mesh from file "myMesh.ovm" in the current directory
fileManager.readFile("myMesh.ovm", myMesh);
// Now myMesh contains the mesh specified in file "myMesh.ovm"
}
bool readFile(const std::string &_filename, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from a file.

Function OpenVolumeMesh::IO::FileManager::readFile() expects a total of four parameters, two of which are mandatory (file name and mesh reference). The other two parameters are optional flags that control whether bottom-up incidences should be computed automatically and whether a topology check should be performed when adding faces and cells. The two flags are turned on per default.