Esempio n. 1
0
def test_icosa_sphere(n=16):
    points, cells = meshzoo.icosa_sphere(n)
    # import meshio
    # meshio.write_points_cells("out.vtk", points, {"triangle": cells})
    assert len(points) == 2562
    assert _near_equal(numpy.sum(points, axis=0), [0.0, 0.0, 0.0])
    assert len(cells) == 5120
Esempio n. 2
0
def generate_triangular_mesh():
    if pathlib.Path.is_file("sphere.xdmf"):
        mesh = meshio.read("sphere.xdmf")
    else:
        points, cells = meshzoo.icosa_sphere(300)
        mesh = meshio.Mesh(points, {"triangle": cells})
        mesh.write("sphere.xdmf")
    return mesh
Esempio n. 3
0
def test_icosa_sphere(n=16):
    points, cells = meshzoo.icosa_sphere(n)
    # import meshio
    # meshio.write_points_cells("out.vtk", points, {"triangle": cells})
    assert len(points) == 2562
    assert _near_equal(numpy.sum(points, axis=0), [0.0, 0.0, 0.0])
    assert len(cells) == 5120
    assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
    assert numpy.all(
        numpy.abs(numpy.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
Esempio n. 4
0
def test_sphere():
    points, cells = meshzoo.icosa_sphere(5)
    mesh = meshplex.Mesh(points, cells)

    run(
        mesh,
        12.413437988936916,
        [0.7864027242108207, 0.05524648209283611],
        [128.70115197256447, 0.3605511489598192],
        [0.5593675314375034, 0.02963260270642986],
    )
Esempio n. 5
0
def test_euler_characteristic():
    points = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]
    cells = [[0, 1, 2]]
    mesh = meshplex.MeshTri(points, cells)
    assert mesh.euler_characteristic == 1
    assert mesh.genus == 0

    points, cells = meshzoo.icosa_sphere(5)
    mesh = meshplex.MeshTri(points, cells)
    assert mesh.euler_characteristic == 2
    assert mesh.genus == 0

    points, cells = meshzoo.moebius(num_twists=1, nl=21, nw=6)
    mesh = meshplex.MeshTri(points, cells)
    assert mesh.euler_characteristic == 0
    with pytest.raises(RuntimeError):
        mesh.genus
Esempio n. 6
0
    def get_regular_points(self, npoints=None, device="gpu0"):
        """
        Get regular points on a Sphere
        Return Tensor of Size [x, 3]
        """
        if not self.npoints == npoints:
            import meshzoo
            verts, faces = meshzoo.icosa_sphere(4)
            self.mesh = ms.Mesh(
                verts, faces
            )  #psymesh.generate_icosphere(1, [0, 0, 0], 4)  # 2562 vertices
            # print('t')
            # print(self.mesh.vertices )
            self.vertex = torch.from_numpy(
                self.mesh.vertices).to(device).float()
            self.num_vertex = self.vertex.size(0)
            self.vertex = self.vertex.transpose(0, 1).contiguous().unsqueeze(0)
            self.npoints = npoints

        return Variable(self.vertex.to(device))
Esempio n. 7
0
def write_tree(filename, n, scaling, res=20, colors_enhancement=2.5):
    import cplot
    import meshio
    import meshzoo

    points, cells = meshzoo.icosa_sphere(res)

    evaluator = EvalCartesian(points.T, scaling, complex_valued=True)
    meshes = []
    for L, level in enumerate(itertools.islice(evaluator, n)):
        for k, vals in enumerate(level):
            srgb1_vals = cplot.get_srgb1(vals, colorspace="cam16")
            # exaggerate colors a bit
            srgb1_vals *= colors_enhancement
            srgb1_vals[srgb1_vals > 1] = 1
            srgb1_vals[srgb1_vals < 0] = 0

            pts = points.copy()

            pts[:, 0] += 2.2 * (k - L)
            pts[:, 2] -= 2.7 * L

            meshes.append(
                meshio.Mesh(pts, {"triangle": cells}, point_data={"srgb1": srgb1_vals})
            )

    # merge meshes
    points = numpy.concatenate([mesh.points for mesh in meshes])
    srgb1_vals = numpy.concatenate([mesh.point_data["srgb1"] for mesh in meshes])
    #
    cells = []
    k = 0
    for mesh in meshes:
        cells.append(mesh.cells[0].data + k)
        k += mesh.points.shape[0]
    cells = numpy.concatenate(cells)

    meshio.write_points_cells(
        filename, points, {"triangle": cells}, point_data={"srgb1": srgb1_vals}
    )
Esempio n. 8
0
def write_single(filename, n, r, scaling, res=20, colors_enhancement=2.5):
    """This function creates a sphere mesh with "srgb1" values. Can be views in ParaView
    by disabling "Map Scalars".
    """
    import cplot
    import meshio
    import meshzoo

    points, cells = meshzoo.icosa_sphere(res)

    evaluator = EvalCartesian(points.T, scaling, complex_valued=True)
    vals = next(itertools.islice(evaluator, n, None))[r]

    srgb1_vals = cplot.get_srgb1(vals, colorspace="cam16")

    # exaggerate colors a bit
    srgb1_vals *= colors_enhancement
    srgb1_vals[srgb1_vals > 1] = 1
    srgb1_vals[srgb1_vals < 0] = 0

    meshio.write_points_cells(
        filename, points, {"triangle": cells}, point_data={"srgb1": srgb1_vals}
    )
Esempio n. 9
0
            self.x_pred_tf: xyz[:, 0:1],
            self.y_pred_tf: xyz[:, 1:2],
            self.z_pred_tf: xyz[:, 2:3]
        }
        u = self.sess.run(self.u_pred, tf_dict)
        return u


