예제 #1
0
파일: demos.py 프로젝트: redhog/pyvista
def glyphs(grid_sz=3, **kwargs):
    """Create several parametric supertoroids using VTK's glyph table functionality."""
    n = 10
    values = np.arange(n)  # values for scalars to look up glyphs by

    # taken from:
    rng = np.random.default_rng()
    params = rng.uniform(0.5, 2,
                         size=(n, 2))  # (n1, n2) parameters for the toroids

    geoms = [pv.ParametricSuperToroid(n1=n1, n2=n2) for n1, n2 in params]

    # get dataset where to put glyphs
    x, y, z = np.mgrid[:grid_sz, :grid_sz, :grid_sz]
    mesh = pv.StructuredGrid(x, y, z)

    # add random scalars
    rng_int = rng.integers(0, n, size=x.size)
    mesh.point_arrays['scalars'] = rng_int

    # construct the glyphs on top of the mesh; don't scale by scalars now
    return mesh.glyph(geom=geoms,
                      indices=values,
                      scale=False,
                      factor=0.3,
                      rng=(0, n - 1))
예제 #2
0
def test_glyph():
    for i, dataset in enumerate(DATASETS):
        result = dataset.glyph()
        assert result is not None
        assert isinstance(result, pyvista.PolyData)
    # Test different options for glyph filter
    sphere = pyvista.Sphere(radius=3.14)
    sphere_sans_arrays = sphere.copy()
    # make cool swirly pattern
    vectors = np.vstack((np.sin(sphere.points[:,
                                              0]), np.cos(sphere.points[:, 1]),
                         np.cos(sphere.points[:, 2]))).T
    # add and scale
    sphere.vectors = vectors * 0.3
    sphere.point_arrays['foo'] = np.random.rand(sphere.n_points)
    sphere.point_arrays['arr'] = np.ones(sphere.n_points)
    result = sphere.glyph(scale=False)
    result = sphere.glyph(scale='arr')
    result = sphere.glyph(scale='arr', orient='Normals', factor=0.1)
    result = sphere.glyph(scale='arr',
                          orient='Normals',
                          factor=0.1,
                          tolerance=0.1)
    result = sphere.glyph(scale='arr',
                          orient='Normals',
                          factor=0.1,
                          tolerance=0.1,
                          clamping=False,
                          rng=[1, 1])
    # passing one or more custom glyphs; many cases for full coverage
    geoms = [
        pyvista.Sphere(),
        pyvista.Arrow(),
        pyvista.ParametricSuperToroid()
    ]
    indices = range(len(geoms))
    result = sphere.glyph(geom=geoms[0])
    result = sphere.glyph(geom=geoms, indices=indices, rng=(0, len(geoms)))
    result = sphere.glyph(geom=geoms)
    result = sphere.glyph(geom=geoms,
                          scale='arr',
                          orient='Normals',
                          factor=0.1,
                          tolerance=0.1)
    result = sphere.glyph(geom=geoms[:1], indices=[None])
    result = sphere_sans_arrays.glyph(geom=geoms)
    with pytest.raises(TypeError):
        # wrong type for the glyph
        sphere.glyph(geom=pyvista.StructuredGrid())
    with pytest.raises(TypeError):
        # wrong type for the indices
        sphere.glyph(geom=geoms, indices=set(indices))
    with pytest.raises(ValueError):
        # wrong length for the indices
        sphere.glyph(geom=geoms, indices=indices[:-1])
예제 #3
0
def supertorus(yScale,
               xScale,
               Height,
               InternalRadius,
               Vertical,
               Horizontal,
               deltaX=0,
               deltaY=0,
               deltaZ=0):
    grid = pv.ParametricSuperToroid(ringradius=xScale,
                                    crosssectionradius=InternalRadius,
                                    xradius=xScale,
                                    yradius=yScale,
                                    zradius=Height,
                                    n1=Vertical,
                                    n2=Horizontal)
    grid.translate([deltaX + 5, deltaY + 5, deltaZ])
    return grid
