本文整理汇总了Python中vtk.vtkContourFilter函数的典型用法代码示例。如果您正苦于以下问题:Python vtkContourFilter函数的具体用法?Python vtkContourFilter怎么用?Python vtkContourFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkContourFilter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visQuadFunc
def visQuadFunc():
""" vtk sample scene with iso contours """
# VTK supports implicit functions of the form f(x,y,z)=constant. These
# functions can represent things spheres, cones, etc. Here we use a
# general form for a quadric to create an elliptical data field.
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
# vtkSampleFunction samples an implicit function over the x-y-z range
# specified (here it defaults to -1,1 in the x,y,z directions).
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(30, 30, 30)
sample.SetImplicitFunction(quadric)
# Create five surfaces F(x,y,z) = constant between range specified. The
# GenerateValues() method creates n isocontour values between the range
# specified.
contours = vtk.vtkContourFilter()
contours.SetInputConnection(sample.GetOutputPort())
contours.GenerateValues(8, 0.0, 1.2)
contMapper = vtk.vtkPolyDataMapper()
contMapper.SetInputConnection(contours.GetOutputPort())
contMapper.SetScalarRange(0.0, 1.2)
contActor = vtk.vtkActor()
contActor.SetMapper(contMapper)
# We'll put a simple outline around the data.
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(sample.GetOutputPort())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.GetProperty().SetColor(1, 0.5, 0)
# extract data from the volume
extract = vtk.vtkExtractVOI()
extract.SetInputConnection(sample.GetOutputPort())
extract.SetVOI(0, 29, 0, 29, 15, 15)
extract.SetSampleRate(1, 2, 3)
contours2 = vtk.vtkContourFilter()
contours2.SetInputConnection(extract.GetOutputPort())
contours2.GenerateValues(8, 0.0, 1.2)
contMapper2 = vtk.vtkPolyDataMapper()
contMapper2.SetInputConnection(contours2.GetOutputPort())
contMapper2.SetScalarRange(0.0, 1.2)
contActor2 = vtk.vtkActor()
contActor2.SetMapper(contMapper2)
return contActor, contActor2, outlineActor, contours, contours2
示例2: get_isosurface
def get_isosurface(self, iso_value=500):
if not self.flag_read:
sys.stderr.write('No Image Loaded!\n')
return
contour = vtk.vtkContourFilter()
normals = vtk.vtkPolyDataNormals()
stripper = vtk.vtkStripper()
mapper = vtk.vtkPolyDataMapper()
contour.SetInputData(self.reader)
contour.SetValue(0, iso_value)
normals.SetInputConnection(contour.GetOutputPort())
normals.SetFeatureAngle(60.0)
normals.ReleaseDataFlagOn()
stripper.SetInputConnection(normals.GetOutputPort())
stripper.ReleaseDataFlagOn()
mapper.SetInputConnection(stripper.GetOutputPort())
mapper.SetScalarVisibility(False)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Default colour, should be changed.
actor.GetProperty().SetDiffuseColor(
[247.0 / 255.0, 150.0 / 255.0, 155.0 / 255.0]) # Look like red
actor.GetProperty().SetSpecular(0.3)
actor.GetProperty().SetSpecularPower(20)
return actor
示例3: __init__
def __init__(self, module_manager, contourFilterText):
# call parent constructor
ModuleBase.__init__(self, module_manager)
self._contourFilterText = contourFilterText
if contourFilterText == 'marchingCubes':
self._contourFilter = vtk.vtkMarchingCubes()
else: # contourFilter == 'contourFilter'
self._contourFilter = vtk.vtkContourFilter()
module_utils.setup_vtk_object_progress(self, self._contourFilter,
'Extracting iso-surface')
# now setup some defaults before our sync
self._config.isoValue = 128;
self._viewFrame = None
self._createViewFrame()
# transfer these defaults to the logic
self.config_to_logic()
# then make sure they come all the way back up via self._config
self.logic_to_config()
self.config_to_view()
示例4: __init__
def __init__ (self, mod_m):
debug ("In CustomGridPlane::__init__ ()")
Common.state.busy ()
Base.Objects.Module.__init__ (self, mod_m)
self.act = None
out = self.mod_m.GetOutput ()
if out.IsA('vtkStructuredGrid'):
self.plane = vtk.vtkStructuredGridGeometryFilter ()
elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'):
if hasattr (vtk, 'vtkImageDataGeometryFilter'):
self.plane = vtk.vtkImageDataGeometryFilter ()
else:
self.plane = vtk.vtkStructuredPointsGeometryFilter ()
elif out.IsA ('vtkRectilinearGrid'):
self.plane = vtk.vtkRectilinearGridGeometryFilter ()
else:
msg = "This module does not support the %s dataset."%(out.GetClassName())
raise Base.Objects.ModuleException, msg
self.cont_fil = vtk.vtkContourFilter ()
self.mapper = self.map = vtk.vtkPolyDataMapper ()
self.actor = self.act = vtk.vtkActor ()
self._initialize ()
self._gui_init ()
self.renwin.Render ()
Common.state.idle ()
示例5: getContour
def getContour(self,value=0.5,arrName='',largestRegion=False):
if arrName == '':
arrName = self.waterArray[self.solver]
contour=vtk.vtkContourFilter()
contour.SetValue(0,value)
self.pointData.SetActiveScalars(arrName)
#contour.SetInputArrayToProcess(1, 0,0, vtkDataObject::FIELD_ASSOCIATION_POINTS , arrName); #something like this may also work
contour.SetInputConnection(self.outputPort)
contour.Update()
if largestRegion:
conn=vtk.vtkConnectivityFilter()
conn.SetInputConnection(contour.GetOutputPort())
conn.SetExtractionModeToLargestRegion()
conn.Update()
connOutput = conn.GetOutput()
IDs = []
for iC in range(connOutput.GetNumberOfCells()): #it has to be so complicated, no polylines are given
cell = connOutput.GetCell(iC)
for i in [0,1]:
ID = cell.GetPointId(i)
if not ID in IDs: IDs.append(ID)
points=[connOutput.GetPoint(i) for i in IDs]
else:
cOutput = contour.GetOutput()
points=[cOutput.GetPoint(i) for i in range(cOutput.GetNumberOfPoints())]
if not points: sys.exit('vtkextract.py: No contours found - wrong initialization of water fraction?')
points = np.array(points)
return points
示例6: create_actors_for_skin_and_bone
def create_actors_for_skin_and_bone(reader):
actors_list = []
for contour_val, color, opacity in SKIN_BONE_LIST:
contour = vtk.vtkContourFilter()
contour.SetInput(reader.GetOutput())
contour.SetNumberOfContours(1)
contour.SetValue(contour_val[0], contour_val[1])
normals = vtk.vtkPolyDataNormals()
normals.SetInput(contour.GetOutput())
normals.SetFeatureAngle(60)
normals.ConsistencyOff()
normals.SplittingOff()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(normals.GetOutput())
mapper.ScalarVisibilityOff()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(color)
actor.GetProperty().SetOpacity(opacity)
actor.RotateX(-90)
actors_list.append(actor)
return actors_list
示例7: render_image
def render_image(vtk_reader):
contour = vtk.vtkContourFilter()
contour.SetInput(vtk_reader.GetOutput())
contour.GenerateValues(20,20,200)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(contour.GetOutput())
mapper.ScalarVisibilityOn()
mapper.SetScalarRange(0,255)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(actor)
renderer.SetBackground(.5, .5, .5)
renderWindow.SetSize(600, 600)
renderWindow.Render()
renderWindowInteractor.Start()
示例8: setUp
def setUp(self):
self.vtk_iso = vtkContourFilter()
# self.vtk_iso.SetInput(...)
self.vtk_dnorm = vtkPolyDataNormals()
self.vtk_subdiv = vtkLinearSubdivisionFilter()
self.vtk_dmap = vtkPolyDataMapper()
示例9: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkContourFilter(), 'Processing.',
('vtkDataSet',), ('vtkPolyData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例10: BuildPolyBallSurface
def BuildPolyBallSurface(self):
#Build a surface for displaying the polyball
if self.PolyBall == None:
return
#Sample the polyball
sampler = vtk.vtkSampleFunction()
sampler.SetImplicitFunction(self.PolyBall)
#Set the bounds to be slightly larger than those of the mesh
meshBounds = self.Mesh.GetBounds()
meshCenter = self.Mesh.GetCenter()
polyBallBounds = [0, 0, 0, 0, 0, 0]
for i in range(0,3):
length = 1.2*(meshBounds[2*i+1] - meshCenter[i])
polyBallBounds[2*i] = meshCenter[i] - length
polyBallBounds[2*i+1] = meshCenter[i] + length
sampler.SetModelBounds(polyBallBounds)
sampler.SetSampleDimensions(self.PolyBallResolution)
sampler.ComputeNormalsOff()
sampler.Update()
#Extract the isosurface at 0
contour = vtk.vtkContourFilter()
contour.SetInput(sampler.GetOutput())
contour.SetValue(0,0.)
contour.Update()
#Set the new model as the mapper input
self.PolyBallActor.GetMapper().SetInput(contour.GetOutput())
示例11: GetXandt
def GetXandt(filelist):
time = []
X_ns = []
X_fs = []
for files in filelist:
data = vtktools.vtu(files)
time.append(data.GetScalarField("Time")[0])
# Get X
data.ugrid.GetPointData().SetActiveScalars('Temperature')
data = data.ugrid
contour = vtk.vtkContourFilter()
if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
contour.SetInput(data)
else:
contour.SetInputData(data)
contour.SetValue(0, 0.0)
contour.Update()
polydata = contour.GetOutput()
bounding_box = polydata.GetBounds()
X_ns.append(bounding_box[1])
X_fs.append(bounding_box[0])
return time, X_ns, X_fs
示例12: __init__
def __init__(self,data_reader,origin,normal,camera_normal):
self.axial=self.get_matrix(data_reader,origin,normal,camera_normal)
# Extract a slice in the desired orientation
self.reslice = vtk.vtkImageReslice()
self.reslice.SetInput(data_reader.get_data_set())
self.reslice.SetOutputDimensionality(2)
self.reslice.SetResliceAxes(self.axial)
self.reslice.SetInterpolationModeToLinear()
self.contour=vtk.vtkContourFilter()
self.contour.SetInputConnection(self.reslice.GetOutputPort())
self.contour.GenerateValues(25, data_reader.get_scalar_range())
self.contour.ComputeScalarsOn()
self.contour.ComputeGradientsOn()
self.cutmapper=vtk.vtkPolyDataMapper()
self.cutmapper.SetInputConnection(self.contour.GetOutputPort())
self.actor=vtk.vtkActor()
self.actor.SetMapper(self.cutmapper)
self.actor.PokeMatrix(self.axial)
c="c"
if origin[0]==c or origin[1]==c or origin[2]==c:
origin=self.center
origin=(float(origin[0]),float(origin[1]),float(origin[2]))
self.actor.SetOrigin(origin)
示例13: test_contours
def test_contours(self):
cell = vtk.vtkUnstructuredGrid()
cell.ShallowCopy(self.Cell)
np = self.Cell.GetNumberOfPoints()
ncomb = pow(2, np)
scalar = vtk.vtkDoubleArray()
scalar.SetName("scalar")
scalar.SetNumberOfTuples(np)
cell.GetPointData().SetScalars(scalar)
incorrectCases = []
for i in range(1,ncomb-1):
c = Combination(np, i)
for p in range(np):
scalar.SetTuple1(p, c[p])
gradientFilter = vtk.vtkGradientFilter()
gradientFilter.SetInputData(cell)
gradientFilter.SetInputArrayToProcess(0,0,0,0,'scalar')
gradientFilter.SetResultArrayName('grad')
gradientFilter.Update()
contourFilter = vtk.vtkContourFilter()
contourFilter.SetInputConnection(gradientFilter.GetOutputPort())
contourFilter.SetNumberOfContours(1)
contourFilter.SetValue(0, 0.5)
contourFilter.Update()
normalsFilter = vtk.vtkPolyDataNormals()
normalsFilter.SetInputConnection(contourFilter.GetOutputPort())
normalsFilter.SetConsistency(0)
normalsFilter.SetFlipNormals(0)
normalsFilter.SetSplitting(0)
calcFilter = vtk.vtkArrayCalculator()
calcFilter.SetInputConnection(normalsFilter.GetOutputPort())
calcFilter.SetAttributeTypeToPointData()
calcFilter.AddVectorArrayName('grad')
calcFilter.AddVectorArrayName('Normals')
calcFilter.SetResultArrayName('dir')
calcFilter.SetFunction('grad.Normals')
calcFilter.Update()
out = vtk.vtkUnstructuredGrid()
out.ShallowCopy(calcFilter.GetOutput())
numPts = out.GetNumberOfPoints()
if numPts > 0:
dirArray = out.GetPointData().GetArray('dir')
for p in range(numPts):
if(dirArray.GetTuple1(p) > 0.0): # all normals are reversed
incorrectCases.append(i)
break
self.assertEquals(','.join([str(i) for i in incorrectCases]), '')
示例14: test_method_signature
def test_method_signature(self):
"""Check if VTK method signatures are parsed correctly."""
p = self.p
# Simple tests.
o = vtk.vtkProperty()
self.assertEqual([(['string'], None)],
p.get_method_signature(o.GetClassName))
if hasattr(vtk, 'vtkArrayCoordinates'):
self.assertEqual([([('float', 'float', 'float')], None),
([None], (['float', 'float', 'float'],)),
([None], ('float', 'float', 'float'))],
p.get_method_signature(o.GetColor))
else:
self.assertEqual([([('float', 'float', 'float')], None),
([None], (('float', 'float', 'float'),))],
p.get_method_signature(o.GetColor))
if hasattr(vtk, 'vtkArrayCoordinates'):
self.assertEqual([([None], ('float', 'float', 'float')),
([None], (['float', 'float', 'float'],))],
p.get_method_signature(o.SetColor))
else:
self.assertEqual([([None], ('float', 'float', 'float')),
([None], (('float', 'float', 'float'),))],
p.get_method_signature(o.SetColor))
# Get VTK version to handle changed APIs.
vtk_ver = vtk.vtkVersion().GetVTKVersion()
# Test vtkObjects args.
o = vtk.vtkContourFilter()
sig = p.get_method_signature(o.SetInput)
if len(sig) == 1:
self.assertEqual([([None], ['vtkDataSet'])],
sig)
elif vtk_ver[:3] in ['4.2', '4.4']:
self.assertEqual([([None], ['vtkDataObject']),
([None], ('int', 'vtkDataObject')),
([None], ['vtkDataSet']),
([None], ('int', 'vtkDataSet'))
], sig)
elif vtk_ver[:2] == '5.' or vtk_ver[:3] == '4.5':
self.assertEqual([([None], ['vtkDataObject']),
([None], ('int', 'vtkDataObject')),
], sig)
self.assertEqual([(['vtkPolyData'], None),
(['vtkPolyData'], ['int'])],
p.get_method_signature(o.GetOutput))
# Test if function arguments work.
self.assertEqual([(['int'], ('int', 'function'))],
p.get_method_signature(o.AddObserver))
# This one's for completeness.
self.assertEqual([([None], ['int'])],
p.get_method_signature(o.RemoveObserver))
示例15: test_to_tvtk_returns_tvtk_object
def test_to_tvtk_returns_tvtk_object(self):
# Given
v = vtk.vtkContourFilter()
# When
x = tvtk.to_tvtk(v)
# Then
self.assertEqual(x.class_name, 'vtkContourFilter')
self.assertTrue(isinstance(x, tvtk_base.TVTKBase))
self.assertTrue(isinstance(x, tvtk.ContourFilter))
self.assertTrue(v is x._vtk_obj)