Skip to content

Commit

Permalink
rescale intensities to the "real" values from scale 0 to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dancergraham committed Oct 20, 2024
1 parent 30a3192 commit fd90816
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ unsafe fn read_points(py: Python<'_>, filepath: &str) -> PyResult<E57> {
let mut color_vec = Vec::with_capacity(pc.records as usize * 3);
let mut intensity_vec = Vec::with_capacity(pc.records as usize);
let mut nrows = 0;
let intensity_min = pc.intensity_limits.map(|limits| limits.min).unwrap_or(0.0);
let intensity_max = pc.intensity_limits.map(|limits| limits.max).unwrap_or(1.0);
for pointcloud in file.pointclouds() {
let mut iter = file
.pointcloud_simple(&pointcloud)
Expand All @@ -67,14 +69,12 @@ unsafe fn read_points(py: Python<'_>, filepath: &str) -> PyResult<E57> {
point_vec.extend([x, y, z]);
nrows += 1
}
// if let Some(intensity) = p.intensity{
// vec.append(intensity as f64)
// }
if let Some(color) = p.color {
color_vec.extend([color.red, color.green, color.blue])
}
if let Some(intensity) = p.intensity {
intensity_vec.push(intensity)
let rescaled_intensity = (intensity * (intensity_max - intensity_min)) + intensity_min;
intensity_vec.push(rescaled_intensity)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/test_e57.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def test_read_intensity():
intensity = pointcloud.intensity
assert isinstance(intensity, np.ndarray)
assert len(intensity) == 1_220
assert np.all(intensity >= 0.3935)
assert np.all(intensity <= 0.5555)


def test_no_rgb_intensity():
pointcloud = e57.read_points(r"testdata/bunnyFloat.e57")
intensity = pointcloud.intensity
assert isinstance(intensity, np.ndarray)
assert len(intensity) == 0


def test_box_dimensions():
Expand Down

0 comments on commit fd90816

Please sign in to comment.