# How to obtain the depth map of a scene in VTK?

**URL:** <https://discourse.vtk.org/t/how-to-obtain-the-depth-map-of-a-scene-in-vtk/14830>\
**Category:** Development\
**Created:** [November 6, 2024, 10:13am UTC](https://discourse.vtk.org/t/how-to-obtain-the-depth-map-of-a-scene-in-vtk/14830 "2024-11-06T10:13:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincac](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lincac/32/9404_2.png) [@Lincac](https://discourse.vtk.org/u/Lincac)\
**Post date:** [November 6, 2024, 10:13am UTC](https://discourse.vtk.org/t/how-to-obtain-the-depth-map-of-a-scene-in-vtk/14830/1 "2024-11-06T10:13:48Z")

</div>

What I obtained using the following method is clearly incorrect

```auto
	auto windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
	windowToImageFilter->SetInputBufferTypeToZBuffer();
	windowToImageFilter->SetInput(window);
	windowToImageFilter->Update();

```

---

<div class="post-metadata">

**Author:** ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)\
**Post date:** [November 6, 2024, 7:06pm UTC](https://discourse.vtk.org/t/how-to-obtain-the-depth-map-of-a-scene-in-vtk/14830/2 "2024-11-06T19:06:26Z")

</div>

Hello @Lincac

You can easily get the Z buffer data like this:

```auto
vtkNew<vtkFloatArray> depthValues;
int* size = window->GetSize();
window->GetZBufferData(0, size[0] - 1, 0, size[1] - 1, depthValues);

```
