Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition of origin: indices_to_points and points_to_indices for voxel #370

Closed
wkentaro opened this issue Apr 12, 2019 · 3 comments
Closed

Comments

@wkentaro
Copy link
Contributor

wkentaro commented Apr 12, 2019

If I run below code

import numpy as np
import trimesh
import trimesh.transformations as tf


matrix = np.ones((2,)*3, dtype=bool)
centers = trimesh.voxel.matrix_to_points(matrix, pitch=0.5, origin=(0,)*3)
print(centers)
centers = trimesh.voxel.matrix_to_points(matrix, pitch=0.5, origin=(0.5/2,)*3)
print(centers)
centers = trimesh.voxel.matrix_to_points(matrix, pitch=0.5, origin=(0.5,)*3)
print(centers)

the output is

[[-0.25 -0.25 -0.25]
 [-0.25 -0.25  0.25]
 [-0.25  0.25 -0.25]
 [-0.25  0.25  0.25]
 [ 0.25 -0.25 -0.25]
 [ 0.25 -0.25  0.25]
 [ 0.25  0.25 -0.25]
 [ 0.25  0.25  0.25]]
[[0.  0.  0. ]
 [0.  0.  0.5]
 [0.  0.5 0. ]
 [0.  0.5 0.5]
 [0.5 0.  0. ]
 [0.5 0.  0.5]
 [0.5 0.5 0. ]
 [0.5 0.5 0.5]]
[[0.25 0.25 0.25]
 [0.25 0.25 0.75]
 [0.25 0.75 0.25]
 [0.25 0.75 0.75]
 [0.75 0.25 0.25]
 [0.75 0.25 0.75]
 [0.75 0.75 0.25]
 [0.75 0.75 0.75]]

This shows currently, the definition of origin is right top corner of the first element. (①in the figure)

Maybe this is too late (since -0.5 is added for a while ago), but for me ② or ③ looks more reasonable as origin. By flipping sign of +-0.5 or removing it.
What do you think about this?

points = (indices - 0.5) * pitch + origin

indices = np.round((points - origin) / pitch + 0.5).astype(int)

@mikedh
Copy link
Owner

mikedh commented Apr 15, 2019

Not sure what the right answer here is. I think generally we probably want "points" to refer to the center of the voxel box?

@wkentaro
Copy link
Contributor Author

I agree that design is the least confusing. In that case, we need to remove -0.5 and 0.5 and that is not backward compatible.

@mikedh
Copy link
Owner

mikedh commented Apr 23, 2019

Closed by #388

@mikedh mikedh closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants