I have make some progress with the following but it thinks my custom data is not define
import vtk
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
class MyCommandData(vtk.vtkDataObject):
def __init__(self):
super(MyCommandData, self).__init__()
self.stdin = ''
self.stdout = ''
self.stderr = ''
self.retcode = 0
class MyCommand(VTKPythonAlgorithmBase):
def __init__(self):
super(MyCommand, self).__init__(nInputPorts=1, inputType='MyCommandData',
nOutputPorts=1, outputType='MyCommandData')
def FillInputPortInformation(self, port, info):
if port == 0:
info.Set(vtk.vtkAlgorithm.INPUT_IS_OPTIONAL(), 1)
info.Set(vtk.vtkDataObject.DATA_TYPE_NAME(),'MyCommandData')
return 1
def FillOutputPortInformation(self, port, info):
if port == 0:
info.Set(vtk.vtkDataObject.DATA_TYPE_NAME(),'MyCommandData')
return 1
def RequestData(self, request, inInfo, outInfo):
input_info = inInfo[0].GetInformationObject(0)
input = MyCommandData.GetData(input_info)
output_info = outInfo.GetInformationObject(0)
output = MyCommandData.GetData(output_info)
return 1
a = MyCommand()
b = MyCommand()
b.AddInputConnection(0, a.GetOutputPort())
b.Update()
Output is
2022-01-11 17:34:58.297 ( 0.149s) [ 4EC3080] vtkDataObjectTypes.cxx:296 WARN| NewDataObject(): You are trying to instantiate DataObjectType "MyCommandData" which does not exist.
2022-01-11 17:34:58.297 ( 0.149s) [ 4EC3080]vtkDemandDrivenPipeline:615 ERR| vtkCompositeDataPipeline (0x5590416af7b0): Algorithm vtkPythonAlgorithm(0x5590416ae360) did not create output for port 0 when asked by REQUEST_DATA_OBJECT and does not specify a concrete DATA_TYPE_NAME.
It is not possible to subclass VTK objects from Python in ways that the C++ code is aware of them as there is no “glue” class which C+±inherits from arbitrary VTK classes and forwards requests to Python code (as is done for VTKPythonAlgorithmBase).