VTK学习笔记(二)-----读入序列图像进行三维体渲染

 体绘制管线Imagedata->=VolumeMapper->Volume->Render->RenderWindow->RenderWindowInteractor

SetBlendModeToComposite()

Set/Get the blend mode.

The default mode is Composite where the scalar values are sampled through the volume and composited in a front-to-back scheme through alpha blending. The final color and opacity is determined using the color and opacity transfer functions.

Maximum and minimum intensity blend modes use the maximum and minimum scalar values, respectively, along the sampling ray. The final color and opacity is determined by passing the resultant value through the color and opacity transfer functions.

Additive blend mode accumulates scalar values by passing each value through the opacity transfer function and then adding up the product of the value and its opacity. In other words, the scalar values are scaled using the opacity transfer function and summed to derive the final color. Note that the resulting image is always grayscale i.e. aggregated values are not passed through the color transfer function. This is because the final value is a derived value and not a real data value along the sampling ray.

Average intensity blend mode works similar to the additive blend mode where the scalar values are multiplied by opacity calculated from the opacity transfer function and then added. The additional step here is to divide the sum by the number of samples taken through the volume. One can control the scalar range by setting the AverageIPScalarRange ivar to disregard scalar values, not in the range of interest, from the average computation. As is the case with the additive intensity projection, the final image will always be grayscale i.e. the aggregated values are not passed through the color transfer function. This is because the resultant value is a derived value and not a real data value along the sampling ray.

IsoSurface blend mode uses contour values defined by the user in order to display scalar values only when the ray crosses the contour. It supports opacity the same way composite blend mode does.

代码: 

void MainWindow::ImageSliceTo3D(){

//生成图像序列的文件名数组
vtkSmartPointer <vtkStringArray> fileArray = 
               vtkSmartPointer <vtkStringArray>::New();
char fileName[128];
for(int i = 1; i < 100; i++)
{
  sprintf(fileName, "VTK_test/Head/head%03d.jpg", i);
  std::string fileStr(fileName);
  fileArray->InsertNextValue(fileStr);
}
//读取JPG序列图像
vtkSmartPointer <vtkJPEGReader> reader = vtkSmartPointer<vtkJPEGReader>::New();
    reader->SetFileNames(fileArray);
    reader->Update();

vtkSmartPointer <vtkSmartVolumeMapper> volumeMapper=
                vtkSmartPointer <vtkSmartVolumeMapper>::New();
    volumeMapper->SetBlendModeToComposite();
    volumeMapper->SetInputData(reader->GetOutput());

vtkSmartPointer <vtkVolumeProperty> volumeProperty=
                vtkSmartPointer <vtkVolumeProperty>::New();
    volumeProperty->ShadeOff();//关闭阴影
    volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);

vtkSmartPointer <vtkPiecewiseFunction> compositeOpacity=
                vtkSmartPointer <vtkPiecewiseFunction>::New();
    compositeOpacity->AddPoint(0.0, 0);//设置像素值小于0的明度为0
    compositeOpacity->AddPoint(255.0, 1.0);//设置像素值大于255的明度为1
    volumeProperty->SetScalarOpacity(compositeOpacity);

vtkSmartPointer <vtkVolume> volume=
                 vtkSmartPointer <vtkVolume>::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);

vtkSmartPointer <vtkRenderer> render=vtkSmartPointer <vtkRenderer>::New();
    render->SetBackground(0.1, 0.4, 0.2);
    render->AddVolume(volume);

vtkSmartPointer <vtkRenderWindow> rw=vtkSmartPointer <vtkRenderWindow>::New();
    rw->SetSize(512,512);
    rw->AddRenderer(render);

vtkSmartPointer <vtkRenderWindowInteractor> rwi=vtkSmartPointer                 
              <vtkRenderWindowInteractor>::New();
    rwi->SetRenderWindow(rw);

    rw->Render();
    rwi->Initialize();
    rwi->Start();

}

效果:

​​​​​​​

参考链接:

https://kitware.github.io/vtk-examples/site/Cxx/VolumeRendering/SmartVolumeMapper/https://kitware.github.io/vtk-examples/site/Cxx/VolumeRendering/SmartVolumeMapper/

VTK: vtkVolumeMapper Class Referencehttps://vtk.org/doc/nightly/html/classvtkVolumeMapper.html#ac17e07d033289f756622d1e7b2a6a0ea

VTK 体绘制讨论_不透明度传输函数 - 一杯清酒邀明月 - 博客园 (cnblogs.com)https://www.cnblogs.com/ybqjymy/p/14239936.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值