Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_init():
with pytest.raises(ValueError):
mesh = pyvista.PolyData(np.array([1]))
with pytest.raises(TypeError):
mesh = pyvista.PolyData(np.array([1]), 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa', 'woa')
def test_invalid_init():
with pytest.raises(ValueError):
mesh = pyvista.PolyData(np.array([1]))
with pytest.raises(TypeError):
mesh = pyvista.PolyData(np.array([1]), 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa')
with pytest.raises(TypeError):
mesh = pyvista.PolyData('woa', 'woa', 'woa')
def test_hanlde_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])))
multi.append(ex.load_ant())
multi.append(ex.load_sphere())
multi.append(ex.load_uniform())
multi.append(ex.load_airplane())
multi.append(ex.load_rectilinear())
# Now check everything
assert multi.n_blocks == 5
assert multi.bounds is not None
assert isinstance(multi[0], pyvista.PolyData)
assert isinstance(multi[1], pyvista.PolyData)
assert isinstance(multi[2], pyvista.UniformGrid)
assert isinstance(multi[3], pyvista.PolyData)
assert isinstance(multi[4], pyvista.RectilinearGrid)
# Now overwrite a block
multi[4] = pyvista.Sphere()
assert isinstance(multi[4], pyvista.PolyData)
multi[4] = vtk.vtkUnstructuredGrid()
assert isinstance(multi[4], pyvista.UnstructuredGrid)
def _the_callback(widget, event_id):
polyline = pyvista.PolyData()
widget.GetPolyData(polyline)
ribbon.shallow_copy(polyline.ribbon(normal=(0,0,1), angle=90.0))
if hasattr(callback, '__call__'):
if pass_widget:
try_callback(callback, polyline, widget)
else:
try_callback(callback, polyline)
return
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
"""
if font_family is None:
font_family = rcParams['font']['family']
if font_size is None:
font_size = rcParams['font']['size']
if point_color is None and text_color is None and kwargs.get('color', None) is not None:
point_color = kwargs.get('color', None)
text_color = kwargs.get('color', None)
if point_color is None:
point_color = rcParams['color']
if text_color is None:
text_color = rcParams['font']['color']
if isinstance(points, np.ndarray):
vtkpoints = pyvista.PolyData(points) # Cast to poly data
elif is_pyvista_obj(points):
vtkpoints = pyvista.PolyData(points.points)
if isinstance(labels, str):
labels = points.point_arrays[labels].astype(str)
else:
raise TypeError('Points type not useable: {}'.format(type(points)))
if len(vtkpoints.points) != len(labels):
raise Exception('There must be one label for each point')
vtklabels = vtk.vtkStringArray()
vtklabels.SetName('labels')
for item in labels:
vtklabels.InsertNextValue(str(item))
vtkpoints.GetPointData().AddArray(vtklabels)
def load_sphere():
""" Loads sphere ply mesh """
return pyvista.PolyData(spherefile)
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
dist = 0.
for i in range(len(cur_ind)-1):
dist += _compute_dist(points[cur_ind[i]], points[cur_ind[i+1]])
if dist < min_dist:
ind = cur_ind
min_dist = dist
return ind.ravel()
if self.__usenbr:
ind = _find_min_path(points)
else:
ind = np.arange(len(points), dtype=int)
if self.__keep_vertices:
poly = pyvista.PolyData(np.copy(points))
else:
poly = pyvista.PolyData()
poly.points = np.copy(points)
if cell_type == vtk.VTK_LINE:
lines = np.c_[np.full(len(ind)-1, 2), ind[0:-1], ind[1:]]
if self.__close_loop:
app = np.append(lines, [[2, ind[-1], ind[0]],], axis=0)
lines = app
poly.lines = lines
elif cell_type == vtk.VTK_POLY_LINE:
cells = vtk.vtkCellArray()
cell = vtk.vtkPolyLine()
if self.__close_loop:
cell.GetPointIds().SetNumberOfIds(len(ind) + 1)
else:
cell.GetPointIds().SetNumberOfIds(len(ind))
for i in ind:
cell.GetPointIds().SetId(i, ind[i])