Commit 3bbc2e3c authored by Alexander Dielen's avatar Alexander Dielen

updated tests to use the new read/write functions

parent 89f4ed30
Pipeline #6300 passed with stages
in 5 minutes and 18 seconds
......@@ -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()
......
......@@ -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'))
......
......@@ -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'))
......
......@@ -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)
......
......@@ -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()
......
......@@ -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,13 +101,7 @@ 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]))
......@@ -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())
......
This diff is collapsed.
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment