-
Notifications
You must be signed in to change notification settings - Fork 113
Description
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:
- Boxes summing or union method
- Box surface area
- Box centroid
Solution Proposal
I'll paste some rough logic of what is supposed to happen
- 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")
- Surface are calculations
def compute_surface_area(self):
return (self.xsize * self.ysize + self.xsize * self.zsize + self.ysize * self.zsize) * 2
- 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.