Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<T> HGrid<T> {
/// Inserts the given `element` into the cell containing the given `point`.
pub fn insert(&mut self, point: &Point3<Real>, element: T) {
let key = self.key(point);
self.cells.entry(key).or_insert_with(Vec::new).push(element)
self.cells.entry(key).or_default().push(element);
}

/// Returns the element attached to the cell containing the given `point`.
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Rust implementation of the [Screened poisson reconstruction](https://www.cs.jhu.
by Kazhdan and Hoppe.
*/

#![warn(clippy::pedantic)]
#![warn(clippy::perf)]
#![allow(clippy::type_complexity, clippy::too_many_arguments)]
#![warn(missing_docs)]

Expand Down
22 changes: 13 additions & 9 deletions src/marching_cubes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ pub struct MeshBuffers {

impl MeshBuffers {
/// The mesh’s index buffer.
#[must_use]
pub fn indices(&self) -> &[u32] {
&self.indices
}

/// The mesh’s vertex buffer.
#[must_use]
pub fn vertices(&self) -> &[Point3<f64>] {
&self.vertices
}

/// Return the results as a soup of triangle, with duplicated vertices.
#[must_use]
pub fn result_as_triangle_soup(&self) -> Vec<Point3<f64>> {
self.indices
.iter()
Expand All @@ -39,6 +42,7 @@ impl MeshBuffers {
/// Constructs a `TriMesh` from this buffer.
///
/// The result is `None` if the index buffer of `self` is empty.
#[must_use]
pub fn result(&self, flags: TriMeshFlags) -> Option<TriMesh> {
let idx: Vec<_> = self
.indices
Expand Down Expand Up @@ -179,14 +183,14 @@ pub(crate) fn march_cube_idx(
let local_corner_1 = INDEX_TO_VERTEX[v1 as usize];

let eid0 = [
first_corner_cell_key[0] + local_corner_0[0] as i32,
first_corner_cell_key[1] + local_corner_0[1] as i32,
first_corner_cell_key[2] + local_corner_0[2] as i32,
first_corner_cell_key[0] + i32::from(local_corner_0[0]),
first_corner_cell_key[1] + i32::from(local_corner_0[1]),
first_corner_cell_key[2] + i32::from(local_corner_0[2]),
];
let eid1 = [
first_corner_cell_key[0] + local_corner_1[0] as i32,
first_corner_cell_key[1] + local_corner_1[1] as i32,
first_corner_cell_key[2] + local_corner_1[2] as i32,
first_corner_cell_key[0] + i32::from(local_corner_1[0]),
first_corner_cell_key[1] + i32::from(local_corner_1[1]),
first_corner_cell_key[2] + i32::from(local_corner_1[2]),
];

let edge_key = SortedPair::new(eid0, eid1);
Expand Down Expand Up @@ -229,9 +233,9 @@ fn lerp_vertices(va: &[u8; 3], vb: &[u8; 3], fa: Real, fb: Real, isoval: Real) -
};

Point3::new(
va[0] as Real + (vb[0] as Real - va[0] as Real) * t,
va[1] as Real + (vb[1] as Real - va[1] as Real) * t,
va[2] as Real + (vb[2] as Real - va[2] as Real) * t,
Real::from(va[0]) + (Real::from(vb[0]) - Real::from(va[0])) * t,
Real::from(va[1]) + (Real::from(vb[1]) - Real::from(va[1])) * t,
Real::from(va[2]) + (Real::from(vb[2]) - Real::from(va[2])) * t,
)
}

Expand Down
8 changes: 8 additions & 0 deletions src/poisson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl PoissonReconstruction {
/// value). Higher values increases computation times.
/// - `max_relaxation_iters`: the maximum number of iterations for the internal
/// conjugate-gradient solver. Values around `10` should be enough for most cases.
#[must_use]
pub fn from_points_and_normals(
points: &[Point3<Real>],
normals: &[Vector3<Real>],
Expand Down Expand Up @@ -125,11 +126,13 @@ impl PoissonReconstruction {
}

/// The domain where the surface’s implicit function is defined.
#[must_use]
pub fn aabb(&self) -> &Aabb {
self.layers.last().unwrap().cells_qbvh.root_aabb()
}

/// Does the given AABB intersect any of the smallest grid cells of the reconstruction?
#[must_use]
pub fn leaf_cells_intersect_aabb(&self, aabb: &Aabb) -> bool {
let mut intersections = vec![];
self.layers
Expand All @@ -143,6 +146,7 @@ impl PoissonReconstruction {
/// Evaluates the value of the implicit function at the given 3D point.
///
/// In order to get a meaningful value, the point must be located inside of [`Self::aabb`].
#[must_use]
pub fn eval(&self, pt: &Point3<Real>) -> Real {
let mut result = 0.0;

Expand All @@ -156,6 +160,7 @@ impl PoissonReconstruction {
/// Evaluates the value of the implicit function’s gradient at the given 3D point.
///
/// In order to get a meaningful value, the point must be located inside of [`Self::aabb`].
#[must_use]
pub fn eval_gradient(&self, pt: &Point3<Real>) -> Vector3<Real> {
let mut result = Vector3::zeros();

Expand All @@ -169,18 +174,21 @@ impl PoissonReconstruction {
/// Reconstructs a mesh from this implicit function using a simple marching-cubes, extracting
/// the isosurface at 0.
#[deprecated = "use `reconstruct_mesh_buffers` or `reconstruct_trimesh` instead"]
#[must_use]
pub fn reconstruct_mesh(&self) -> Vec<Point3<Real>> {
self.reconstruct_mesh_buffers().result_as_triangle_soup()
}

/// Reconstructs a `TriMesh` from this implicit function using a simple marching-cubes, extracting
/// the isosurface at 0.
#[must_use]
pub fn reconstruct_trimesh(&self, flags: TriMeshFlags) -> Option<TriMesh> {
self.reconstruct_mesh_buffers().result(flags)
}

/// Reconstructs a mesh from this implicit function using a simple marching-cubes, extracting
/// the isosurface at 0.
#[must_use]
pub fn reconstruct_mesh_buffers(&self) -> MeshBuffers {
let mut result = MeshBuffers::default();
let mut visited = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion src/poisson_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ impl PoissonLayer {
Self {
grid,
cells_qbvh,
ordered_nodes,
grid_node_idx,
ordered_nodes,
node_weights,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl TriQuadraticBspline {
let mut result = 1.0;

for i in 0..3 {
result *= eval_bspline(pt[i], self.center[i], self.width)
result *= eval_bspline(pt[i], self.center[i], self.width);
}

result
Expand Down