VTK读取DICOM图像

时间:2022-04-25 12:58:21
 转自:http://blog.sina.com.cn/s/blog_6ff958e30101a3wj.html 1.用vtkDICOMImageReader  #include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageActor.h"
#include "vtkDICOMImageReader.h"
#include "vtkImageShiftScale.h"
int main ()
{
    vtkDICOMImageReader *dcmReader = vtkDICOMImageReader::New();
    dcmReader->SetDirectoryName("E:\medicalimages\vhm");
    dcmReader->SetDataByteOrderToLittleEndian();
 double x,y,z;
 dcmReader->GetDataSpacing(x,y,z);
 dcmReader->SetDataSpacing(x,y,z);
 vtkImageShiftScale *shifter = vtkImageShiftScale::New();
 shifter->SetInputConnection(dcmReader->GetOutputPort());
 shifter->SetShift(70);
 shifter->SetScale(0.5);
 shifter->SetOutputScalarTypeToUnsignedChar();
 vtkImageActor *actor = vtkImageActor::New();
 actor->SetInput(shifter->GetOutput());
 vtkRenderer *aRender = vtkRenderer::New(); //设置绘制类
 aRender->AddActor(actor);
 vtkRenderWindow*renWin=vtkRenderWindow::New();//设置绘制窗口
 renWin->SetSize(500, 500); //设置背景颜色和绘制窗口大小
 renWin->AddRenderer(aRender); //装载绘制类
 vtkRenderWindowInteractor*iRen=vtkRenderWindowInteractor::New();//设置绘制窗口的交互
 iRen->SetRenderWindow(renWin); //装载绘制窗口
  renWin->Render(); //窗口进行绘制
 iRen->Initialize(); 
 iRen->Start(); //初始化并进行交互绘制
 
2.用vtkVolume16Reader,不限定DCM文件,不过文件后缀要以.1 .2 .3...来命名,工作有得做,而且不能读太多图片,vtkArray承载不了太多数据.而且图片会错位
            vtkVolume16Reader v16 = new vtkVolume16Reader();
            v16.SetDataDimensions(512, 512);
            v16.SetDataByteOrderToLittleEndian();
            v16.SetFilePrefix("F:\LiverGUI\SE4\IM");
            v16.SetImageRange(1, 100);
            v16.SetDataSpacing(1.0, 1.0, 1.0); 

3.读raw data...用vtkImageData,读取用vtkImageReader更快!具体查vtk 手册吧!
       private void volumeRendering(String filePath, int[] dims, int []shrinkFactor,vtkRenderWindow renWin)
        {
            //接口说明
            //1.filePath:dat文件名