if __name__ == "__main__":
    # Domain bounds
    r = 1.
    xa, xb, ya, yb, za, zb = -r, r, -r, r, -r, r
    lb = np.array([xa, ya, za])
    ub = np.array([xb, yb, zb])
    # geometry
    P, T = meshzoo.icosa_sphere(40)
    # plot_mesh_3D(P, T)
    # adjacency matrix
    amat = adjacency_mat(T)
    # degree of polynomials to train the finite difference operator
    deg_hard = [0, 1]  # hard constraints
    deg_soft = [2]  # soft constraints
    w_A_hard = 20
    w_A_soft = 1

    layers = [3, 100, 100, 100, 1]
    x_var, y_var, z_var = sp.symbols('x, y, z')

    u_exa = lambda x, y, z: x * np.sin(y) + z
    rhs_exa = lambda x, y, z: -(3 * z + 4 * x * y * np.cos(y) + x *
                                (4 - y**2) * np.sin(y))
Esempio n. 10
0
Spheres
=======

Display two spheres with Surface layers
"""

try:
    from meshzoo import icosa_sphere
except ModuleNotFoundError as e:
    raise ModuleNotFoundError(
        "This example uses a meshzoo but meshzoo is not installed. "
        "To install try 'pip install meshzoo'."
    ) from e
import napari


vert, faces = icosa_sphere(10)

vert *= 100

sphere1 = (vert + 30, faces)
sphere2 = (vert - 30, faces)

viewer = napari.Viewer(ndisplay=3)
surface1 = viewer.add_surface(sphere1)
surface2 = viewer.add_surface(sphere2)
viewer.reset_view()

if __name__ == '__main__':
    napari.run()
Esempio n. 11
0
labels_layer = viewer.add_labels(
    labeled,
    name='labels',
    blending='translucent',
    experimental_clipping_planes=[plane_parameters],
)

# POINTS
points_layer = viewer.add_points(
    np.random.rand(20, 3) * 64,
    size=5,
    experimental_clipping_planes=[plane_parameters],
)

# SPHERE
sphere_vert, sphere_faces = icosa_sphere(10)
sphere_vert *= 20
sphere_vert += 32
surface_layer = viewer.add_surface(
    (sphere_vert, sphere_faces),
    experimental_clipping_planes=[plane_parameters],
)

# SHAPES
shapes_data = np.random.rand(3, 4, 3) * 64

shapes_layer = viewer.add_shapes(
    shapes_data,
    face_color=['magenta', 'green', 'blue'],
    experimental_clipping_planes=[plane_parameters],
)
Esempio n. 12
0
approximate 1. It appears that this holds on average, but not for all
test vectors.

'''

import matplotlib.pyplot as plt
import meshzoo
import numpy as np

import flux.compressed_form_factors as cff

from flux.shape import TrimeshShapeModel

tol = 1e-2

V, F = meshzoo.icosa_sphere(15)

# stretch out the sphere
V[:, 0] *= 3
V[:, 1] *= 2
V[:, 2] *= 1

shape_model = TrimeshShapeModel(V, F)

# make surface normals inward facing
outward = (shape_model.P*shape_model.N).sum(1) > 0
shape_model.N[outward] *= -1

FF = cff.CompressedFormFactorMatrix(shape_model, tol=1e-2,
                                    max_rank=30, min_size=400, max_depth=1,
                                    RootBlock=cff.FormFactorOctreeBlock)
Esempio n. 13
0
def sphere(h):
    # edge length of regular icosahedron with radius 1
    l = 1 / numpy.sin(0.4 * numpy.pi)
    n = int(l / h)
    return meshzoo.icosa_sphere(n)
Esempio n. 14
0
def create_sphere(n_subdivide=3):
    # 3 makes 642 verts, 1280 faces,
    # 4 makes 2562 verts, 5120 faces
    verts, faces = meshzoo.icosa_sphere(2**n_subdivide)
    return verts, faces
Esempio n. 15
0
def generate_unity_sphere(n):
    xyz, v = meshzoo.icosa_sphere(n)
    return {'points': xyz, 'vertices': v}, xyz.shape[0]