From 3bbc2e3c052b99c2008c4ed268a5033a32d060ab Mon Sep 17 00:00:00 2001 From: Alexander Dielen Date: Fri, 23 Feb 2018 13:47:36 +0100 Subject: [PATCH] updated tests to use the new read/write functions --- tests/test_indices.py | 3 +- tests/test_property_array.py | 3 +- tests/test_property_list.py | 3 +- tests/test_read_write_obj.py | 104 ++---------------- tests/test_read_write_off.py | 86 +++++---------- tests/test_read_write_om.py | 87 ++++----------- tests/test_read_write_ply.py | 200 ++++++++++------------------------- tests/test_read_write_stl.py | 37 ++----- 8 files changed, 123 insertions(+), 400 deletions(-) diff --git a/tests/test_indices.py b/tests/test_indices.py index b81240f..f20bc96 100644 --- a/tests/test_indices.py +++ b/tests/test_indices.py @@ -96,8 +96,7 @@ class Python(unittest.TestCase): self.assertEqual(indices2.shape, (self.mesh.n_vertices(), 3)) def test_face_vertex_indices_trimesh(self): - self.mesh = openmesh.TriMesh() - openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj') + self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj') indices1 = self.mesh.face_vertex_indices() indices2 = self.mesh.fv_indices() diff --git a/tests/test_property_array.py b/tests/test_property_array.py index 722ed8a..95099a7 100644 --- a/tests/test_property_array.py +++ b/tests/test_property_array.py @@ -6,8 +6,7 @@ import numpy as np class Python(unittest.TestCase): def setUp(self): - self.mesh = openmesh.TriMesh() - openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj') + self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj') def test_vertex_property_array(self): self.assertFalse(self.mesh.has_vertex_property('random')) diff --git a/tests/test_property_list.py b/tests/test_property_list.py index 85a6369..dcdaf59 100644 --- a/tests/test_property_list.py +++ b/tests/test_property_list.py @@ -6,8 +6,7 @@ import numpy as np class Python(unittest.TestCase): def setUp(self): - self.mesh = openmesh.TriMesh() - openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj') + self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj') def test_vertex_property_list(self): self.assertFalse(self.mesh.has_vertex_property('random')) diff --git a/tests/test_read_write_obj.py b/tests/test_read_write_obj.py index cbd8b6b..0981499 100644 --- a/tests/test_read_write_obj.py +++ b/tests/test_read_write_obj.py @@ -3,30 +3,15 @@ import openmesh class ReadWriteOBJ(unittest.TestCase): - def setUp(self): - self.mesh = openmesh.TriMesh() - def test_load_simple_obj(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal.obj") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal.obj") self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_faces(), 12) def test_load_simple_obj_check_halfedge_and_vertex_normals(self): - self.mesh.request_halfedge_normals() - self.mesh.request_vertex_normals() - - options = openmesh.Options() - options += openmesh.Options.VertexNormal - - file_name = "TestFiles/cube-minimal.obj" - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal.obj", vertex_normal=True) + self.mesh.update_halfedge_normals() self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -85,66 +70,11 @@ class ReadWriteOBJ(unittest.TestCase): self.mesh.release_halfedge_normals() def test_load_simple_obj_force_vertex_colors_although_not_available(self): - self.mesh.request_vertex_colors() - - file_name = "TestFiles/cube-minimal.obj" - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) - - self.assertEqual(self.mesh.n_vertices(), 8) - self.assertEqual(self.mesh.n_edges(), 18) - self.assertEqual(self.mesh.n_faces(), 12) - self.assertEqual(self.mesh.n_halfedges(), 36) - - def test_load_simple_obj_check_texcoords(self): - self.mesh.request_halfedge_texcoords2D() - - options = openmesh.Options() - options += openmesh.Options.FaceTexCoord - - file_name = "TestFiles/cube-minimal-texCoords.obj" - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle( 0))[0], 1.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle( 0))[1], 1.0) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(10))[0], 3.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(10))[1], 3.0) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(19))[0], 6.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(19))[1], 6.0) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(24))[0], 7.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(24))[1], 7.0) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(30))[0], 9.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(30))[1], 9.0) - - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(35))[0], 12.0) - self.assertEqual(self.mesh.texcoord2D(self.mesh.halfedge_handle(35))[1], 12.0) - - self.mesh.release_halfedge_texcoords2D() + with self.assertRaises(RuntimeError): + openmesh.read_trimesh("TestFiles/cube-minimal.obj", vertex_color=True) def test_load_obj_with_material(self): - self.mesh.request_face_colors() - - options = openmesh.Options() - options += openmesh.Options.FaceColor - - file_name = "TestFiles/square_material.obj" - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/square_material.obj", face_color=True) fh = self.mesh.face_handle(self.mesh.halfedge_handle(0)) self.assertTrue(fh.is_valid()) @@ -156,16 +86,7 @@ class ReadWriteOBJ(unittest.TestCase): self.mesh.release_face_colors() def test_load_simple_obj_with_vertex_colors_after_vertices(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - file_name = "TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj" - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj", vertex_color=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -190,16 +111,7 @@ class ReadWriteOBJ(unittest.TestCase): self.mesh.release_vertex_colors() def test_load_simple_obj_with_vertex_colors_as_vc_lines(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - file_name = "TestFiles/cube-minimal-vertex-colors-as-vc-lines.obj" - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertex-colors-as-vc-lines.obj", vertex_color=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) diff --git a/tests/test_read_write_off.py b/tests/test_read_write_off.py index 98abae7..f64f5cf 100644 --- a/tests/test_read_write_off.py +++ b/tests/test_read_write_off.py @@ -8,20 +8,17 @@ import numpy as np class ReadWriteOFF(unittest.TestCase): def setUp(self): - self.mesh = openmesh.TriMesh() if not os.path.exists('OutFiles'): os.makedirs('OutFiles') def test_load_simple_off_file(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.off") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/cube1.off") self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_faces(), 15048) def test_write_and_read_vertex_colors_to_and_from_off_file(self): + self.mesh = openmesh.TriMesh() self.mesh.request_vertex_colors() self.mesh.add_vertex(np.array([0, 0, 1])) @@ -45,12 +42,8 @@ class ReadWriteOFF(unittest.TestCase): self.assertEqual(count, 0) - options = openmesh.Options() - options += openmesh.Options.VertexColor - options += openmesh.Options.ColorFloat - - openmesh.write_mesh(self.mesh, "OutFiles/temp.off", options) - openmesh.read_mesh(self.mesh, "OutFiles/temp.off", options) + openmesh.write_mesh("OutFiles/temp.off", self.mesh, vertex_color=True, color_float=True) + self.mesh = openmesh.read_trimesh("OutFiles/temp.off", vertex_color=True, color_float=True) # Check if vertices still have the same color count = 0 @@ -64,23 +57,14 @@ class ReadWriteOFF(unittest.TestCase): self.mesh.release_vertex_colors() def test_write_and_read_float_vertex_colors_to_and_from_off_file(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options(openmesh.Options.VertexColor) - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) - - options.clear() - options += openmesh.Options.VertexColor - options += openmesh.Options.ColorFloat + # Read the mesh + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) # Write the mesh - ok = openmesh.write_mesh(self.mesh, "OutFiles/cube_floating.off", options) - self.assertTrue(ok) - ok = openmesh.read_mesh(self.mesh, "OutFiles/cube_floating.off", options) - self.assertTrue(ok) + openmesh.write_mesh("OutFiles/cube_floating.off", self.mesh, vertex_color=True, color_float=True) + + # Read the mesh again + self.mesh = openmesh.read_trimesh("OutFiles/cube_floating.off", vertex_color=True, color_float=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -102,37 +86,23 @@ class ReadWriteOFF(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) - self.assertTrue(options.color_is_float()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_write_and_read_binary_float_vertex_colors_to_and_from_off_file(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options(openmesh.Options.VertexColor) - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) - - options.clear() - options += openmesh.Options.VertexColor - options += openmesh.Options.Binary - options += openmesh.Options.ColorFloat - + # Read the mesh + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) + # Write the mesh - ok = openmesh.write_mesh(self.mesh, "OutFiles/cube_floating_binary.off", options) - self.assertTrue(ok) - self.mesh.clear() - options.clear() - options += openmesh.Options.VertexColor - options += openmesh.Options.Binary - options += openmesh.Options.ColorFloat - ok = openmesh.read_mesh(self.mesh, "OutFiles/cube_floating_binary.off", options) - self.assertTrue(ok) + openmesh.write_mesh("OutFiles/cube_floating_binary.off", self.mesh, vertex_color=True, binary=True, color_float=True) + + # Read the mesh again + self.mesh = openmesh.read_trimesh("OutFiles/cube_floating_binary.off", vertex_color=True, binary=True, color_float=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -154,12 +124,12 @@ class ReadWriteOFF(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertFalse(options.face_has_color()) - self.assertTrue(options.vertex_has_color()) - self.assertTrue(options.color_is_float()) - self.assertTrue(options.is_binary()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertFalse(self.mesh.has_face_colors()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() diff --git a/tests/test_read_write_om.py b/tests/test_read_write_om.py index 4b2c759..5399b39 100644 --- a/tests/test_read_write_om.py +++ b/tests/test_read_write_om.py @@ -7,40 +7,15 @@ import numpy as np class ReadWriteOM(unittest.TestCase): def setUp(self): - self.mesh = openmesh.TriMesh() if not os.path.exists('OutFiles'): os.makedirs('OutFiles') def test_load_simple_om_force_vertex_colors_although_not_available(self): - self.mesh.request_vertex_colors() - - file_name = "TestFiles/cube-minimal.om" - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) - - self.assertEqual(self.mesh.n_vertices(), 8) - self.assertEqual(self.mesh.n_edges(), 18) - self.assertEqual(self.mesh.n_faces(), 12) - self.assertEqual(self.mesh.n_halfedges(), 36) - - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertFalse(options.vertex_has_color()) + with self.assertRaises(RuntimeError): + openmesh.read_trimesh("TestFiles/cube-minimal.om", vertex_color=True) def test_load_simple_om_with_texcoords(self): - self.mesh.request_vertex_texcoords2D() - - options = openmesh.Options() - options += openmesh.Options.VertexTexCoord - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-texCoords.om", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-texCoords.om", vertex_tex_coord=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -58,21 +33,16 @@ class ReadWriteOM(unittest.TestCase): self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[0], 12.0) self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[1], 12.0) - self.assertFalse(options.vertex_has_normal()) - self.assertTrue(options.vertex_has_texcoord()) - self.assertFalse(options.vertex_has_color()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertTrue(self.mesh.has_vertex_texcoords1D()) + self.assertTrue(self.mesh.has_vertex_texcoords2D()) + self.assertTrue(self.mesh.has_vertex_texcoords3D()) + self.assertFalse(self.mesh.has_vertex_colors()) self.mesh.release_vertex_texcoords2D() def test_load_simple_om_with_vertex_colors(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-vertexColors.om", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertexColors.om", vertex_color=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -94,14 +64,16 @@ class ReadWriteOM(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_write_triangle(self): - filename = "OutFiles/triangle-minimal.om"; + self.mesh = openmesh.TriMesh() # Generate data v1 = self.mesh.add_vertex(np.array([1.0, 0.0, 0.0])) @@ -110,15 +82,11 @@ class ReadWriteOM(unittest.TestCase): self.mesh.add_face(v1, v2, v3) # Save - ok = openmesh.write_mesh(self.mesh, filename) - self.assertTrue(ok) - - # Reset - self.mesh.clear() + filename = "OutFiles/triangle-minimal.om" + openmesh.write_mesh(filename, self.mesh) # Load - ok = openmesh.read_mesh(self.mesh, filename) - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh(filename) # Compare self.assertEqual(self.mesh.n_vertices(), 3) @@ -133,14 +101,8 @@ class ReadWriteOM(unittest.TestCase): os.remove(filename) def test_write_triangle_vertex_integer_color(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - options += openmesh.Options.ColorFloat - - filename = "OutFiles/triangle-minimal-ColorsPerVertex.om" - + self.mesh = openmesh.TriMesh() + # Generate data v1 = self.mesh.add_vertex(np.array([1.0, 0.0, 0.0])) v2 = self.mesh.add_vertex(np.array([0.0, 1.0, 0.0])) @@ -156,16 +118,13 @@ class ReadWriteOM(unittest.TestCase): self.mesh.set_color(v3, c3) # Save - ok = openmesh.write_mesh(self.mesh, filename, options) - self.assertTrue(ok) + filename = "OutFiles/triangle-minimal-ColorsPerVertex.om" + openmesh.write_mesh(filename, self.mesh, vertex_color=True, color_float=True) self.mesh.release_vertex_colors() # Load - cmpMesh = openmesh.TriMesh() - cmpMesh.request_vertex_colors() - ok = openmesh.read_mesh(cmpMesh, filename, options) - self.assertTrue(ok) + cmpMesh = openmesh.read_trimesh(filename, vertex_color=True, color_float=True) self.assertTrue(cmpMesh.has_vertex_colors()) diff --git a/tests/test_read_write_ply.py b/tests/test_read_write_ply.py index 9056631..87f4281 100644 --- a/tests/test_read_write_ply.py +++ b/tests/test_read_write_ply.py @@ -5,69 +5,33 @@ import os class ReadWritePLY(unittest.TestCase): def setUp(self): - self.mesh = openmesh.TriMesh() if not os.path.exists('OutFiles'): os.makedirs('OutFiles') def test_load_simple_point_ply_file_with_bad_encoding(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/pointCloudBadEncoding.ply") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/pointCloudBadEncoding.ply") self.assertEqual(self.mesh.n_vertices(), 10) self.assertEqual(self.mesh.n_edges(), 0) self.assertEqual(self.mesh.n_faces(), 0) def test_load_simple_point_ply_file_with_good_encoding(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/pointCloudGoodEncoding.ply") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/pointCloudGoodEncoding.ply") self.assertEqual(self.mesh.n_vertices(), 10) self.assertEqual(self.mesh.n_edges(), 0) self.assertEqual(self.mesh.n_faces(), 0) def test_load_simple_ply(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal.ply") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal.ply") self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_faces(), 12) def test_load_simple_ply_force_vertex_colors_although_not_available(self): - self.mesh.request_vertex_colors() - - file_name = "TestFiles/cube-minimal.ply" - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, file_name, options) - - self.assertTrue(ok) - - self.assertEqual(self.mesh.n_vertices(), 8) - self.assertEqual(self.mesh.n_edges(), 18) - self.assertEqual(self.mesh.n_faces(), 12) - self.assertEqual(self.mesh.n_halfedges(), 36) - - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertFalse(options.vertex_has_color()) + with self.assertRaises(RuntimeError): + openmesh.read_trimesh("TestFiles/cube-minimal.ply", vertex_color=True) def test_load_simple_ply_with_vertex_colors(self): - self.mesh.request_vertex_colors() - - file_name = "TestFiles/cube-minimal.ply" - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-vertexColors.ply", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertexColors.ply", vertex_color=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -89,21 +53,16 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_load_ply_from_mesh_lab_with_vertex_colors(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -124,32 +83,19 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[0], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) + + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_write_and_read_binary_ply_with_vertex_colors(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) - - options += openmesh.Options.Binary - - ok = openmesh.write_mesh(self.mesh, "OutFiles/meshlab_binary.ply", options) - self.assertTrue(ok) - - self.mesh.clear - - ok = openmesh.read_mesh(self.mesh, "OutFiles/meshlab_binary.ply", options) - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) + openmesh.write_mesh("OutFiles/meshlab_binary.ply", self.mesh, vertex_color=True, binary=True) + self.mesh = openmesh.read_trimesh("OutFiles/meshlab_binary.ply", vertex_color=True, binary=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -170,31 +116,19 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[0], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) + + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_write_and_read_ply_with_float_vertex_colors(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) - - options += openmesh.Options.ColorFloat - - ok = openmesh.write_mesh(self.mesh, "OutFiles/meshlab_float.ply", options) - self.assertTrue(ok) - - self.mesh.clear - ok = openmesh.read_mesh(self.mesh, "OutFiles/meshlab_float.ply", options) - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) + openmesh.write_mesh("OutFiles/meshlab_float.ply", self.mesh, vertex_color=True, color_float=True) + self.mesh = openmesh.read_trimesh("OutFiles/meshlab_float.ply", vertex_color=True, color_float=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -216,32 +150,18 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) - self.assertTrue(options.color_is_float()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_write_and_read_binary_ply_with_float_vertex_colors(self): - self.mesh.request_vertex_colors() - - options = openmesh.Options() - options += openmesh.Options.VertexColor - - ok = openmesh.read_mesh(self.mesh, "TestFiles/meshlab.ply", options) - - self.assertTrue(ok) - - options += openmesh.Options.ColorFloat - options += openmesh.Options.Binary - - ok = openmesh.write_mesh(self.mesh, "OutFiles/meshlab_binary_float.ply", options) - self.assertTrue(ok) - - self.mesh.clear - ok = openmesh.read_mesh(self.mesh, "OutFiles/meshlab_binary_float.ply", options) - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True) + openmesh.write_mesh("OutFiles/meshlab_binary_float.ply", self.mesh, vertex_color=True, color_float=True, binary=True) + self.mesh = openmesh.read_trimesh("OutFiles/meshlab_binary_float.ply", vertex_color=True, color_float=True, binary=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -263,23 +183,16 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[1], 0.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) - self.assertFalse(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertTrue(options.vertex_has_color()) - self.assertTrue(options.color_is_float()) - self.assertTrue(options.is_binary()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertTrue(self.mesh.has_vertex_colors()) self.mesh.release_vertex_colors() def test_load_simple_ply_with_texcoords(self): - self.mesh.request_vertex_texcoords2D() - - options = openmesh.Options() - options += openmesh.Options.VertexTexCoord - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-texCoords.ply", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-texCoords.ply", vertex_tex_coord=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) @@ -297,29 +210,26 @@ class ReadWritePLY(unittest.TestCase): self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[0], 12.0) self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[1], 12.0) - self.assertFalse(options.vertex_has_normal()) - self.assertTrue(options.vertex_has_texcoord()) - self.assertFalse(options.vertex_has_color()) + self.assertFalse(self.mesh.has_vertex_normals()) + self.assertTrue(self.mesh.has_vertex_texcoords1D()) + self.assertTrue(self.mesh.has_vertex_texcoords2D()) + self.assertTrue(self.mesh.has_vertex_texcoords3D()) + self.assertFalse(self.mesh.has_vertex_colors()) self.mesh.release_vertex_texcoords2D() def test_load_simple_ply_with_normals(self): - self.mesh.request_vertex_normals() - - options = openmesh.Options() - options += openmesh.Options.VertexNormal - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-normals.ply", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-normals.ply", vertex_normal=True) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_faces(), 12) - self.assertTrue(options.vertex_has_normal()) - self.assertFalse(options.vertex_has_texcoord()) - self.assertFalse(options.vertex_has_color()) + self.assertTrue(self.mesh.has_vertex_normals()) + self.assertFalse(self.mesh.has_vertex_texcoords1D()) + self.assertFalse(self.mesh.has_vertex_texcoords2D()) + self.assertFalse(self.mesh.has_vertex_texcoords3D()) + self.assertFalse(self.mesh.has_vertex_colors()) self.assertEqual(self.mesh.normal(self.mesh.vertex_handle(0))[0], 0.0) self.assertEqual(self.mesh.normal(self.mesh.vertex_handle(0))[1], 0.0) diff --git a/tests/test_read_write_stl.py b/tests/test_read_write_stl.py index 64de9a3..bce085b 100644 --- a/tests/test_read_write_stl.py +++ b/tests/test_read_write_stl.py @@ -3,27 +3,14 @@ import openmesh class ReadWriteSTL(unittest.TestCase): - def setUp(self): - self.mesh = openmesh.TriMesh() - def test_load_simple_stl_file(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.stl") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/cube1.stl") self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_faces(), 15048) def test_load_simple_stl_file_with_normals(self): - self.mesh.request_face_normals() - - options = openmesh.Options() - options += openmesh.Options.FaceNormal - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.stl", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube1.stl", face_normal=True) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[0], -0.038545) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[1], -0.004330) @@ -36,28 +23,16 @@ class ReadWriteSTL(unittest.TestCase): self.mesh.release_face_normals() def test_load_simple_stl_binary_file(self): - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1Binary.stl") - - self.assertTrue(ok) - + self.mesh = openmesh.read_trimesh("TestFiles/cube1Binary.stl") self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_faces(), 15048) def test_load_simple_stl_binary_file_with_normals(self): - self.mesh.request_face_normals() - - options = openmesh.Options() - options += openmesh.Options.FaceNormal - options += openmesh.Options.Binary - - ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1Binary.stl", options) - - self.assertTrue(ok) + self.mesh = openmesh.read_trimesh("TestFiles/cube1Binary.stl", face_normal=True, binary=True) - self.assertTrue(options.is_binary()) - self.assertTrue(options.face_has_normal()) - self.assertFalse(options.vertex_has_normal()) + self.assertTrue(self.mesh.has_face_normals()) + self.assertFalse(self.mesh.has_vertex_normals()) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[0], -0.038545, 5) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[1], -0.004330, 5) -- GitLab