I have a mesh model (.ply file) and I have rendered it with VTK and changed the camera viewpoint.
From the new camera viewpoint how can I render an RGB and a depth image? I think this might be raytracing, but not sure
EDIT
I want to generate a real depth map, as opposed to just a visualization of the depth. The visualization can be achieved by using values in Z buffer and scaling between 0-255 but this does not provide real depth information.
To get the real world depth from the camera I have done the following:
double z = render_win->GetZbufferDataAtPoint(x,y);
worldPicker->Pick(x, y, z, renderer);
worldPicker->GetPickPosition(coords);
double euclidean_distance = sqrt(pow((coords[0] - cam_pos[0]), 2) + pow(coords[1] - cam_pos[1], 2) + pow(coords[2] - cam_pos[2], 2));
where cam_pos is the camera position in real world coordinates. This seems to do the trick
Here is a short few lines if you already have the application set up and rendering, this has to be after the mesh has rendered at least once
// Screenshot
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
vtkSmartPointer<vtkWindowToImageFilter>::New();
windowToImageFilter->SetInput(renderWindow);
windowToImageFilter->SetMagnification(3); //set the resolution of the output image (3 times the current resolution of vtk render window)
windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
windowToImageFilter->Update();
vtkSmartPointer<vtkPNGWriter> writer =
vtkSmartPointer<vtkPNGWriter>::New();
writer->SetFileName("screenshot2.png");
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
writer->Write();
This is from the VTK Public Wiki
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With