vtk实现两个相同的DICOM文件同步旋转

vtk实现两个相同的DICOM文件同步旋转

vtk工具包在C++中的应用:

  • 简介
  • 代码块

目录

  • vtk实现两个相同的DICOM文件同步旋转
    • 目录
    • 简介
    • 代码块


简介

DICOM标准的推出与实现,大大简化了医学影像信息交换的实现,推动了远程放射学系统、图像管理与通信系统(PACS)的研究与发展,并且由于DICOM的开放性与互联性,使得与其它医学应用系统(HIS、RIS等)的集成成为可能。

使用同一个相机(vtkCamera)实现两幅DICOM三维重建图像的同步旋转。


代码块

(代码块语法遵循标准markdown代码:)

#include <vtkDICOMImageReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkPolyDataNormals.h>
#include <vtkProperty.h>
#include <vtkContourFilter.h>
#include <vtkStripper.h>
#include <vtkImageActor.h>
#include <vtkInteractorStyle.h>
#include<vtkSmartPointer.h>


int main()
{
    //读取DICOM数据
    vtkDICOMImageReader   *reader =  vtkDICOMImageReader::New();
    reader->SetDataByteOrderToLittleEndian();//设置图像数据的字端序转换成小字端序
    reader->SetDirectoryName("D://DicomImages/xiongqiang2/");
    reader->SetDataSpacing(1.0,1.0,0.48);//设置图像像素间距和序列间距
    reader->SetDataOrigin(0.0, 0.0, 0.0);//设置基准点
    //轮廓连线算法
    vtkContourFilter *boneExtractor=vtkContourFilter::New() ;
    boneExtractor->SetInputConnection(reader->GetOutputPort()) ;
    boneExtractor->SetValue(0,500) ;
    vtkPolyDataNormals *boneNormals=vtkPolyDataNormals::New() ;
    boneNormals->SetInputConnection(boneExtractor->GetOutputPort()) ;
    boneNormals->SetFeatureAngle(60.0) ;//法向量
    vtkStripper *boneStripper=vtkStripper::New() ;//三角几何图元
    boneStripper->SetInputConnection(boneNormals->GetOutputPort()) ;
    vtkPolyDataMapper *boneMapper=vtkPolyDataMapper::New() ;
    boneMapper->SetInputConnection(boneStripper->GetOutputPort()) ;
    boneMapper->ScalarVisibilityOff() ;
    vtkActor *bone=vtkActor::New() ;
    bone->SetMapper(boneMapper) ;
    bone->GetProperty()->SetDiffuseColor(1,1,1) ;
    bone->GetProperty()->SetOpacity(1) ;
    //-----------------------显示三维图像-----------------------------//
    vtkCamera *aCamera3D=vtkCamera::New() ;
    aCamera3D->SetViewUp(0,0,-1) ;
    aCamera3D->SetPosition(0,1,0) ;
    aCamera3D->SetFocalPoint(0,0,0) ;
    aCamera3D->ComputeViewPlaneNormal() ;
    vtkSmartPointer<vtkRenderer> rendererOld = 
        vtkSmartPointer<vtkRenderer>::New();
    rendererOld->AddActor(bone) ;
    rendererOld->SetActiveCamera(aCamera3D) ;
    rendererOld->ResetCamera() ;
    aCamera3D->Dolly(1) ;   
    rendererOld->SetBackground(1.0,0.96,0.56) ;
    rendererOld->SetViewport(0.0,0.0,0.5,1.0);
    vtkSmartPointer<vtkRenderer> rendererNew = 
        vtkSmartPointer<vtkRenderer>::New();
    rendererNew->AddActor(bone) ;
    rendererNew->SetActiveCamera(aCamera3D) ;
    rendererNew->ResetCamera() ;
    aCamera3D->Dolly(1) ;   
    rendererNew->SetBackground(0.7,0.9,1.0) ;
    rendererNew->SetViewport(0.5,0.0,1.0,1.0);
    vtkRenderWindow *renWin=vtkRenderWindow::New() ;
    renWin->AddRenderer(rendererOld) ;
    renWin->AddRenderer(rendererNew) ;
    renWin->SetSize(800,400) ;
    rendererOld->ResetCameraClippingRange() ;
    rendererNew->ResetCameraClippingRange() ;
    vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New() ;
    iren->SetRenderWindow(renWin) ;
    vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();//交互摄像机
    iren->SetInteractorStyle(style);
    iren->Initialize() ;
    iren->Start() ;
    style->Delete();
    iren->Delete();
    aCamera3D->Delete();
    renWin->Delete();
    bone->Delete();
    boneMapper->Delete();
    boneStripper->Delete();
    boneNormals->Delete();
    boneExtractor->Delete();
    reader->Delete();
    return 0 ;
}

注:第一次写博客,只是先试一下。


你可能感兴趣的:(vtk三维重建,医学图像处理,C++,vtk,医学图像处理,DICOM)