Skip to content

Commit 01a5645

Browse files
committed
Fix segfault in poisson disk downsampling of empty point cloud
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
1 parent a5ce154 commit 01a5645

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/sample_point_cloud.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ IGL_INLINE void blue_noise_downsample(const Eigen::MatrixBase<DerivedV> & X,
3535

3636
// Make a uniform random sampling with 30*expected_number_of_points.
3737
const int nx = X.rows();
38-
38+
39+
// An empty input has nothing to sample. Return early before computing the
40+
// grid bounds, since colwise().minCoeff()/maxCoeff() are undefined on a
41+
// zero-row matrix and would otherwise crash.
42+
if (nx == 0) {
43+
XI.resize(0);
44+
return;
45+
}
46+
3947
// Rescale so that s = 1
4048
Eigen::Matrix<int,Eigen::Dynamic,3,Eigen::RowMajor> Xs = ((X.rowwise()-X.colwise().minCoeff())/s).template cast<int>();
4149
const int w = Xs.maxCoeff() + 1;

tests/test_examples.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def test_mesh_sampling(self):
8181
if bc1.shape == bc3.shape:
8282
self.assertFalse(np.all(bc1 == bc3))
8383

84+
def test_poisson_disk_downsample_empty(self):
85+
import point_cloud_utils as pcu
86+
import numpy as np
87+
88+
empty = np.zeros((0, 3), dtype=np.float64)
89+
s_idx = pcu.downsample_point_cloud_poisson_disk(empty, 0.1, random_seed=1234567)
90+
self.assertEqual(s_idx.shape[0], 0)
91+
8492
def test_downsample_point_cloud_on_voxel_grid(self):
8593
import point_cloud_utils as pcu
8694
import numpy as np

0 commit comments

Comments
 (0)