def setUp(self): import tempfile self.tmp_dir = tempfile.mkdtemp('bodylabs-test') self.truth = { 'box_v': np.array([[0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 0.5, -0.5], [0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5], [0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5]]).T, 'box_f': np.array([[0, 1, 2], [3, 2, 1], [0, 2, 4], [6, 4, 2], [0, 4, 1], [5, 1, 4], [7, 5, 6], [4, 6, 5], [7, 6, 3], [2, 3, 6], [7, 3, 5], [1, 5, 3]]), 'box_segm': { 'a': np.array(range(6), dtype=np.uint32), 'b': np.array([6, 10, 11], dtype=np.uint32), 'c': np.array([7, 8, 9], dtype=np.uint32) }, 'box_segm_overlapping': { 'a': np.array(range(6), dtype=np.uint32), 'b': np.array([6, 10, 11], dtype=np.uint32), 'c': np.array([7, 8, 9], dtype=np.uint32), 'd': np.array([1, 2, 8], dtype=np.uint32) }, 'landm': { 'pospospos': 0, 'negnegneg': 7 }, 'landm_xyz': { 'pospospos': np.array([0.5, 0.5, 0.5]), 'negnegneg': np.array([-0.5, -0.5, -0.5]) }, } self.test_obj_url = vc.uri( '/unittest/serialization/obj/test_box_simple.obj') self.test_obj_path = vc( '/unittest/serialization/obj/test_box_simple.obj') self.test_obj_with_vertex_colors_url = vc.uri( '/unittest/serialization/obj/test_box_simple_with_vertex_colors.obj' ) self.test_obj_with_landmarks_url = vc.uri( '/unittest/serialization/obj/test_box.obj') self.test_obj_with_landmarks_path = vc( '/unittest/serialization/obj/test_box.obj') self.test_pp_path = vc('/unittest/serialization/obj/test_box.pp') self.test_obj_with_overlapping_groups_path = vc( '/unittest/serialization/obj/test_box_with_overlapping_groups.obj') self.obj_with_texure = "s3://bodylabs-korper-assets/is/ps/shared/data/body/korper_testdata/textured_mean_scape_female.obj" self.obj_with_texure_mtl = "s3://bodylabs-korper-assets/is/ps/shared/data/body/korper_testdata/textured_mean_scape_female.mtl" self.obj_with_texure_tex = "s3://bodylabs-korper-assets/is/ps/shared/data/body/korper_testdata/textured_mean_scape_female.png"
def test_keep_segments(self): mesh = obj.load( vc('/templates/cached_model_templates/sm_2013_f_0005.obj')) expected_parts = [ 'rightCalf', 'head', 'rightHand', 'leftTorso', 'midsection', 'leftFoot', 'rightTorso', 'rightThigh', 'leftCalf', 'rightShoulder', 'leftShoulder', 'leftThigh', 'pelvis', 'leftForearm', 'rightFoot', 'leftHand', 'rightUpperArm', 'rightForearm', 'leftUpperArm' ] self.assertEqual(set(mesh.segm.keys()), set(expected_parts)) self.assertEqual(len(mesh.segm['rightFoot']), 3336) self.assertEqual(len(mesh.segm['leftFoot']), 3336) segments_to_keep = ['leftFoot', 'rightFoot'] mesh.keep_segments(segments_to_keep) self.assertEqual(len(mesh.f), 6672) self.assertEqual(len(mesh.segm['rightFoot']), 3336) self.assertEqual(len(mesh.segm['leftFoot']), 3336) self.assertEqual(set(mesh.segm.keys()), set(segments_to_keep)) max_f_index = np.max(mesh.segm.values()) self.assertEqual(max_f_index, mesh.f.shape[0] - 1)
def test_keep_vertices_with_empty_list_does_not_warn(self, warn): mesh = obj.load( vc('/templates/cached_model_templates/sm_2013_f_0005.obj')) mesh.keep_vertices([]) self.assertFalse(warn.called)
def test_flip_faces(self): raw_box = Mesh(vc('/unittest/serialization/obj/test_box_simple.obj')) box = Mesh(v=raw_box.v, f=raw_box.f) box.reset_normals() original_vn = box.vn.copy() original_f = box.f.copy() box.flip_faces() box.reset_normals() self.assertEqual(box.f.shape, original_f.shape) for face, orig_face in zip(box.f, original_f): self.assertNotEqual(list(face), list(orig_face)) self.assertEqual(set(face), set(orig_face)) np.testing.assert_array_almost_equal(box.vn, np.negative(original_vn))
def test_keep_vertices_without_f(self): mesh = obj.load( vc('/templates/cached_model_templates/sm_2013_f_0005.obj')) mesh.segm = None mesh.f = None indices_to_keep = [1, 2, 3, 5, 8, 273, 302, 11808, 11847, 12031, 12045] expected_verts = mesh.v[indices_to_keep] mesh.keep_vertices(indices_to_keep) np.testing.assert_array_equal(mesh.v, expected_verts) self.assertIs(mesh.f, None)
def test_keep_vertices_without_segm(self): mesh = obj.load( vc('/templates/cached_model_templates/sm_2013_f_0005.obj')) mesh.segm = None indices_to_keep, expected_verts, expected_face_vertices = self.indicies_for_testing_keep_vertices( mesh) mesh.keep_vertices(indices_to_keep) np.testing.assert_array_equal(mesh.v, expected_verts) np.testing.assert_array_equal(mesh.v[mesh.f.flatten()], expected_face_vertices) max_v_index = np.max(mesh.f.flatten()) self.assertLessEqual(max_v_index, mesh.v.shape[0] - 1)
def test_keep_vertices(self): mesh = obj.load( vc('/templates/cached_model_templates/sm_2013_f_0005.obj')) # set vc and vc for completeness mesh.set_vertex_colors("blue") mesh.reset_normals() indices_to_keep, expected_verts, expected_face_vertices = self.indicies_for_testing_keep_vertices( mesh) mesh.keep_vertices(indices_to_keep) np.testing.assert_array_equal(mesh.v, expected_verts) np.testing.assert_array_equal(mesh.v[mesh.f.flatten()], expected_face_vertices) max_v_index = np.max(mesh.f.flatten()) self.assertLessEqual(max_v_index, mesh.v.shape[0] - 1)
def test_load_bsf(self): expected_mesh = ply.load(vc('/unittest/bsf/bsf_example.ply')) bsf_mesh = bsf.load(vc('/unittest/bsf/bsf_example.bsf')) np.testing.assert_array_almost_equal(bsf_mesh.v, expected_mesh.v) np.testing.assert_equal(bsf_mesh.f, expected_mesh.f)