医站点医维基

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1960|回复: 5

[VTK] VTK例子18-DicomReader转换成Volume显示

[复制链接]

336

主题

410

回帖

2806

积分

管理员

积分
2806

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2015-12-5 18:02:35 | 显示全部楼层 |阅读模式
DicomReader转换成Volume显示
#include "stdafx.h"
#include "stdafx.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageData.h"
#include "vtkProperty.h"
#include "vtkCellPicker.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkVolume16Reader.h"
#include "vtkCamera.h"
#include "vtkImageMapToColors.h"
#include "vtkImagePlaneWidget.h"
#include "vtkImageCast.h"
#include "vtkDICOMImageReader.h"
#include "vtkVolumeRayCastIsosurfaceFunction.h"
#include "vtkVolumeRayCastMIPFunction.h"
#include "vtkVolumeTextureMapper2D.h"
int main(int argc, char **argv)
{
    vtkRenderer *aRender = vtkRenderer::New();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(aRender);
    vtkRenderWindowInteractor *iRen = vtkRenderWindowInteractor::New();
    iRen->SetRenderWindow(renWin);
    vtkDICOMImageReader    *v16 = vtkDICOMImageReader::New();   
    v16->SetDataByteOrderToLittleEndian();
    v16->SetDirectoryName("C:/DATADIR/brain");
    v16->SetDataSpacing(0.8, 0.8, 1);
    //vtkImageShiftScale *shiftScale=vtkImageShiftScale::New();
    //shiftScale->SetInputConnection(v16->GetOutputPort());
    //shiftScale->SetScale(0.2);
    //shiftScale->SetOutputScalarTypeToUnsignedChar();
   
    vtkImageCast  *cast=vtkImageCast::New();
    cast->SetInput((vtkDataObject *)v16->GetOutput());
    cast->SetOutputScalarTypeToUnsignedShort();
    cast->ClampOverflowOn();
    //设置不透明度传递函数
    vtkPiecewiseFunction  *opacityTransferFunction=vtkPiecewiseFunction::New();
    opacityTransferFunction->AddPoint(100,0.0);
    opacityTransferFunction->AddPoint(255,1.0);
    //opacityTransferFunction->AddPoint(80, 0.0);
    //opacityTransferFunction->AddPoint(110, 0.3);
    //opacityTransferFunction->AddPoint(130, 0.9);
    //opacityTransferFunction->AddPoint(150, 1.0);
    //设置颜色传递函数
    vtkColorTransferFunction  *colorTransferFunction=vtkColorTransferFunction::New();
    colorTransferFunction->AddRGBPoint(2069,0xff/255.0, 0x31/255.0, 0x2e/255.0);
    colorTransferFunction->AddRGBPoint(2208,0xff/255.0, 0xff/255.0, 0xff/255.0);
    colorTransferFunction->AddRGBPoint(2473,0xff/255.0, 0xf4/255.0, 0x78/255.0);
    colorTransferFunction->AddRGBPoint(2745,0xff/255.0, 0xff/255.0, 0xff/255.0);
    colorTransferFunction->AddRGBPoint(3566,0xff/255.0, 0xff/255.0, 0xff/255.0);
    colorTransferFunction->AddRGBPoint(5063,0xfd/255.0, 0xff/255.0, 0xfb/255.0);
   
    //colorTransferFunction->AddRGBPoint(80.0, 0.0, 0.0, 0.0);
    //colorTransferFunction->AddRGBPoint(110.0,0.976, 0.961, 1.0);
    //colorTransferFunction->AddRGBPoint(130.0, 0.984, 0.322, 0.322);
    //colorTransferFunction->AddRGBPoint(150.0, 0.984, 0.322, 0.322);
    //设置梯度传递函数
    vtkPiecewiseFunction *gradientTransferFunction = vtkPiecewiseFunction::New();
    gradientTransferFunction->AddPoint(0, 1);
    gradientTransferFunction->AddPoint(500, 1);
    gradientTransferFunction-> AddSegment (600, 1, 1400, 1);
    gradientTransferFunction->AddPoint(1600, 0);
    vtkVolumeProperty  *volumeProperty=vtkVolumeProperty::New();
    //volumeProperty->SetColor(colorTransferFunction);
    //volumeProperty->SetScalarOpacity(opacityTransferFunction);
    //volumeProperty->SetGradientOpacity(gradientTransferFunction);
    //volumeProperty->ShadeOn();
    //volumeProperty->SetInterpolationTypeToLinear();
    volumeProperty->SetColor(colorTransferFunction);
    volumeProperty->SetScalarOpacity(opacityTransferFunction);
    volumeProperty->SetGradientOpacity(gradientTransferFunction);
    volumeProperty->SetInterpolationTypeToLinear();
    volumeProperty->SetAmbient(0.1);
    volumeProperty->SetDiffuse(0.9);
    volumeProperty->SetSpecular(0.2);
    volumeProperty->SetSpecularPower(10);
    volumeProperty->ShadeOn();
    //定义光线投射方法为合成体绘制方法
    vtkVolumeRayCastCompositeFunction   *raycastFunction=vtkVolumeRayCastCompositeFunction::New();
    //raycastFunction->SetCompositeMethodToInterpolateFirst();
    vtkVolumeRayCastMapper  *volumeMapper=vtkVolumeRayCastMapper::New();
    volumeMapper->SetVolumeRayCastFunction(raycastFunction);
    //volumeMapper->SetInput(shiftScale->GetOutput());
    volumeMapper->SetInput(cast->GetOutput());
    vtkVolume  *volume=vtkVolume::New();
    volume->SetProperty(volumeProperty);
    volume->SetMapper(volumeMapper);
    aRender->AddVolume(volume);
    aRender->SetBackground(0,0,0);
    renWin->SetSize(600,600);
    vtkCellPicker* picker=vtkCellPicker::New();
    picker->SetTolerance(0.005);
    vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
    planeWidgetX->SetInteractor(iRen);
    planeWidgetX->SetKeyPressActivationValue('x');
    planeWidgetX->SetPicker(picker);
    planeWidgetX->RestrictPlaneToVolumeOn();
    planeWidgetX->GetPlaneProperty()->SetColor(1,0,0);
    //planeWidgetX->SetTexturePlaneProperty(ipwProp);
    planeWidgetX->TextureInterpolateOff();
    planeWidgetX->SetResliceInterpolateToNearestNeighbour();
    planeWidgetX->SetInput(cast->GetOutput());
    planeWidgetX->SetPlaneOrientationToXAxes();
    planeWidgetX->SetSlicePosition(100);
    planeWidgetX->DisplayTextOn();
    planeWidgetX->On();
    planeWidgetX->InteractionOn();//启动交互
    vtkImageMapToColors* colorMap =    vtkImageMapToColors::New();
    colorMap->PassAlphaToOutputOff();
    colorMap->SetActiveComponent(0);
    colorMap->SetOutputFormatToLuminance();
    colorMap->SetInput(planeWidgetX->GetResliceOutput());//读取要显示的切面
//  colorMap->SetLookupTable(planeWidgetX->GetLookupTable());         
    iRen->Initialize();
    //renWin->Render();
    iRen->Start();
    v16->Delete();
    cast->Delete();
    planeWidgetX->Delete();
    opacityTransferFunction->Delete();
    colorTransferFunction->Delete();
    volumeProperty->Delete();
    raycastFunction->Delete();
    volumeMapper->Delete();
    volume->Delete();
    aRender->Delete();
    renWin->Delete();
    iRen->Delete();
    return 0;
}
18.png
回复

使用道具 举报

24

主题

462

回帖

1231

积分

版主

积分
1231

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-13 07:48:25 | 显示全部楼层
次贴无用,检定完毕!
回复

使用道具 举报

0

主题

399

回帖

804

积分

高级会员

积分
804

最佳新人

发表于 2016-5-18 21:59:11 | 显示全部楼层
看看学习一下!
回复

使用道具 举报

0

主题

396

回帖

791

积分

高级会员

积分
791

最佳新人

发表于 2016-5-19 09:13:10 | 显示全部楼层
谢谢啊版主
回复

使用道具 举报

119

主题

457

回帖

1524

积分

版主

积分
1524

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-23 01:55:24 | 显示全部楼层
厉害
回复

使用道具 举报

138

主题

436

回帖

1502

积分

版主

积分
1502

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-24 04:04:41 | 显示全部楼层
感谢分享感谢分享感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|关于我们|医维基|网站地图|Archiver|手机版|医疗之家 ( 沪ICP备2023001278号-1 )  

GMT+8, 2024-5-2 21:53 , Processed in 0.168465 second(s), 31 queries .

Designed by Medical BBS

快速回复 返回顶部 返回列表