本文整理汇总了Python中pyvista.PolyData方法的典型用法代码示例。如果您正苦于以下问题:Python pyvista.PolyData方法的具体用法?Python pyvista.PolyData怎么用?Python pyvista.PolyData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvista
的用法示例。
在下文中一共展示了pyvista.PolyData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_point_set
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def make_point_set():
"""Ignore the contents of this function. Just know that it returns an
n by 3 numpy array of structured coordinates."""
n, m = 29, 32
x = np.linspace(-200, 200, num=n) + np.random.uniform(-5, 5, size=n)
y = np.linspace(-200, 200, num=m) + np.random.uniform(-5, 5, size=m)
xx, yy = np.meshgrid(x, y)
A, b = 100, 100
zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))
points = np.c_[xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)]
foo = pv.PolyData(points)
foo.rotate_z(36.6)
return foo.points
# Get the points as a 2D NumPy array (N by 3)
示例2: test_init_from_arrays_with_vert
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_init_from_arrays_with_vert():
vertices = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, -1],
[0, 1.5, 1.5]])
# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3], # quad
[3, 0, 1, 4], # triangle
[3, 1, 2, 4], # triangle
[1, 5]]).astype(np.int8) # vertex
mesh = pyvista.PolyData(vertices, faces)
assert mesh.n_points == 6
assert mesh.n_cells == 4
示例3: test_init_from_arrays_triangular
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_init_from_arrays_triangular():
vertices = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, -1]])
# mesh faces
faces = np.vstack([[3, 0, 1, 2],
[3, 0, 1, 4],
[3, 1, 2, 4]])
mesh = pyvista.PolyData(vertices, faces)
assert mesh.n_points == 5
assert mesh.n_cells == 3
mesh = pyvista.PolyData(vertices, faces, deep=True)
assert mesh.n_points == 5
assert mesh.n_cells == 3
示例4: test_delaunay_2d
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_delaunay_2d():
n = 20
x = np.linspace(-200, 200, num=n) + np.random.uniform(-5, 5, size=n)
y = np.linspace(-200, 200, num=n) + np.random.uniform(-5, 5, size=n)
xx, yy = np.meshgrid(x, y)
A, b = 100, 100
zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))
# Get the points as a 2D NumPy array (N by 3)
points = np.c_[xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)]
pdata = pyvista.PolyData(points)
surf = pdata.delaunay_2d()
# Make sure we have an all triangle mesh now
assert np.all(surf.faces.reshape((-1, 4))[:, 0] == 3)
# test inplace
pdata.delaunay_2d(inplace=True)
assert np.allclose(pdata.points, surf.points)
示例5: test_is_all_triangles
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_is_all_triangles():
# mesh points
vertices = np.array([[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0.5, 0.5, -1]])
# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3], # square
[3, 0, 1, 4], # triangle
[3, 1, 2, 4]]) # triangle
mesh = pyvista.PolyData(vertices, faces)
assert not mesh.is_all_triangles()
mesh = mesh.triangulate()
assert mesh.is_all_triangles()
示例6: test_sample_over_line
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_sample_over_line():
"""Test that we get a sampled line."""
name = 'values'
line = pyvista.Line([0, 0, 0], [0, 0, 10], 9)
line[name] = np.linspace(0, 10, 10)
sampled_line = line.sample_over_line([0, 0, 0.5], [0, 0, 1.5], 2)
expected_result = np.array([0.5, 1, 1.5])
assert np.allclose(sampled_line[name], expected_result)
assert name in line.array_names # is name in sampled result
# test no resolution
sphere = pyvista.Sphere(center=(4.5,4.5,4.5), radius=4.5)
sampled_from_sphere = sphere.sample_over_line([3, 1, 1], [-3, -1, -1])
assert sampled_from_sphere.n_points == sphere.n_cells + 1
# is sampled result a polydata object
assert isinstance(sampled_from_sphere, pyvista.PolyData)
示例7: test_arrows
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_arrows(grid):
sphere = pyvista.Sphere(radius=3.14)
# 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 scales
sphere.vectors = vectors*0.3
assert np.allclose(sphere.active_vectors, vectors*0.3)
assert np.allclose(sphere.vectors, vectors*0.3)
assert sphere.active_vectors_info[1] == '_vectors'
arrows = sphere.arrows
assert isinstance(arrows, pyvista.PolyData)
assert np.any(arrows.points)
sphere.set_active_vectors('_vectors')
assert sphere.active_vectors_name == '_vectors'
示例8: test_handle_array_with_null_name
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_handle_array_with_null_name():
poly = pyvista.PolyData()
# Add point array with no name
poly.GetPointData().AddArray(pyvista.convert_array(np.array([])))
html = poly._repr_html_()
assert html is not None
pdata = poly.point_arrays
assert pdata is not None
assert len(pdata) == 1
# Add cell array with no name
poly.GetCellData().AddArray(pyvista.convert_array(np.array([])))
html = poly._repr_html_()
assert html is not None
cdata = poly.cell_arrays
assert cdata is not None
assert len(cdata) == 1
# Add field array with no name
poly.GetFieldData().AddArray(pyvista.convert_array(np.array([5, 6])))
html = poly._repr_html_()
assert html is not None
fdata = poly.field_arrays
assert fdata is not None
assert len(fdata) == 1
示例9: test_shallow_copy_back_propagation
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_shallow_copy_back_propagation():
"""Test that the original data object's points get modified after a
shallow copy.
Reference: https://github.com/pyvista/pyvista/issues/375#issuecomment-531691483
"""
# Case 1
points = vtk.vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 0.0, 0.0)
points.InsertNextPoint(2.0, 0.0, 0.0)
original = vtk.vtkPolyData()
original.SetPoints(points)
wrapped = pyvista.PolyData(original, deep=False)
wrapped.points[:] = 2.8
orig_points = vtk_to_numpy(original.GetPoints().GetData())
assert np.allclose(orig_points, wrapped.points)
# Case 2
original = vtk.vtkPolyData()
wrapped = pyvista.PolyData(original, deep=False)
wrapped.points = np.random.rand(5, 3)
orig_points = vtk_to_numpy(original.GetPoints().GetData())
assert np.allclose(orig_points, wrapped.points)
示例10: test_multi_block_list_index
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def test_multi_block_list_index(ant, sphere, uniform, airplane, globe):
multi = multi_from_datasets(ant, sphere, uniform, airplane, globe)
# Now check everything
indices = [0, 3, 4]
sub = multi[indices]
assert len(sub) == len(indices)
for i, j in enumerate(indices):
assert id(sub[i]) == id(multi[j])
assert sub.get_block_name(i) == multi.get_block_name(j)
# check list of key names
multi = MultiBlock()
multi["foo"] = pyvista.Sphere()
multi["goo"] = pyvista.Box()
multi["soo"] = pyvista.Cone()
indices = ["goo", "foo"]
sub = multi[indices]
assert len(sub) == len(indices)
assert isinstance(sub["foo"], PolyData)
示例11: update_coordinates
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def update_coordinates(self, points, mesh=None, render=True):
"""Update the points of an object in the plotter.
Parameters
----------
points : np.ndarray
Points to replace existing points.
mesh : vtk.PolyData or vtk.UnstructuredGrid, optional
Object that has already been added to the Plotter. If
None, uses last added mesh.
render : bool, optional
Forces an update to the render window. Default True.
"""
if mesh is None:
mesh = self.mesh
mesh.points = points
if render:
self.render()
示例12: ParametricBour
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def ParametricBour(**kwargs):
"""Generate Bour's minimal surface.
Return
------
surf : pyvista.PolyData
ParametricBour surface
Examples
--------
Create a ParametricBour mesh
>>> import pyvista
>>> mesh = pyvista.ParametricBour()
>>> mesh.plot(color='w', smooth_shading=True) # doctest:+SKIP
"""
parametric_function = vtk.vtkParametricBour()
center = kwargs.pop('center', [0., 0., 0.])
direction = kwargs.pop('direction', [0., 0., 1.])
surf = surface_from_para(parametric_function, **kwargs)
translate(surf, center, direction)
return surf
示例13: ParametricHenneberg
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def ParametricHenneberg(**kwargs):
"""Generate Henneberg's minimal surface.
Return
------
surf : pyvista.PolyData
ParametricHenneberg surface
Examples
--------
Create a ParametricHenneberg mesh
>>> import pyvista
>>> mesh = pyvista.ParametricHenneberg()
>>> mesh.plot(color='w', smooth_shading=True) # doctest:+SKIP
"""
parametric_function = vtk.vtkParametricHenneberg()
center = kwargs.pop('center', [0., 0., 0.])
direction = kwargs.pop('direction', [0., 0., 1.])
surf = surface_from_para(parametric_function, **kwargs)
translate(surf, center, direction)
return surf
示例14: to_vtk_unstructured
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def to_vtk_unstructured(pos, fields): # pragma: no cover
"""Export a field to vtk structured rectilinear grid file.
Parameters
----------
pos : :class:`list`
the position tuple, containing main direction and transversal
directions
fields : :class:`dict` or :class:`numpy.ndarray`
Unstructured fields to be saved.
Either a single numpy array as returned by SRF,
or a dictionary of fields with theirs names as keys.
Returns
-------
:class:`pyvista.UnstructuredGrid`
A PyVista unstructured grid of the unstructured field data. Data arrays
live on the point data of this PyVista dataset. This is essentially
a point cloud with no topology.
"""
x, y, z, fields = _vtk_unstructured_helper(pos=pos, fields=fields)
try:
import pyvista as pv
grid = pv.PolyData(np.c_[x, y, z]).cast_to_unstructured_grid()
grid.point_arrays.update(fields)
except ImportError:
raise ImportError("Please install PyVista to create VTK datasets.")
return grid
示例15: lines_from_points
# 需要导入模块: import pyvista [as 别名]
# 或者: from pyvista import PolyData [as 别名]
def lines_from_points(points):
"""Given an array of points, make a line set"""
poly = pv.PolyData()
poly.points = points
cells = np.full((len(points)-1, 3), 2, dtype=np.int_)
cells[:, 1] = np.arange(0, len(points)-1, dtype=np.int_)
cells[:, 2] = np.arange(1, len(points), dtype=np.int_)
poly.lines = cells
return poly