A simple STL serializer and deserializer
Project description
OpenSTL
A simple yet fast header-only library to read/write, serialize/deserialize STL (stereolithography) files and data for C++ and Python.
Performances benchmark
Discover the staggering performance of OpenSTL in comparison to numpy-stl, thanks to its powerful C++ backend.
Write: 2 to 3 times faster than numpy-stl.
Read: 1 to 12 times faster than numpy-stl.
Rotate: 1 to 12 times faster than numpy-stl.
Python Usage
Install
pip install openstl
or pip install -U git+https://github.com/Innoptech/OpenSTL@main
Read and write from a STL file
import openstl
# Define an array of triangles
# Following the STL standard, each triangle is defined with : normal, v0, v1, v2
triangles = np.array([
[[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]],
[[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0]],
])
# Serialize the triangles to a file
openstl.write("output.stl", triangles, openstl.format.binary) # Or openstl.format.ascii (slower but human readable)
# Deserialize triangles from a file
deserialized_triangles = openstl.read("output.stl")
# Print the deserialized triangles
print("Deserialized Triangles:", deserialized_triangles)
C++ Usage
Read STL from file
std::ifstream file(filename, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Error: Unable to open file '" << filename << "'" << std::endl;
}
// Deserialize the triangles in either binary or ASCII format
std::vector<openstl::Triangle> triangles = openstl::deserializeStl(file);
file.close();
Write STL to a file
std::ofstream file(filename, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Error: Unable to open file '" << filename << "'" << std::endl;
}
std::vector<openstl::Triangle> originalTriangles{}; // User triangles
openstl::serializeStl(originalTriangles, file, openstl::StlFormat::Binary); // Or StlFormat::ASCII
if (file.fail()) {
std::cerr << "Error: Failed to write to file " << filename << std::endl;
} else {
std::cout << "File " << filename << " has been successfully written." << std::endl;
}
file.close();
Serialize STL to a stream
std::stringstream ss;
std::vector<openstl::Triangle> originalTriangles{}; // User triangles
openstl::serializeStl(originalTriangles, ss, openstl::StlFormat::Binary); // Or StlFormat::ASCII
Integrate to your codebase
Smart method
Include this repository with CMAKE Fetchcontent and link your executable/library to openstl::core
library.
Choose weither you want to fetch a specific branch or tag using GIT_TAG
. Use the main
branch to keep updated with the latest improvements.
include(FetchContent)
FetchContent_Declare(
openstl
GIT_REPOSITORY https://github.com/Innoptech/OpenSTL.git
GIT_TAG main
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(openstl)
Naïve method
Simply add stl.h to your codebase.
Test
git clone https://github.com/Innoptech/OpenSTL
mkdir OpenSTL/build && cd OpenSTL/build
cmake -DOPENSTL_BUILD_TESTS=ON .. && cmake --build .
ctest .
Requirements
C++11 or higher.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for openstl-1.0.0-pp310-pypy310_pp73-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf8469c2904f0b6ec3cc9a0417d7e40fa3676fd86812467436052e9459404137 |
|
MD5 | 8bcd2220909003b651d56e3a1e2c429c |
|
BLAKE2b-256 | f0f37fa02afbedbe7401adc80f1bbb3d5d11973ffcbab046a4593b4e942a0293 |
Hashes for openstl-1.0.0-pp39-pypy39_pp73-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 052f6d76f39b5db0c7b4b1f58c4b6a9894744d20889becd10282c204a16bc880 |
|
MD5 | 4448aaa8211a0122083e908d33cdfee7 |
|
BLAKE2b-256 | f1f8708654c4cfbd68d9d83622f2c46935b5e6f367b06bfb025d4d189e16d215 |
Hashes for openstl-1.0.0-pp38-pypy38_pp73-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf9b2e5993d5ce0bdab4d4d26c0ff35d039ccecc892d0b420e869e4396019c3 |
|
MD5 | 9bd158637baa77e160ab24a5a70791bc |
|
BLAKE2b-256 | 06f64d5ac00dd55253a1b9274a5514329ea881da127cb040aeb7a098b129c30c |
Hashes for openstl-1.0.0-pp37-pypy37_pp73-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 115e0b0a19fc6d553f4b647fde9c3b18292533c3e85c731546d7b69009939df1 |
|
MD5 | ab2b116f91f879a660257f3efc30846d |
|
BLAKE2b-256 | 62f8ec85157c618222137f99198df3fffd8f7f3d1618af9bdfa2b8e6b3eeeb6e |
Hashes for openstl-1.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53c657ba548544d1f9ca0ef46ccb1d09a0ce7fcb89331a6b786767cfa943a0aa |
|
MD5 | 9e6bb90c1a266f4d8d5c31c55405d397 |
|
BLAKE2b-256 | 75b02dc95478971ba16219250d134cfe8d0e2ee217b62b551380bca503d7f265 |
Hashes for openstl-1.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597d701578d2764bfa6b40bd0c1b2305e69ac1fec65fc34fe78e9ab152bf3794 |
|
MD5 | 9bcc936f0542dea8b6f1e8091e913c6c |
|
BLAKE2b-256 | e652f5581d803877d8d5d281bc1c075ae0e8a41a587511dd1f226bc8917beff7 |
Hashes for openstl-1.0.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a238e603eb601d5d9dc69e1bd1d07633a4c0ed6e9f4fc29c15cc36ee87c9d81 |
|
MD5 | b72b1d51dcdaba3ab66f9d40fce5e417 |
|
BLAKE2b-256 | d6f74e9f34b11c40e7b452e3bf2267b5c26df1cbc14cd2eaca01d6dc5d56538e |
Hashes for openstl-1.0.0-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b1061a97b66cc24598339aaaa5c6a90be69e0dc4fd485616fcdf21834f564a7 |
|
MD5 | 3043e6300fd9cae0b640fef8f86f9b25 |
|
BLAKE2b-256 | 3bb991f5ee4d5256fd0c8206850ee146f9ead8d509f9e5826dacc1281bd22b1a |
Hashes for openstl-1.0.0-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06fbc2a4d77f5c5f9f9d71e605d976b5313985425e381c8ca8cddc45e9cf601e |
|
MD5 | 0cc5f500b082ac7400bab884ecb9a809 |
|
BLAKE2b-256 | e49c4b78ddfa258b995a701afa1c8cd84c11ee3ebeb7a6ca001381f61e09a193 |
Hashes for openstl-1.0.0-cp37-cp37m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a686c230c5aa160b075c30557966140c67907ace21e384c38475ae73b70ee5d |
|
MD5 | c22a785c548421f10e8d8aa5b23a6d39 |
|
BLAKE2b-256 | bf88f95e1f4d826c87ef512f310cdff0e88e702c529254eb253d348fbd0cd7f0 |
Hashes for openstl-1.0.0-cp36-cp36m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c14112e88893897429abf607ccbe2e4b0ad693d73b4022921b0846884ee9e5c8 |
|
MD5 | 68737b3586faff7ecba4c61cd9477541 |
|
BLAKE2b-256 | 6e7177b461450c4483764c67a73377a31c08560029d3bfa23d5c041c571692c7 |