opencubes
opencubes copied to clipboard
Reducing rotations based on bounding box constraint
This change enhance run time performance of python implementation by reducing number of rotations necessary.
The logic is based on bounding box of the new cube shape. Since cube is already cropped we can safely use np.shape as bounding box.
Performance improvement tested for n = 8
Without improvement
With improvement
New steps
- After creating expanded cube it is rotated such that np.shape values are sorted order. This will help analyzing cube in later stages. Ex: if input cube.shape is (4, 1, 2) it will be rotated into (1, 2, 4)
- Based on the bounding box possible rotations can be constrained. As an example lets assume object bounding box size is (1, 2, 4). Any cube has same shape should have same bounding box. So search space should only have objects which contained in (1, 2, 4) bounding box. To keep bounding box constraint cube can be rotated in only 4 ways.
Following is the list of all possibilities
-
All axes size is equal No constraints are possible. Should be validated for 24 rotations.
-
Two axes sizes are equal other axis size is different Only 8 rotations are possible without breaking bounding box `for _ in range(0, 4): yield cube cube = np.rot90(cube, 1, equal_axes)
cube = np.rot90(cube, 2, (diff_axis, equal_axes[0]))
for _ in range(0, 4): yield cube cube = np.rot90(cube, 1, equal_axes)`
-
All axes sizes are different. Only 4 rotations are possible without breaking bounding box. yield cube yield np.rot90(cube, 2, (0, 1)) yield np.rot90(cube, 2, (0, 2)) yield np.rot90(cube, 2, (1, 2))
looks good and is well commented, however your choice of ordering of the axis (first <= second <= third) is the opposite to the previous ordering method, if possible could that be reversed to (first >= second >= third) , otherwise I'm happy to merge this asap!
Logic is updated to provide (first >= second >= third) axis size ordering.