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

📄 raycast.cpp

📁 vtk中一些类的具体定义方法
💻 CPP
字号:


#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.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 "vtkImageCast.h"
#include "vtkVolumeRayCastIsosurfaceFunction.h"
#include "vtkVolumeRayCastMIPFunction.h"
#include "vtkVolumeTextureMapper2D.h"


int main()
{
	vtkRenderer *aRender = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(aRender);
	vtkRenderWindowInteractor *iRen = vtkRenderWindowInteractor::New();
		iRen->SetRenderWindow(renWin);
		
		vtkVolume16Reader *reader = vtkVolume16Reader::New();
		reader->SetDataDimensions(64,64);
		reader->SetDataByteOrderToLittleEndian();
		reader->SetFilePrefix ("E://Data/headsq/quarter");
		reader->SetImageRange(1, 93);
		reader->SetDataSpacing (1.0, 1.0, 0.48);
					
		
		vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();		

		opacityTransferFunction->AddPoint(0, 0.0);
		opacityTransferFunction->AddPoint(500, 0.0);
		opacityTransferFunction->AddPoint(550, 0.5);
		opacityTransferFunction->AddPoint(600, 0.73);
		opacityTransferFunction->AddPoint(900, 0.9);
		opacityTransferFunction->AddPoint(1300, 2.0);
		opacityTransferFunction->ClampingOn();		
		
		vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
		colorTransferFunction->AddRGBPoint(0.0,0.0,0.0,0.0);
			colorTransferFunction->AddRGBPoint(500.0,0.1, 0.1, 0.1);
			colorTransferFunction->AddRGBPoint(550.0,0.5,0.5,0.5);
			colorTransferFunction->AddRGBPoint(600.0,0.7,0.7,0.7);
			colorTransferFunction->AddRGBPoint(900.0,0.85,0.85,0.85);
			colorTransferFunction->AddRGBPoint(1300, 1.0, 1.0, 1.0);
		
		vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
		volumeProperty->SetColor(colorTransferFunction);
		volumeProperty->SetScalarOpacity(opacityTransferFunction);
		volumeProperty->ShadeOn();
		volumeProperty->SetInterpolationTypeToLinear();

		vtkVolumeRayCastIsosurfaceFunction *isoraycastFunction = vtkVolumeRayCastIsosurfaceFunction::New();
			isoraycastFunction->SetIsoValue(55);

		vtkVolumeRayCastMIPFunction *mipraycastFunction = vtkVolumeRayCastMIPFunction::New();
			mipraycastFunction->SetMaximizeMethodToOpacity();
			mipraycastFunction->SetMaximizeMethodToScalarValue();

		vtkVolumeRayCastCompositeFunction *raycastFunction = vtkVolumeRayCastCompositeFunction::New();
		vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
		volumeMapper->SetVolumeRayCastFunction(isoraycastFunction);
		volumeMapper->SetInput(reader->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->SetActiveCamera(camera);
		aRender->AddVolume(volume);
		aRender->SetBackground(0, 0, 0);

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

		iRen->Initialize();
		iRen->Start();
		return 0;
		
}

⌨️ 快捷键说明

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