Skip to content

bbox_numpy to mesh.aabb method integration or Box class extra features #1456

@2twenity

Description

@2twenity

Feature Request

Hello everyone, I'd like to implement some extra features as a developer to Box so the mesh.aabb returns more flexible object. Ideal case would be a box that is fully based on numpy and represented simply as 2 diagonal points (2 numpy arrays). Maybe some flag could be added to mesh.aabb so we can choose which sort of a box we expect.

Details

Problem statement
I'm playing with compas_model bvh.from_meshes method and trying to implement bvh based on aabb nodes. To calculate parameters like SAH (Surface Are Heuristic) the following box methods are required:

  1. Boxes summing or union method
  2. Box surface area
  3. Box centroid

Solution Proposal
I'll paste some rough logic of what is supposed to happen

  1. add method or "union" which will allow to sum 2 instances of a Box class
def __add__(self, box):
    """Returns a 3D summary box that contains both of summed boxes"""
    if isinstance(box, SuperchargedBox):
        all_points = self.points + box.points
            return self.from_points(all_points)
    else:
        raise TypeError("Instances belong to different classes")
  1. Surface are calculations
def compute_surface_area(self):
        return (self.xsize * self.ysize + self.xsize * self.zsize + self.ysize * self.zsize) * 2
  1. Centroid
def centroid(self) -> Point:
        """Returns a Centroid of the Box"""
        arr_max = np.asarray([self.xmax, self.ymax, self.zmax])
        arr_min = np.asarray([self.xmin, self.ymin, self.zmin])

        res = (arr_max + arr_min) / 2
        return Point(*res)

Alternatives
If the box is represented as 2 numpy arrays (2 points of the diagonal). So none of the extra calculations called on constructors methods. It'll also allow to make infinitely small box and infinitely big boxes for summing/union operations.

Also, as I mentioned, some sort of flexibility when making calling a mesh.aabb would be useful.

Mesh.aabb(numpy_box=True) -> bbox_numpy

Or these changes could be made in compas_model. I'd appreciate your feedback on these changes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions