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

📄 volum.cxx

📁 这是个VTK和ITK编写的体绘制的例子
💻 CXX
字号:
//
//知周
//

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkStructuredPointsReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"

#pragma comment (lib, "vtkFiltering.lib")
#pragma comment (lib, "vtkRendering.lib")
#pragma comment (lib, "vtkIO.lib")
#pragma comment (lib, "vtkVolumeRendering.lib")

int main (int argc, char **argv)
{
	vtkRenderer *aRenderer = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(aRenderer);
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
	
	vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
	reader->SetFileName(".\\ironProt.vtk");

	vtkVolumeRayCastCompositeFunction *ComositeFun = vtkVolumeRayCastCompositeFunction::New();
	vtkVolumeRayCastMapper *VolMapper = vtkVolumeRayCastMapper::New();
	VolMapper->SetInputConnection(reader->GetOutputPort());
	VolMapper->SetVolumeRayCastFunction(ComositeFun);	
	vtkVolume *Volume = vtkVolume::New();
	Volume->SetMapper(VolMapper);

	vtkColorTransferFunction *gTFun = vtkColorTransferFunction::New();
	gTFun->AddRGBSegment(128.0,126/255.0,16/255.0,16/255.0,	255.0,64/255.0,255/255.0,16/255.0);	
	vtkVolumeProperty *VolProperty = vtkVolumeProperty::New();
	VolProperty->SetColor(gTFun);
	

	vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
	oTFun->AddSegment(48,0.0,256,1.0);//改变第一个数据,可以得到不同的体透明度
	VolProperty->SetScalarOpacity(oTFun);
	VolProperty->SetInterpolationTypeToLinear();
	VolProperty->ShadeOn();
	Volume->SetProperty(VolProperty);
	
	aRenderer->AddActor(Volume);
	aRenderer->SetBackground(1,1,1);
	renWin->SetSize(640,480);
	aRenderer->ResetCameraClippingRange();
	iren->Initialize();
	iren->Start(); 

	aRenderer->Delete();
	renWin->Delete();
	iren->Delete();
	
	return 0;
}

⌨️ 快捷键说明

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