0
votes

I am using VTK to render an depth image, and have set up the connections. However, when it comes to saving the output of the renderer as png file I get the warning, that the PngWriter only supports unsigned char and unsigned short inputs.

vtkSmartPointer<vtkPNGWriter> imageWriter = vtkSmartPointer<vtkPNGWriter>::New();
imageWriter->SetInputConnection(zFilter->GetOutputPort());
imageWriter->SetFileName( qPrintable(QString("outdepth_%1.png").arg(i)) );
imageWriter->Write();

This is my code (inside a loop) , basically I need sth like (unsigned short) zFilter->GetOutputPort() - which of course does not makye any sense at all, it is just for clarification what should be casted

1

1 Answers

1
votes

You can use vtkImageCast to cast image from scalar type that zFilter produces to unsigned short.

For that purpose you can use vtkImageCast::SetOutputScalarTypeToUnsignedShort().

Your code will then look something like this:

vtkSmartPointer<vtkImageCast> cast = vtkSmartPointer<vtkImageCast>::New();
cast->SetInputConnection(zFilter->GetOutputPort());
cast->SetOutputScalarTypeToUnsignedShort();
vtkSmartPointer<vtkPNGWriter> imageWriter = vtkSmartPointer<vtkPNGWriter>::New();
imageWriter->SetInputConnection(cast->GetOutputPort());
imageWriter->Write();