提取点集
"""
Extract Points
~~~~~~~~~~~~~~
This example will demonstrate how to extract the points and PointData of
any input data set that has valid PointData into a `vtkPolyData` object.
This example demos :class:`PVGeo.filters.ExtractPoints`
"""
# sphinx_gallery_thumbnail_number = 2
import os
import pyvista
from PVGeo.filters import ExtractPoints
###############################################################################
# Have some input data source with valid PointData
"""Load a globe source."""
dir_path=r"C:\pyvista-master\pyvista-master\pyvista\examples"
globefile = os.path.join(dir_path, 'globe.vtk')
mapfile=os.path.join(dir_path, '2k_earth_daymap.jpg')
globe = pyvista.PolyData(globefile)
globe.textures['2k_earth_daymap'] = pyvista.read_texture(mapfile)
globe.plot()
###############################################################################
# Apply the filter:
polyData = ExtractPoints().apply(globe)
polyData.plot()
ExtractPoints:
1个输入vtkDataSet
1个输出vtkPolyData
class ExtractPoints(FilterBase):
"""Extracts XYZ coordinates and point/cell data from an input ``vtkDataSet``
"""
__displayname__ = 'Extract Points'
__category__ = 'filter'
def __init__(self):
FilterBase.__init__(self,
nInputPorts=1, inputType='vtkDataSet',
nOutputPorts=1, outputType='vtkPolyData')
def RequestData(self, request, inInfo, outInfo):
"""Used by pipeline to generate output"""
# Get input/output of Proxy
pdi = self.GetInputData(inInfo, 0, 0)
pdo = self.GetOutputData(outInfo, 0)
#### Perfrom task ####
# Get the Points over the NumPy interface
wpdi = dsa.WrapDataObject(pdi) # NumPy wrapped input
if not hasattr(wpdi, 'Points'):
raise _helpers.PVGeoError('Input data object does not have XYZ points.')
points = np.array(wpdi.Points) # New NumPy array of poins so we dont destroy input
# Now transfer data
f = vtk.vtkCellDataToPointData()
f.SetInputData(pdi)
f.Update()
d = f.GetOutput()
pdo.ShallowCopy(interface.points_to_poly_data(points))
_helpers.copy_arrays_to_point_data(d, pdo, 0) # 0 is point data
return 1