Skip to content

Commit

Permalink
Fix duplicate faces in TirMesh connected components
Browse files Browse the repository at this point in the history
Fix #115
  • Loading branch information
sebcrozet committed Jan 15, 2023
1 parent 9e7abd6 commit d870907
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ parry2d-f64 = { path = "crates/parry2d-f64" }
parry3d-f64 = { path = "crates/parry3d-f64" }

#simba = { path = "../simba" }
simba = { git = "https://github.com/dimforge/simba", rev = "45a5266eb36ed9d25907e9bf9130cd4ac846a748" }
nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "0cf79aef0e6155befc3279a3145f1940822b8377" }
#simba = { git = "https://github.com/dimforge/simba", rev = "45a5266eb36ed9d25907e9bf9130cd4ac846a748" }
#nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "0cf79aef0e6155befc3279a3145f1940822b8377" }
6 changes: 3 additions & 3 deletions crates/parry2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "^0.7.3", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
simba = { version = "0.8", default-features = false }
nalgebra = { version = "0.32", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
rkyv = { version = "0.7", optional = true }
Expand All @@ -65,5 +65,5 @@ bytemuck = { version = "1", features = [ "derive" ], optional = true }
cust = { version = "0.3", optional = true }

[dev-dependencies]
simba = { version = "0.7", default-features = false, features = [ "partial_fixed_point_support" ] }
simba = { version = "0.8", default-features = false, features = [ "partial_fixed_point_support" ] }
oorandom = "11"
6 changes: 3 additions & 3 deletions crates/parry2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "^0.7.3", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
simba = { version = "0.8", default-features = false }
nalgebra = { version = "0.32", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
rkyv = { version = "0.7", optional = true }
Expand All @@ -65,5 +65,5 @@ bytemuck = { version = "1", features = [ "derive" ], optional = true }
cust = { version = "0.3", optional = true }

[dev-dependencies]
simba = { version = "0.7", default-features = false, features = [ "partial_fixed_point_support" ] }
simba = { version = "0.8", default-features = false, features = [ "partial_fixed_point_support" ] }
oorandom = "11"
4 changes: 2 additions & 2 deletions crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "^0.7.3", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
simba = { version = "0.8", default-features = false }
nalgebra = { version = "0.32", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive", "rc"]}
rkyv = { version = "0.7", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "^0.7.3", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
simba = { version = "0.8", default-features = false }
nalgebra = { version = "0.32", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive", "rc"]}
rkyv = { version = "0.7", optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/parry3d/tests/geometry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ mod cylinder_cuboid_contact;
mod epa3;
mod still_objects_toi;
mod time_of_impact3;
mod trimesh_connected_components;
mod trimesh_intersection;
mod trimesh_trimesh_toi;
31 changes: 31 additions & 0 deletions crates/parry3d/tests/geometry/trimesh_connected_components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use parry3d::math::Point;
use parry3d::shape::{TriMesh, TriMeshFlags};

#[test]
// From https://github.com/dimforge/parry/issues/115
fn mesh_connected_components_grouped_faces() {
let verts = vec![
// Face 0
Point::new(15.82, 6.455, -0.15), // <- Vertex shared with face 1.
Point::new(9.915, 6.455, -0.15),
Point::new(9.915, 6.4, 0.0), // <- Vertex shared with face 1.
// Face1
Point::new(15.82, 6.455, -0.15), // <- Vertex shared with face 0.
Point::new(9.915, 6.4, 0.0), // <- Vertex shared with face 0.
Point::new(15.82, 6.4, 0.0),
];

let mut roof = TriMesh::new(verts, vec![[0, 1, 2], [3, 4, 5]]);

if let Err(e) =
roof.set_flags(TriMeshFlags::MERGE_DUPLICATE_VERTICES | TriMeshFlags::CONNECTED_COMPONENTS)
{
dbg!(e);
assert!(false);
}

let components = roof.connected_components().unwrap();
println!("components: {:?}", components);
assert_eq!(components.ranges.len(), 2); // Only one connected-component (two range values).
assert_eq!(components.grouped_faces.len(), 2); // Only two faces in the connected-component.
}
8 changes: 5 additions & 3 deletions src/shape/trimesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,20 +921,22 @@ impl TriMesh {
// NOTE: we can only compute connected components if the topology
// has been computed too. So instead of making this method
// public, the `.compute_topology` method has a boolean to
// compute the connected componets too.
// compute the connected components too.
fn compute_connected_components(&mut self) {
let topo = self.topology.as_ref().unwrap();
let mut face_colors = vec![u32::MAX; topo.faces.len()];
let mut grouped_faces = Vec::new();
let mut ranges = vec![0];
let mut stack = vec![];

for i in 0..topo.faces.len() {
if face_colors[i] == u32::MAX {
let mut stack = vec![i as u32];
let color = ranges.len() as u32 - 1;
face_colors[i] = color;
grouped_faces.push(i as u32);
stack.push(i as u32);

while let Some(tri_id) = stack.pop() {
grouped_faces.push(tri_id);
let eid = topo.faces[tri_id as usize].half_edge;
let edge_a = &topo.half_edges[eid as usize];
let edge_b = &topo.half_edges[edge_a.next as usize];
Expand Down

0 comments on commit d870907

Please sign in to comment.