vtk读取序列医学Dicom图片进行体绘制(vtkVolumeRayCastCompositeFunction类)

来源:互联网 发布:淘宝方舟生存进化steam 编辑:程序博客网 时间:2024/06/02 14:09

#include "vtkRenderer.h"#include "vtkRenderWindow.h"#include "vtkRenderWindowInteractor.h"#include "vtkActor.h"#include "vtkSmartPointer.h"#include "vtkProperty.h"#include "vtkCamera.h"#include "vtkDICOMImageReader.h"#include "vtkImageCast.h"#include "vtkPiecewiseFunction.h"#include "vtkColorTransferFunction.h"#include "vtkVolumeProperty.h"#include "vtkVolumeRayCastCompositeFunction.h"#include "vtkVolumeRayCastMapper.h"#include "vtkVolume.h"void main(){vtkSmartPointer<vtkDICOMImageReader>dicomImagereader=vtkSmartPointer<vtkDICOMImageReader>::New();dicomImagereader->SetDirectoryName("E:\\tougu");dicomImagereader->SetDataByteOrderToLittleEndian();vtkSmartPointer<vtkImageCast>readerImageCast=vtkSmartPointer<vtkImageCast>::New();readerImageCast->SetInputConnection(dicomImagereader->GetOutputPort());readerImageCast->SetOutputScalarTypeToUnsignedShort();readerImageCast->Update();vtkSmartPointer<vtkPiecewiseFunction>opactiyTransferFunction=vtkSmartPointer<vtkPiecewiseFunction>::New();opactiyTransferFunction->AddPoint(120,0.0);opactiyTransferFunction->AddPoint(250,1.0);opactiyTransferFunction->AddPoint(520,1.0);opactiyTransferFunction->AddPoint(650,0.0);vtkSmartPointer<vtkColorTransferFunction>colorTransferFunction=vtkSmartPointer<vtkColorTransferFunction>::New();colorTransferFunction->AddRGBPoint(120, 255/255.0, 98/255.0, 98/255.0);colorTransferFunction->AddRGBPoint(250,  255/255.0, 255/255.0, 180/255.0);colorTransferFunction->AddRGBPoint(520, 1.0, 1.0, 1.0);colorTransferFunction->AddRGBPoint(650, 1.0, 1.0, 1.0);vtkSmartPointer<vtkPiecewiseFunction>gradientTransferFunction=vtkSmartPointer<vtkPiecewiseFunction>::New();gradientTransferFunction->AddPoint(120, 2.0);gradientTransferFunction->AddPoint(250, 2.0);gradientTransferFunction->AddPoint(520, 0.1); gradientTransferFunction->AddPoint(650, 0.1);vtkSmartPointer<vtkVolumeProperty>volumeProperty=vtkSmartPointer<vtkVolumeProperty>::New();volumeProperty->SetColor(colorTransferFunction);volumeProperty->SetScalarOpacity(opactiyTransferFunction);volumeProperty->SetGradientOpacity(gradientTransferFunction);volumeProperty->ShadeOn();//阴影//volumeProperty->SetInterpolationTypeToLinear();//直线与样条插值之间逐发函数volumeProperty->SetAmbient(0.2);//环境光系数volumeProperty->SetDiffuse(0.9);//漫反射volumeProperty->SetSpecular(0.2);//高光系数volumeProperty->SetSpecularPower(10);//高光强度vtkSmartPointer<vtkVolumeRayCastCompositeFunction>compositeRaycastFunction=vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();vtkSmartPointer<vtkVolumeRayCastMapper>volumeMapper=vtkSmartPointer<vtkVolumeRayCastMapper>::New();volumeMapper->SetVolumeRayCastFunction(compositeRaycastFunction);//载入体绘制方法volumeMapper->SetInputConnection(readerImageCast->GetOutputPort());/*fixedPointVolumeMapper=vtkFixedPointVolumeRayCastMapper::New();fixedPointVolumeMapper->SetInput(dicomImagereader->GetOutput());*/vtkSmartPointer<vtkVolume>volume=vtkSmartPointer<vtkVolume>::New();volume->SetMapper(volumeMapper);volume->SetProperty(volumeProperty);//设置体属性vtkSmartPointer<vtkRenderer>ren1=vtkSmartPointer<vtkRenderer>::New();ren1->AddVolume(volume);ren1->SetBackground(1,1,1);vtkSmartPointer<vtkRenderWindow>renWin=vtkSmartPointer<vtkRenderWindow>::New();renWin->AddRenderer(ren1);renWin->SetSize(800,800);vtkSmartPointer<vtkRenderWindowInteractor>iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();iren->SetRenderWindow(renWin);renWin->Render();iren->Start();}

读取序列的Dicom图片并用vtkVolumeRayCastCompositeFunction进行体绘制,其关键就在于不透明函数参数,以及颜色参数的设置




0 0
原创粉丝点击