diff --git a/Cargo.lock b/Cargo.lock index c17c328..c7f66c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,7 +393,7 @@ dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", + "memoffset 0.8.0", "scopeguard", ] @@ -643,9 +643,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" [[package]] name = "is-terminal" @@ -801,6 +801,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "nalgebra" version = "0.32.2" @@ -911,9 +920,9 @@ dependencies = [ [[package]] name = "numpy" -version = "0.18.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b0fee4571867d318651c24f4a570c3f18408cf95f16ccb576b3ce85496a46e" +checksum = "bef41cbb417ea83b30525259e30ccef6af39b31c240bda578889494c5392d331" dependencies = [ "libc", "ndarray", @@ -1099,14 +1108,14 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.18.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfb848f80438f926a9ebddf0a539ed6065434fd7aae03a89312a9821f81b8501" +checksum = "9a89dc7a5850d0e983be1ec2a463a171d20990487c3cfcd68b5363f1ee3d6fe0" dependencies = [ "cfg-if", "indoc", "libc", - "memoffset", + "memoffset 0.9.0", "parking_lot", "pyo3-build-config", "pyo3-ffi", @@ -1116,9 +1125,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.18.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98a42e7f42e917ce6664c832d5eee481ad514c98250c49e0b03b20593e2c7ed0" +checksum = "07426f0d8fe5a601f26293f300afd1a7b1ed5e78b2a705870c5f30893c5163be" dependencies = [ "once_cell", "target-lexicon", @@ -1126,9 +1135,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.18.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0707f0ab26826fe4ccd59b69106e9df5e12d097457c7b8f9c0fd1d2743eec4d" +checksum = "dbb7dec17e17766b46bca4f1a4215a85006b4c2ecde122076c562dd058da6cf1" dependencies = [ "libc", "pyo3-build-config", @@ -1136,25 +1145,26 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.18.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978d18e61465ecd389e1f235ff5a467146dc4e3c3968b90d274fe73a5dd4a438" +checksum = "05f738b4e40d50b5711957f142878cfa0f28e054aa0ebdfc3fd137a843f74ed3" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 1.0.109", + "syn 2.0.11", ] [[package]] name = "pyo3-macros-backend" -version = "0.18.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e0e1128f85ce3fca66e435e08aa2089a2689c1c48ce97803e13f63124058462" +checksum = "0fc910d4851847827daf9d6cdd4a823fbdaab5b8818325c5e97a86da79e8881f" dependencies = [ + "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.11", ] [[package]] @@ -1627,9 +1637,9 @@ dependencies = [ [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "url" diff --git a/Cargo.toml b/Cargo.toml index 40200c8..07f38c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,12 @@ version = "0.19.0" edition = "2018" [dependencies] -pyo3 = { version = "0.18", features = ["extension-module", "abi3-py38"] } +pyo3 = { version = "0.20", features = ["extension-module", "abi3-py38"] } parry3d-f64 = { version = "0.13", features = ["dim3", "f64", "enhanced-determinism"] } rayon = "1.7" rand = "0.8" rand_pcg = "0.3" -numpy = "0.18" +numpy = "0.20" log = "0.4.20" # ndarray is a dependency of numpy. diff --git a/python/ncollpyde/_ncollpyde.pyi b/python/ncollpyde/_ncollpyde.pyi index 2ac2874..4d0f231 100644 --- a/python/ncollpyde/_ncollpyde.pyi +++ b/python/ncollpyde/_ncollpyde.pyi @@ -17,7 +17,7 @@ class TriMeshWrapper: self, points: Points, indices: Indices, n_rays: int, ray_seed: int ): ... def contains( - self, points: Points, n_rays: Optional[int], consensus: int, parallel: bool + self, points: Points, n_rays: int, consensus: int, parallel: bool ) -> npt.NDArray[np.bool_]: ... def distance( self, points: Points, signed: bool, parallel: bool diff --git a/python/ncollpyde/main.py b/python/ncollpyde/main.py index 553435c..74662a3 100644 --- a/python/ncollpyde/main.py +++ b/python/ncollpyde/main.py @@ -217,7 +217,7 @@ def contains( :param coords: :param n_rays: Optional[int] If None, use the maximum rays defined on construction. - If < 0, use signed distance strategy + If < 1, use signed distance strategy (more robust, but slower for many meshes). Otherwise, use this many meshes, up to the maximum defined on construction. :param consensus: Optional[int] @@ -235,7 +235,7 @@ def contains( coords = self._as_points(coords) if n_rays is None: n_rays = self.n_rays - elif n_rays < 0: + elif n_rays < 1: n_rays = None elif n_rays > self.n_rays: logger.warning( @@ -245,6 +245,7 @@ def contains( if n_rays is None: consensus = 1 + n_rays = 0 else: if consensus is None: consensus = n_rays // 2 + 1 diff --git a/src/interface.rs b/src/interface.rs index d1b4c56..addc5b2 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,4 +1,3 @@ -use std::fmt::Debug; use std::iter::repeat_with; use ndarray::{Array2, ArrayView1}; @@ -17,13 +16,13 @@ use crate::utils::{ points_cross_mesh, random_dir, sdf_inner, Precision, FLAGS, }; -fn vec_to_point(v: Vec) -> Point { - Point::new(v[0], v[1], v[2]) -} +// fn vec_to_point(v: Vec) -> Point { +// Point::new(v[0], v[1], v[2]) +// } -fn point_to_vec(p: &Point) -> Vec { - vec![p.x, p.y, p.z] -} +// fn point_to_vec(p: &Point) -> Vec { +// vec![p.x, p.y, p.z] +// } #[pyclass] pub struct TriMeshWrapper { @@ -96,20 +95,21 @@ impl TriMeshWrapper { collected.into_pyarray(py) } + // #[pyo3(signature = (points, n_rays=None, consensus=None, parallel=None))] pub fn contains<'py>( &self, py: Python<'py>, points: PyReadonlyArray2, - n_rays: Option, + n_rays: usize, consensus: usize, parallel: bool, ) -> &'py PyArray1 { let p_arr = points.as_array(); let zipped = Zip::from(p_arr.rows()); - let collected = if let Some(n) = n_rays { + let collected = if n_rays >= 1 { // use ray casting - let rays = &self.ray_directions[..n]; + let rays = &self.ray_directions[..n_rays]; let clos = |r: ArrayView1| { mesh_contains_point(&self.mesh, &Point::new(r[0], r[1], r[2]), rays, consensus) }; @@ -242,7 +242,7 @@ impl TriMeshWrapper { .as_array() .rows() .into_iter() - .zip(tgt_points.as_array().rows().into_iter()) + .zip(tgt_points.as_array().rows()) .zip(0_u64..) .for_each(|((src, tgt), i)| { if let Some((pt, is_bf)) = points_cross_mesh( @@ -265,25 +265,6 @@ impl TriMeshWrapper { ) } - #[deprecated] - pub fn intersections_many_threaded( - &self, - src_points: Vec>, - tgt_points: Vec>, - ) -> (Vec, Vec>, Vec) { - let (idxs, (intersections, is_backface)) = src_points - .into_par_iter() - .zip(tgt_points.into_par_iter()) - .enumerate() - .filter_map(|(i, (src, tgt))| { - points_cross_mesh(&self.mesh, &vec_to_point(src), &vec_to_point(tgt)) - .map(|o| (i as u64, (point_to_vec(&o.0), o.1))) - }) - .unzip(); - - (idxs, intersections, is_backface) - } - pub fn intersections_many_threaded2<'py>( &self, py: Python<'py>, diff --git a/src/utils.rs b/src/utils.rs index 5594583..00db46b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -83,7 +83,7 @@ pub fn mesh_contains_point( return false; } } - return false; + false } pub fn mesh_contains_point_oriented(mesh: &TriMesh, point: &Point) -> bool { diff --git a/tests/test_bench.py b/tests/test_bench.py index 4dc5d1f..9f26011 100644 --- a/tests/test_bench.py +++ b/tests/test_bench.py @@ -221,7 +221,7 @@ def test_trimesh_contains(trimesh_volume, sample_points, expected, benchmark): @pytest.mark.benchmark(group=CONTAINS_SERIAL) -@pytest.mark.parametrize("n_rays", [0, 1, 2, 4, 8, 16]) +@pytest.mark.parametrize("n_rays", [1, 2, 4, 8, 16]) def test_ncollpyde_contains(mesh, n_rays, sample_points, expected, benchmark): ncollpyde_volume = Volume.from_meshio(mesh, n_rays=n_rays) ncollpyde_volume.threads = False diff --git a/tests/test_ncollpyde.py b/tests/test_ncollpyde.py index 2130375..c030506 100644 --- a/tests/test_ncollpyde.py +++ b/tests/test_ncollpyde.py @@ -57,12 +57,6 @@ def test_contains_results(volume: Volume): assert np.allclose(ray, psnorms) -def test_0_rays(mesh): - vol = Volume.from_meshio(mesh, n_rays=0) - points = [p for p, _ in points_expected] - assert np.array_equal(vol.contains(points), [False] * len(points)) - - def test_no_validation(mesh): triangles = mesh.cells_dict["triangle"] Volume(mesh.points, triangles, True)