def test_quaternion(self): q = np.array([0.9997472337219893, 0.0, 0.0, 0.022482630300529462]) assert np.array_equal(self.box.q, q) # alternative attribute for the quaternion assert np.array_equal(self.box.quaternion, q) box = BoundingBox3D(self.box.cx, self.box.cy, self.box.cz, q=self.box.q) assert np.array_equal(self.box.q, box.q)
def test_init_non_center(self): cx, cy, cz = self.box.cx, self.box.cy, self.box.cz box = BoundingBox3D( cx - self.box.length / 2, cy - self.box.width / 2, cz - self.box.height / 2, self.box.length, self.box.width, self.box.height, is_center=False, ) assert np.array_equal(box.center, self.box.center)
def test_euler_angles(self): box = BoundingBox3D( 3.163, z=2.468, y=34.677, height=1.529, width=1.587, length=3.948, euler_angles=[0, 0, -1.59], ) q = np.array([0.7002847660410397, 0.0, 0.0, -0.713863604935036]) assert np.allclose(box.q, q)
def test_from_xyz_xyz(): xyz1 = [10, 0, 0] xyz2 = [50, 60, 70] # Test with smallest, largest bbox = BoundingBox3D.from_xyzxyz(xyz1, xyz2) assert np.allclose(bbox.center, np.array([30, 30, 35])) # Test with largest, smallest point # The order of the points should not matter bbox = BoundingBox3D.from_xyzxyz(xyz2, xyz1) assert np.allclose(bbox.center, np.array([30, 30, 35])) # Make sure the dimensions are correct assert bbox.length == 40 assert bbox.width == 60 assert bbox.height == 70 # Test with a different set of opposite points # No longer absolute min and absolute max xyz1 = [10, 0, 70] xyz2 = [50, 60, 0] bbox = BoundingBox3D.from_xyzxyz(xyz2, xyz1) assert np.allclose(bbox.center, np.array([30, 30, 35]))
def create_bounding_box(): values = { "position": { "x": 6.536307742091793, "y": -2.1117338632172125, "z": 1.1549238563313258, }, "rotation": { "x": -0.08282295820270243, "y": -0.10018696688968483, "z": -0.6927483959297558, }, "dimensions": { "x": 2.3551822605229615, "y": 2.075954356460532, "z": 0.7333401523302493, }, } center = np.array([ values["position"]["x"], values["position"]["y"], values["position"]["z"] ]) dimensions = np.array([ values["dimensions"]["x"], values["dimensions"]["y"], values["dimensions"]["z"], ]) rotation = np.array([ values["rotation"]["x"], values["rotation"]["y"], values["rotation"]["z"] ]) bbox = BoundingBox3D.from_center_dimension_euler(center=center, dimension=dimensions, euler_angles=rotation) return bbox
def setup_class(cls): # sample cuboid cuboid = { "center": { "x": -49.19743041908411, "y": 12.38666074615689, "z": 0.782056864653507, }, "dimensions": { "length": 5.340892485711914, "width": 2.457703972075464, "height": 1.9422248281533563, }, "rotation": { "w": 0.9997472337219893, "x": 0.0, "y": 0.0, "z": 0.022482630300529462, }, } center = cuboid["center"] dim = cuboid["dimensions"] rotation = cuboid["rotation"] cls.box = BoundingBox3D( center["x"], center["y"], center["z"], length=dim["length"], width=dim["width"], height=dim["height"], rw=rotation["w"], rx=rotation["x"], ry=rotation["y"], rz=rotation["z"], ) cls.cuboid = cuboid
def test_init_center(self): box = BoundingBox3D(*[self.box.cx, self.box.cy, self.box.cz], is_center=True) assert np.array_equal(box.center, self.box.center)