コード例 #1
0
def test_inr():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    mesh = pygalmesh.remesh_surface(
        os.path.join(this_dir, "meshes", "lion-head.off"),
        edge_size=0.025,
        facet_angle=25,
        facet_size=0.1,
        facet_distance=0.001,
        verbose=False,
    )

    tol = 1.0e-3
    ref = [
        3.705640e-01,
        -3.711630e-01,
        4.754940e-01,
        -4.728260e-01,
        4.998690e-01,
        -4.998350e-01,
    ]
    assert abs(max(mesh.points[:, 0]) - ref[0]) < tol * abs(ref[0])
    assert abs(min(mesh.points[:, 0]) - ref[1]) < tol * abs(ref[1])
    assert abs(max(mesh.points[:, 1]) - ref[2]) < tol * abs(ref[2])
    assert abs(min(mesh.points[:, 1]) - ref[3]) < tol * abs(ref[3])
    assert abs(max(mesh.points[:, 2]) - ref[4]) < tol * abs(ref[4])
    assert abs(min(mesh.points[:, 2]) - ref[5]) < tol * abs(ref[5])

    vol = sum(
        helpers.compute_triangle_areas(mesh.points, mesh.get_cells_type("triangle"))
    )
    ref = 1.917942005786831
    assert abs(vol - ref) < ref * 1.0e-3
コード例 #2
0
def test_orient_lion():
    helpers.download(
        "lion-head.off",
        "e4b00c47fee69a37a0d95ab71a63cc74",
        url=
        "https://raw.githubusercontent.com/CGAL/cgal/master/Mesh_3/examples/Mesh_3/data/"
    )
    mesh = meshio.read("/tmp/lion-head.off")
    faces = mesh.cells["triangle"]
    area = sum(helpers.compute_triangle_areas(mesh.points, faces))

    # Shuffle some normals
    for i in [10, 20, 30, 40, 50]:
        faces[i, [0, 1]] = faces[i, [1, 0]]

    mesh.cells["triangle"] = faces
    mesh_oriented = pygalmesh.orient_surface_mesh(mesh)
    area_oriented = sum(
        helpers.compute_triangle_areas(mesh_oriented.points,
                                       mesh_oriented.cells["triangle"]))

    assert area == area_oriented
コード例 #3
0
def test_remesh_lion():
    helpers.download(
        "lion-head.off",
        "e4b00c47fee69a37a0d95ab71a63cc74",
        url=
        "https://raw.githubusercontent.com/CGAL/cgal/master/Mesh_3/examples/Mesh_3/data/"
    )
    mesh_in = meshio.read("/tmp/lion-head.off")
    mesh_out = pygalmesh.remesh_surface(mesh_in,
                                        edge_size=0.025,
                                        facet_angle=25,
                                        facet_size=0.1,
                                        facet_distance=0.001)

    area_in = sum(
        helpers.compute_triangle_areas(mesh_in.points,
                                       mesh_in.cells["triangle"]))
    area_out = sum(
        helpers.compute_triangle_areas(mesh_out.points,
                                       mesh_out.cells["triangle"]))
    err_rel = abs(area_in - area_out) / area_in

    assert err_rel < 0.005
    return
コード例 #4
0
def test_disk():
    h = 0.1
    n = int(2 * numpy.pi / h)
    points = numpy.array([[
        numpy.cos(alpha), numpy.sin(alpha)
    ] for alpha in numpy.linspace(0.0, 2 * numpy.pi, n + 1, endpoint=False)])
    constraints = [[k, k + 1] for k in range(n)] + [[n, 0]]
    mesh = pygalmesh.generate_2d(
        points,
        constraints,
        max_edge_size=h,
        num_lloyd_steps=0,
    )
    areas = compute_triangle_areas(mesh.points,
                                   mesh.get_cells_type("triangle"))
    assert numpy.all(areas > 1.0e-5)
コード例 #5
0
ファイル: test_surface_mesh.py プロジェクト: uvilla/pygalmesh
def test_sphere():
    radius = 1.0
    s = pygalmesh.Ball([0.0, 0.0, 0.0], radius)
    mesh = pygalmesh.generate_surface_mesh(s,
                                           angle_bound=30,
                                           radius_bound=0.1,
                                           distance_bound=0.1,
                                           verbose=False)

    tol = 1.0e-2
    assert abs(max(mesh.points[:, 0]) - radius) < tol
    assert abs(min(mesh.points[:, 0]) + radius) < tol
    assert abs(max(mesh.points[:, 1]) - radius) < tol
    assert abs(min(mesh.points[:, 1]) + radius) < tol
    assert abs(max(mesh.points[:, 2]) - radius) < tol
    assert abs(min(mesh.points[:, 2]) + radius) < tol

    areas = helpers.compute_triangle_areas(mesh.points,
                                           mesh.get_cells_type("triangle"))
    surface_area = sum(areas)
    assert abs(surface_area - 4 * numpy.pi * radius**2) < 0.1