예제 #4
0
def glyphs(grid_sz=3):
    """Create several parametric supertoroids using VTK's glyph table functionality.

    Parameters
    ----------
    grid_sz : int, optional
        Create ``grid_sz x grid_sz`` supertoroids.

    Returns
    -------
    pyvista.PolyData
        Mesh of supertoroids.

    See Also
    --------
    plot_glyphs

    Examples
    --------
    >>> from pyvista import demos
    >>> mesh = demos.glyphs()
    >>> mesh.plot()

    """
    n = 10
    values = np.arange(n)  # values for scalars to look up glyphs by

    # taken from:
    rng = np.random.default_rng()
    params = rng.uniform(0.5, 2, size=(n, 2))  # (n1, n2) parameters for the toroids

    geoms = [pv.ParametricSuperToroid(n1=n1, n2=n2) for n1, n2 in params]

    # get dataset where to put glyphs
    x, y, z = np.mgrid[:grid_sz, :grid_sz, :grid_sz]
    mesh = pv.StructuredGrid(x, y, z)

    # add random scalars
    rng_int = rng.integers(0, n, size=x.size)
    mesh.point_data['scalars'] = rng_int

    # construct the glyphs on top of the mesh; don't scale by scalars now
    return mesh.glyph(geom=geoms, indices=values, scale=False,
                      factor=0.3, rng=(0, n - 1))
예제 #5
0
파일: demos.py 프로젝트: yngvem/pyvista
def glyphs(grid_sz=3, **kwargs):
    """Plot several parametric supertoroids using VTK's glyph table functionality."""
    n = 10
    values = np.arange(n)  # values for scalars to look up glyphs by

    # taken from:
    rng = np.random.default_rng()
    params = rng.uniform(0.5, 2,
                         size=(n, 2))  # (n1, n2) parameters for the toroids

    geoms = [pv.ParametricSuperToroid(n1=n1, n2=n2) for n1, n2 in params]

    # get dataset where to put glyphs
    x, y, z = np.mgrid[:grid_sz, :grid_sz, :grid_sz]
    mesh = pv.StructuredGrid(x, y, z)

    # add random scalars
    rng_int = rng.integers(0, n, size=x.size)
    mesh.point_arrays['scalars'] = rng_int

    # construct the glyphs on top of the mesh; don't scale by scalars now
    glyphs = mesh.glyph(geom=geoms,
                        indices=values,
                        scale=False,
                        factor=0.3,
                        rng=(0, n - 1))

    # create plotter and add our glyphs with some nontrivial lighting
    plotter = pv.Plotter()
    plotter.add_mesh(glyphs,
                     specular=1,
                     specular_power=15,
                     smooth_shading=True,
                     show_scalar_bar=False,
                     **kwargs)
    plotter.show()
예제 #6
0
# the table, and it has to be the same length as ``geom`` if specified. If it is
# absent a default value of ``range(len(geom))`` is assumed.

# get dataset for the glyphs: supertoroids in xy plane
# use N random kinds of toroids over a mesh with 27 points
N = 5
values = np.arange(N)  # values for scalars to look up glyphs by

# taken from:
# rng = np.random.default_rng()
# params = rng.uniform(0.5, 2, size=(N, 2))  # (n1, n2) parameters for the toroids
params = np.array([[1.56821334, 0.99649769], [1.08247844, 1.83758874],
                   [1.49598881, 0.83495047], [1.52442129, 0.89600688],
                   [1.92212387, 0.78096621]])

geoms = [pv.ParametricSuperToroid(n1=n1, n2=n2) for n1, n2 in params]

# get dataset where to put glyphs
x, y, z = np.mgrid[:3, :3, :3]
mesh = pv.StructuredGrid(x, y, z)

# add random scalars
# rng_int = rng.integers(0, N, size=x.size)
rng_int = np.array([
    4, 1, 2, 0, 4, 0, 1, 4, 3, 1, 1, 3, 3, 4, 3, 4, 4, 3, 3, 2, 2, 1, 1, 1, 2,
    0, 3
])
mesh.point_data['scalars'] = rng_int

