def test_from_mesh(self): """Make a mesh and verify the bounding box's corners are correct.""" indices = np.array([0, 1, 2, 1, 3, 2, 2, 3, 4], dtype=np.uint32) vertices = np.column_stack( [ Vector3f(0, 0, 0), Vector3f(1, 0, 0), Vector3f(0, 1, 0), Vector3f(1, 1, 0), Vector3f(1, 1, 1), ] ) normals = np.column_stack([Vector3f(0, 0, 1)] * 5) self.assertEqual(vertices.shape, normals.shape) self.assertEqual(indices.shape, (9,)) mesh = Mesh(indices, vertices, normals) box = ComputeBbox().from_mesh(mesh) corners = box.corners() corners_target = np.column_stack( [ [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0], ] ) np.testing.assert_array_equal(corners, corners_target)
def test_random_points(self): """ Make three random points and verify the bounding box's corners are correct """ point1 = Vector3f(-1, -2, -3) point2 = Vector3f(0, 2, 1) point3 = Vector3f(1, 2, 3) points = np.column_stack([point1, point2, point3]) box = ComputeBbox().from_point_cloud(points) corners = box.corners() corners_target = np.column_stack([ [-1.0, -2.0, 3.0], [1.0, -2.0, 3.0], [1.0, 2.0, 3.0], [-1.0, 2.0, 3.0], [-1.0, -2.0, -3.0], [1.0, -2.0, -3.0], [1.0, 2.0, -3.0], [-1.0, 2.0, -3.0], ]) np.testing.assert_array_equal(corners, corners_target)
def test_unit_cube(self): """ Make three points inside a unit cube and verify the bounding box's corners are correct """ point1 = Vector3(1, 0, 0) point2 = Vector3(0, 1, 0) point3 = Vector3(0, 0, 1) points = np.column_stack([point1, point2, point3]) box = ComputeBbox().from_point_cloud(points) corners = box.corners() corners_target = np.column_stack([ [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0], ]) np.testing.assert_array_equal(corners, corners_target)