⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 volumerender.cpp

📁 vtk中一些类的具体定义方法
💻 CPP
字号:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastMIPFunction.h"
#include "vtkVolumeRayCastIsosurfaceFunction.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkVolume16Reader.h"
#include "vtkCamera.h"
#include "vtkDICOMImageReader.h"
#include "vtkImageCast.h"


int main()
{
	vtkRenderer *aRender = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(aRender);
	vtkRenderWindowInteractor *iRen = vtkRenderWindowInteractor::New();
		iRen->SetRenderWindow(renWin);
		

	vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
		reader->SetDataByteOrderToLittleEndian();
		reader->SetDirectoryName("E:\\Data\\chest");
		reader->SetDataSpacing(3.2, 3.2, 1.5);


	vtkImageCast *readerImageCast = vtkImageCast::New();
		readerImageCast->SetInput((vtkDataObject *)reader->GetOutput());
		readerImageCast->SetOutputScalarTypeToUnsignedChar();
		readerImageCast->ClampOverflowOn();
		
	

	vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
		opacityTransferFunction->AddPoint(0, 0.0);
		opacityTransferFunction->AddSegment(30, 0.1, 300, 0.9);
		opacityTransferFunction->AddPoint(700, 1.0);
		opacityTransferFunction->AddPoint(1000, 2.0);
		opacityTransferFunction->ClampingOn();	
		
	vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
		colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
		colorTransferFunction->AddRGBPoint(30.0, 0.7, 0.7, 0.7);
		colorTransferFunction->AddRGBPoint(300.0, 0.9, 0.9, 0.9);
		colorTransferFunction->AddRGBPoint(700.0, 1.0, 1.0, 1.0);
		colorTransferFunction->AddRGBPoint(1000.0, 2.0, 2.0, 2.0);

		vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
		volumeProperty->SetColor(colorTransferFunction);
		volumeProperty->SetScalarOpacity(opacityTransferFunction);
		volumeProperty->ShadeOn();
		volumeProperty->SetInterpolationTypeToLinear();

		vtkVolumeRayCastIsosurfaceFunction *isoFunction = vtkVolumeRayCastIsosurfaceFunction::New();
		isoFunction->SetIsoValue(150.0);
		
		vtkVolumeRayCastMIPFunction *mipFunction = vtkVolumeRayCastMIPFunction::New();		

		vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
		vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
		volumeMapper->SetVolumeRayCastFunction(compositeFunction);
		volumeMapper->SetInput(readerImageCast->GetOutput());


		vtkVolume *volume = vtkVolume::New();
		volume->SetMapper(volumeMapper);
		volume->SetProperty(volumeProperty);
     
		vtkCamera *camera = vtkCamera::New();
		camera->SetViewUp(0,0,1);
        camera->SetPosition(0,2,0);
		camera->SetFocalPoint(0,0,0);
		camera->Dolly(1.2);

		aRender->AddVolume(volume);
		aRender->SetBackground(0, 0, 0);

		renWin->SetSize(200, 200);
		renWin->Render();

		iRen->Initialize();
		iRen->Start();


		aRender->Delete();
		renWin->Delete();
		iRen->Delete();
		reader->Delete();
		opacityTransferFunction->Delete();
		colorTransferFunction->Delete();
		volumeMapper->Delete();
		volumeProperty->Delete();
		compositeFunction->Delete();
		volume->Delete();
		camera->Delete();

		return 0;
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -