def test_on_demand_calc(self): # check if standard properties are requested on demand, # i.e. if it doesn't crash it works mesh = self.one_triangle() mesh.calc_halfedge_normal(openmesh.HalfedgeHandle(0)) mesh = self.one_triangle() mesh.calc_vertex_normal(openmesh.VertexHandle(0)) mesh = self.one_triangle() mesh.calc_vertex_normal_fast(openmesh.VertexHandle(0)) mesh = self.one_triangle() mesh.calc_vertex_normal_correct(openmesh.VertexHandle(0)) mesh = self.one_triangle() mesh.calc_vertex_normal_loop(openmesh.VertexHandle(0))
def test_on_demand_setter(self): # check if standard properties are requested on demand, # i.e. if it doesn't crash it works mesh = self.one_triangle() mesh.set_normal(openmesh.VertexHandle(0), np.array([0, 0, 0])) mesh = self.one_triangle() mesh.set_normal(openmesh.HalfedgeHandle(0), np.array([0, 0, 0])) mesh = self.one_triangle() mesh.set_normal(openmesh.FaceHandle(0), np.array([0, 0, 0])) mesh = self.one_triangle() mesh.set_color(openmesh.VertexHandle(0), np.array([0, 0, 0, 0])) mesh = self.one_triangle() mesh.set_color(openmesh.HalfedgeHandle(0), np.array([0, 0, 0, 0])) mesh = self.one_triangle() mesh.set_color(openmesh.EdgeHandle(0), np.array([0, 0, 0, 0])) mesh = self.one_triangle() mesh.set_color(openmesh.FaceHandle(0), np.array([0, 0, 0, 0])) mesh = self.one_triangle() mesh.set_texcoord1D(openmesh.VertexHandle(0), np.array([0])) mesh = self.one_triangle() mesh.set_texcoord1D(openmesh.HalfedgeHandle(0), np.array([0])) mesh = self.one_triangle() mesh.set_texcoord2D(openmesh.VertexHandle(0), np.array([0, 0])) mesh = self.one_triangle() mesh.set_texcoord2D(openmesh.HalfedgeHandle(0), np.array([0, 0])) mesh = self.one_triangle() mesh.set_texcoord3D(openmesh.VertexHandle(0), np.array([0, 0, 0])) mesh = self.one_triangle() mesh.set_texcoord3D(openmesh.HalfedgeHandle(0), np.array([0, 0, 0]))
def test_on_demand_delete(self): # check if standard properties are requested on demand, # i.e. if it doesn't crash it works mesh = self.one_triangle() mesh.delete_vertex(openmesh.VertexHandle(0)) mesh.garbage_collection() mesh = self.one_triangle() mesh.delete_edge(openmesh.EdgeHandle(0)) mesh.garbage_collection() mesh = self.one_triangle() mesh.delete_face(openmesh.FaceHandle(0)) mesh.garbage_collection()
def _next_ring(mesh, last_ring, other): res = [] def is_new_vertex(idx): return (idx not in last_ring and idx not in other and idx not in res) for vh1 in last_ring: vh1 = om.VertexHandle(vh1) after_last_ring = False for vh2 in mesh.vv(vh1): if after_last_ring: if is_new_vertex(vh2.idx()): res.append(vh2.idx()) if vh2.idx() in last_ring: after_last_ring = True for vh2 in mesh.vv(vh1): if vh2.idx() in last_ring: break if is_new_vertex(vh2.idx()): res.append(vh2.idx()) return res
def test_on_demand_update(self): # check if standard properties are requested on demand, # i.e. if it doesn't crash it works mesh = self.one_triangle() mesh.update_normal(openmesh.FaceHandle(0)) mesh = self.one_triangle() mesh.update_face_normals() mesh = self.one_triangle() mesh.update_normal(openmesh.HalfedgeHandle(0)) mesh = self.one_triangle() mesh.update_halfedge_normals() mesh = self.one_triangle() mesh.update_normal(openmesh.VertexHandle(0)) mesh = self.one_triangle() mesh.update_vertex_normals() mesh = self.one_triangle() mesh.update_normals()
def test_halfedge_iter_skipping_low_level(self): # Add some vertices self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(-1, -1, 1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d( 1, -1, 1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d( 1, 1, 1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(-1, 1, 1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(-1, -1, -1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d( 1, -1, -1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d( 1, 1, -1))) self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(-1, 1, -1))) # Add six faces to form a cube self.mesh.add_face(self.vhandle[0], self.vhandle[1], self.vhandle[3]) self.mesh.add_face(self.vhandle[1], self.vhandle[2], self.vhandle[3]) self.mesh.add_face(self.vhandle[7], self.vhandle[6], self.vhandle[5]) self.mesh.add_face(self.vhandle[7], self.vhandle[5], self.vhandle[4]) self.mesh.add_face(self.vhandle[1], self.vhandle[0], self.vhandle[4]) self.mesh.add_face(self.vhandle[1], self.vhandle[4], self.vhandle[5]) self.mesh.add_face(self.vhandle[2], self.vhandle[1], self.vhandle[5]) self.mesh.add_face(self.vhandle[2], self.vhandle[5], self.vhandle[6]) self.mesh.add_face(self.vhandle[3], self.vhandle[2], self.vhandle[6]) self.mesh.add_face(self.vhandle[3], self.vhandle[6], self.vhandle[7]) self.mesh.add_face(self.vhandle[0], self.vhandle[3], self.vhandle[7]) self.mesh.add_face(self.vhandle[0], self.vhandle[7], self.vhandle[4]) # Test setup: # # 3 ======== 2 # / /| # / / | z # 0 ======== 1 | | # | | | | y # | 7 | 6 | / # | | / | / # | |/ |/ # 4 ======== 5 -------> x # Check setup self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_halfedges(), 36) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_faces(), 12) # Run over all halfedges heCounter = 0 self.mesh.request_face_status() self.mesh.request_vertex_status() self.mesh.request_halfedge_status() # Get second edge eh = self.mesh.edge_handle(2) # Delete one edge self.mesh.delete_edge(eh) # Check setup ( No garbage collection, so nothing should change!) self.assertEqual(self.mesh.n_edges(), 18) self.assertEqual(self.mesh.n_halfedges(), 36) self.assertEqual(self.mesh.n_vertices(), 8) self.assertEqual(self.mesh.n_faces(), 12) # ===================================================== # Try to add low level edge with invalid incidents and # check skipping iterator # ===================================================== # Add a low level edge without handles eh_test = self.mesh.edge_handle(self.mesh.new_edge(openmesh.VertexHandle(), openmesh.VertexHandle())) count = 0 found_4 = False found_5 = False found_36 = False found_37 = False for he in self.mesh.shalfedges(): if he.idx() == 4: found_4 = True if he.idx() == 5: found_5 = True if he.idx() == 36: found_36 = True if he.idx() == 37: found_37 = True count += 1 self.assertEqual(count, 36) self.assertFalse(found_4) self.assertFalse(found_5) self.assertTrue(found_36) self.assertTrue(found_37) # ===================================================== # Try to delete one edge with invalid incidents and # check skipping iterator # ===================================================== # Delete one edge and recheck (Halfedges 4 and 5) self.mesh.delete_edge(eh_test) count = 0 found_4 = False found_5 = False found_36 = False found_37 = False for he in self.mesh.shalfedges(): if he.idx() == 4: found_4 = True if he.idx() == 5: found_5 = True if he.idx() == 36: found_36 = True if he.idx() == 37: found_37 = True count += 1 self.assertEqual(count, 34) self.assertFalse(found_4) self.assertFalse(found_5) self.assertFalse(found_36) self.assertFalse(found_37)
def vh_from_sv(omesh, sv): supervertices = omesh.vertex_property_array('supervertex') result = np.where(supervertices == id(sv)) assert np.shape(result) == (1, 1) return om.VertexHandle(result[0][0])