opencubes icon indicating copy to clipboard operation
opencubes copied to clipboard

Reducing rotations based on bounding box constraint

Open rubaiate opened this issue 2 years ago • 2 comments

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 image

With improvement image

New steps

  1. 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)
  2. 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

  1. All axes size is equal No constraints are possible. Should be validated for 24 rotations.

  2. 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)`

  3. 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))

rubaiate avatar Aug 18 '23 14:08 rubaiate

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!

bertie2 avatar Aug 22 '23 20:08 bertie2

Logic is updated to provide (first >= second >= third) axis size ordering.

rubaiate avatar Aug 23 '23 14:08 rubaiate