C++ 如何在C++;用QT?

C++ 如何在C++;用QT?,c++,qt,vtk,C++,Qt,Vtk,我正在使用VTK渲染深度图像,并设置了连接。但是,当将渲染器的输出保存为png文件时,我得到一个警告,即PngWriter只支持无符号字符和无符号短输入 vtkSmartPointer<vtkPNGWriter> imageWriter = vtkSmartPointer<vtkPNGWriter>::New(); imageWriter->SetInputConnection(zFilter->GetOutputPort()); imageWriter-&g

我正在使用VTK渲染深度图像,并设置了连接。但是,当将渲染器的输出保存为png文件时,我得到一个警告,即PngWriter只支持无符号字符和无符号短输入

vtkSmartPointer<vtkPNGWriter> imageWriter = vtkSmartPointer<vtkPNGWriter>::New();
imageWriter->SetInputConnection(zFilter->GetOutputPort());
imageWriter->SetFileName( qPrintable(QString("outdepth_%1.png").arg(i)) );
imageWriter->Write();
vtkSmartPointer imageWriter=vtkSmartPointer::New();
imageWriter->SetInputConnection(zFilter->GetOutputPort());
imageWriter->SetFileName(qPrintable(QString(“outdepth_%1.png”).arg(i));
imageWriter->Write();
这是我的代码(在一个循环中),基本上我需要像
(unsigned short)zFilter->GetOutputPort()
-这当然没有任何意义,它只是为了澄清应该浇铸什么

您可以使用它将图像从
zFilter
生成的标量类型转换为
unsigned short

为此,您可以使用
vtkImageCast::SetOutputScalarTypeToUnsignedShort()

您的代码将如下所示:

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