RequestUpdateExtent
测试1
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.util import keys
# 元数据
requestKey = keys.MakeKey(keys.IntegerRequestKey, "a request", "my module")
class MySource(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=0,
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MySource RequestInformation:")
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MySource RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MySource RequestData:")
return 1
class MyFilter(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=1, inputType='vtkPolyData',
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MyFilter RequestInformation:")
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MyFilter RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MyFilter RequestData:")
# print (outInfo.GetInformationObject(0))
return 1
s = MySource()
f = MyFilter()
f.SetInputConnection(s.GetOutputPort())
# f.Update()
f.UpdateInformation()
outInfo = f.GetOutputInformation(0)
outInfo.Set(requestKey, 0)
f.PropagateUpdateExtent()
发送请求:
f.UpdateInformation()
outInfo = f.GetOutputInformation(0)
outInfo.Set(requestKey, 0)
f.PropagateUpdateExtent()
输出:
MySource和MyFilter中原数据a request: 0
MySource RequestInformation:
MyFilter RequestInformation:
MyFilter RequestUpdateExtent:
vtkInformation (0000018D6DE58F50)
Debug: Off
Modified Time: 230
Reference Count: 2
Registered Events: (none)
PRODUCER: vtkCompositeDataPipeline(0000018D6D5A0710) port 0
DATA_OBJECT: vtkPolyData(0000018D6DE58440)
UPDATE_PIECE_NUMBER: 0
UPDATE_NUMBER_OF_PIECES: 1
UPDATE_NUMBER_OF_GHOST_LEVELS: 0
a request: 0
MySource RequestUpdateExtent:
vtkInformation (0000018D6DE59D50)
Debug: Off
Modified Time: 242
Reference Count: 3
Registered Events: (none)
PRODUCER: vtkCompositeDataPipeline(0000018D6D5A2720) port 0
DATA_OBJECT: vtkPolyData(0000018D6B33D280)
CONSUMERS: vtkCompositeDataPipeline(0000018D6D5A0710) port 0
UPDATE_PIECE_NUMBER: 0
UPDATE_NUMBER_OF_PIECES: 1
UPDATE_NUMBER_OF_GHOST_LEVELS: 0
a request: 0
测试2
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.util import keys
metaDataKey = keys.MakeKey(keys.DataObjectMetaDataKey, \
"a meta-data", "my module")
requestKey = keys.MakeKey(keys.IntegerRequestKey, "a request", "my module")
class MySource(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=0,
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MySource RequestInformation:")
# outInfo.GetInformationObject(0).Set(metaDataKey, vtk.vtkPolyData())
# print (outInfo.GetInformationObject(0))
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MySource RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MySource RequestData:")
# print (outInfo.GetInformationObject(0))
return 1
class MyFilter(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=1, inputType='vtkPolyData',
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MyFilter RequestInformation:")
# print (outInfo.GetInformationObject(0))
# metaData = inInfo[0].GetInformationObject(0).Get(
# metaDataKey)
# newMetaData = metaData.NewInstance()
# newMetaData.ShallowCopy(metaData)
# someArray = vtk.vtkCharArray()
# someArray.SetName("someArray")
# newMetaData.GetFieldData().AddArray(someArray)
# outInfo.GetInformationObject(0).Set(metaDataKey, newMetaData)
# print (outInfo.GetInformationObject(0))
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MyFilter RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
areq = outInfo.GetInformationObject(0).Get(requestKey)
inInfo[0].GetInformationObject(0).Set(requestKey, areq + 1)
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MyFilter RequestData:")
# print (outInfo.GetInformationObject(0))
return 1
s = MySource()
f = MyFilter()
f.SetInputConnection(s.GetOutputPort())
# f.Update()
f.UpdateInformation()
outInfo = f.GetOutputInformation(0)
outInfo.Set(requestKey, 0)
f.PropagateUpdateExtent()
输出:
MySource RequestInformation:
MyFilter RequestInformation:
MyFilter RequestUpdateExtent:
vtkInformation (0000019826985EE0)
Debug: Off
Modified Time: 230
Reference Count: 2
Registered Events: (none)
PRODUCER: vtkCompositeDataPipeline(00000198268DA7B0) port 0
DATA_OBJECT: vtkPolyData(0000019823F0D670)
UPDATE_PIECE_NUMBER: 0
UPDATE_NUMBER_OF_PIECES: 1
UPDATE_NUMBER_OF_GHOST_LEVELS: 0
a request: 0
MySource RequestUpdateExtent:
vtkInformation (00000198269855E0)
Debug: Off
Modified Time: 243
Reference Count: 3
Registered Events: (none)
PRODUCER: vtkCompositeDataPipeline(00000198268D9BD0) port 0
CONSUMERS: vtkCompositeDataPipeline(00000198268DA7B0) port 0
DATA_OBJECT: vtkPolyData(0000019826983120)
UPDATE_PIECE_NUMBER: 0
UPDATE_NUMBER_OF_PIECES: 1
UPDATE_NUMBER_OF_GHOST_LEVELS: 0
a request: 1
执行过程:
outInfo.Set(requestKey, 0)
->MyFilter.RequestUpdateExtent()
->MySource.RequestUpdateExtent()
- 在RequestInformation中,源(source)生成的元数据(meta-data),默认向下游复制以及修改后的值向下传递。
- 在 RequestUpdateExtent中, 下游会发送改变元数据的请求,改变的值传递给上游。
RequestData
RequestInformation
和RequestUpdateExtent
传递的是轻量级的元数据。RequestData
和RequestInformation
相似都是向下游传递数据,不同的地方是它传递的是重量级的数据。
测试
import vtk
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.util import keys
requestKey = keys.MakeKey(keys.IntegerRequestKey, "a request", "my module")
class MySource(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=0,
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MySource RequestInformation:")
# outInfo.GetInformationObject(0).Set(metaDataKey, vtk.vtkPolyData())
# print (outInfo.GetInformationObject(0))
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MySource RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MySource RequestData:")
print (outInfo.GetInformationObject(0))
outInfo0 = outInfo.GetInformationObject(0)
areq = outInfo0.Get(requestKey)
s = vtk.vtkSphereSource()
s.SetRadius(areq)
s.Update()
output = outInfo0.Get(vtk.vtkDataObject.DATA_OBJECT())
output.ShallowCopy(s.GetOutput())
print (output)
return 1
class MyFilter(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=1, inputType='vtkPolyData',
nOutputPorts=1, outputType='vtkPolyData')
def RequestInformation(self, request, inInfo, outInfo):
print ("MyFilter RequestInformation:")
# print (outInfo.GetInformationObject(0))
# metaData = inInfo[0].GetInformationObject(0).Get(
# metaDataKey)
# newMetaData = metaData.NewInstance()
# newMetaData.ShallowCopy(metaData)
# someArray = vtk.vtkCharArray()
# someArray.SetName("someArray")
# newMetaData.GetFieldData().AddArray(someArray)
# outInfo.GetInformationObject(0).Set(metaDataKey, newMetaData)
# print (outInfo.GetInformationObject(0))
return 1
def RequestUpdateExtent(self, request, inInfo, outInfo):
print ("MyFilter RequestUpdateExtent:")
print (outInfo.GetInformationObject(0))
areq = outInfo.GetInformationObject(0).Get(requestKey)
inInfo[0].GetInformationObject(0).Set(requestKey, areq + 1)
return 1
def RequestData(self, request, inInfo, outInfo):
print ("MyFilter RequestData:")
inInfo0 = inInfo[0].GetInformationObject(0)
outInfo0 = outInfo.GetInformationObject(0)
input = inInfo0.Get(vtk.vtkDataObject.DATA_OBJECT())
output = outInfo0.Get(vtk.vtkDataObject.DATA_OBJECT())
sh = vtk.vtkShrinkPolyData()
sh.SetInputData(input)
sh.Update()
output.ShallowCopy(sh.GetOutput())
print (output)
return 1
s = MySource()
f = MyFilter()
f.SetInputConnection(s.GetOutputPort())
f.UpdateInformation()
outInfo = f.GetOutputInformation(0)
outInfo.Set(requestKey, 0)
f.PropagateUpdateExtent()
f.Update()