VTK 加在DICOM及3D纹理映射法

#include "vtkDICOMImageReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageCast.h"
#include "vtkBMPReader.h"
#include "vtkImageSobel3D.h"
#include "vtkImageFFT.h"
#include "vtkImageRFFT.h"
#include "vtkImageButterworthHighPass.h"
#include "vtkImageButterworthLowPass.h"
#include "vtkImageMedian3D.h"
#include "vtkImageContinuousErode3D.h"
#include "vtkImageContinuousDilate3D.h"
#include "vtkImageDilateErode3D.h"
#include "vtkImageAnisotropicDiffusion3D.h"
#include "vtkImageRange3D.h"
#include "vtkImageVariance3D.h"
#include "vtkImageGaussianSmooth.h"
#include "vtkImageGradient.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkDataObjectWriter.h"
#include "vtkCutter.h"
#include "vtkPlane.h"
#include "vtkOpenGLVolumeTextureMapper3D.h"
#include "vtkLookupTable.h"
#include "vtkClipVolume.h"
#include "vtkClipDataSet.h"
#include "vtkImageClip.h"
#include "vtkStructuredGridClip.h"
void main()
{
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
	renWin->AddRenderer(ren);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);
  vtkDICOMImageReader   *reader =  vtkDICOMImageReader::New();
	reader->SetDataByteOrderToLittleEndian();
	reader->SetDirectoryName("E://CT ");
	reader->SetDataSpacing(3.2, 3.2, 1.5);
	reader->SetDataOrigin(0.0, 0.0, 0.0);
  vtkPlane *plane=vtkPlane::New();
	//plane->SetOrigin(((vtkDataObject *)readerImageCast->GetOutput())->GetCenter());//设置切平面的原点
	plane->SetNormal(-1,0,0);//设置切平面的法向量
	plane->SetOrigin(100,0,0);
  vtkImageCast *readerImageCast = vtkImageCast::New();
	readerImageCast->SetInputConnection(reader->GetOutputPort());
	readerImageCast->SetOutputScalarTypeToUnsignedChar();
	readerImageCast->ClampOverflowOn();

  vtkStructuredGridClip *clipper=vtkStructuredGridClip::New();
    clipper->SetInputConnection(readerImageCast->GetOutputPort());
//    clipper->SetClipFunction(plane);
//    clipper->InsideOutOn();

  reader->Delete();

  vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
  //定义一个分段线性函数映射。 为体绘制透视图的转换函数
    opacityTransferFunction->AddPoint(  20.0 , 0.0);
    opacityTransferFunction->AddPoint(  100.0, 0.15);
    opacityTransferFunction->AddPoint(  120, 0.2);
    opacityTransferFunction->AddPoint(  130, 0.3);
    opacityTransferFunction->AddPoint(  200, 0.3);
    opacityTransferFunction->AddPoint(  255,  1.0);

  vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
  //伪彩的添加
	colorTransferFunction->AddRGBPoint(0.0,0.5,  0.0,  0.0);
    colorTransferFunction->AddRGBPoint(60.0, 0.8,  0.5,  0.5);
    colorTransferFunction->AddRGBPoint(128.0, 0.6,  0.2, 0.3);
    colorTransferFunction->AddRGBPoint(196.0, 0.81, 0.27, 0.1);
    colorTransferFunction->AddRGBPoint(255.0, 0.9,  0.9,  0.9);

  vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
  //represents the common properties for rendering a volume
  //设定一个体绘容器的属性
	volumeProperty->SetColor(colorTransferFunction);
	//Set the color of a volume to an RGB transfer function for the component indicated by index
	volumeProperty->SetScalarOpacity(opacityTransferFunction);
	//scalar(梯度) 不透明度属性
	volumeProperty->ShadeOn();
	//阴影If shading is turned on, the mapper may perform shading calculations
	volumeProperty->SetInterpolationTypeToLinear();
	//Set the interpolation(添写,插补) type for sampling a volume.
	volumeProperty->SetAmbient(0.2);
    volumeProperty->SetDiffuse(0.9);
    volumeProperty->SetSpecular(0.2);
    volumeProperty->SetSpecularPower(10);

  //纹理映射法
  vtkOpenGLVolumeTextureMapper3D  *volumeMapper=vtkOpenGLVolumeTextureMapper3D::New();
    volumeMapper->SetInputConnection(readerImageCast->GetOutputPort());


  vtkVolume *volume = vtkVolume::New();
	//表示透示图中的一组三维数据
	  volume->SetMapper(volumeMapper);
	  volume->SetProperty(volumeProperty);

	ren->AddVolume(volume);
	ren->SetBackground(1, 1, 1);
	renWin->SetSize(600, 600);
	renWin->Render();

	iren->Initialize();
	iren->Start();
    ren->ResetCameraClippingRange ();

	volumeMapper->Delete();
	readerImageCast->Delete();
	iren->Delete();
	ren->Delete();
	renWin->Delete();
	opacityTransferFunction->Delete();
	volumeProperty->Delete();
//    gs->Delete();
	volume->Delete();
	colorTransferFunction->Delete();
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值