Vtk 读取并显示图像:三种方法
用到 vtkJPEGReader 类。
包含的头文件:
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageViewer.h"
#include "vtkJPEGReader.h"
#include "vtkImageActor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkActor2D.h"
方法一:
使用 vtkImageMapper 和 vtkAcotor2D 来实现
int main(int argc, char **argv)
{
int extent[6];
vtkJPEGReader *m_reader = vtkJPEGReader::New();
m_reader->SetFileName("C:\Users\igst\Documents\美图图库\荷叶.jpg");
m_reader->SetDataByteOrderToLittleEndian();
m_reader->SetDataScalarTypeToUnsignedChar();
m_reader->SetFileDimensionality(3);
vtkImageMapper *mapper=vtkImageMapper::New();
mapper->SetInput(m_reader->GetOutput());
mapper->SetColorLevel(128);
mapper->SetColorWindow(256);
vtkActor2D *actor=vtkActor2D::New();
actor->SetMapper(mapper);
vtkRenderer *m_Renderer = vtkRenderer::New();
vtkRenderWindow *m_RenWin = vtkRenderWindow::New();
m_RenWin->AddRenderer(m_Renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(m_RenWin);
vtkInteractorStyleImage *interactor = vtkInteractorStyleImage::New();
iren->SetInteractorStyle(interactor);
m_Renderer->AddActor(actor);
m_Renderer->SetBackground(0.1, 0.2, 0.4);
m_RenWin->Render();
m_reader->GetDataExtent(extent);//如果把这条命令放在 Render()的前面则无效 m_RenWin-
>SetSize(extent[1],extent[3]);
iren->Initialize();
iren->Start();