Skip to content

Commit 9067d81

Browse files
committed
Update to 0.4.0
1 parent 2d43500 commit 9067d81

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+30-26
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ documentation: https://docs.rs/mesh_to_sdf/latest/mesh_to_sdf/
2424

2525
## `mesh_to_sdf`: Convert a mesh to a signed distance field (SDF).
2626

27-
⚠️ This crate is still in its early stages. Expect the API to change.
28-
29-
---
30-
3127
This crate provides two entry points:
3228

3329
- [`generate_sdf`]: computes the signed distance field for the mesh defined by `vertices` and `indices` at the points `query_points`.
@@ -47,9 +43,8 @@ let sdf: Vec<f32> = generate_sdf(
4743
&vertices,
4844
Topology::TriangleList(Some(&indices)), // TriangleList as opposed to TriangleStrip
4945
&query_points,
50-
AccelerationMethod::Bvh, // Use bvh to accelerate queries.
51-
SignMethod::Raycast, // How the sign is computed.
52-
); // Raycast is robust but requires the mesh to be watertight.
46+
AccelerationMethod::RtreeBvh, // Use an r-tree and a bvh to accelerate queries.
47+
);
5348

5449
for point in query_points.iter().zip(sdf.iter()) {
5550
// distance is positive outside the mesh and negative inside.
@@ -67,9 +62,11 @@ let sdf: Vec<f32> = generate_grid_sdf(
6762
&vertices,
6863
Topology::TriangleList(Some(&indices)),
6964
&grid,
70-
SignMethod::Normal, // How the sign is computed.
71-
); // Normal might leak negative distances outside the mesh
72-
// but works for all meshes, even surfaces.
65+
SignMethod::Raycast, // How the sign is computed.
66+
// Raycast is robust but requires the mesh to be watertight.
67+
// and is more expensive.
68+
// Normal might leak negative distances outside the mesh
69+
); // but works for all meshes, even surfaces.
7370

