Commit 4a4c47ec authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED volume rendering for VTK8

modified so that VTK6 and VTK7 version is still available
parent bda13aa1
# Note: add flag DISABLED to disable a specific action
camitk_extension(ACTION_EXTENSION camitk_extension(ACTION_EXTENSION
NEEDS_QTXML NEEDS_QTXML
DEFINES COMPILE_VOLUME_RENDERING_ACTION_API DEFINES COMPILE_VOLUME_RENDERING_ACTION_API
......
...@@ -27,9 +27,15 @@ ...@@ -27,9 +27,15 @@
// -- vtk stuff -- // -- vtk stuff --
#include <vtkImageCast.h> #include <vtkImageCast.h>
#include <vtkVolume.h> #include <vtkVolume.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkPiecewiseFunction.h> #include <vtkPiecewiseFunction.h>
#if VTK_MAJOR_VERSION == 8
#include <vtkFixedPointVolumeRayCastMapper.h>
#else
#include <vtkVolumeRayCastMapper.h>
#include <vtkVolumeRayCastCompositeFunction.h> #include <vtkVolumeRayCastCompositeFunction.h>
#endif
#include <vtkColorTransferFunction.h> #include <vtkColorTransferFunction.h>
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h> #include <vtkRenderWindow.h>
...@@ -59,12 +65,10 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio ...@@ -59,12 +65,10 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio
myWidget = nullptr; myWidget = nullptr;
volumeName = "volume-rendering"; volumeName = "volume-rendering";
// Setting name, description and input component // Setting name, description and input component
setName("Volume Rendering"); setName("Volume Rendering");
setEmbedded(false); setEmbedded(false);
setDescription(tr("Volume rendering of 3D medical image using ray casting<br/>\ setDescription(tr("Volume rendering of 3D medical image using ray casting<br/>(Use Ctrl+R to render a selected image volume)"));
(Use Ctrl+R to render a selected image volume)"));
setComponent("ImageComponent"); setComponent("ImageComponent");
// Setting classification family and tags // Setting classification family and tags
...@@ -76,31 +80,14 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio ...@@ -76,31 +80,14 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio
// add shortcut // add shortcut
getQAction()->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); getQAction()->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
getQAction()->setShortcutContext(Qt::ApplicationShortcut); getQAction()->setShortcutContext(Qt::ApplicationShortcut);
/*
// Define default colors
defaultTransparencies.insert( 0, 0.0);
defaultTransparencies.insert(255, 1.0);
defaultColors.insert( 0, QColor(204, 77, 51, 255));
defaultColors.insert(255, QColor(128, 128, 128, 255));
defaultGradientOpacities.insert(0, 0.0);
defaultGradientOpacities.insert(90, 0.5);
defaultGradientOpacities.insert(150, 1.0);
defaultAmbiant = 0.4;
defaultDiffuse = 0.6;
defaultSpecular = 0.2;
*/
} }
// --------------- getWidget ------------------- // --------------- getWidget ---------------
QWidget* VolumeRenderingAction::getWidget() { QWidget* VolumeRenderingAction::getWidget() {
return nullptr; return nullptr;
} }
// --------------- apply ------------------- // --------------- apply ---------------
Action::ApplyStatus VolumeRenderingAction::apply() { Action::ApplyStatus VolumeRenderingAction::apply() {
foreach (Component* comp, getTargets()) { foreach (Component* comp, getTargets()) {
ImageComponent* input = dynamic_cast<ImageComponent*>(comp); ImageComponent* input = dynamic_cast<ImageComponent*>(comp);
...@@ -109,6 +96,7 @@ Action::ApplyStatus VolumeRenderingAction::apply() { ...@@ -109,6 +96,7 @@ Action::ApplyStatus VolumeRenderingAction::apply() {
return SUCCESS; return SUCCESS;
} }
// --------------- process ---------------
void VolumeRenderingAction::process(ImageComponent* comp) { void VolumeRenderingAction::process(ImageComponent* comp) {
bool isVisible = comp->getVolumeRenderingChild()->getVisibility(InteractiveViewer::get3DViewer()); bool isVisible = comp->getVolumeRenderingChild()->getVisibility(InteractiveViewer::get3DViewer());
bool existVR = (comp->getVolumeRenderingChild()->getProp(volumeName) != NULL); bool existVR = (comp->getVolumeRenderingChild()->getProp(volumeName) != NULL);
...@@ -139,6 +127,7 @@ void VolumeRenderingAction::process(ImageComponent* comp) { ...@@ -139,6 +127,7 @@ void VolumeRenderingAction::process(ImageComponent* comp) {
} }
// --------------- createVolumeRendering ---------------
void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) { void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
// Get the transfer function from the widget // Get the transfer function from the widget
QMap<int, double> transparencies = myWidget->getTransparencyPoints(); QMap<int, double> transparencies = myWidget->getTransparencyPoints();
...@@ -150,8 +139,8 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) { ...@@ -150,8 +139,8 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
QMap<int, double> gradientOpacities = myWidget->getOpacityPoints(); QMap<int, double> gradientOpacities = myWidget->getOpacityPoints();
QMap<int, double>::const_iterator gradientIt; QMap<int, double>::const_iterator gradientIt;
double ambiant = myWidget->getAmbiant(); double ambiant = myWidget->getAmbiant();
double diffuse = myWidget->getDiffuse(); double diffuse = myWidget->getDiffuse();
double specular = myWidget->getSpecular(); double specular = myWidget->getSpecular();
// FILTER // FILTER
...@@ -166,16 +155,21 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) { ...@@ -166,16 +155,21 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
magnitudeFilter->Update(); magnitudeFilter->Update();
// MAPPER // MAPPER
#if VTK_MAJOR_VERSION == 8
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
volumeMapper->SetInputData(magnitudeFilter->GetOutput());
#else
vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New(); vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New();
volumeMapper->SetInputData(magnitudeFilter->GetOutput()); volumeMapper->SetInputData(magnitudeFilter->GetOutput());
// The volume will be displayed by ray-cast alpha compositing. // The volume will be displayed by ray-cast alpha compositing.
// A ray-cast mapper is needed to do the ray-casting, and a // A ray-cast mapper is needed to do the ray-casting, and a
// compositing function is needed to do the compositing along the ray. // compositing function is needed to do the compositing along the ray.
vtkSmartPointer<vtkVolumeRayCastCompositeFunction> rayCastFunction = vtkSmartPointer<vtkVolumeRayCastCompositeFunction> rayCastFunction =
vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New(); vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();
volumeMapper->SetVolumeRayCastFunction(rayCastFunction); volumeMapper->SetVolumeRayCastFunction(rayCastFunction);
#endif
// RENDERER // RENDERER
// Here, there is only one renderer : the one of the volume, but contains many properties // Here, there is only one renderer : the one of the volume, but contains many properties
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment