vtk 3维render 提升速度几种方法

vtk体绘制速度提升几点小Tip

1. 使用vtkImageResample,通过线性插值方式对输入的数据进行重新采样,来修改输出的数据的spacing及extent。一般使用

方法: SetAxisMagnificationFactor进行设置。

   SetInput(reader.GetOutput());

  SetAxisMagnificationFactor(0,  0.5);

  SetAxisMagnificationFactor(1,  0.5);

     SetAxisMagnificationFactor(2,  0.5);//重新设置x,y,z方向上的space。

   适度放宽space,降低图形的显示质量,可以读取稍大的数据。

2. 对读入的数据采用vtkImageShrink3D进行subsampling(二次抽样),可以使加速读入数据。一般使用方法:SetShrinkFactors(3,3,3)和AveragingOn。SetShrinkFactors方法 定义了x,y,z 抽样精密度 如果都是0,没必要用这个函数。如果subsampling得值过大,那么rendering的结果较差。可以使用一些平滑函数进行优化,减少数据的梯度感和粗糙感。如高斯平滑函数:

  SetInputConnection(reader->GetOutput());
      SetDimensionality(3)
      SetRadiusFactors(1,1,0)

3. 对于vtkVolumeRayCastMapper映射来说,使用函数SetImageSampleDistance设置SampleDistance。但同时,默认状态下自动调节显示效果的功能是开启的,所以要设置sampledistance,则需要关闭自动调节功能即AutoAdjustSampleDistancesOff(),(如果仍然采用自动调节作用,则可以通过SetAutoAdjustSampleDistances (int)来进行交互设置)如下所示:

vtkVolumeRayCastMapper:

SetImageSampleDistance(2);

AutoAdjustSampleDistancesOff();

4. vtkLODProp3D可以加入多个Mapper,通过设置time,决定某一时刻显示哪一个Mapper。通常的做法是当在旋转时选择交互性好但准确率稍差的Mapper,当停止时,又会显示比较费时但绘制准确的Mapper。对于RayCastMapper来说,则不需要使用vtkLODProp3D。如下所示:

vtkVolumeTextureMapper2D *lowresMapper = vtkVolumeTextureMapper2D::New();

       lowresMapper->SetInput(reader->GetOutput());

vtkVolumeRayCaster *hiresMapper = vtkVolumeRayCaster::New();

       hiresMapper->SetInput(reader->GetOutput());

vtkLODProp3D *volumeLOD = vtkLODProp3D::New();

       volumeLOD->AddLOD(lowresMapper, volumeProperty, 0.0);

volumeLOD->AddLOD(hiresMapper, volumeProperty, 0.0);

转:https://blog.csdn.net/colddie/article/details/8966596

猜你喜欢

转载自blog.csdn.net/eric_e/article/details/85228016