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): ...@@ -96,8 +96,7 @@ class Python(unittest.TestCase):
self.assertEqual(indices2.shape, (self.mesh.n_vertices(), 3)) self.assertEqual(indices2.shape, (self.mesh.n_vertices(), 3))
def test_face_vertex_indices_trimesh(self): def test_face_vertex_indices_trimesh(self):
self.mesh = openmesh.TriMesh() self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj')
openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj')
indices1 = self.mesh.face_vertex_indices() indices1 = self.mesh.face_vertex_indices()
indices2 = self.mesh.fv_indices() indices2 = self.mesh.fv_indices()
......
...@@ -6,8 +6,7 @@ import numpy as np ...@@ -6,8 +6,7 @@ import numpy as np
class Python(unittest.TestCase): class Python(unittest.TestCase):
def setUp(self): def setUp(self):
self.mesh = openmesh.TriMesh() self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj')
openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj')
def test_vertex_property_array(self): def test_vertex_property_array(self):
self.assertFalse(self.mesh.has_vertex_property('random')) self.assertFalse(self.mesh.has_vertex_property('random'))
......
...@@ -6,8 +6,7 @@ import numpy as np ...@@ -6,8 +6,7 @@ import numpy as np
class Python(unittest.TestCase): class Python(unittest.TestCase):
def setUp(self): def setUp(self):
self.mesh = openmesh.TriMesh() self.mesh = openmesh.read_trimesh('TestFiles/cube-minimal.obj')
openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj')
def test_vertex_property_list(self): def test_vertex_property_list(self):
self.assertFalse(self.mesh.has_vertex_property('random')) self.assertFalse(self.mesh.has_vertex_property('random'))
......
...@@ -3,30 +3,15 @@ import openmesh ...@@ -3,30 +3,15 @@ import openmesh
class ReadWriteOBJ(unittest.TestCase): class ReadWriteOBJ(unittest.TestCase):
def setUp(self):
self.mesh = openmesh.TriMesh()
def test_load_simple_obj(self): def test_load_simple_obj(self):
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal.obj") self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal.obj")
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
self.assertEqual(self.mesh.n_faces(), 12) self.assertEqual(self.mesh.n_faces(), 12)
def test_load_simple_obj_check_halfedge_and_vertex_normals(self): def test_load_simple_obj_check_halfedge_and_vertex_normals(self):
self.mesh.request_halfedge_normals() self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal.obj", vertex_normal=True)
self.mesh.request_vertex_normals() self.mesh.update_halfedge_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.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -85,66 +70,11 @@ class ReadWriteOBJ(unittest.TestCase): ...@@ -85,66 +70,11 @@ class ReadWriteOBJ(unittest.TestCase):
self.mesh.release_halfedge_normals() self.mesh.release_halfedge_normals()
def test_load_simple_obj_force_vertex_colors_although_not_available(self): def test_load_simple_obj_force_vertex_colors_although_not_available(self):
self.mesh.request_vertex_colors() with self.assertRaises(RuntimeError):
openmesh.read_trimesh("TestFiles/cube-minimal.obj", vertex_color=True)
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()
def test_load_obj_with_material(self): def test_load_obj_with_material(self):
self.mesh.request_face_colors() self.mesh = openmesh.read_trimesh("TestFiles/square_material.obj", face_color=True)
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)
fh = self.mesh.face_handle(self.mesh.halfedge_handle(0)) fh = self.mesh.face_handle(self.mesh.halfedge_handle(0))
self.assertTrue(fh.is_valid()) self.assertTrue(fh.is_valid())
...@@ -156,16 +86,7 @@ class ReadWriteOBJ(unittest.TestCase): ...@@ -156,16 +86,7 @@ class ReadWriteOBJ(unittest.TestCase):
self.mesh.release_face_colors() self.mesh.release_face_colors()
def test_load_simple_obj_with_vertex_colors_after_vertices(self): def test_load_simple_obj_with_vertex_colors_after_vertices(self):
self.mesh.request_vertex_colors() self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj", vertex_color=True)
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.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -190,16 +111,7 @@ class ReadWriteOBJ(unittest.TestCase): ...@@ -190,16 +111,7 @@ class ReadWriteOBJ(unittest.TestCase):
self.mesh.release_vertex_colors() self.mesh.release_vertex_colors()
def test_load_simple_obj_with_vertex_colors_as_vc_lines(self): def test_load_simple_obj_with_vertex_colors_as_vc_lines(self):
self.mesh.request_vertex_colors() self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertex-colors-as-vc-lines.obj", vertex_color=True)
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.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
......
...@@ -8,20 +8,17 @@ import numpy as np ...@@ -8,20 +8,17 @@ import numpy as np
class ReadWriteOFF(unittest.TestCase): class ReadWriteOFF(unittest.TestCase):
def setUp(self): def setUp(self):
self.mesh = openmesh.TriMesh()
if not os.path.exists('OutFiles'): if not os.path.exists('OutFiles'):
os.makedirs('OutFiles') os.makedirs('OutFiles')
def test_load_simple_off_file(self): def test_load_simple_off_file(self):
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.off") self.mesh = openmesh.read_trimesh("TestFiles/cube1.off")
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_vertices(), 7526)
self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_edges(), 22572)
self.assertEqual(self.mesh.n_faces(), 15048) self.assertEqual(self.mesh.n_faces(), 15048)
def test_write_and_read_vertex_colors_to_and_from_off_file(self): def test_write_and_read_vertex_colors_to_and_from_off_file(self):
self.mesh = openmesh.TriMesh()
self.mesh.request_vertex_colors() self.mesh.request_vertex_colors()
self.mesh.add_vertex(np.array([0, 0, 1])) self.mesh.add_vertex(np.array([0, 0, 1]))
...@@ -45,12 +42,8 @@ class ReadWriteOFF(unittest.TestCase): ...@@ -45,12 +42,8 @@ class ReadWriteOFF(unittest.TestCase):
self.assertEqual(count, 0) self.assertEqual(count, 0)
options = openmesh.Options() openmesh.write_mesh("OutFiles/temp.off", self.mesh, vertex_color=True, color_float=True)
options += openmesh.Options.VertexColor self.mesh = openmesh.read_trimesh("OutFiles/temp.off", vertex_color=True, color_float=True)
options += openmesh.Options.ColorFloat
openmesh.write_mesh(self.mesh, "OutFiles/temp.off", options)
openmesh.read_mesh(self.mesh, "OutFiles/temp.off", options)
# Check if vertices still have the same color # Check if vertices still have the same color
count = 0 count = 0
...@@ -64,23 +57,14 @@ class ReadWriteOFF(unittest.TestCase): ...@@ -64,23 +57,14 @@ class ReadWriteOFF(unittest.TestCase):
self.mesh.release_vertex_colors() self.mesh.release_vertex_colors()
def test_write_and_read_float_vertex_colors_to_and_from_off_file(self): def test_write_and_read_float_vertex_colors_to_and_from_off_file(self):
self.mesh.request_vertex_colors() # Read the mesh
self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True)
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
# Write the mesh # Write the mesh
ok = openmesh.write_mesh(self.mesh, "OutFiles/cube_floating.off", options) openmesh.write_mesh("OutFiles/cube_floating.off", self.mesh, vertex_color=True, color_float=True)
self.assertTrue(ok)
ok = openmesh.read_mesh(self.mesh, "OutFiles/cube_floating.off", options) # Read the mesh again
self.assertTrue(ok) 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_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -102,37 +86,23 @@ class ReadWriteOFF(unittest.TestCase): ...@@ -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))[1], 0.0)
self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0)
self.assertFalse(options.vertex_has_normal()) self.assertFalse(self.mesh.has_vertex_normals())
self.assertFalse(options.vertex_has_texcoord()) self.assertFalse(self.mesh.has_vertex_texcoords1D())
self.assertTrue(options.vertex_has_color()) self.assertFalse(self.mesh.has_vertex_texcoords2D())
self.assertTrue(options.color_is_float()) self.assertFalse(self.mesh.has_vertex_texcoords3D())
self.assertTrue(self.mesh.has_vertex_colors())
self.mesh.release_vertex_colors() self.mesh.release_vertex_colors()
def test_write_and_read_binary_float_vertex_colors_to_and_from_off_file(self): def test_write_and_read_binary_float_vertex_colors_to_and_from_off_file(self):
self.mesh.request_vertex_colors() # Read the mesh
self.mesh = openmesh.read_trimesh("TestFiles/meshlab.ply", vertex_color=True)
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
# Write the mesh # Write the mesh
ok = openmesh.write_mesh(self.mesh, "OutFiles/cube_floating_binary.off", options) openmesh.write_mesh("OutFiles/cube_floating_binary.off", self.mesh, vertex_color=True, binary=True, color_float=True)
self.assertTrue(ok)
self.mesh.clear() # Read the mesh again
options.clear() self.mesh = openmesh.read_trimesh("OutFiles/cube_floating_binary.off", vertex_color=True, binary=True, color_float=True)
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)
self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -154,12 +124,12 @@ class ReadWriteOFF(unittest.TestCase): ...@@ -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))[1], 0.0)
self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0)
self.assertFalse(options.vertex_has_normal()) self.assertFalse(self.mesh.has_vertex_normals())
self.assertFalse(options.vertex_has_texcoord()) self.assertFalse(self.mesh.has_vertex_texcoords1D())
self.assertFalse(options.face_has_color()) self.assertFalse(self.mesh.has_vertex_texcoords2D())
self.assertTrue(options.vertex_has_color()) self.assertFalse(self.mesh.has_vertex_texcoords3D())
self.assertTrue(options.color_is_float()) self.assertFalse(self.mesh.has_face_colors())
self.assertTrue(options.is_binary()) self.assertTrue(self.mesh.has_vertex_colors())
self.mesh.release_vertex_colors() self.mesh.release_vertex_colors()
......
...@@ -7,40 +7,15 @@ import numpy as np ...@@ -7,40 +7,15 @@ import numpy as np
class ReadWriteOM(unittest.TestCase): class ReadWriteOM(unittest.TestCase):
def setUp(self): def setUp(self):
self.mesh = openmesh.TriMesh()
if not os.path.exists('OutFiles'): if not os.path.exists('OutFiles'):
os.makedirs('OutFiles') os.makedirs('OutFiles')
def test_load_simple_om_force_vertex_colors_although_not_available(self): def test_load_simple_om_force_vertex_colors_although_not_available(self):
self.mesh.request_vertex_colors() with self.assertRaises(RuntimeError):
openmesh.read_trimesh("TestFiles/cube-minimal.om", vertex_color=True)
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())
def test_load_simple_om_with_texcoords(self): def test_load_simple_om_with_texcoords(self):
self.mesh.request_vertex_texcoords2D() self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-texCoords.om", vertex_tex_coord=True)
options = openmesh.Options()
options += openmesh.Options.VertexTexCoord
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-texCoords.om", options)
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -58,21 +33,16 @@ class ReadWriteOM(unittest.TestCase): ...@@ -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))[0], 12.0)
self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[1], 12.0) self.assertEqual(self.mesh.texcoord2D(self.mesh.vertex_handle(7))[1], 12.0)
self.assertFalse(options.vertex_has_normal()) self.assertFalse(self.mesh.has_vertex_normals())
self.assertTrue(options.vertex_has_texcoord()) self.assertTrue(self.mesh.has_vertex_texcoords1D())
self.assertFalse(options.vertex_has_color()) 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() self.mesh.release_vertex_texcoords2D()
def test_load_simple_om_with_vertex_colors(self): def test_load_simple_om_with_vertex_colors(self):
self.mesh.request_vertex_colors() self.mesh = openmesh.read_trimesh("TestFiles/cube-minimal-vertexColors.om", vertex_color=True)
options = openmesh.Options()
options += openmesh.Options.VertexColor
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube-minimal-vertexColors.om", options)
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_vertices(), 8)
self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_edges(), 18)
...@@ -94,14 +64,16 @@ class ReadWriteOM(unittest.TestCase): ...@@ -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))[1], 0.0)
self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0) self.assertEqual(self.mesh.color(self.mesh.vertex_handle(7))[2], 1.0)
self.assertFalse(options.vertex_has_normal()) self.assertFalse(self.mesh.has_vertex_normals())
self.assertFalse(options.vertex_has_texcoord()) self.assertFalse(self.mesh.has_vertex_texcoords1D())
self.assertTrue(options.vertex_has_color()) 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() self.mesh.release_vertex_colors()
def test_write_triangle(self): def test_write_triangle(self):
filename = "OutFiles/triangle-minimal.om"; self.mesh = openmesh.TriMesh()
# Generate data # Generate data
v1 = self.mesh.add_vertex(np.array([1.0, 0.0, 0.0])) v1 = self.mesh.add_vertex(np.array([1.0, 0.0, 0.0]))
...@@ -110,15 +82,11 @@ class ReadWriteOM(unittest.TestCase): ...@@ -110,15 +82,11 @@ class ReadWriteOM(unittest.TestCase):
self.mesh.add_face(v1, v2, v3) self.mesh.add_face(v1, v2, v3)
# Save # Save
ok = openmesh.write_mesh(self.mesh, filename) filename = "OutFiles/triangle-minimal.om"
self.assertTrue(ok) openmesh.write_mesh(filename, self.mesh)
# Reset
self.mesh.clear()
# Load # Load
ok = openmesh.read_mesh(self.mesh, filename) self.mesh = openmesh.read_trimesh(filename)
self.assertTrue(ok)
# Compare # Compare
self.assertEqual(self.mesh.n_vertices(), 3) self.assertEqual(self.mesh.n_vertices(), 3)
...@@ -133,14 +101,8 @@ class ReadWriteOM(unittest.TestCase): ...@@ -133,14 +101,8 @@ class ReadWriteOM(unittest.TestCase):
os.remove(filename) os.remove(filename)
def test_write_triangle_vertex_integer_color(self): def test_write_triangle_vertex_integer_color(self):
self.mesh.request_vertex_colors() self.mesh = openmesh.TriMesh()
options = openmesh.Options()
options += openmesh.Options.VertexColor
options += openmesh.Options.ColorFloat
filename = "OutFiles/triangle-minimal-ColorsPerVertex.om"
# Generate data # Generate data
v1 = self.mesh.add_vertex(np.array([1.0, 0.0, 0.0])) 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])) v2 = self.mesh.add_vertex(np.array([0.0, 1.0, 0.0]))
...@@ -156,16 +118,13 @@ class ReadWriteOM(unittest.TestCase): ...@@ -156,16 +118,13 @@ class ReadWriteOM(unittest.TestCase):
self.mesh.set_color(v3, c3) self.mesh.set_color(v3, c3)
# Save # Save
ok = openmesh.write_mesh(self.mesh, filename, options) filename = "OutFiles/triangle-minimal-ColorsPerVertex.om"
self.assertTrue(ok) openmesh.write_mesh(filename, self.mesh, vertex_color=True, color_float=True)
self.mesh.release_vertex_colors() self.mesh.release_vertex_colors()
# Load # Load
cmpMesh = openmesh.TriMesh() cmpMesh = openmesh.read_trimesh(filename, vertex_color=True, color_float=True)
cmpMesh.request_vertex_colors()
ok = openmesh.read_mesh(cmpMesh, filename, options)
self.assertTrue(ok)
self.assertTrue(cmpMesh.has_vertex_colors()) self.assertTrue(cmpMesh.has_vertex_colors())
......
This diff is collapsed.
...@@ -3,27 +3,14 @@ import openmesh ...@@ -3,27 +3,14 @@ import openmesh
class ReadWriteSTL(unittest.TestCase): class ReadWriteSTL(unittest.TestCase):
def setUp(self):
self.mesh = openmesh.TriMesh()
def test_load_simple_stl_file(self): def test_load_simple_stl_file(self):
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.stl") self.mesh = openmesh.read_trimesh("TestFiles/cube1.stl")
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_vertices(), 7526)
self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_edges(), 22572)
self.assertEqual(self.mesh.n_faces(), 15048) self.assertEqual(self.mesh.n_faces(), 15048)
def test_load_simple_stl_file_with_normals(self): def test_load_simple_stl_file_with_normals(self):
self.mesh.request_face_normals() self.mesh = openmesh.read_trimesh("TestFiles/cube1.stl", face_normal=True)
options = openmesh.Options()
options += openmesh.Options.FaceNormal
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1.stl", options)
self.assertTrue(ok)
self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[0], -0.038545) 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) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[1], -0.004330)
...@@ -36,28 +23,16 @@ class ReadWriteSTL(unittest.TestCase): ...@@ -36,28 +23,16 @@ class ReadWriteSTL(unittest.TestCase):
self.mesh.release_face_normals() self.mesh.release_face_normals()
def test_load_simple_stl_binary_file(self): def test_load_simple_stl_binary_file(self):
ok = openmesh.read_mesh(self.mesh, "TestFiles/cube1Binary.stl") self.mesh = openmesh.read_trimesh("TestFiles/cube1Binary.stl")
self.assertTrue(ok)
self.assertEqual(self.mesh.n_vertices(), 7526) self.assertEqual(self.mesh.n_vertices(), 7526)
self.assertEqual(self.mesh.n_edges(), 22572) self.assertEqual(self.mesh.n_edges(), 22572)
self.assertEqual(self.mesh.n_faces(), 15048) self.assertEqual(self.mesh.n_faces(), 15048)
def test_load_simple_stl_binary_file_with_normals(self): def test_load_simple_stl_binary_file_with_normals(self):
self.mesh.request_face_normals() self.mesh = openmesh.read_trimesh("TestFiles/cube1Binary.stl", face_normal=True, binary=True)
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.assertTrue(options.is_binary()) self.assertTrue(self.mesh.has_face_normals())
self.assertTrue(options.face_has_normal()) self.assertFalse(self.mesh.has_vertex_normals())
self.assertFalse(options.vertex_has_normal())
self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[0], -0.038545, 5) 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) self.assertAlmostEqual(self.mesh.normal(self.mesh.face_handle(0))[1], -0.004330, 5)
......
Markdown is supported
0% or