daavoo / pyntcloud

pyntcloud is a Python library for working with 3D point clouds.
http://pyntcloud.readthedocs.io
MIT License
1.39k stars 221 forks source link

The logic of `io.las.read_las_with_laspy()` may not meet the las data specification. #333

Closed nokonoko1203 closed 3 months ago

nokonoko1203 commented 2 years ago

Hello. Thanks for the nice library! I think I may have found a bug, could you please check?

Describe the bug The logic of io.las.read_las_with_laspy() may not meet the las data specification. https://github.com/daavoo/pyntcloud/blob/c9dcf59eacbec33de0279899a43fe73c5c094b09/pyntcloud/io/las.py#L46

To Reproduce Steps to reproduce the behavior:

first x point value: 531578298

x_point = las.X[0]

x scale: 7.131602618438667e-08 -> 0.0000007

x_scale = header.x_scale

x offset: -44528.753

x_offset = header.x_offset

x_coordinate output from above variables: -44490.842948180776

real_coordinate_x = (x_point * x_scale) + x_offset

- The value calculated from laspy based on `EPSG:6676` is indeed at Kakegawa Castle!
  - https://www.google.co.jp/maps/place/34%C2%B046'30.3%22N+138%C2%B000'50.1%22E/@34.775077,138.0117243,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x2ce21e9ef0b19341!8m2!3d34.775077!4d138.013913?hl=ja
- But in read_las_with_laspy(), the logic is as follows, and the offset values are not added
https://github.com/daavoo/pyntcloud/blob/c9dcf59eacbec33de0279899a43fe73c5c094b09/pyntcloud/io/las.py#L55

**Expected behavior**
Offset values are taken into account for the xyz coordinates of the DataFrame.

**Screenshots**
Does not exist.

**Desktop (please complete the following information):**
 - OS: macOS Monterey v12.4
 - Browser: Does not used.
 - Version

Conda -V conda 4.12.0 ❯ conda list | grep pyntcloud pyntcloud 0.3.0 pyhd8ed1ab_0 conda-forge



**Additional context**
If the above context looks OK, shall I create a PullRequest?
daavoo commented 2 years ago

Hola @nokonoko1203 ! Thanks for reporting.

If the above context looks OK, shall I create a PullRequest?

It looks OK to me, don't hesitate on opening the P.R.

nokonoko1203 commented 2 years ago

@daavoo Thanks for checking! I thought I followed the documentation(https://github.com/daavoo/pyntcloud/blob/c9dcf59eacbec33de0279899a43fe73c5c094b09/docs/contributing.rst) to install, but I get errors in 12 tests.

Do you know this?

I am hiding personal information, but here are the complete steps I tested.

% cd ~
% git clone https://github.com/daavoo/pyntcloud.git
% conda create -n pyntcloud python=3.7
% conda activate pyntcloud
% pip install -e pyntcloud
% pip install numba flake8 pytest
% cd pyntcloud
% pytest -v
================================================================================================= test session starts ==================================================================================================
platform darwin -- Python 3.7.12, pytest-7.1.2, pluggy-1.0.0 -- ~opt/anaconda3/envs/pyntcloud/bin/python3.7
cachedir: .pytest_cache
rootdir: ~/pyntcloud
collected 148 items / 12 errors  

... # more error log

_________________________________________________________________________ ERROR collecting tests/unit/structures/test_voxelgrid_structures.py __________________________________________________________________________
import file mismatch:
imported module 'test_voxelgrid_structures' has this __file__ attribute:

~/pyntcloud/tests/integration/structures/test_voxelgrid_structures.py
which is not the same as the test file we want to collect:

~/pyntcloud/tests/unit/structures/test_voxelgrid_structures.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
=============================================================================================== short test summary info ================================================================================================
ERROR tests/unit/filters/test_kdtree_filters.py
ERROR tests/unit/filters/test_xyz_filters.py
ERROR tests/unit/samplers/test_mesh_samplers.py
ERROR tests/unit/samplers/test_points_samplers.py
ERROR tests/unit/samplers/test_voxelgrid_samplers.py
ERROR tests/unit/scalar_fields/test_eigenvalues_scalar_fields.py
ERROR tests/unit/scalar_fields/test_k_neighbors_scalar_fields.py
ERROR tests/unit/scalar_fields/test_normals_scalar_fields.py
ERROR tests/unit/scalar_fields/test_rgb_scalar_fields.py
ERROR tests/unit/scalar_fields/test_voxlegrid_scalar_fields.py
ERROR tests/unit/scalar_fields/test_xyz_scalar_fields.py
ERROR tests/unit/structures/test_voxelgrid_structures.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 12 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================================== 12 errors in 0.43s ==================================================================================================         
nokonoko1203 commented 2 years ago

However, it does not affect the part I am modifying, so I have created a PR. Please confirm. https://github.com/daavoo/pyntcloud/pull/335