Skip to content

Commit

Permalink
docs: add c++ examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanchristopheruel committed Mar 22, 2024
1 parent 08b1582 commit 98db892
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ scale = 1000.0
quad[:,1:4,:] *= scale # Avoid scaling normals
```

### Converting Triangles --> Vertices and Faces
### Converting Triangles -> Vertices and Faces
```python
import openstl

Expand All @@ -89,7 +89,7 @@ triangles = [
vertices, faces = openstl.convert.verticesandfaces(triangles)
```

### Converting Vertices and Faces --> Triangles
### Converting Vertices and Faces -> Triangles
```python
import openstl

Expand All @@ -113,6 +113,8 @@ triangles = openstl.convert.triangles(vertices, faces)
# C++ Usage
### Read STL from file
```c++
#include <openstl/core/stl.h>

std::ifstream file(filename, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Error: Unable to open file '" << filename << "'" << std::endl;
Expand Down Expand Up @@ -149,6 +151,33 @@ std::vector<openstl::Triangle> originalTriangles{}; // User triangles
openstl::serialize(originalTriangles, ss, openstl::StlFormat::Binary); // Or StlFormat::ASCII
```
### Converting Triangles -> Vertices and Faces
```c++
using namespace openstl
std::vector triangles = {
// normal, vertices 0, vertices 1, vertices 2
Triangle{{0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f}, {2.0f, 2.0f, 2.0f}, {3.0f, 3.0f, 3.0f}},
Triangle{{0.0f, 0.0f, 1.0f}, {2.0f, 2.0f, 2.0f}, {3.0f, 3.0f, 3.0f}, {4.0f, 4.0f, 4.0f}}
};
const auto& [vertices, faces] = convertToVerticesAndFaces(triangles);
```

### Converting Vertices and Faces -> Triangles
```c++
using namespace openstl

std::vector vertices = {
Vec3{0.0f, 0.0f, 0.0f}, Vec3{1.0f, 1.0f, 1.0f}, Vec3{2.0f, 2.0f, 2.0f}, Vec3{3.0f, 3.0f, 3.0f}
};
std::vector<Face> faces = {
{0, 1, 2}, {3, 1, 2}
};

const auto& triangles = convertToTriangles(vertices, faces);
```
# Integrate to your codebase
### Smart method
Include this repository with CMAKE Fetchcontent and link your executable/library to `openstl::core` library.
Expand Down

0 comments on commit 98db892

Please sign in to comment.