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
NEEDS_QTXML
DEFINES COMPILE_VOLUME_RENDERING_ACTION_API
......
......@@ -27,9 +27,15 @@
// -- vtk stuff --
#include <vtkImageCast.h>
#include <vtkVolume.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkPiecewiseFunction.h>
#if VTK_MAJOR_VERSION == 8
#include <vtkFixedPointVolumeRayCastMapper.h>
#else
#include <vtkVolumeRayCastMapper.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#endif
#include <vtkColorTransferFunction.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
......@@ -59,12 +65,10 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio
myWidget = nullptr;
volumeName = "volume-rendering";
// Setting name, description and input component
setName("Volume Rendering");
setEmbedded(false);
setDescription(tr("Volume rendering of 3D medical image using ray casting<br/>\
(Use Ctrl+R to render a selected image volume)"));
setDescription(tr("Volume rendering of 3D medical image using ray casting<br/>(Use Ctrl+R to render a selected image volume)"));
setComponent("ImageComponent");
// Setting classification family and tags
......@@ -76,31 +80,14 @@ VolumeRenderingAction::VolumeRenderingAction(ActionExtension* extension) : Actio
// add shortcut
getQAction()->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
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() {
return nullptr;
}
// --------------- apply -------------------
// --------------- apply ---------------
Action::ApplyStatus VolumeRenderingAction::apply() {
foreach (Component* comp, getTargets()) {
ImageComponent* input = dynamic_cast<ImageComponent*>(comp);
......@@ -109,6 +96,7 @@ Action::ApplyStatus VolumeRenderingAction::apply() {
return SUCCESS;
}
// --------------- process ---------------
void VolumeRenderingAction::process(ImageComponent* comp) {
bool isVisible = comp->getVolumeRenderingChild()->getVisibility(InteractiveViewer::get3DViewer());
bool existVR = (comp->getVolumeRenderingChild()->getProp(volumeName) != NULL);
......@@ -139,6 +127,7 @@ void VolumeRenderingAction::process(ImageComponent* comp) {
}
// --------------- createVolumeRendering ---------------
void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
// Get the transfer function from the widget
QMap<int, double> transparencies = myWidget->getTransparencyPoints();
......@@ -150,8 +139,8 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
QMap<int, double> gradientOpacities = myWidget->getOpacityPoints();
QMap<int, double>::const_iterator gradientIt;
double ambiant = myWidget->getAmbiant();
double diffuse = myWidget->getDiffuse();
double ambiant = myWidget->getAmbiant();
double diffuse = myWidget->getDiffuse();
double specular = myWidget->getSpecular();
// FILTER
......@@ -166,16 +155,21 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) {
magnitudeFilter->Update();
// MAPPER
#if VTK_MAJOR_VERSION == 8
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
volumeMapper->SetInputData(magnitudeFilter->GetOutput());
#else
vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New();
volumeMapper->SetInputData(magnitudeFilter->GetOutput());
// The volume will be displayed by ray-cast alpha compositing.
// A ray-cast mapper is needed to do the ray-casting, and a
// compositing function is needed to do the compositing along the ray.
vtkSmartPointer<vtkVolumeRayCastCompositeFunction> rayCastFunction =
vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();
volumeMapper->SetVolumeRayCastFunction(rayCastFunction);
#endif
// RENDERER
// Here, there is only one renderer : the one of the volume, but contains many properties
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