mikepound / opencubes

A community improved version of the polycubes project!
MIT License
44 stars 23 forks source link

Reducing rotations based on bounding box constraint #45

Open rubaiate opened 11 months ago

rubaiate commented 11 months ago

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

bertie2 commented 11 months ago

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!

rubaiate commented 11 months ago

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