Commit ee0b852e authored by Alexander Dielen's avatar Alexander Dielen

added more property tests

parent 177240cf
Pipeline #6168 passed with stage
in 1 minute and 14 seconds
......@@ -284,7 +284,52 @@ class Property(unittest.TestCase):
self.assertEqual(self.mesh.vertex_property("intProp", next(v_it)), 2)
self.assertEqual(self.mesh.vertex_property("intProp", next(v_it)), 2)
def test_add_remove_property(self):
self.assertFalse(self.mesh.has_vertex_property('test'))
self.assertFalse(self.mesh.has_halfedge_property('test'))
self.assertFalse(self.mesh.has_edge_property('test'))
self.assertFalse(self.mesh.has_face_property('test'))
self.mesh.vertex_property('test') # adds the prop implicitly
self.assertTrue(self.mesh.has_vertex_property('test'))
self.assertFalse(self.mesh.has_halfedge_property('test'))
self.assertFalse(self.mesh.has_edge_property('test'))
self.assertFalse(self.mesh.has_face_property('test'))
self.mesh.halfedge_property('test') # adds the prop implicitly
self.assertTrue(self.mesh.has_vertex_property('test'))
self.assertTrue(self.mesh.has_halfedge_property('test'))
self.assertFalse(self.mesh.has_edge_property('test'))
self.assertFalse(self.mesh.has_face_property('test'))
self.mesh.edge_property('test') # adds the prop implicitly
self.assertTrue(self.mesh.has_vertex_property('test'))
self.assertTrue(self.mesh.has_halfedge_property('test'))
self.assertTrue(self.mesh.has_edge_property('test'))
self.assertFalse(self.mesh.has_face_property('test'))
self.mesh.face_property('test') # adds the prop implicitly
self.assertTrue(self.mesh.has_vertex_property('test'))
self.assertTrue(self.mesh.has_halfedge_property('test'))
self.assertTrue(self.mesh.has_edge_property('test'))
self.assertTrue(self.mesh.has_face_property('test'))
self.mesh.remove_vertex_property('test')
self.assertFalse(self.mesh.has_vertex_property('test'))
self.assertTrue(self.mesh.has_halfedge_property('test'))
self.assertTrue(self.mesh.has_edge_property('test'))
self.assertTrue(self.mesh.has_face_property('test'))
self.mesh.remove_halfedge_property('test')
self.assertFalse(self.mesh.has_vertex_property('test'))
self.assertFalse(self.mesh.has_halfedge_property('test'))
self.assertTrue(self.mesh.has_edge_property('test'))
self.assertTrue(self.mesh.has_face_property('test'))
self.mesh.remove_edge_property('test')
self.assertFalse(self.mesh.has_vertex_property('test'))
self.assertFalse(self.mesh.has_halfedge_property('test'))
self.assertFalse(self.mesh.has_edge_property('test'))
self.assertTrue(self.mesh.has_face_property('test'))
self.mesh.remove_face_property('test')
self.assertFalse(self.mesh.has_vertex_property('test'))
self.assertFalse(self.mesh.has_halfedge_property('test'))
self.assertFalse(self.mesh.has_edge_property('test'))
self.assertFalse(self.mesh.has_face_property('test'))
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(Property)
......
......@@ -10,6 +10,7 @@ class Python(unittest.TestCase):
openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj')
def test_vertex_property_array(self):
self.assertFalse(self.mesh.has_vertex_property('random'))
# c_contiguous
arr1 = np.random.rand(self.mesh.n_vertices(), 10)
self.mesh.set_vertex_property_array('random', arr1)
......@@ -26,8 +27,18 @@ class Python(unittest.TestCase):
for vh in self.mesh.vertices():
arr3 = self.mesh.vertex_property('random', vh)
self.assertTrue(np.allclose(arr1.T[vh.idx()], arr3))
# single columns
arr1 = np.random.rand(10, self.mesh.n_vertices())
for vh in self.mesh.vertices():
self.mesh.set_vertex_property('random', vh, arr1[:, vh.idx()])
arr2 = self.mesh.vertex_property_array('random')
self.assertTrue(np.allclose(arr1.T, arr2))
for vh in self.mesh.vertices():
arr3 = self.mesh.vertex_property('random', vh)
self.assertTrue(np.allclose(arr1.T[vh.idx()], arr3))
def test_halfedge_property_array(self):
self.assertFalse(self.mesh.has_halfedge_property('random'))
# c_contiguous
arr1 = np.random.rand(self.mesh.n_halfedges(), 10)
self.mesh.set_halfedge_property_array('random', arr1)
......@@ -44,8 +55,18 @@ class Python(unittest.TestCase):
for hh in self.mesh.halfedges():
arr3 = self.mesh.halfedge_property('random', hh)
self.assertTrue(np.allclose(arr1.T[hh.idx()], arr3))
# single columns
arr1 = np.random.rand(10, self.mesh.n_halfedges())
for hh in self.mesh.halfedges():
self.mesh.set_halfedge_property('random', hh, arr1[:, hh.idx()])
arr2 = self.mesh.halfedge_property_array('random')
self.assertTrue(np.allclose(arr1.T, arr2))
for hh in self.mesh.halfedges():
arr3 = self.mesh.halfedge_property('random', hh)
self.assertTrue(np.allclose(arr1.T[hh.idx()], arr3))
def test_edge_property_array(self):
self.assertFalse(self.mesh.has_edge_property('random'))
# c_contiguous
arr1 = np.random.rand(self.mesh.n_edges(), 10)
self.mesh.set_edge_property_array('random', arr1)
......@@ -62,8 +83,18 @@ class Python(unittest.TestCase):
for eh in self.mesh.edges():
arr3 = self.mesh.edge_property('random', eh)
self.assertTrue(np.allclose(arr1.T[eh.idx()], arr3))
# single columns
arr1 = np.random.rand(10, self.mesh.n_edges())
for eh in self.mesh.edges():
self.mesh.set_edge_property('random', eh, arr1[:, eh.idx()])
arr2 = self.mesh.edge_property_array('random')
self.assertTrue(np.allclose(arr1.T, arr2))
for eh in self.mesh.edges():
arr3 = self.mesh.edge_property('random', eh)
self.assertTrue(np.allclose(arr1.T[eh.idx()], arr3))
def test_face_property_array(self):
self.assertFalse(self.mesh.has_face_property('random'))
# c_contiguous
arr1 = np.random.rand(self.mesh.n_faces(), 10)
self.mesh.set_face_property_array('random', arr1)
......@@ -80,6 +111,15 @@ class Python(unittest.TestCase):
for fh in self.mesh.faces():
arr3 = self.mesh.face_property('random', fh)
self.assertTrue(np.allclose(arr1.T[fh.idx()], arr3))
# single columns
arr1 = np.random.rand(10, self.mesh.n_faces())
for fh in self.mesh.faces():
self.mesh.set_face_property('random', fh, arr1[:, fh.idx()])
arr2 = self.mesh.face_property_array('random')
self.assertTrue(np.allclose(arr1.T, arr2))
for fh in self.mesh.faces():
arr3 = self.mesh.face_property('random', fh)
self.assertTrue(np.allclose(arr1.T[fh.idx()], arr3))
if __name__ == '__main__':
......
import unittest
import openmesh
import numpy as np
class Python(unittest.TestCase):
def setUp(self):
self.mesh = openmesh.TriMesh()
openmesh.read_mesh(self.mesh, 'TestFiles/cube-minimal.obj')
def test_vertex_property_list(self):
self.assertFalse(self.mesh.has_vertex_property('random'))
res = self.mesh.vertex_property('random')
self.assertTrue(all(val is None for val in res))
rnd = [np.random.rand(10) for h in self.mesh.vertices()]
self.mesh.set_vertex_property('random', rnd)
res = self.mesh.vertex_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
for i in range(self.mesh.n_vertices()):
rnd[i][:] = np.random.rand(10)
res = self.mesh.vertex_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
def test_halfedge_property_list(self):
self.assertFalse(self.mesh.has_halfedge_property('random'))
res = self.mesh.halfedge_property('random')
self.assertTrue(all(val is None for val in res))
rnd = [np.random.rand(10) for h in self.mesh.halfedges()]
self.mesh.set_halfedge_property('random', rnd)
res = self.mesh.halfedge_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
for i in range(self.mesh.n_halfedges()):
rnd[i][:] = np.random.rand(10)
res = self.mesh.halfedge_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
def test_edge_property_list(self):
self.assertFalse(self.mesh.has_edge_property('random'))
res = self.mesh.edge_property('random')
self.assertTrue(all(val is None for val in res))
rnd = [np.random.rand(10) for h in self.mesh.edges()]
self.mesh.set_edge_property('random', rnd)
res = self.mesh.edge_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
for i in range(self.mesh.n_edges()):
rnd[i][:] = np.random.rand(10)
res = self.mesh.edge_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
def test_face_property_list(self):
self.assertFalse(self.mesh.has_face_property('random'))
res = self.mesh.face_property('random')
self.assertTrue(all(val is None for val in res))
rnd = [np.random.rand(10) for h in self.mesh.faces()]
self.mesh.set_face_property('random', rnd)
res = self.mesh.face_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
for i in range(self.mesh.n_faces()):
rnd[i][:] = np.random.rand(10)
res = self.mesh.face_property('random')
self.assertTrue(np.allclose(np.stack(rnd), np.stack(res)))
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(Python)
unittest.TextTestRunner(verbosity=2).run(suite)
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