How to use VTK filters and writers in a catalyst python pipeline?

Continuing the discussion from Help! How create a "depth map" using ParaView (Is it possible):

I am trying to use script provide in the link above in a catalyst pipeline. I tried a programmable filter in paraview, but that did not seem to work in catalyst. Instead I decided to just modify the script catalyst generates and put that code in it, but I am having trouble getting it to write any data.

My pipeline has this in it:

ss = vtk.vtkWindowToImageFilter() 
ss.SetInputBufferTypeToZBuffer()
ss.SetInput(renderView1.SMProxy.GetRenderWindow())
writer = XMLImageDataWriter(ss.GetOutputPort())
coprocessor.RegisterWriter(writer, "z_buffer_%t.vti", 1)

but i see this:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "./volume2.py", line 218, in DoCoProcessing
  File "//lib/python3.8/site-packages/paraview/coprocessing.py", line 212, in UpdateProducers
    self.CreatePipeline(datadescription)
  File "./volume2.py", line 169, in CreatePipeline
  File "./volume2.py", line 34, in _CreatePipeline
  File "./volume2.py", line 162, in Pipeline
  File "//lib/python3.8/site-packages/paraview/simple.py", line 2243, in CreateObject
    raise RuntimeError ("Expecting a proxy as input.")
RuntimeError: Expecting a proxy as input.

In general what is the method for using arbitrary vtk filters and writers in a catalyst pipeline? I have looked at the Custom Python Script Pipeline section in the manual but it was not clear to me.

Here is the error I was seeing when trying to use vtkXMLImageDataWriter

Traceback (most recent call last):
File “”, line 2, in
File “./volume2.py”, line 219, in DoCoProcessing
File “//lib/python3.8/site-packages/paraview/coprocessing.py”, line 212, in UpdateProducers
self.CreatePipeline(datadescription)
File “./volume2.py”, line 170, in CreatePipeline
File “./volume2.py”, line 34, in _CreatePipeline
File “./volume2.py”, line 164, in Pipeline
File “//lib/python3.8/site-packages/paraview/coprocessing.py”, line 489, in RegisterWriter
writer.add_attribute(“parameters”, writerParametersProxy)
AttributeError: ‘vtkmodules.vtkIOXML.vtkXMLImageDataWriter’ object has no attribute ‘add_attribute’

Corresponding code:

ss = vtk.vtkWindowToImageFilter()
ss.SetInputBufferTypeToZBuffer()
ss.SetInput(renderView1.SMProxy.GetRenderWindow())
writer = vtk.vtkXMLImageDataWriter()
writer.SetInputConnection(ss.GetOutputPort())
coprocessor.RegisterWriter(writer, “z_buffer_%t.vti”, 1)

I tried a ProgrammableFilter again. Using this as the script:

      import vtk                                                                                                                                                                                                                           
      from paraview.simple import GetActiveView                                                                                                                                                                                            
      ss = vtk.vtkWindowToImageFilter()                                                                                                                                                                                                    
      ss.SetShouldRerender(True)                                                                                                                                                                                                           
      ss.SetInputBufferTypeToZBuffer()                                                                                                                                                                                                     
      ss.SetInput(GetActiveView().SMProxy.GetRenderWindow())                                                                                                                                                                               
      ss.Update()                                                                                                                                                                                                                          
      output = ss.GetOutput()

but it seems to seg fault due to the call to Update(), if I don’t call update the filter never seems to produce any output:

