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

Fix caching of TransformForest #363

Merged
merged 1 commit into from
Apr 1, 2019

Conversation

wkentaro
Copy link
Contributor

@wkentaro wkentaro commented Apr 1, 2019

What is the problem?

Caching in TransformForest seems not so robust.

If we have below program and we run it several times, I got below output, which is unexpected.

program

#!/usr/bin/env python

import numpy as np
import trimesh


scene = trimesh.Scene()
scene.add_geometry(trimesh.creation.axis(0.01))

scene.set_camera()
print('transform (old):\n', scene.camera.transform)
scene.camera.transform = np.eye(4)
print('transform (new):\n', scene.camera.transform)

scene.show()

output

% python spam.py
transform (old):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]
transform (new):
 [[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

% python spam.py
transform (old):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]
transform (new):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]

% python spam.py
transform (old):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]
transform (new):
 [[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

% python spam.py
transform (old):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]
transform (new):
 [[1.         0.         0.         0.04514312]
 [0.         1.         0.         0.04509278]
 [0.         0.         1.         0.23255776]
 [0.         0.         0.         1.        ]]

The transform (new) must be always identity matrix (I expect) but it's not.
This problem is caused by the caching strategy in trimesh.scene.transforms.TransformForest, and this PR fixes it.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.09% when pulling b21f988 on wkentaro:caching_transform_forest into f42f7a6 on mikedh:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.09% when pulling b21f988 on wkentaro:caching_transform_forest into f42f7a6 on mikedh:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.09% when pulling b21f988 on wkentaro:caching_transform_forest into f42f7a6 on mikedh:master.

@mikedh
Copy link
Owner

mikedh commented Apr 1, 2019

Good catch! I wonder if _updated should just be a random number (i.e. in a tight loop does it execute faster than the time resolution.) I'll add a test as well- thanks for the PR!

@mikedh mikedh merged commit 77ddd08 into mikedh:master Apr 1, 2019
@wkentaro
Copy link
Contributor Author

wkentaro commented Apr 1, 2019 via email

@wkentaro wkentaro deleted the caching_transform_forest branch April 5, 2019 08:33
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

Successfully merging this pull request may close these issues.

None yet

3 participants