scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
scimesh::stl_io Namespace Reference

Functions for reading and writing STL files. More...

Functions

Mesh read_stl (const std::string &path)
 Load a mesh from an STL file (ASCII or binary).
 
void write_stl_binary (const std::string &path, const Mesh &mesh)
 Write a mesh to a binary STL file.
 
void write_stl_ascii (const std::string &path, const Mesh &mesh)
 Write a mesh to an ASCII STL file.
 
void write_stl (const std::string &path, const Mesh &mesh, const std::string &format)
 Write a mesh to an STL file, choosing the format.
 

Detailed Description

Functions for reading and writing STL files.

Function Documentation

◆ read_stl()

Mesh scimesh::stl_io::read_stl ( const std::string &  path)
inline

Load a mesh from an STL file (ASCII or binary).

STL files contain only raw triangle geometry — each triangle is stored independently with its own vertices (no indexed face set sharing). Colors and normals are not stored in STL files.

Parameters
pathFilesystem path to the .stl file.
Returns
A Mesh with vertices and triangles populated.
Exceptions
std::runtime_errorif the file cannot be opened or parsed.
Example
Mesh part = scimesh::stl_io::read_stl("bracket.stl");
// STL has no colors — set a uniform color for rendering
part.default_color = Color(0.5f, 0.5f, 0.5f);
Mesh read_stl(const std::string &path)
Load a mesh from an STL file (ASCII or binary).
Definition stl_io.h:45
An RGBA color with floating-point components.
Definition types.h:88
A 3D triangle mesh using an indexed face set representation.
Definition mesh.h:76
Color default_color
Fallback color when no per-vertex or per-face color is set.
Definition mesh.h:160
Note on colors
STL files are geometry-only. After loading, set mesh.default_color or populate mesh.colors manually for rendering.
See also
write_stl(), read_obj(), read_ply()

Definition at line 45 of file stl_io.h.

◆ write_stl()

void scimesh::stl_io::write_stl ( const std::string &  path,
const Mesh mesh,
const std::string &  format 
)
inline

Write a mesh to an STL file, choosing the format.

Parameters
pathOutput file path.
meshThe mesh to write.
formatEither "binary" (compact, recommended) or "ascii" (human-readable but large).
Exceptions
std::runtime_errorif the file cannot be created.
Example
scimesh::stl_io::write_stl("output.stl", mesh, "binary");
scimesh::stl_io::write_stl("output_ascii.stl", mesh, "ascii");
void write_stl(const std::string &path, const Mesh &mesh, const std::string &format)
Write a mesh to an STL file, choosing the format.
Definition stl_io.h:179
See also
write_stl_binary(), write_stl_ascii(), read_stl()

Definition at line 179 of file stl_io.h.

◆ write_stl_ascii()

void scimesh::stl_io::write_stl_ascii ( const std::string &  path,
const Mesh mesh 
)
inline

Write a mesh to an ASCII STL file.

ASCII STL is human-readable (you can open it in a text editor) but much larger than binary STL.

Parameters
pathOutput file path.
meshThe mesh to write.
Exceptions
std::runtime_errorif the file cannot be created.
See also
write_stl_binary(), write_stl()

Definition at line 140 of file stl_io.h.

◆ write_stl_binary()

void scimesh::stl_io::write_stl_binary ( const std::string &  path,
const Mesh mesh 
)
inline

Write a mesh to a binary STL file.

Binary STL is more compact than ASCII. The file begins with an 80-byte header followed by a triangle count and per-triangle data.

Parameters
pathOutput file path.
meshThe mesh to write.
Exceptions
std::runtime_errorif the file cannot be created.
See also
write_stl_ascii(), write_stl()

Definition at line 90 of file stl_io.h.