本文整理汇总了Python中vtk.vtkThreshold函数的典型用法代码示例。如果您正苦于以下问题:Python vtkThreshold函数的具体用法?Python vtkThreshold怎么用?Python vtkThreshold使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkThreshold函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stripGrid
def stripGrid(vtk_grid):
# Strip out masked points.
if vtk_grid.IsA("vtkStructuredGrid"):
if vtk_grid.GetCellBlanking():
visArray = vtk_grid.GetCellVisibilityArray()
visArray.SetName("BlankingArray")
vtk_grid.GetCellData().AddArray(visArray)
thresh = vtk.vtkThreshold()
thresh.SetInputData(vtk_grid)
thresh.ThresholdByUpper(0.5)
thresh.SetInputArrayToProcess(0, 0, 0,
"vtkDataObject::FIELD_ASSOCIATION_CELLS",
"BlankingArray")
thresh.Update()
vtk_grid = thresh.GetOutput()
elif vtk_grid.GetPointBlanking():
visArray = vtk_grid.GetPointVisibilityArray()
visArray.SetName("BlankingArray")
vtk_grid.GetPointData().AddArray(visArray)
thresh = vtk.vtkThreshold()
thresh.SetInputData(vtk_grid)
thresh.SetUpperThreshold(0.5)
thresh.SetInputArrayToProcess(0, 0, 0,
"vtkDataObject::FIELD_ASSOCIATION_POINTS",
"BlankingArray")
thresh.Update()
vtk_grid = thresh.GetOutput()
return vtk_grid
示例2: testUnstructured
def testUnstructured(self):
rt = vtk.vtkRTAnalyticSource()
rt.SetWholeExtent(-5, 5, -5, 5, -5, 5)
t = vtk.vtkThreshold()
t.SetInputConnection(rt.GetOutputPort())
t.ThresholdByUpper(-10)
s = vtk.vtkSphere()
s.SetRadius(2)
s.SetCenter(0,0,0)
c = vtk.vtkTableBasedClipDataSet()
c.SetInputConnection(t.GetOutputPort())
c.SetClipFunction(s)
c.SetInsideOut(1)
c.Update()
self.assertEqual(c.GetOutput().GetNumberOfCells(), 64)
eg = vtk.vtkEnSightGoldReader()
eg.SetCaseFileName(VTK_DATA_ROOT + "/Data/EnSight/elements.case")
eg.Update()
pl = vtk.vtkPlane()
pl.SetOrigin(3.5, 3.5, 0.5)
pl.SetNormal(0, 0, 1)
c.SetInputConnection(eg.GetOutputPort())
c.SetClipFunction(pl)
c.SetInsideOut(1)
c.Update()
data = c.GetOutputDataObject(0).GetBlock(0)
self.assertEqual(data.GetNumberOfCells(), 75)
rw = vtk.vtkRenderWindow()
ren = vtk.vtkRenderer()
rw.AddRenderer(ren)
mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(data)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren.AddActor(actor)
ac = ren.GetActiveCamera()
ac.SetPosition(-7.9, 9.7, 14.6)
ac.SetFocalPoint(3.5, 3.5, 0.5)
ac.SetViewUp(0.08, 0.93, -0.34)
rw.Render()
ren.ResetCameraClippingRange()
rtTester = vtk.vtkTesting()
for arg in sys.argv[1:]:
rtTester.AddArgument(arg)
rtTester.AddArgument("-V")
rtTester.AddArgument("tableBasedClip.png")
rtTester.SetRenderWindow(rw)
rw.Render()
rtResult = rtTester.RegressionTest(10)
示例3: threshold
def threshold(polydata, arrayname, valuerange=[0, 1], iscelldata=True,
allscalars=True):
"""Extract those cells from polydata whose pointdata/celldata values are
within a specified range.
For pointdata, cells are included if scalar values of all cell points are
within the range (allscalars=True) or if the scalar value of at least one of
the cell points is within the range (allscalar=False).
"""
thresholdfilter = vtk.vtkThreshold()
thresholdfilter.SetInput(polydata)
thresholdfilter.ThresholdBetween(valuerange[0], valuerange[1])
if iscelldata:
thresholdfilter.SetInputArrayToProcess(0, 0, 0,
vtk.vtkDataObject.
FIELD_ASSOCIATION_CELLS, arrayname)
else:
thresholdfilter.SetInputArrayToProcess(0, 0, 0,
vtk.vtkDataObject.
FIELD_ASSOCIATION_POINTS, arrayname)
if allscalars:
thresholdfilter.AllScalarsOn()
else:
thresholdfilter.AllScalarsOff()
thresholdfilter.Update()
surfacefilter = vtk.vtkDataSetSurfaceFilter()
surfacefilter.SetInput(thresholdfilter.GetOutput())
surfacefilter.Update()
return surfacefilter.GetOutput()
示例4: save_lesion
def save_lesion(output_file, input_file, field, limits):
reader = v.vtkXMLUnstructuredGridReader()
reader.SetFileName(input_file)
reader.Update()
threshold = v.vtkThreshold()
threshold.SetInput(reader.GetOutput())
if limits[0] is None:
threshold.ThresholdByLower(limits[1])
elif limits[1] is None:
threshold.ThresholdByUpper(limits[0])
else:
threshold.ThresholdBetween(*limits)
threshold.SetInputArrayToProcess(0, 0, 0, v.vtkDataObject.FIELD_ASSOCIATION_CELLS, field)
threshold.Update()
extract_surface = v.vtkDataSetSurfaceFilter()
extract_surface.SetInput(threshold.GetOutput())
extract_surface.Update()
writer = v.vtkXMLPolyDataWriter()
writer.SetFileName(output_file)
writer.SetInput(extract_surface.GetOutput())
writer.Write()
示例5: getThresholdedUGrid
def getThresholdedUGrid(
ugrid,
field_support,
field_name,
threshold_value,
threshold_by_upper_or_lower,
verbose=0):
mypy.my_print(verbose, "*** getThresholdedUGrid ***")
threshold = vtk.vtkThreshold()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
threshold.SetInputData(ugrid)
else:
threshold.SetInput(ugrid)
if (field_support == "points"):
association = vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS
elif (field_support == "cells"):
association = vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS
threshold.SetInputArrayToProcess(0, 0, 0, association, field_name)
if (threshold_by_upper_or_lower == "upper"):
threshold.ThresholdByUpper(threshold_value)
elif (threshold_by_upper_or_lower == "lower"):
threshold.ThresholdByLower(threshold_value)
threshold.Update()
thresholded_ugrid = threshold.GetOutput()
return thresholded_ugrid
示例6: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkThreshold(), 'Processing.',
('vtkDataSet',), ('vtkUnstructuredGrid',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例7: initialize
def initialize (self):
debug ("In Threshold::initialize ()")
self.fil = vtk.vtkThreshold ()
self.fil.SetInput (self.prev_fil.GetOutput ())
self.data_name = self.mod_m.get_scalar_data_name ()
dr = self.mod_m.get_scalar_data_range ()
self.fil.ThresholdBetween (dr[0], dr[1])
self.fil.Update ()
示例8: CreateSurfaceCells
def CreateSurfaceCells(self,inMesh):
#Remove the surface cells from the mesh
cellDimFilter = vtkvmtkcontrib.vtkvmtkCellDimensionFilter()
cellDimFilter.SetInput(inMesh)
cellDimFilter.ThresholdByUpper(3)
cellDimFilter.Update()
volumetricMesh = cellDimFilter.GetOutput()
#Get new surface cells
geomFilter = vtk.vtkGeometryFilter()
geomFilter.SetInput(cellDimFilter.GetOutput())
geomFilter.Update()
newSurfaceCells = geomFilter.GetOutput()
#If the celEntityIdArray exist, project the original entity ids
cellEntityIdsArray = newSurfaceCells.GetCellData().GetArray(self.CellEntityIdsArrayName)
if (cellEntityIdsArray != None):
#Convert the surface cells to poly data
surfaceCellsToSurface = vmtkscripts.vmtkMeshToSurface()
surfaceCellsToSurface.Mesh = newSurfaceCells
surfaceCellsToSurface.Execute()
#Get the original surface cells
meshThreshold = vtk.vtkThreshold()
meshThreshold.SetInput(self.Mesh)
meshThreshold.ThresholdByUpper(self.WallCellEntityId+0.5)
meshThreshold.SetInputArrayToProcess(0,0,0,1,self.CellEntityIdsArrayName)
meshThreshold.Update()
meshToSurface = vmtkscripts.vmtkMeshToSurface()
meshToSurface.Mesh = meshThreshold.GetOutput()
meshToSurface.Execute()
#Project the entity ids form the old surface cells to the new surface cells
#TODO: This is hackish(need for a tolerance), find a beeter way
projector = vtkvmtkcontrib.vtkvmtkSurfaceProjectCellArray()
projector.SetInput(surfaceCellsToSurface.Surface)
projector.SetReferenceSurface(meshToSurface.Surface)
projector.SetProjectedArrayName(self.CellEntityIdsArrayName)
projector.SetDefaultValue(self.WallCellEntityId)
projector.SetDistanceTolerance(self.Tolerance)
projector.Update()
#Convert the surface cells back to unstructured grid
surfaceToMesh = vmtkscripts.vmtkSurfaceToMesh()
surfaceToMesh.Surface = projector.GetOutput()
surfaceToMesh.Execute()
newSurfaceCells = surfaceToMesh.Mesh
#append the new surface cells to the volumetric elements
appendFilter = vtkvmtk.vtkvmtkAppendFilter()
appendFilter.AddInput(volumetricMesh)
appendFilter.AddInput(newSurfaceCells)
appendFilter.Update()
return appendFilter.GetOutput()
示例9: _plotInternalCustomBoxfill
def _plotInternalCustomBoxfill(self):
"""Implements the logic to render a custom boxfill."""
self._mappers = []
self._customBoxfillArgs = self._prepContours()
tmpLevels = self._customBoxfillArgs["tmpLevels"]
tmpColors = self._customBoxfillArgs["tmpColors"]
tmpOpacities = self._customBoxfillArgs["tmpOpacities"]
style = self._gm.fillareastyle
luts = []
geos = []
wholeDataMin, wholeDataMax = vcs.minmax(self._originalData1)
_colorMap = self.getColorMap()
assert(style != 'solid' or len(tmpLevels) == 1)
for i, l in enumerate(tmpLevels):
# Ok here we are trying to group together levels can be, a join
# will happen if: next set of levels continues where one left off
# AND pattern is identical
# TODO this should really just be a single polydata/mapper/actor:
for j, color in enumerate(tmpColors[i]):
mapper = vtk.vtkPolyDataMapper()
lut = vtk.vtkLookupTable()
th = vtk.vtkThreshold()
th.ThresholdBetween(l[j], l[j + 1])
th.SetInputConnection(self._vtkPolyDataFilter.GetOutputPort())
geoFilter2 = vtk.vtkDataSetSurfaceFilter()
geoFilter2.SetInputConnection(th.GetOutputPort())
# Make the polydata output available here for patterning later
geoFilter2.Update()
geos.append(geoFilter2)
mapper.SetInputConnection(geoFilter2.GetOutputPort())
lut.SetNumberOfTableValues(1)
r, g, b, a = self.getColorIndexOrRGBA(_colorMap, color)
if style == 'solid':
tmpOpacity = tmpOpacities[j]
if tmpOpacity is None:
tmpOpacity = a / 100.
else:
tmpOpacity = tmpOpacities[j] / 100.
lut.SetTableValue(0, r / 100., g / 100., b / 100., tmpOpacity)
else:
lut.SetTableValue(0, 1., 1., 1., 0.)
mapper.SetLookupTable(lut)
mapper.SetScalarRange(l[j], l[j + 1])
luts.append([lut, [l[j], l[j + 1], False]])
# Store the mapper only if it's worth it?
# Need to do it with the whole slab min/max for animation
# purposes
if not (l[j + 1] < wholeDataMin or l[j] > wholeDataMax):
self._mappers.append(mapper)
self._resultDict["vtk_backend_luts"] = luts
if len(geos) > 0:
self._resultDict["vtk_backend_geofilters"] = geos
示例10: ThresholdMesh
def ThresholdMesh(self):
thresholder = vtk.vtkThreshold()
thresholder.SetInputData(self.InitialMesh)
if (self.ThresholdUpper):
thresholder.ThresholdByUpper(self.Threshold)
else:
thresholder.ThresholdByLower(self.Threshold)
thresholder.SetInputArrayToProcess(0,0,0,1,self.ArrayName)
thresholder.Update()
self.Mesh = thresholder.GetOutput()
示例11: cellthreshold
def cellthreshold(polydata, arrayname, start=0, end=1):
threshold = vtk.vtkThreshold()
threshold.SetInputData(polydata)
threshold.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,arrayname)
threshold.ThresholdBetween(start,end)
threshold.Update()
surfer = vtk.vtkDataSetSurfaceFilter()
surfer.SetInputConnection(threshold.GetOutputPort())
surfer.Update()
return surfer.GetOutput()
示例12: makeUnstructVTKVOIThres
def makeUnstructVTKVOIThres(vtkObj,extent,limits):
"""Make volume of interest and threshold for rectilinear grid."""
# Check for the input
cellCore = vtk.vtkExtractUnstructuredGrid()
cellCore.SetExtent(extent)
cellCore.SetInput(vtkObj)
cellThres = vtk.vtkThreshold()
cellThres.AllScalarsOn()
cellThres.SetInputConnection(cellCore.GetOutputPort())
cellThres.ThresholdBetween(limits[0],limits[1])
cellThres.Update()
return cellThres.GetOutput(), cellCore.GetOutput()
示例13: pointthreshold
def pointthreshold(polydata, arrayname, start=0, end=1,alloff=0):
threshold = vtk.vtkThreshold()
threshold.SetInputData(polydata)
threshold.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS,arrayname)
threshold.ThresholdBetween(start,end)
if (alloff):
threshold.AllScalarsOff()
threshold.Update()
surfer = vtk.vtkDataSetSurfaceFilter()
surfer.SetInputConnection(threshold.GetOutputPort())
surfer.Update()
return surfer.GetOutput()
示例14: thresFilt
def thresFilt(vtkObj,arrName,value,thType='Upper'):
thresFilt = vtk.vtkThreshold()
thresFilt.SetInputData(vtkObj)
if thType in 'Upper':
thresFilt.ThresholdByUpper(value)
elif thType in 'Lower':
thresFilt.ThresholdByLower(value)
elif thType in 'Between':
thresFilt.ThresholdBetween(value[0],value[1])
thresFilt.AllScalarsOn()
thresFilt.SetInputArrayToProcess(0,0,0,vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS,arrName)
thresFilt.Update()
return thresFilt.GetOutput()
示例15: _plotInternalBoxfill
def _plotInternalBoxfill(self):
"""Implements the logic to render a non-custom boxfill."""
# Prep mapper
mapper = vtk.vtkPolyDataMapper()
self._mappers = [mapper]
if self._gm.ext_1 and self._gm.ext_2:
mapper.SetInputConnection(self._vtkPolyDataFilter.GetOutputPort())
self._resultDict["vtk_backend_geofilters"] = \
[self._vtkPolyDataFilter]
else:
thr = vtk.vtkThreshold()
thr.SetInputConnection(self._vtkPolyDataFilter.GetOutputPort())
if not self._gm.ext_1 and not self._gm.ext_2:
thr.ThresholdBetween(self._contourLevels[0],
self._contourLevels[-1])
elif self._gm.ext_1 and not self._gm.ext_2:
thr.ThresholdByLower(self._contourLevels[-1])
elif not self._gm.ext_1 and self._gm.ext_2:
thr.ThresholdByUpper(self._contourLevels[0])
geoFilter2 = vtk.vtkDataSetSurfaceFilter()
geoFilter2.SetInputConnection(thr.GetOutputPort())
mapper.SetInputConnection(geoFilter2.GetOutputPort())
self._resultDict["vtk_backend_geofilters"] = [geoFilter2]
# Colortable bit
# make sure length match
numLevels = len(self._contourLevels)
while len(self._contourColors) < numLevels:
self._contourColors.append(self._contourColors[-1])
lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(numLevels)
_colorMap = self.getColorMap()
for i in range(numLevels):
r, g, b, a = self.getColorIndexOrRGBA(_colorMap, self._contourColors[i])
lut.SetTableValue(i, r / 100., g / 100., b / 100., a / 100.)
mapper.SetLookupTable(lut)
if numpy.allclose(self._contourLevels[0], -1.e20):
lmn = self._min - 1.
else:
lmn = self._contourLevels[0]
if numpy.allclose(self._contourLevels[-1], 1.e20):
lmx = self._mx + 1.
else:
lmx = self._contourLevels[-1]
mapper.SetScalarRange(lmn, lmx)
self._resultDict["vtk_backend_luts"] = [[lut, [lmn, lmx, True]]]