简介
vtkImageViewer2是用于显示2D图像的便捷类。它将vtkRenderWindow、vtkRenderer、vtkImageActor和vtkImageMapToWindowLevelColors中的功能打包为一个易于使用的类。此类还创建了一个图像交互器样式(vtkInteractiorStyleImage),该样式允许缩放和平移图像,并支持图像上的交互式窗口/级别操作。注意,vtkImageViewer2只是这些类的包装器。(附CT数据)
代码
下面展示 代码实现
。
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
#include "vtkSmartPointer.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellPicker.h"
#include "vtkCommand.h"
#include "vtkImageActor.h"
#include "vtkImageReslice.h"
#include "vtkInteractorStyleImage.h"
#include "vtkImageMapToColors.h"
#include "vtkImagePlaneWidget.h"
#include "vtkImageReader.h"
#include "vtkInteractorEventRecorder.h"
#include "vtkLookupTable.h"
#include "vtkOutlineFilter.h"
#include "vtkDICOMImageReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkPlaneSource.h"
#include "vtkPlane.h"
#include "vtkResliceCursorActor.h"
#include "vtkResliceCursorPolyDataAlgorithm.h"
#include "vtkResliceCursor.h"
#include "vtkResliceCursorWidget.h"
#include "vtkResliceCursorLineRepresentation.h"
#include "vtkBiDimensionalWidget.h"
#include "vtkNIFTIImageReader.h"
#include"vtkAxesActor.h"
#include"vtkTransform.h"
#include"vtkTextActor.h"
#include"vtkProperty2D.h"
#include"vtkImageViewer2.h"
int main()
{
vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
reader->SetFileName("..\\volume-0.nii");
reader->Update();
double range[2] = {};
reader->GetOutput()->GetScalarRange(range);
vtkSmartPointer<vtkRenderer> ren[4];
vtkSmartPointer<vtkImageViewer2> viewer[3];
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->SetMultiSamples(0);
for (int i = 0; i < 4; i++)
{
ren[i] = vtkSmartPointer<vtkRenderer>::New();
renWin->AddRenderer(ren[i]);
}
int dims[3] = {};
reader->GetOutput()->GetDimensions(dims);
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
for (size_t i = 0; i < 3; i++)
{
viewer[i] = vtkSmartPointer<vtkImageViewer2>::New();
viewer[i]->SetInputData(reader->GetOutput());
viewer[i]->SetRenderWindow(renWin);
viewer[i]->SetRenderer(ren[i]);
viewer[i]->SetColorWindow(range[1]);
viewer[i]->SetColorLevel((range[0] + range[1]) / 2.0);
viewer[i]->SetupInteractor(iren);
}
viewer[0]->SetSliceOrientationToXY();
viewer[1]->SetSliceOrientationToXZ();
viewer[2]->SetSliceOrientationToYZ();
viewer[0]->SetSlice(dims[2] / 2);
viewer[1]->SetSlice(dims[1] / 2);
viewer[2]->SetSlice(dims[0] / 2);
ren[0]->SetBackground(0.1, 0.1, 0.1);
ren[1]->SetBackground(0.1, 0.1, 0.1);
ren[2]->SetBackground(0.1, 0.1, 0.1);
ren[3]->SetBackground(0.1, 0.1, 0.1);
renWin->SetSize(600, 600);
ren[0]->SetViewport(0, 0, 0.5, 0.5);
ren[1]->SetViewport(0.5, 0, 1, 0.5);
ren[2]->SetViewport(0, 0.5, 0.5, 1);
ren[3]->SetViewport(0.5, 0.5, 1, 1);
renWin->Render();
ren[3]->GetActiveCamera()->Elevation(110);
ren[3]->GetActiveCamera()->SetViewUp(0, 0, -1);
ren[3]->GetActiveCamera()->Azimuth(45);
ren[3]->GetActiveCamera()->Dolly(1.15);
ren[3]->ResetCameraClippingRange();
vtkSmartPointer< vtkInteractorStyleImage > style = vtkSmartPointer< vtkInteractorStyleImage >::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
return EXIT_SUCCESS;
}
链接: 百度网盘
提取码:3bf2