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.