Figure : The TriLite library provides tools to repair a scanned mesh, resulting in a watertight mesh.
TriLite is a header-only C++ library designed for efficient manipulation of triangle meshes. It offers a variety of functionalities including mesh reading/writing, distance calculations, and mesh processing algorithms, all without relying on a garbage collector. This ensures that the mesh topology remains consistent across various operations, regardless of the format used for writing and reading back the mesh.
- Mesh I/O: Supports multiple mesh file formats including STL, OBJ, OFF, and PLY.
- Distance Calculations: Includes functions to compute Hausdorff and mean Euclidean distances between meshes.
- Mesh Processing: Provides tools for mesh decimation, hole filling, smoothing, and repairing for 3D printing.
- Consistency: Ensures the same mesh topology is maintained when writing and reading back meshes.
A unique aspect of TriLite is its design choice to avoid using a garbage collector. This means:
- Compact Mesh Structure: There can't be at any time any isolated vertex or any face marked as deleted (as with a garbage collector). If a face is deleted or a vertex becoming isolated, it is swapped with the last element and popped back to remove it definitively from the structure in O(L) (with L the largest vertex valence). Any order of operations always leads to a compact mesh structure.
- Consistent Mesh Topology: When writing a mesh to a file and reading it back, the topology remains unchanged. For example, when writing an STL file, points that coincide are slightly adjusted to prevent merging when read back, preserving the original mesh structure.
To integrate TriLite into your C++ project, include the header files and compile with the Eigen flag.
For Python, you can install the latest released version via pip:
sudo apt-get install -y g++-12 libeigen3-dev
pip install trilite
Alternatively, you can build, install, and test the module using the provided Makefile:
make
- g++-12 or later
- Eigen3
- Python 3.x
- pybind11
- numpy
#include "TriLite/Modules/Distance.hpp"
#include "TriLite/Modules/IO.hpp"
#include "TriLite/Modules/Processing.hpp"
int main() {
// Reading a mesh
TL::Trimesh mesh1 = TL::IO::ReadMeshFile("input.obj");
// Copying the mesh
TL::Trimesh mesh2(mesh1);
// Simplify the copied mesh
TL::Processing::Simplify(mesh2);
// Writing the simplified mesh back to a file
TL::IO::WriteMeshFile(mesh2, "output.stl");
// Calculating Hausdorff distance between the meshes
double distance = TL::Distance::Hausdorff(mesh1, mesh2, 1e-6);
std::cout << "Hausdorff distance: " << distance << std::endl;
return 0;
}
import trilite as TL
# Reading a mesh
mesh1 = TL.IO.ReadMeshFile("input.obj")
# Copying the mesh
mesh2 = TL.Trimesh(mesh1)
# Simplify the copied mesh
TL.Processing.Simplify(mesh2)
# Writing the simplified mesh back to a file
TL.IO.WriteMeshFile(mesh2, "output.stl")
# Calculating Hausdorff distance between the meshes
distance = TL.Distance.Hausdorff(mesh1, mesh2, 1e-6)
print(f"Hausdorff distance: {distance}")
TriLite is rigorously tested over the entire Thingi10k dataset. The Python tests for these are located in the python/tests
directory. You can run these tests using:
make DATASET=/path/to/Thingi10k/raw_meshes
- The C++ code follows the Google C++ Style Guide.
- The Python code follows PEP8.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit a pull request.
TriLite is developed and maintained by the MeshLite team. Special thanks to all the contributors and users who have supported this project.
For any questions or suggestions, please contact us at [email protected].
If you find this project useful, please consider giving it a star on GitHub. Your support is appreciated!