def test_triangle_edges(): mesh = TriangleSoup([(0, 1, 2), (2, 1, 3)]) assert all(mesh.segment_soup().elements == [(0, 1), (1, 2), (0, 2), (1, 3), (2, 3)]) assert all(mesh.triangle_edges() == [(0, 1, 2), (1, 3, 4)])
def test_nonmanifold_triangles(): random.seed(71318) triangles = array([(0,1,1),(2,3,2),(4,4,5), # degenerate triangles (6,7,8), # lone triangle (9,10,11),(11,10,12), # correctly oriented pair (13,14,15),(14,15,16), # incorrectly oriented pair (17,18,19),(17,19,18),(17,20,21),(17,21,20), # touching spheres (22,23,24),(22,25,26), # touching triangles (27,28,29),(27,29,28)],int32) # manifold sphere closed = asarray(range(18)+range(22,27)) open = asarray(range(6)+[14,15,17,22]) for _ in xrange(5): # Results should be covariant under sparsity and permutation map = injection(30) tris = map[triangles] # Results should be invariant under cyclic permutation of triangles s = random.randint(3,size=len(tris)).reshape(-1,1) tris = hstack([tris,tris])[arange(len(tris)).reshape(-1,1),hstack([s,s+1,s+2])] # Are we good? mesh = TriangleSoup(ascontiguousarray(tris)) assert all(mesh.nonmanifold_nodes(False)==sort(map[closed])) assert all(mesh.nonmanifold_nodes(True)==sort(map[open]))
def test_nonmanifold_triangles(): random.seed(71318) triangles = array( [ (0, 1, 1), (2, 3, 2), (4, 4, 5), # degenerate triangles (6, 7, 8), # lone triangle (9, 10, 11), (11, 10, 12), # correctly oriented pair (13, 14, 15), (14, 15, 16), # incorrectly oriented pair (17, 18, 19), (17, 19, 18), (17, 20, 21), (17, 21, 20), # touching spheres (22, 23, 24), (22, 25, 26), # touching triangles (27, 28, 29), (27, 29, 28) ], int32) # manifold sphere closed = asarray(range(18) + range(22, 27)) open = asarray(range(6) + [14, 15, 17, 22]) for _ in xrange(5): # Results should be covariant under sparsity and permutation map = injection(30) tris = map[triangles] # Results should be invariant under cyclic permutation of triangles s = random.randint(3, size=len(tris)).reshape(-1, 1) tris = hstack([tris, tris])[arange(len(tris)).reshape(-1, 1), hstack([s, s + 1, s + 2])] # Are we good? mesh = TriangleSoup(ascontiguousarray(tris)) assert all(mesh.nonmanifold_nodes(False) == sort(map[closed])) assert all(mesh.nonmanifold_nodes(True) == sort(map[open]))
def test_triangle_edges(): mesh = TriangleSoup([(0,1,2),(2,1,3)]) assert all(mesh.segment_soup().elements==[(0,1),(1,2),(0,2),(1,3),(2,3)]) assert all(mesh.triangle_edges()==[(0,1,2),(1,3,4)])
def test_nodes_touched(): mesh = TriangleSoup([(4,7,5)]) assert all(mesh.nodes_touched()==[4,5,7])
def test_adjacent_triangles(): mesh = TriangleSoup([(0,1,2),(2,1,3)]) assert all(mesh.adjacent_elements()==[(-1,1,-1),(0,-1,-1)])
def test_bending_quadruples(): mesh = TriangleSoup([(0,1,2),(2,1,3)]) assert all(mesh.bending_tuples()==[(0,1,2,3)])
def test_boundary_mesh(): mesh = TriangleSoup([(0,1,2),(2,1,3)]) boundary = mesh.boundary_mesh() assert all(boundary.elements==[[0,1],[2,0],[1,3],[3,2]])
def test_incident_triangles(): mesh = TriangleSoup([(0,1,2),(0,3,4)]) incident = mesh.incident_elements() incident = map(list,incident) assert incident==[[0,1],[0],[0],[1],[1]]
def test_nodes_touched(): mesh = TriangleSoup([(4, 7, 5)]) assert all(mesh.nodes_touched() == [4, 5, 7])
def test_adjacent_triangles(): mesh = TriangleSoup([(0, 1, 2), (2, 1, 3)]) assert all(mesh.adjacent_elements() == [(-1, 1, -1), (0, -1, -1)])
def test_bending_quadruples(): mesh = TriangleSoup([(0, 1, 2), (2, 1, 3)]) assert all(mesh.bending_tuples() == [(0, 1, 2, 3)])
def test_boundary_mesh(): mesh = TriangleSoup([(0, 1, 2), (2, 1, 3)]) boundary = mesh.boundary_mesh() assert all(boundary.elements == [[0, 1], [2, 0], [1, 3], [3, 2]])
def test_incident_triangles(): mesh = TriangleSoup([(0, 1, 2), (0, 3, 4)]) incident = mesh.incident_elements() incident = map(list, incident) assert incident == [[0, 1], [0], [0], [1], [1]]