Help! How create a "depth map" using ParaView (Is it possible)

Hello!
Is it possible to create а “Depth map” using ParaView?

(If you don’t know what is “Depth map”, you can read here = https://en.wikipedia.org/wiki/Depth_map )

There are no filters in the ParaView that could create “Depth Map” directly. (I think so, but may be i wrong.)
But I hope that this can be achieved using “Python Shell”. If this is really possible, then please tell me how to create a “Depth map”. And what needs to be done for this in detail and step by step.

Kind regards

Hi,
There is probably a easier way to do it but here is a solution using VTK python bindings:

import vtk
ss = vtk.vtkWindowToImageFilter()
ss.SetInputBufferTypeToZBuffer()
ss.SetInput(GetActiveView().SMProxy.GetRenderWindow())
writer = vtk.vtkXMLImageDataWriter()
writer.SetInputConnection(ss.GetOutputPort())
writer.SetFileName('/tmp/capture.vti')
writer.Write()

More information here: https://www.vtk.org/doc/nightly/html/classvtkWindowToImageFilter.html

Cheers,
Michael

1 Like

Thank you very much for your answer!

I tried this script, but it didn’t run in my “ParaView”.
I think that the reason is that there is no “VTK” in my “ParaView”. May be I wrong?
Although, if I enter a single string “import vtk”, it does not produce any errors.

One more question:
Where can I find detailed and step-by-step instructions on how to (properly) install the “VTK” for my “ParaView”?

ParaView cannot run without VTK, you already have it installed. What is the error in your ParaView?

I’m run this script.
I changed only one line.
instead:
writer.SetFileName('/tmp/capture.vti')
I put:
writer.SetFileName('C:/first.avi')

After that, the file (filename.avi) appeared in the specified directory (‘C:’). But this file isn’t opened by any video player.

Also, after run this script, appears that “error message”:

ERROR: In C:\bbd\7cc78367\build\superbuild\paraview\src\VTK\IO\XML\vtkXMLWriter.cxx, line 928
vtkXMLImageDataWriter (0000000012AED660): Error opening output file "C:irst.avi"

ERROR: In C:\bbd\7cc78367\build\superbuild\paraview\src\VTK\IO\XML\vtkXMLWriter.cxx, line 931
vtkXMLImageDataWriter (0000000012AED660): Error code "Invalid argument"

ERROR: In C:\bbd\7cc78367\build\superbuild\paraview\src\VTK\Common\ExecutionModel\vtkExecutive.cxx, line 784
vtkCompositeDataPipeline (0000000012DA1F00): Algorithm vtkXMLImageDataWriter(0000000012AED660) returned failure for request: vtkInformation (0000000012DD4340)
Debug: Off
Modified Time: 344927
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: -1

Besides that I tried to run this script on another machine (Windows).
Look at the screen of my error message below.
This is a code without any corrections:

And there is no “error messages” when I changed line in code like in first example:
writer.SetFileName('C:/first.avi')

And also the file (first.avi) appeared now in the specified directory (‘C:’). But this file isn’t opened by any video player.
The same thing happens when I try to replace it with:
writer.SetFileName('D:/first.jpg')

Hi,
Use vtkJPEGWriter instead of vtkXMLImageDataWriter if you want to save it in JPG format.

Cheers,
Michael

More important for me is getting a “video file” as a result. Because I work in ParaView with “Animation View”.

But also I need for obtain an image (for eg, jpeg), but this is not so important like get a video.
I tried to get an image. I change script as you said and used:
vtkJPEGWriter instead of vtkXMLImageDataWriter
But my “ParaView” gives an error. May be I did somethong wrong?

There is my new script:

import vtk
ss = vtk.vtkWindowToImageFilter()
ss.SetInputBufferTypeToZBuffer()
ss.SetInput(GetActiveView().SMProxy.GetRenderWindow())
writer = vtk.vtkJPEGWriter()
writer.SetInputConnection(ss.GetOutputPort())
writer.SetFileName('D:/second.jpg')
writer.Write()

There is my “error logs” (from 2 machines):

Warning: In C:\bbd\7cc78367\build\superbuild\paraview\src\VTK\IO\Image\vtkJPEGWriter.cxx, line 243
vtkJPEGWriter (0000000016306410): JPEGWriter only supports unsigned char input

1a

Is it possible to create a “depth map” for “video file” (from “Animation View”)?
Hope for your support.
Kind regards.

There is the Python script, that works without any errors.
This script write image in *.tif format.

import vtk
view = GetActiveView().GetRenderWindow()
buffer = vtk.vtkWindowToImageFilter()
buffer.SetInputBufferTypeToZBuffer()
buffer.SetInput(view)
buffer.Update()
writer = vtk.vtkTIFFWriter()
writer.SetInputConnection(buffer.GetOutputPort())
writer.SetFileName("D:/new.tif")
view.Render()
writer.Write()

But I have 2 questions:

1) The image, which is obtained as a result of the script - have “inversed colors”.
I’ll explain.
For “depth map”, it is important that the nearest parts of the object are white, and the farthest parts are black. But result of the execution of this script - the colors are the opposite (the nearest is black, and the farthest is white).

Question:
How to invert colors (using Python code)?

2) More important for me is getting a “video file” as a result. Because I work in ParaView with “Animation View”.

Question:
Is it possible to export а video (animation) from ParaView using a “Python shell”?
(For example, in *.avi or any other video format.)

I recommend GetActiveView().CaptureZBuffer().