7471
for x in 0..cell_count[0] {
7572
for y in 0..cell_count[1] {
@@ -89,7 +86,7 @@ Indices can be of any type that implements `Into<u32>`, e.g. `u16` and `u32`. To
8986
If the indices are not provided, they are supposed to be `0..vertices.len()`.
9087

9188
For vertices, this library aims to be as generic as possible by providing a trait `Point` that can be implemented for any type.
92-
Implementations for most common math libraries are gated behind feature flags. By default, only `[f32; 3]` is provided.
89+
Implementations for most common math libraries are gated behind feature flags. By default, `[f32; 3]` and `nalgebra::[Point3, Vector3]` are provided.
9390
If you do not find your favorite library, feel free to implement the trait for it and submit a PR or open an issue.
9491

9592
---
@@ -102,9 +99,26 @@ This crate provides two methods to compute the sign of the distance:
10299
- [`SignMethod::Normal`]: uses the normals of the triangles to estimate the sign by doing a dot product with the direction of the query point.
103100
It works for non-watertight meshes but might leak negative distances outside the mesh.
104101

105-
For grid generation, `Raycast` is ~1% slower.
106-
For query points, `Raycast` is ~10% slower.
107-
Note that it depends on the query points / grid size to triangle ratio, but this gives a rough idea.
102+
Using `Raycast` is slower than `Normal` but gives better results. Performances depends on the triangle count and method used.
103+
On big dataset, `Raycast` is 5-10% slower for grid generation and rtree based methods. On smaller dataset, the difference can be worse
104+
depending on whether the query is triangle intensive or query point intensive.
105+
For bvh the difference is negligible between the two methods.
106+
107+
---
108+
109+
##### Acceleration structures
110+
111+
For generic queries, you can use acceleration structures to speed up the computation.
112+
- [`AccelerationMethod::None`]: no acceleration structure. This is the slowest method but requires no extra memory. Scales really poorly.
113+
- [`AccelerationMethod::Bvh`]: Bounding Volume Hierarchy. Accepts a `SignMethod`.
114+
- [`AccelerationMethod::Rtree`]: R-tree. Uses `SignMethod::Normal`. The fastest method assuming you have more than a couple thousands of queries.
115+
- [`AccelerationMethod::RtreeBvh`] (default): Uses R-tree for nearest neighbor search and Bvh for `SignMethod::Raycast`. 5-10% slower than `Rtree` on big datasets.
116+
117+
If your mesh is watertight and you have more than a thousand queries/triangles, you should use `AccelerationMethod::RtreeBvh` for best performances.
118+
If it's not watertight, you can use `AccelerationMethod::Rtree` instead.
119+
120+
`Rtree` methods are 3-4x faster than `Bvh` methods for big enough data. On small meshes, the difference is negligible.
121+
`AccelerationMethod::None` scales really poorly and should be avoided unless for small datasets or if you're really tight on memory.
108122

109123
---
110124

@@ -123,25 +137,15 @@ Currently, the following libraries are supported:
123137
- [nalgebra] ([`nalgebra::Vector3<f32>`] and [`nalgebra::Point3<f32>`])
124138
- `[f32; 3]`
125139

140+
[nalgebra] is always available as it's used internally in the bvh tree.
141+
126142
---
127143

128144
##### Serialization
129145

130146
If you want to serialize and deserialize signed distance fields, you need to enable the `serde` feature.
131147
This features also provides helpers to save and load signed distance fields to and from files via `save_to_file` and `read_from_file`.
132148

133-
---
134-
135-
##### Benchmarks
136-
137-
[`generate_grid_sdf`] is much faster than [`generate_sdf`] and should be used whenever possible.
138-
[`generate_sdf`] does not allocate memory (except for the result array) but is slow. A faster implementation is planned for the future.
139-
140-
[`SignMethod::Raycast`] is slightly slower than [`SignMethod::Normal`] but is robust and should be used whenever possible (~1% in [`generate_grid_sdf`], ~10% in [`generate_sdf`]).
141-
142-
---
143-
144-
TODO: Add benchmarks against other libraries.
145149

146150
## `mesh_to_sdf_client` Mesh to SDF visualization client.
147151

mesh_to_sdf/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mesh_to_sdf"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "Mesh to signed distance field (SDF) converter"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

mesh_to_sdf/README.md

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# mesh_to_sdf
22

3-
⚠️ This crate is still in its early stages. Expect the API to change.
4-
5-
---
6-
73
This crate provides two entry points:
84

95
- [`generate_sdf`]: computes the signed distance field for the mesh defined by `vertices` and `indices` at the points `query_points`.
@@ -42,9 +38,11 @@ let sdf: Vec<f32> = generate_grid_sdf(
4238
&vertices,
4339
Topology::TriangleList(Some(&indices)),
4440
&grid,
45-
SignMethod::Normal, // How the sign is computed.
46-
); // Normal might leak negative distances outside the mesh
47-
// but works for all meshes, even surfaces.
41+
SignMethod::Raycast, // How the sign is computed.
42+
// Raycast is robust but requires the mesh to be watertight.
43+
// and is more expensive.
44+
// Normal might leak negative distances outside the mesh
45+
); // but works for all meshes, even surfaces.
4846

4947
for x in 0..cell_count[0] {
5048
for y in 0..cell_count[1] {
@@ -64,7 +62,7 @@ Indices can be of any type that implements `Into<u32>`, e.g. `u16` and `u32`. To
6462
If the indices are not provided, they are supposed to be `0..vertices.len()`.
6563

6664
For vertices, this library aims to be as generic as possible by providing a trait `Point` that can be implemented for any type.
67-
Implementations for most common math libraries are gated behind feature flags. By default, only `[f32; 3]` is provided.
65+
Implementations for most common math libraries are gated behind feature flags. By default, `[f32; 3]` and `nalgebra::[Point3, Vector3]` are provided.
6866
If you do not find your favorite library, feel free to implement the trait for it and submit a PR or open an issue.
6967

7068
---
@@ -77,22 +75,26 @@ This crate provides two methods to compute the sign of the distance:
7775
- [`SignMethod::Normal`]: uses the normals of the triangles to estimate the sign by doing a dot product with the direction of the query point.
7876
It works for non-watertight meshes but might leak negative distances outside the mesh.
7977

80-
Both methods have roughly the same performances, depending on the acceleration structure used for generic queries.
78+
Using `Raycast` is slower than `Normal` but gives better results. Performances depends on the triangle count and method used.
79+
On big dataset, `Raycast` is 5-10% slower for grid generation and rtree based methods. On smaller dataset, the difference can be worse
80+
depending on whether the query is triangle intensive or query point intensive.
81+
For bvh the difference is negligible between the two methods.
8182

8283
---
8384

8485
##### Acceleration structures
8586

8687
For generic queries, you can use acceleration structures to speed up the computation.
87-
- [`AccelerationMethod::None`]: no acceleration structure. This is the slowest method but requires no extra memory.
88+
- [`AccelerationMethod::None`]: no acceleration structure. This is the slowest method but requires no extra memory. Scales really poorly.
8889
- [`AccelerationMethod::Bvh`]: Bounding Volume Hierarchy. Accepts a `SignMethod`.
89-
- [`AccelerationMethod::Rtree`]: R-tree. Only compatible with `SignMethod::Normal`. The fastest method assuming you have more than a couple thousands of queries.
90-
- [`AccelerationMethod::RtreeBvh`] (default): Uses R-tree for nearest neighbor search and Bvh for raycasting.
90+
- [`AccelerationMethod::Rtree`]: R-tree. Uses `SignMethod::Normal`. The fastest method assuming you have more than a couple thousands of queries.
91+
- [`AccelerationMethod::RtreeBvh`] (default): Uses R-tree for nearest neighbor search and Bvh for `SignMethod::Raycast`. 5-10% slower than `Rtree` on big datasets.
9192

9293
If your mesh is watertight and you have more than a thousand queries/triangles, you should use `AccelerationMethod::RtreeBvh` for best performances.
9394
If it's not watertight, you can use `AccelerationMethod::Rtree` instead.
9495

95-
`Rtree` methods are ~4x faster than `Bvh` methods for big enough data. `AccelerationMethod::None` scales really poorly and should be avoided unless for small datasets or if you're really tight on memory.
96+
`Rtree` methods are 3-4x faster than `Bvh` methods for big enough data. On small meshes, the difference is negligible.
97+
`AccelerationMethod::None` scales really poorly and should be avoided unless for small datasets or if you're really tight on memory.
9698

9799
---
98100

@@ -111,20 +113,13 @@ Currently, the following libraries are supported:
111113
- [nalgebra] ([`nalgebra::Vector3<f32>`] and [`nalgebra::Point3<f32>`])
112114
- `[f32; 3]`
113115

116+
[nalgebra] is always available as it's used internally in the bvh tree.
117+
114118
---
115119

116120
##### Serialization
117121

118122
If you want to serialize and deserialize signed distance fields, you need to enable the `serde` feature.
119123
This features also provides helpers to save and load signed distance fields to and from files via `save_to_file` and `read_from_file`.
120124

121-
---
122-
123-
##### Benchmarks
124-
125-
[`generate_grid_sdf`] is much faster than [`generate_sdf`] and should be used whenever possible.
126-
[`generate_sdf`] does not allocate memory (except for the result array) but is slow. A faster implementation is planned for the future.
127-
128-
[`SignMethod::Raycast`] is slightly slower than [`SignMethod::Normal`] but is robust and should be used whenever possible (~1% in [`generate_grid_sdf`], ~10% in [`generate_sdf`]).
129-
130125
License: MIT OR Apache-2.0

mesh_to_sdf_client/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mesh_to_sdf_client"
33
authors = ["Etienne Desbois <[email protected]>"]
4-
version = "0.3.1"
4+
version = "0.4.0"
55
edition = "2021"
66
homepage = "https://github.com/Azkellas/mesh_to_sdf"
77
license = "MIT OR Apache-2.0"

0 commit comments

Comments
 (0)