# ExternalVTKWidget volume rendering high CPU usage

**URL:** https://discourse.vtk.org/t/externalvtkwidget-volume-rendering-high-cpu-usage/5012
**Category:** Support
**Created:** [January 15, 2021, 12:21am UTC](https://discourse.vtk.org/t/externalvtkwidget-volume-rendering-high-cpu-usage/5012 "2021-01-15T00:21:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kmilo9999](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kmilo9999](https://discourse.vtk.org/u/Kmilo9999)
#### Post date: [January 15, 2021, 12:21am UTC](https://discourse.vtk.org/t/externalvtkwidget-volume-rendering-high-cpu-usage/5012/1 "2021-01-15T00:21:05Z")

</div>

Hello,

I am using my custom rendering engine and I would like to use vtk to render volume data on it. Also, I am using ExternalVTKWidget to use vtk with the engine’s opengl context. I Followed the examples of ExternalVTKWidget , and it works with meshes and isosurfaces. At the moment of load volume data, the frame rate is low. The Visual Studio profiler reports a high use of the CPU when it reaches the function:

```
int vtkOpenGLRenderer::UpdateGeometry(vtkFrameBufferObjectBase* fbo)

```

I’m not sure if something is wrong at the moment of loading the data. Maybe using the wrong readers or mappers.

I wonder if someone has ever had this problem.

The following is the code I use to load volume data:

```
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volumeMapper =
    vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();

  std::string filePath = std::string("FullHead.mhd");
  vtkSmartPointer<vtkMetaImageReader> metaReader =
    vtkSmartPointer<vtkMetaImageReader>::New();
  metaReader->SetFileName(filePath.c_str());
  metaReader->Update();

  vtkSmartPointer<vtkAlgorithm> reader =
    vtkSmartPointer<vtkAlgorithm>::New();
  vtkSmartPointer<vtkImageData> input =
    vtkSmartPointer<vtkImageData>::New();

  input = metaReader->GetOutput();
  reader = metaReader;
  volumeMapper->SetInputConnection(reader->GetOutputPort());

  vtkSmartPointer<vtkVolumeProperty> volumeProperty =
    vtkSmartPointer<vtkVolumeProperty>::New();
  volumeProperty->SetInterpolationTypeToLinear();
  volumeProperty->SetIndependentComponents(true);

  vtkSmartPointer<vtkPiecewiseFunction> opacityFun =
    vtkSmartPointer<vtkPiecewiseFunction>::New();
  volumeProperty->SetScalarOpacity(opacityFun);

  vtkSmartPointer<vtkColorTransferFunction> colorFun =
    vtkSmartPointer<vtkColorTransferFunction>::New();
  volumeProperty->SetColor(colorFun);

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

  colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0);
  opacityFun->AddSegment(opacityLevel - 0.5 * opacityWindow, 0.0,
    opacityLevel + 0.5 * opacityWindow, 1.0);
  volumeMapper->SetBlendModeToMaximumIntensity();

  _vtkRenderer->AddVolume(volume);
  _vtkRenderer->ResetCamera();

```

I appreciate the help in advance.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 15, 2021, 2:22am UTC](https://discourse.vtk.org/t/externalvtkwidget-volume-rendering-high-cpu-usage/5012/2 "2021-01-15T02:22:32Z")

</div>

Use vtkGPUVolumeRayCastMapper instead of the legacy CPU mapper for faster rendering. You can get several magnitudes faster volume rendering if you have a discrete GPU and 2-4x faster if you just have integrated graphics.

---

<div class="post-metadata">

### Author: ![Kmilo9999](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kmilo9999](https://discourse.vtk.org/u/Kmilo9999)
#### Post date: [January 15, 2021, 3:12am UTC](https://discourse.vtk.org/t/externalvtkwidget-volume-rendering-high-cpu-usage/5012/3 "2021-01-15T03:12:35Z")

</div>

replacing vtkFixedPointVolumeRayCastMapper by vtkGPUVolumeRayCastMapper did the trick.

Thank you @lassoan
