我正在尝试从 3d 原始图像中获取 2d 切片,并且正在查看 vtkImageViewer2 上的输出,但我得到了一个空白窗口。
恐怕我不能让这段代码更短,因为这个管道中的每个步骤都是必要的,如此处所述: 我遵循的示例。
您还需要一个原始图像及其头文件FullHead.raw.gz,它使用FullHead.mhd作为头文件。
这是我的代码:
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkRenderWindowInteractor.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkImageReslice.h>
#include <vtkImageData.h>
#include <vtkLookupTable.h>
#include <vtkImageMapToColors.h>
#include <vtkImageViewer2.h>
#include <vtkMatrix4x4.h>
int main(){
vtkSmartPointer<vtkImageData> imagedata =
vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkRenderWindow> m_renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
std:string file_path = "FullHead.mhd";
vtkSmartPointer<vtkMetaImageReader> m_rawImageReader =
vtkSmartPointer<vtkMetaImageReader>::New();
m_rawImageReader->SetFileName(file_path.c_str());
imagedata = m_rawImageReader->GetOutput();
double * center = imagedata->GetCenter();
static double axialElements[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();
resliceAxes->DeepCopy(axialElements);
resliceAxes->SetElement(0, 3, center[0]);
resliceAxes->SetElement(1, 3, center[1]);
resliceAxes->SetElement(2, 3, center[2]);
vtkSmartPointer<vtkImageReslice> imageReslice =
vtkSmartPointer<vtkImageReslice>::New();
imageReslice->SetInputConnection(m_rawImageReader-
>GetOutputPort());
imageReslice->SetOutputDimensionality(2);
imageReslice->SetResliceAxes(resliceAxes);
imageReslice->SetInterpolationModeToLinear();
// Create a greyscale lookup table
vtkSmartPointer<vtkLookupTable> table =
vtkSmartPointer<vtkLookupTable>::New();
table->SetRange(0, 2000); // image intensity range
table->SetValueRange(0.0, 1.0); // from black to
white
table->SetSaturationRange(0.0, 0.0); // no color
saturation
table->SetRampToLinear();
table->Build();
// Map the image through the lookup table
vtkSmartPointer<vtkImageMapToColors> color =
vtkSmartPointer<vtkImageMapToColors>::New();
color->SetLookupTable(table);
color->SetInputConnection(imageReslice-
>GetOutputPort());
vtkSmartPointer<vtkImageViewer2> viewier =
vtkSmartPointer<vtkImageViewer2>::New();
viewier->SetInputData(color->GetOutput());
viewier->SetRenderWindow(m_renderWindow);
viewier->SetupInteractor(m_renderWindow-
>GetInteractor());
viewier->Render();
return 0;
}
看来我不完全理解这个管道。那么,有没有人知道如何正确地做到这一点?