VTK 生成完全不透明体渲染的问题

问题描述

你好, 我目前正在尝试使用 VTK 及其体积渲染算法

我想创建一个体积,其中部分是透明的、半透明的,有些是不透明/实心的。 我测试了所有非结构化网格体积渲染器,但对于每个渲染器,我都无法得到完全不透明的结果。

我的代码

vtkNew<vtkPiecewiseFunction> opacityTransferFunction;  
opacityTransferFunction->AddPoint(0,1.0);
opacityTransferFunction->AddPoint(255,1.0);

vtkNew<vtkColorTransferFunction> colorTransferFunction;
colorTransferFunction->AddRGBPoint(0,0.0,1.0);
colorTransferFunction->AddRGBPoint(255,1.0,0.0);

vtkNew<vtkVolumeProperty> volumeProperty;
volumeProperty->ShadeOff();
volumeProperty->SetInterpolationType(0);
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);

vtkNew<vtkOpenGLProjectedtetrahedraMapper> volumeMapper;
/// Adding a dataset with pointwise scalar array all set to 255
volumeMapper->SetInputData(dataset);

vtkNew<vtkVolume> volume;
volume->SetProperty(volumeProperty);
volume->SetMapper(volumeMapper);

renderer->AddVolume(volume);

这里是问题的截图:-

enter image description here

如您所见,区域 1 的不透明度高于区域 2,因为要穿透的材料更多。此外,您还可以看到区域 1 标签旁边的线,这些线位于卷后面,根本不应该被看到。

如果你能帮助我,我会很高兴,谢谢!

解决方法

opacityTransferFunction 决定了您要渲染的图像部分。 在您编写的代码中,您渲染了 0 到 255 之间的阈值,并且不透明度为 1, 因此渲染的结果都是不透明的。 以下代码可能有效

vtkNew<vtkPiecewiseFunction> opacityTransferFunction;  
opacityTransferFunction->AddPoint(0,0.0);
opacityTransferFunction->AddPoint(50,0.2);
opacityTransferFunction->AddPoint(150,0.5);
opacityTransferFunction->AddPoint(255,1.0);

vtkNew<vtkColorTransferFunction> colorTransferFunction;
colorTransferFunction->AddRGBPoint(0,0.0,0.0);
colorTransferFunction->AddRGBPoint(50,0.2,0.3);
colorTransferFunction->AddRGBPoint(150,0.4,0.6);
colorTransferFunction->AddRGBPoint(255,1.0,1.0);