VTK读写数据
2023-12-21 22:45:50
png格式图片转jpg
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
#include <vtkSmartPointer.h>
#include <vtkPNGReader.h>
#include <vtkJPEGWriter.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
//测试文件:data/VTK-logo.png
int main(int argc, char* argv[])
{
char * fileName = (char*)"D:/VTKCODE/testvtk01/1.png";
//读取PNG图像
vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
reader->SetFileName(fileName);
vtkSmartPointer<vtkInteractorStyleImage> style = vtkSmartPointer<vtkInteractorStyleImage>::New();
//显示读取的单幅PNG图像
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetInteractorStyle(style);
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
imageViewer->SetSize(640, 480);
imageViewer->GetRenderWindow()->SetWindowName("ReadWriteSingleImage");
//保存成JPG图像
vtkSmartPointer<vtkJPEGWriter> writer = vtkSmartPointer<vtkJPEGWriter>::New();
writer->SetFileName("VTK-logo.jpg");
writer->SetInputConnection(reader->GetOutputPort());
writer->Write();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
显示序列化图片:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
#include <stdio.h>
#include <vtkSmartPointer.h>
#include <vtkStringArray.h>
#include <vtkJPEGReader.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
using namespace std;
int main()
{
//生成文件序列组名
vtkSmartPointer <vtkStringArray> fileArray =
vtkSmartPointer <vtkStringArray>::New();
char fileName[128];
for (int i = 1; i < 100; i++)
{
sprintf_s(fileName, "D:/VTKCODE/testvtk01/Head/head%03d.jpg", i);
string fileStr(fileName);
fileArray->InsertNextValue(fileStr);
}
//读取JPG序列图像
vtkSmartPointer <vtkJPEGReader> reader =
vtkSmartPointer <vtkJPEGReader>::New();
reader->SetFileNames(fileArray);
//显示
vtkSmartPointer<vtkImageViewer2> viewer =
vtkSmartPointer<vtkImageViewer2>::New();
viewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> interact =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
//默认选择第50张切片
viewer->SetSlice(50);
//viewer->SetSliceOrientationToXY();
viewer->SetSliceOrientationToXZ();
//viewer->SetSliceOrientationToYZ();
viewer->SetupInteractor(interact);
viewer->Render();
interact->Start();
return 0;
}
文章来源:https://blog.csdn.net/weixin_48657573/article/details/135126439
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!