def test_bounding_box_io(self): """ Save and load a bounding_box project. Also try overwriting the project (should fail). """ project_scene = ProjectScene(project_type="bounding_box") bounds = Box3d([-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]) po = ProjectObject(id="1", bounds=bounds, category="chair") project_scene.elements["1"] = po # test saving project_scene.save(path=self.temp_directory, project_name="test") xml_path = os.path.join(self.temp_directory, "test", "test.xml") self.assertTrue(os.path.isfile(xml_path)) # test overwriting self.assertRaises(OSError, project_scene.save, path=self.temp_directory, project_name="test") # test loading project_scene = ProjectScene.load(path=self.temp_directory, project_name="test") self.assertIsInstance(project_scene, ProjectScene) self.assertIsInstance(project_scene.elements, ProjectObjectDict) # ::: TODO: improve check with equality test on project_scene # Check bounding box for the first ProjectObject po = project_scene.elements["1"] self.assertTrue(po.bounds.almost_equal(bounds, atol=0.01)) self.assertEqual(po.category, "chair")
def test_meshes_io(self): """Test reading and writing gltf objects.""" po = ProjectObject( id="foobar", project_type="meshes", meshes=self.meshes, pose=self.pose, category="chair", ) object_xml = po.save(self.temp_directory) po2 = ProjectObject.load("meshes", object_xml, self.temp_directory) self.assertTrue(po2.almost_equal(po))
def test_constructor(self): """ Test constructor. """ po = ProjectObject(id="1", project_type="bounding_box", bounds=self.bounds) self.assertTrue(isinstance(po.pose, Pose3)) self.assertTrue(isinstance(po.category, "".__class__)) po.pose.assert_almost_equal(Pose3()) self.assertTrue(po.bounds.almost_equal(self.bounds)) self.assertIs(po.meshes, None) self.assertIs(po.voxels, None) self.assertTrue(po.category == "unknown") self.assertEqual(po.id, "1") self.assertEqual(po.symmetry, ObjectSymmetry()) self.assertAlmostEqual(po.score, -1)
def test_transform_pose(self): po = ProjectObject(id="1", bounds=self.bounds, pose=Pose3()) po2 = po.transform_pose(self.pose) self.assertTrue(po2.pose.almost_equal(self.pose))