# construct the glyphs on top of the mesh; don't scale by scalars now
glyphs = mesh.glyph(geom=geoms,
예제 #7
0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Creating parametric objects
"""

# sphinx_gallery_thumbnail_number = 12
import pyvista as pv
from math import pi

###############################################################################
# This example demonstrates how to plot parametric objects using pyvista
#
# Supertoroid
# +++++++++++

supertoroid = pv.ParametricSuperToroid(n1=0.5)
supertoroid.plot(color='tan', smooth_shading=True)

################################################################################
# Parametric Ellipsoid
# ++++++++++++++++++++

# Ellipsoid with a long x axis
ellipsoid = pv.ParametricEllipsoid(10, 5, 5)
ellipsoid.plot(color='tan')

################################################################################
# Partial Parametric Ellipsoid
# ++++++++++++++++++++++++++++

# cool plotting direction
def test_ParametricSuperToroid():
    geom = pyvista.ParametricSuperToroid()
    assert geom.n_points
예제 #9
0
~~~~~~~~~~~~

Tetrahedralize a super toroid surface.

"""
# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
import tetgen
import numpy as np

###############################################################################
# Create and tetrahedralize a super torid.
#
# We merge the points here to make sure that the surface is manifold.

toroid = pv.ParametricSuperToroid(u_res=50, v_res=50,
                                  w_res=50).clean(tolerance=1E-9)
tet = tetgen.TetGen(toroid)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot()

###############################################################################
# Plot the tesselated mesh.

# get cell centroids
cells = grid.cells.reshape(-1, 5)[:, 1:]
cell_center = grid.points[cells].mean(1)

# extract cells below the 0 xy plane
mask = cell_center[:, 2] < 0
cell_ind = mask.nonzero()[0]
예제 #10
0
"""
Super Toroid
~~~~~~~~~~~~

Tetrahedralize a super toroid surface
"""
# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
import tetgen
import numpy as np

###############################################################################
toroid = pv.ParametricSuperToroid()
tet = tetgen.TetGen(toroid)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot()

###############################################################################

# get cell centroids
cells = grid.cells.reshape(-1, 5)[:, 1:]
cell_center = grid.points[cells].mean(1)

# extract cells below the 0 xy plane
mask = cell_center[:, 2] < 0
cell_ind = mask.nonzero()[0]
subgrid = grid.extract_cells(cell_ind)

# advanced plotting
plotter = pv.Plotter()
예제 #11
0
# ringradius (double, optional) – The radius from the center to the middle of 
#    the ring of the supertoroid. Default is 1.
# crosssectionradius (double, optional) – The radius of the cross section of
#    ring of the supertoroid. Default = 0.5.
# xradius (double, optional) – The scaling factor for the x-axis. Default is 1.
# yradius (double, optional) – The scaling factor for the y-axis. Default is 1.
# zradius (double, optional) – The scaling factor for the z-axis. Default is 1.
# n1 (double, optional) – The shape of the torus ring. Default is 1.
# n2 (double, optional) – The shape of the cross section of the ring. 
#    Default is 1.

import pyvista as pv

# create supertorus #1
supertoroid = pv.ParametricSuperToroid(ringradius=1, crosssectionradius=0.5,
                                       xradius=1, yradius=1, zradius=3,
                                       n1=1, n2=1)

# create supertorus #2 and translate it to another position
# Note: to keep the heights OK, crosssectionradius*zradius should be the same
supertoroid2 = pv.ParametricSuperToroid(ringradius=1, crosssectionradius=0.1,
                                       xradius=1, yradius=1, zradius=15,
                                       n1=1, n2=1)
supertoroid2.translate([0, 0, 3])

# create plotting objects
plotter = pv.Plotter()
plotter.add_mesh(supertoroid, 'r')
plotter.add_mesh(supertoroid2, 'b')

# show plotted objects
예제 #12
0
import numpy as np
import pyvista as pv

# get dataset for the glyphs: supertoroid in xy plane
saucer = pv.ParametricSuperToroid(ringradius=1, n2=1, zradius=1)
saucer.rotate_y(90)
# saucer.plot()  #  <-- check how a single saucer looks like

# get dataset where to put glyphs
x,y,z = np.mgrid[-10:10, -10:10, :1]
mesh = pv.StructuredGrid(x, y, z)

# construct the glyphs on top of the mesh
glyphs = mesh.glyph(geom=saucer, factor=0.3)
# glyphs.plot()  #  <-- simplest way to plot it

# create Plotter and add our glyphs with some nontrivial lighting
plotter = pv.Plotter(window_size=(1000, 800))
plotter.add_mesh(glyphs, color=[0.5, 0.2, 0.2], specular=1, specular_power=15)

plotter.show()