Reading in a meshΒΆ

Applications commonly need to read a mesh file from disk. Quest provides the STLReader class, which can read binary or ASCII STL files, as well as the PSTLReader class for use in parallel codes. STL (stereolithography) is a common file format for triangle surface meshes. The STL reader classes will read the file from disk and build a mint::Mesh object.

The code examples are excerpts from the file <axom>/src/tools/mesh_tester.cpp.

We include the STL reader header

#include "axom/quest/stl/STLReader.hpp"

and also the mint Mesh and UnstructuredMesh headers.

#include "axom/mint/mesh/Mesh.hpp"
#include "axom/mint/mesh/UnstructuredMesh.hpp"

For convenience, we use typedefs in the axom namespace.

using namespace axom;

using UMesh = mint::UnstructuredMesh<mint::SINGLE_SHAPE>;

The following example shows usage of the STLReader class:

  // Read file
  SLIC_INFO("Reading file: '" << params.stlInput << "'...\n");
  quest::STLReader* reader = new quest::STLReader();
  reader->setFileName(params.stlInput);
  reader->read();

  // Get surface mesh
  UMesh* surface_mesh = new UMesh(3, mint::TRIANGLE);
  reader->getMesh(surface_mesh);

  // Delete the reader
  delete reader;
  reader = nullptr;

  SLIC_INFO("Mesh has " << surface_mesh->getNumberOfNodes() << " vertices and "
                        << surface_mesh->getNumberOfCells() << " triangles.");

After reading the STL file, the STLReader::getMesh method gives access to the underlying mesh data. The reader may then be deleted.