体渲染-------颜色、不透明度调整

      看到3DSlicer和paraview中的颜色不透明度调整,你是否也有心动。经过多天摸索,发现这虽然是个小模块,可是如果真是自己做,还挺复杂(可能是自己VTK和QT学的还不够好)。

     但是CTK已经为我门做好了,我试着编译和写了个Demo,但是最新的CTK只支持VTK8的版本,如果是用的VTK7也想做一个类似的东西怎么办?那就是把VTK8的东西添加到VTK7上然后修改。具体如下:

vtkGUISupportQt工程中添加了QVTKOPenGLWidget类
vtkRenderingOpenGL2工程中修改了vtkOpenGLRenderWindow类
vtkRenderingCore工程中修改了vtkRenderer, vtkRenderWindow类

这些可以通过和vtk-7.1.1中对应的类比较一下。

最终结果如下:

体渲染-------颜色、不透明度调整_第1张图片

我把资源上传到了,大家下载吧。

具体Demo代码如下:

#include "testCTK.h"


testCTK::testCTK(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
 
	// Create transfer mapping scalar value to opacity.
	opacityTransferFunction = vtkSmartPointer::New();
	opacityTransferFunction->AddPoint(0.0, 0.0);
	opacityTransferFunction->AddPoint(36.0, 0.125);
	opacityTransferFunction->AddPoint(72.0, 0.25);
	opacityTransferFunction->AddPoint(108.0, 0.375);
	opacityTransferFunction->AddPoint(144.0, 0.5);
	opacityTransferFunction->AddPoint(180.0, 0.625);
	opacityTransferFunction->AddPoint(216.0, 0.75);
	opacityTransferFunction->AddPoint(255.0, 0.875);

	// Create transfer mapping scalar value to color.
	colorTransferFunction = vtkSmartPointer::New();
	colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
	colorTransferFunction->AddRGBPoint(36.0, 1.0, 0.0, 0.0);
	colorTransferFunction->AddRGBPoint(72.0, 1.0, 1.0, 0.0);
	colorTransferFunction->AddRGBPoint(108.0, 0.0, 1.0, 0.0);
	colorTransferFunction->AddRGBPoint(144.0, 0.0, 1.0, 1.0);
	colorTransferFunction->AddRGBPoint(180.0, 0.0, 0.0, 1.0);
	colorTransferFunction->AddRGBPoint(216.0, 1.0, 0.0, 1.0);
	colorTransferFunction->AddRGBPoint(255.0, 1.0, 1.0, 1.0);
	gradientOpacity = vtkSmartPointer::New();
		
	gradientOpacity->AddPoint(10, 0.0);
	gradientOpacity->AddPoint(90, 0.5);
	gradientOpacity->AddPoint(100, 1.0);
	 
		
	volumeProperty = vtkSmartPointer::New();
	volumeProperty->SetColor(colorTransferFunction);
	volumeProperty->SetScalarOpacity(opacityTransferFunction);
	volumeProperty->SetGradientOpacity(gradientOpacity);
	volumeProperty->ShadeOff();
	volumeProperty->SetInterpolationTypeToLinear();
	m_layout = new QGridLayout(this);
 
	m_ctkVTKVolumePropertyWidget = new ctkVTKVolumePropertyWidget(this);
	m_ctkVTKVolumePropertyWidget->setVolumeProperty(volumeProperty);
	m_ctkVTKVolumePropertyWidget->show();
	m_layout->addWidget(m_ctkVTKVolumePropertyWidget);
	
	setLayout(m_layout);
}

 

你可能感兴趣的:(CTK)