Loguru caught a signal: SIGSEGV
Stack trace:
[truncated]
123 0x7f3d9206aca2 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 386
122 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
121 0x7f3d92071bbf vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1343
120 0x7f3d9206be51 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 129
119 0x7f3d9206eee9 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 57
118 0x7f3d92074bc0 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 80
117 0x7f3d914b3470 vtkPythonProgrammableFilter::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 16
116 0x7f3d8f42713d vtkProgrammableFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 61
115 0x7f3d914b2de0 vtkPythonProgrammableFilter::Exec(char const*, char const*) + 5568
114 0x7f3d9bab949f vtkPythonInterpreter::RunSimpleString(char const*) + 335
113 0x7f3d9b8f12fd PyRun_SimpleStringFlags + 61
112 0x7f3d9b8f13ad PyRun_StringFlags + 125
111 0x7f3d9b8f4483 /usr/lib/libpython3.8.so.1.0(+0x1d2483) [0x7f3d9b8f4483]
110 0x7f3d9b8fa248 /usr/lib/libpython3.8.so.1.0(+0x1d8248) [0x7f3d9b8fa248]
109 0x7f3d9b8eeb03 PyEval_EvalCode + 35
108 0x7f3d9b83e654 _PyEval_EvalCodeWithName + 772
107 0x7f3d9b83fd08 _PyEval_EvalFrameDefault + 920
106 0x7f3d9b85087d _PyFunction_Vectorcall + 413
105 0x7f3d9b83e654 _PyEval_EvalCodeWithName + 772
104 0x7f3d9b844a78 _PyEval_EvalFrameDefault + 20744
103 0x7f3d9b84918c _PyObject_MakeTpCall + 1116
102 0x7f3d9b8569ea PyCFunction_Call + 410
101 0x7f3cf29b4ab1 //lib/python3.8/site-packages/vtkmodules/vtkCommonExecutionModel.so(+0x2bab1) [0x7f3cf29b4ab1]
100 0x7f3d920b27a7 vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 279
99 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
98 0x7f3d92071bbf vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1343
97 0x7f3d9206be51 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 129
96 0x7f3d9206eee9 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 57
95 0x7f3d92074bc0 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 80
94 0x7f3d8e045661 vtkWindowToImageFilter::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 161
93 0x7f3d8e044e4b vtkWindowToImageFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 4123
92 0x7f3d9b123372 /usr/lib/libvtkCommonCore-pv5.8.so.1(+0x4cc372) [0x7f3d9b123372]
91 0x7f3d910c3a9f vtkSMViewProxy::StillRender() + 143
90 0x7f3d910c307e vtkSMViewProxy::Update() + 334
89 0x7f3d925f24e4 vtkPVSessionBase::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 52
88 0x7f3d925f44b2 vtkPVSessionCore::ExecuteStreamInternal(vtkClientServerStream const&, bool) + 242
87 0x7f3d8a9caafd vtkClientServerInterpreter::ProcessStream(vtkClientServerStream const&) + 29
86 0x7f3d8a9ca64e vtkClientServerInterpreter::ProcessOneMessage(vtkClientServerStream const&, int) + 190
85 0x7f3d8a9ca535 vtkClientServerInterpreter::ProcessCommandInvoke(vtkClientServerStream const&, int) + 1173
84 0x7f3d92b5514d vtkPVRenderViewCommand(vtkClientServerInterpreter*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&, void*) + 23053
83 0x7f3d91042ed5 vtkPVRenderView::Update() + 149
82 0x7f3d9105671c vtkPVView::Update() + 268
81 0x7f3d91054b8f vtkPVView::CallProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformationVector*) + 159
80 0x7f3d90fc5d76 vtkGeometryRepresentationWithFaces::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 22
79 0x7f3d90fc3c09 vtkGeometryRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 25
78 0x7f3d910083af vtkPVDataRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 239
77 0x7f3d920b27a7 vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 279
76 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
75 0x7f3d920717aa vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 298
74 0x7f3d9206aca2 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 386
73 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
72 0x7f3d920717aa vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 298
71 0x7f3d9206aca2 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 386
70 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
69 0x7f3d92071bbf vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1343
68 0x7f3d9206be51 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 129
67 0x7f3d9206eee9 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 57
66 0x7f3d92074bc0 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 80
65 0x7f3d914b3470 vtkPythonProgrammableFilter::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 16
64 0x7f3d8f42713d vtkProgrammableFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 61
63 0x7f3d914b2de0 vtkPythonProgrammableFilter::Exec(char const*, char const*) + 5568
62 0x7f3d9bab949f vtkPythonInterpreter::RunSimpleString(char const*) + 335
61 0x7f3d9b8f12fd PyRun_SimpleStringFlags + 61
60 0x7f3d9b8f13ad PyRun_StringFlags + 125
59 0x7f3d9b8f4483 /usr/lib/libpython3.8.so.1.0(+0x1d2483) [0x7f3d9b8f4483]
58 0x7f3d9b8fa248 /usr/lib/libpython3.8.so.1.0(+0x1d8248) [0x7f3d9b8fa248]
57 0x7f3d9b8eeb03 PyEval_EvalCode + 35
56 0x7f3d9b83e654 _PyEval_EvalCodeWithName + 772
55 0x7f3d9b83fd08 _PyEval_EvalFrameDefault + 920
54 0x7f3d9b85087d _PyFunction_Vectorcall + 413
53 0x7f3d9b83e654 _PyEval_EvalCodeWithName + 772
52 0x7f3d9b844a78 _PyEval_EvalFrameDefault + 20744
51 0x7f3d9b84918c _PyObject_MakeTpCall + 1116
50 0x7f3d9b8569ea PyCFunction_Call + 410
49 0x7f3cf29b4ab1 //lib/python3.8/site-packages/vtkmodules/vtkCommonExecutionModel.so(+0x2bab1) [0x7f3cf29b4ab1]
48 0x7f3d920b27a7 vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 279
47 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
46 0x7f3d92071bbf vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1343
45 0x7f3d9206be51 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 129
44 0x7f3d9206eee9 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 57
43 0x7f3d92074bc0 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 80
42 0x7f3d8e045661 vtkWindowToImageFilter::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 161
41 0x7f3d8e044e4b vtkWindowToImageFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 4123
40 0x7f3d9b123372 /usr/lib/libvtkCommonCore-pv5.8.so.1(+0x4cc372) [0x7f3d9b123372]
39 0x7f3d910c3a9f vtkSMViewProxy::StillRender() + 143
38 0x7f3d910c307e vtkSMViewProxy::Update() + 334
37 0x7f3d925f24e4 vtkPVSessionBase::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 52
36 0x7f3d925f44b2 vtkPVSessionCore::ExecuteStreamInternal(vtkClientServerStream const&, bool) + 242
35 0x7f3d8a9caafd vtkClientServerInterpreter::ProcessStream(vtkClientServerStream const&) + 29
34 0x7f3d8a9ca64e vtkClientServerInterpreter::ProcessOneMessage(vtkClientServerStream const&, int) + 190
33 0x7f3d8a9ca535 vtkClientServerInterpreter::ProcessCommandInvoke(vtkClientServerStream const&, int) + 1173
32 0x7f3d92b5514d vtkPVRenderViewCommand(vtkClientServerInterpreter*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&, void*) + 23053
31 0x7f3d91042ed5 vtkPVRenderView::Update() + 149
30 0x7f3d9105671c vtkPVView::Update() + 268
29 0x7f3d91054b8f vtkPVView::CallProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformationVector*) + 159
28 0x7f3d90fc5d76 vtkGeometryRepresentationWithFaces::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 22
27 0x7f3d90fc3c09 vtkGeometryRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 25
26 0x7f3d910083af vtkPVDataRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 239
25 0x7f3d920b27a7 vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 279
24 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
23 0x7f3d920717aa vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 298
22 0x7f3d9206aca2 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 386
21 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
20 0x7f3d920717aa vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 298
19 0x7f3d9206aca2 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 386
18 0x7f3d920b1411 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 881
17 0x7f3d92071bbf vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1343
16 0x7f3d9206be51 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 129
15 0x7f3d9206eee9 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 57
14 0x7f3d92074bc0 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 80
13 0x7f3d914b3470 vtkPythonProgrammableFilter::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 16
12 0x7f3d8f42713d vtkProgrammableFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 61
11 0x7f3d914b2de0 vtkPythonProgrammableFilter::Exec(char const*, char const*) + 5568
10 0x7f3d9bab949f vtkPythonInterpreter::RunSimpleString(char const*) + 335
9 0x7f3d9b8f12fd PyRun_SimpleStringFlags + 61
8 0x7f3d9b8f138c PyRun_StringFlags + 92
7 0x7f3d9b8f16e4 PyParser_ASTFromStringObject + 164
6 0x7f3d9b86d8e4 PyAST_FromNodeObject + 308
5 0x7f3d9b86e2b0 /usr/lib/libpython3.8.so.1.0(+0x14c2b0) [0x7f3d9b86e2b0]
4 0x7f3d9b870f78 /usr/lib/libpython3.8.so.1.0(+0x14ef78) [0x7f3d9b870f78]
3 0x7f3d9b86fab7 /usr/lib/libpython3.8.so.1.0(+0x14dab7) [0x7f3d9b86fab7]
2 0x7f3d9b784e5d /usr/lib/libpython3.8.so.1.0(+0x62e5d) [0x7f3d9b784e5d]
1 0x7f3d9b9498cd _PyUnicode_Ready + 29
0 0x7f3d9a86d960 /usr/lib/libpthread.so.0(+0x14960) [0x7f3d9a86d960]
( 3.269s) [ 7C462E80] :0 FATL| Signal: SIGSEGV

I don’t advise using the vtk level directly inside a catalyst Python script because it can be tricky to get things to work correctly within the MPI parallel context. It can be done but there can be problems.

In this case I believe the best way to get a depth map is instead to get the active view and then call CaptureDepthBuffer() on it.

I’m not using MPI and do not plan to (I specifically built paraview without MPI).

I was actually able to get this to work:

view = GetActiveView()
ss = vtk.vtkWindowToImageFilter()
ss.SetInputBufferTypeToZBuffer()
ss.SetInput(view.SMProxy.GetRenderWindow())
ss.Update()
writer = vtk.vtkXMLImageDataWriter()
writer.SetInputConnection(ss.GetOutputPort())
writer.SetFileName("z_buffer_%02d.vti" % view.ViewTime)
writer.Write()

by putting the above code in DoCoProcessing. If I wanted to use CaptureDepthBuffer() where would it go?

I tried putting something like that (CaptureDepthBuffer) in the Pipeline class itself and using ImageDataUniformGrid but I couldn’t figure out how to write it to a file. I was still getting expecting a proxy as input error when I passed the ImageDataUniformGrid to XMLImageDataWriter.

I’d really like to understand what the process is for writing a custom pipeline in python, but I don’t understand how the API works.