本文整理汇总了Python中vtk.vtkExtractVOI函数的典型用法代码示例。如果您正苦于以下问题:Python vtkExtractVOI函数的具体用法?Python vtkExtractVOI怎么用?Python vtkExtractVOI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkExtractVOI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkExtractVOI(), 'Processing.',
('vtkImageData',), ('vtkImageData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例2: getPlane
def getPlane(self, data, plane, xCoordinate, yCoordinate, zCoordinate, applyZScaling = 0):
"""
Get a plane from given the volume
"""
xAxis, yAxis, zAxis = 0, 1, 2
dataWidth, dataHeight, dataDepth = data.GetDimensions()
if not self.voi:
self.voi = vtk.vtkExtractVOI()
else:
self.voi.RemoveAllInputs()
if not self.permute:
self.permute = vtk.vtkImagePermute()
else:
self.permute.RemoveAllInputs()
self.permute.SetInputConnection(data.GetProducerPort())
spacing = data.GetSpacing()
xscale = 1
yscale = 1
if plane == "zy":
data.SetUpdateExtent(xCoordinate, xCoordinate, 0, dataHeight - 1, 0, dataDepth - 1)
self.permute.SetFilteredAxes(zAxis, yAxis, xAxis)
self.permute.Update()
data = self.permute.GetOutput()
self.voi.SetInput(data)
self.voi.SetVOI(0, dataDepth - 1, 0, dataHeight - 1, xCoordinate, xCoordinate)
xdim = dataDepth
ydim = dataHeight
if applyZScaling:
xdim *= spacing[2]
xscale = spacing[2]
elif plane == "xz":
data.SetUpdateExtent(0, dataWidth - 1, yCoordinate, yCoordinate, 0, dataDepth - 1)
self.permute.SetFilteredAxes(xAxis, zAxis, yAxis)
self.permute.Update()
data = self.permute.GetOutput()
self.voi.SetInput(data)
self.voi.SetVOI(0, dataWidth - 1, 0, dataDepth - 1, yCoordinate, yCoordinate)
xdim = dataWidth
ydim = dataDepth
if applyZScaling:
ydim *= spacing[2]
yscale = 1
self.voi.Update()
if applyZScaling:
self.voi.Update()
return lib.ImageOperations.scaleImage(self.voi.GetOutput(), interpolation = 2, xfactor = xscale, yfactor = yscale)
self.voi.Update()
return self.voi.GetOutput()
示例3: buildPipeline
def buildPipeline(self):
""" execute() -> None
Dispatch the vtkRenderer to the actual rendering widget
"""
self.initialOrigin = self.input.GetOrigin()
self.initialExtent = self.input.GetExtent()
self.initialSpacing = self.input.GetSpacing()
self.initialAoi = self.getUnscaledWorldExtent( self.initialExtent, self.initialSpacing )
self.currentAoi = list( self.initialAoi )
self.clip = vtk.vtkExtractVOI()
self.inputModule.inputToAlgorithm( self.clip )
self.pad = vtk.vtkImageMagnify()
self.pad.InterpolateOn()
self.pad.SetInputConnection( self.clip.GetOutputPort() )
self.imageInfo = vtk.vtkImageChangeInformation()
self.imageInfo.SetInputConnection( self.pad.GetOutputPort() )
self.imageInfo.SetOutputOrigin( self.initialOrigin[0], self.initialOrigin[1], self.initialOrigin[2] )
self.imageInfo.SetOutputExtentStart( self.initialExtent[0], self.initialExtent[2], self.initialExtent[4] )
self.imageInfo.SetOutputSpacing( self.initialSpacing[0], self.initialSpacing[1], self.initialSpacing[2] )
self.setExtent( self.initialExtent )
self.set3DOutput( port=self.imageInfo.GetOutputPort() )
示例4: _handlerVoiSaveButton
def _handlerVoiSaveButton(self, event):
input_data = self.getPrimaryInput()
filename = self.controlFrame.voiFilenameText.GetValue()
if input_data and self._voi_widget.GetEnabled() and filename:
# see if we need to reset to zero origin
zor = self.controlFrame.voiResetToOriginCheck.GetValue()
extractVOI = vtk.vtkExtractVOI()
extractVOI.SetInput(input_data)
extractVOI.SetVOI(self._currentVOI)
writer = vtk.vtkXMLImageDataWriter()
writer.SetDataModeToBinary()
writer.SetFileName(filename)
if zor:
ici = vtk.vtkImageChangeInformation()
ici.SetOutputExtentStart(0,0,0)
ici.SetInput(extractVOI.GetOutput())
writer.SetInput(ici.GetOutput())
else:
writer.SetInput(extractVOI.GetOutput())
writer.Write()
示例5: __init__
def __init__(self, parent=None):
self.nameSize = 24
self.CrosshairNode = None
self.CrosshairNodeObserverTag = None
self.frame = qt.QFrame(parent)
self.frame.setLayout(qt.QVBoxLayout())
modulePath = slicer.modules.dataprobe.path.replace("DataProbe.py","")
self.iconsDIR = modulePath + '/Resources/Icons'
self.showImage = False
# Used in _createMagnifiedPixmap()
self.imageCrop = vtk.vtkExtractVOI()
self.painter = qt.QPainter()
self.pen = qt.QPen()
self._createSmall()
#Helper class to calculate and display tensor scalars
self.calculateTensorScalars = CalculateTensorScalars()
# Observe the crosshair node to get the current cursor position
self.CrosshairNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLCrosshairNode')
if self.CrosshairNode:
self.CrosshairNodeObserverTag = self.CrosshairNode.AddObserver(slicer.vtkMRMLCrosshairNode.CursorPositionModifiedEvent, self.processEvent)
示例6: 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
示例7: initialize
def initialize (self):
debug ("In ExtractGrid::__init__ ()")
self.fil = vtk.vtkExtractVOI()
self.dim = [0,0,0]
self._set_input()
self.fil.UpdateWholeExtent()
self.fil.Update ()
self.voi_slider = []
self.sr_slider = []
示例8: _MakeXYActors
def _MakeXYActors(self, reduce=1):
# get a texture-mapped actor
extent = self._ImageReslice.GetOutputExtent()
origin = self._ImageReslice.GetOutputOrigin()
spacing = self._ImageReslice.GetOutputSpacing()
bounds = [origin[0] + spacing[0] * (extent[0] - 0.5),
origin[0] + spacing[0] * (extent[1] + 0.5),
origin[1] + spacing[1] * (extent[2] - 0.5),
origin[1] + spacing[1] * (extent[3] + 0.5),
origin[2] + spacing[2] * (extent[4] - 0.5),
origin[2] + spacing[2] * (extent[5] + 0.5)]
for sliceNumber in range(extent[4], old_div((extent[5] + 1), reduce)):
# the z position of the slice
z = origin[2] + reduce * sliceNumber * spacing[2]
plane = vtk.vtkPlaneSource()
plane.SetXResolution(1)
plane.SetYResolution(1)
plane.SetOrigin(bounds[0], bounds[2], z)
plane.SetPoint1(bounds[1], bounds[2], z)
plane.SetPoint2(bounds[0], bounds[3], z)
imageClip = vtk.vtkExtractVOI()
imageClip.SetInput(self._ImageToStructuredPoints.GetOutput())
imageClip.SetVOI(extent[0], extent[1],
extent[2], extent[3],
reduce * sliceNumber, reduce * sliceNumber)
imageClip.ReleaseDataFlagOn()
texture = vtk.vtkTexture()
texture.SetQualityTo32Bit()
texture.SetInput(imageClip.GetOutput())
texture.RepeatOff()
texture.InterpolateOn()
texture.MapColorScalarsThroughLookupTableOff()
for i in range(3):
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(plane.GetOutput())
mapper.SetClippingPlanes(self._ClippingPlanes[i])
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetTexture(texture)
actor.PickableOff()
actor.SetProperty(self._PropertyXY)
self._PlanesXY.append(plane)
self._ImageClipsXY.append(imageClip)
self._ActorsXY.append(actor)
numberOfPlanes = (extent[5] - extent[4] + 1) / reduce * 3
return self._ActorsXY[-numberOfPlanes:]
示例9: ExtractVOI
def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf):
"""
Cropping the vtkImagedata according
with values.
"""
voi = vtk.vtkExtractVOI()
voi.SetVOI(xi,xf,yi,yf,zi,zf)
voi.SetInputData(imagedata)
voi.SetSampleRate(1, 1, 1)
voi.Update()
return voi.GetOutput()
示例10: updateRendering
def updateRendering(self):
"""
Update the Rendering of this module
"""
data = self.getInput(1)
x,y,z = self.dataUnit.getDimensions()
data = optimize.optimize(image = data, updateExtent = (0, x-1, 0, y-1, 0, z-1))
if data.GetNumberOfScalarComponents() > 3:
extract = vtk.vtkImageExtractComponents()
extract.SetInput(data)
extract.SetComponents(1, 1, 1)
data = extract.GetOutput()
if data.GetNumberOfScalarComponents() > 1:
self.luminance.SetInput(data)
data = self.luminance.GetOutput()
z = self.parameters["Slice"]
ext = (0, x - 1, 0, y - 1, z, z)
voi = vtk.vtkExtractVOI()
voi.SetVOI(ext)
voi.SetInput(data)
slice = voi.GetOutput()
self.geometry.SetInput(slice)
self.warp.SetInput(self.geometry.GetOutput())
self.warp.SetScaleFactor(self.parameters["Scale"])
self.merge.SetGeometry(self.warp.GetOutput())
if slice.GetNumberOfScalarComponents() == 1:
maptocol = vtk.vtkImageMapToColors()
ctf = self.getInputDataUnit(1).getColorTransferFunction()
maptocol.SetInput(slice)
maptocol.SetLookupTable(ctf)
maptocol.Update()
scalars = maptocol.GetOutput()
else:
scalars = slice
self.merge.SetScalars(scalars)
data = self.merge.GetOutput()
if self.parameters["Normals"]:
self.normals.SetInput(data)
self.normals.SetFeatureAngle(self.parameters["FeatureAngle"])
print "Feature angle=", self.parameters["FeatureAngle"]
data = self.normals.GetOutput()
self.mapper.SetInput(data)
self.mapper.Update()
VisualizationModule.updateRendering(self)
self.parent.Render()
示例11: __init__
def __init__(self):
"""
Initialization
"""
lib.ProcessingFilter.ProcessingFilter.__init__(self, (1, 1))
self.reportGUI = None
self.measurements = []
self.vtkfilter = vtk.vtkExtractVOI()
self.vtkfilter.AddObserver("ProgressEvent", lib.messenger.send)
lib.messenger.connect(self.vtkfilter, 'ProgressEvent', self.updateProgress)
self.translation = []
self.descs = {"UseROI": "Use Region of Interest to define resulting region", \
"ROI": "Region of Interest Used in Cutting", \
"FirstSlice": "First Slice in Resulting Stack", \
"LastSlice": "Last Slice in Resulting Stack"}
self.filterDesc = "Extracts a subset from a dataset by removing slices from the top and/or bottom and/or by using a ROI to specify the subset in X and Y.\nInput: Any image\nOutput: Extracted image"
示例12: getSlice
def getSlice(volume, zslice, startpos=None, endpos=None):
"""
Extract a given slice from a volume
"""
voi = vtk.vtkExtractVOI()
voi.SetInputConnection(volume.GetProducerPort())
if startpos:
startx, starty = startpos
endx, endy = endpos
else:
# startx, starty = 0, 0
# endx, endy = volume.GetDimensions()[0:2]
startx, endx, starty, endy, a, b = volume.GetExtent()
voi.SetVOI((int(startx), int(endx), int(starty), int(endy), int(zslice), int(zslice)))
voi.Update()
data = voi.GetOutput()
return data
示例13: _set_input
def _set_input (self):
""" This function tries its best to use an appropriate filter
for the given input data."""
debug ("In ExtractGrid::_set_input ()")
out = self.prev_fil.GetOutput ()
dim = out.GetDimensions ()
self.dim = [dim[0] -1, dim[1] -1, dim[2] -1]
if out.IsA ('vtkStructuredGrid'):
f = vtk.vtkExtractGrid()
elif out.IsA ('vtkRectilinearGrid'):
f = vtk.vtkExtractRectilinearGrid()
elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'):
f = vtk.vtkExtractVOI()
else:
msg = "This module does not support the given "\
"output - %s "%(out.GetClassName ())
raise Base.Objects.ModuleException, msg
if f.GetClassName() != self.fil.GetClassName():
self.fil = f
self.fil.SetInput (out)
示例14: ExtractVOI
def ExtractVOI(self):
wholeExtent = self.Image.GetExtent()
origin = self.Image.GetOrigin()
spacing = self.Image.GetSpacing()
newVOI = [0,0,0,0,0,0]
newVOI[0] = max(wholeExtent[0],int(math.ceil((self.BoxBounds[0]-origin[0])/spacing[0])))
newVOI[1] = min(wholeExtent[1],int(math.floor((self.BoxBounds[1]-origin[0])/spacing[0])))
newVOI[2] = max(wholeExtent[2],int(math.ceil((self.BoxBounds[2]-origin[1])/spacing[1])))
newVOI[3] = min(wholeExtent[3],int(math.floor((self.BoxBounds[3]-origin[1])/spacing[1])))
newVOI[4] = max(wholeExtent[4],int(math.ceil((self.BoxBounds[4]-origin[2])/spacing[2])))
newVOI[5] = min(wholeExtent[5],int(math.floor((self.BoxBounds[5]-origin[2])/spacing[2])))
extractVOI = vtk.vtkExtractVOI()
extractVOI.SetInputData(self.CroppedImage)
extractVOI.SetVOI(newVOI)
extractVOI.Update()
self.CroppedImage.DeepCopy(extractVOI.GetOutput())
示例15: getTimepoint
def getTimepoint(self, n, onlyDims = 0):
"""
Return the nth timepoint
"""
if not self.readers:
self.getReadersFromFilenames()
if self.is3DImage():
if not self.readers:
raise Logging.GUIError("Attempt to read bad timepoint", "Timepoint %d is not defined by the given filenames" % n)
self.reader = self.readers[0]
minZ = n * self.slicesPerTimepoint
maxZ = (n+1) * self.slicesPerTimepoint - 1
extract = vtk.vtkExtractVOI()
extract.SetInput(self.reader.GetOutput())
extract.SetVOI(0, self.x - 1, 0, self.y - 1, minZ, maxZ)
changeInfo = vtk.vtkImageChangeInformation()
changeInfo.SetInput(extract.GetOutput())
changeInfo.SetOutputOrigin(0, 0, 0)
changeInfo.SetExtentTranslation((0,0,-minZ))
data = changeInfo.GetOutput()
else:
if n >= len(self.readers):
n = 0
raise Logging.GUIError("Attempt to read bad timepoint", "Timepoint %d is not defined by the given filenames" % n)
self.reader = self.readers[n]
data = self.reader.GetOutput()
if not self.voxelsize:
size = data.GetSpacing()
x, y, z = [size.GetElement(x) for x in range(0, 3)]
self.voxelsize = (x, y, z)
print "Read voxel size", self.voxelsize
if onlyDims:
return
return data