Skip to content

Commit 80c83be

Browse files
committed
Empty triangle list check and clarification in the example in README.md
1 parent af02ca0 commit 80c83be

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# TriangleMeshDistance
22
Header only, single file, simple and efficient C++ library to compute the signed distance function to a triangle mesh.
33

4-
The distance computation to the triangle collection is accelerated with a sphere bounding volume hierarchy. The sign of the distance is resolved with the method presented in *"Generating Signed Distance Fields From Triangle Meshes"* by Bærentzen, Andreas & Aanæs, Henrik. (2002).
4+
The distance computation to the triangle collection is accelerated with a sphere bounding volume hierarchy. The signed of the distance is resolved with the method presented in *"Generating Signed Distance Fields From Triangle Meshes"* by Bærentzen, Andreas & Aanæs, Henrik. (2002).
55

66
## Example
77
```cpp
88
// Declare mesh vertices and triangles
99
std::vector<std::array<double, 3>> vertices;
1010
std::vector<std::array<int, 3>> triangles;
1111

12+
// (... fill the `vertices` and `triangles` with the mesh data ...)
13+
1214
// Initialize TriangleMeshDistance
1315
tmd::TriangleMeshDistance mesh_distance(vertices, triangles);
1416

@@ -24,6 +26,6 @@ std::cout << "Nearest triangle index: " << result.triangle_id << std::endl;
2426
2527
2628
## What you need to know about TriangleMeshDistance
27-
- `TriangleMeshDistance` keeps an internal copy of the vertex and triangle data.
29+
- `TriangleMeshDistance` keeps a copy of the vertex and triangle data passed as input.
2830
- Additionally, the pseudonormals required to compute signed distances are calculated and stored at building time.
29-
- `TriangleMeshDistance` can be declared empty and constructed multiple times with different meshes. This can potentially reuse memory allocations.
31+
- `TriangleMeshDistance` can be declared empty and constructed multiple times with different meshes. This can potentially reuse memory allocations.

TriangleMeshDistance/include/tmd/TriangleMeshDistance.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance(const Eigen::Vec
270270

271271
inline void tmd::TriangleMeshDistance::_construct()
272272
{
273+
if (this->triangles.size() == 0) {
274+
std::cout << "DistanceTriangleMesh error: Empty triangle list." << std::endl;
275+
exit(-1);
276+
}
277+
273278
// Build the tree containing the triangles
274279
std::vector<Triangle> triangles;
275280

0 commit comments

Comments
 (0)