Example #1
0
def test_face_adjacency_halfedge():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_adjacency_halfedge(0, 1) == (1, 7)
Example #2
0
def cube():
    return Mesh.from_polyhedron(6)
Example #3
0
def test_clear():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    mesh.clear()
    assert mesh.number_of_faces() == 0
    assert mesh.number_of_vertices() == 0
    assert mesh.number_of_edges() == 0
Example #4
0
def test_from_lines():
    lines = compas.json_load(compas.get('lines.json'))
    mesh = Mesh.from_lines(lines)
    assert mesh.number_of_faces() == 10
    assert mesh.number_of_vertices() == 32
    assert mesh.number_of_edges() == 40
Example #5
0
def test_from_polyhedron():
    mesh = Mesh.from_polyhedron(8)
    assert mesh.number_of_faces() == 8
    assert mesh.number_of_vertices() == 6
    assert mesh.number_of_edges() == 12
Example #6
0
        if callback:
            callback(k, callback_args)


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas

    from compas.datastructures import Mesh
    from compas_plotters import MeshPlotter

    mesh = Mesh.from_obj(compas.get('faces.obj'))

    fixed = list(mesh.vertices_where({'vertex_degree': 2}))

    lines = []
    for u, v in mesh.edges():
        lines.append({
            'start': mesh.vertex_coordinates(u, 'xy'),
            'end': mesh.vertex_coordinates(v, 'xy'),
            'color': '#cccccc',
            'width': 1.0,
        })

    mesh_smooth_area(mesh, fixed=fixed, kmax=100)

    plotter = MeshPlotter(mesh, figsize=(10, 7))
Example #7
0
def test_from_ply():
    mesh = Mesh.from_ply(compas.get('tubemesh.ply'))
    assert mesh.number_of_faces() == 342
    assert mesh.number_of_vertices() == 200
    assert mesh.number_of_edges() == 541
Example #8
0
def test_vertex_neighborhood_centroid():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_neighborhood_centroid(0) == [1.0, 1.0, 0.0]
    assert mesh.vertex_neighborhood_centroid(1) == [
        2.0, 0.6666666666666666, 0.0
    ]
Example #9
0
def test_vertex_curvature():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.vertex_curvature(0) == 0.0029617825994936453
    assert mesh.vertex_curvature(5) == 0.036193074384009094
Example #10
0
def test_vertex_area():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_area(0) == 1
    assert mesh.vertex_area(15) == 4
Example #11
0
def test_vertex_laplacian():

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_laplacian(0) == [1.0, 1.0, 0.0]
    assert mesh.vertex_laplacian(1) == [0.0, 0.6666666666666666, 0.0]
Example #12
0
def test_vertex_coordinates():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_coordinates(15) == [6.0, 4.0, 0.0]
    assert mesh.vertex_coordinates(15, 'yx') == [4.0, 6.0]
Example #13
0
def test_is_face_on_boundary():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.is_face_on_boundary(0)
    assert not mesh.is_face_on_boundary(8)
Example #14
0
def test_face_adjacency_vertices():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_adjacency_vertices(0, 1) == [1, 7]
Example #15
0
def test_face_curvature():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_curvature(0) == 0.0035753184898039566

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_curvature(0) == 0
Example #16
0
def test_face_normal():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_normal(0) == (0.5435358481001584, -0.16248515023849733,
                                   0.8235091728584537)
Example #17
0
def test_edges_on_boundary():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert len(mesh.edges_on_boundary()) == 36
Example #18
0
def test_face_centroid():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_centroid(0) == [
        3.94185334444046, 2.024157851934433, 1.3333333134651184
    ]
Example #19
0
def test_from_obj():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.number_of_faces() == 25
    assert mesh.number_of_vertices() == 36
    assert mesh.number_of_edges() == 60
Example #20
0
def test_face_center():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_center(0) == [
        3.944329439044577, 2.0258867968680776, 1.332040166602369
    ]
Example #21
0
def test_from_off():
    mesh = Mesh.from_off(compas.get('cube.off'))
    assert mesh.number_of_faces() == 6
    assert mesh.number_of_vertices() == 8
    assert mesh.number_of_edges() == 12
Example #22
0
def test_face_area():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_area(0) == 0.3374168482414756
Example #23
0
def tet():
    return Mesh.from_polyhedron(4)
Example #24
0
def test_face_flatness():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_flatness(0) == 0.23896112582475654

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_flatness(0) == 0
Example #25
0
def test_to_vertices_and_faces():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    vertices, faces = mesh.to_vertices_and_faces()
    assert len(vertices) == 36
    assert len(faces) == 25
Example #26
0
def test_face_aspect_ratio():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_aspect_ratio(0) == 1.2813792520925738

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_aspect_ratio(0) == 1
Example #27
0
def test_copy():
    mesh1 = Mesh.from_obj(compas.get('faces.obj'))
    mesh2 = mesh1.copy()
    assert mesh1.number_of_faces() == mesh2.number_of_faces()
    assert mesh1.number_of_vertices() == mesh2.number_of_vertices()
    assert mesh1.number_of_edges() == mesh2.number_of_edges()
Example #28
0
def test_face_skewness():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_skewness(0) == 0.2432393485343291

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_skewness(0) == 0
Example #29
0
def test_add_vertex():
    mesh = Mesh.from_stl(compas.get('cube_binary.stl'))
    v = mesh.number_of_vertices()
    key = mesh.add_vertex(x=0, y=1, z=2)
    assert mesh.vertex_attributes(key, 'xyz') == [0, 1, 2]
    assert mesh.number_of_vertices() == v + 1
Example #30
0
def test_from_ply():
    mesh = Mesh.from_ply(compas.get('bunny.ply'))
    assert mesh.number_of_faces() == 69451
    assert mesh.number_of_vertices() == 35947
    assert mesh.number_of_edges() == 104288