Commit 72918cd9 authored by Emmanuel Promayon's avatar Emmanuel Promayon

Merge branch 'feature/vtk8-compatibility' into 'develop'

Feature/vtk8 compatibility

See merge request !119
parents 2eaece56 d0ffc0ab
Check the website http://camitk.imag.fr for build instruction, the latest news and update!
Check the website http://camitk.imag.fr for build instructions, the latest news and update!
......@@ -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();
......
......@@ -65,7 +65,7 @@ MeshToImageStencil::MeshToImageStencil(ActionExtension* extension) : Action(exte
Property* originProperty = new Property(tr("Origin"), QVariant(QVector3D(0.0, 0.0, 0.0)), tr("The origin frame position"), "");
addParameter(originProperty);
Property* spacingProperty = new Property(tr("Spacing"), QVariant(QVector3D(0.0, 0.0, 0.0)), tr("The spacing between each voxel"), "");
Property* spacingProperty = new Property(tr("Spacing"), QVariant(QVector3D(1.0, 1.0, 1.0)), tr("The spacing between each voxel"), "");
addParameter(spacingProperty);
Property* outputFileProperty = new Property(tr("Output file"), "", tr("The output filename"), "");
......@@ -124,10 +124,18 @@ Action::ApplyStatus MeshToImageStencil::process(MeshComponent* comp) {
// compute dimensions
int dim[3];
dim[0] = dimension.x();
dim[1] = dimension.y();
dim[2] = dimension.z();
// if no dimension are specified used the bounds and spacing to compute a default value
if (dimension.x() == dimension.y() == dimension.z() == 0.0) {
for (int i = 0; i < 3; i++) {
dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i]));
}
CAMITK_WARNING(QString("Dimensions not set → set to (%1,%2,%3), deduced using bounds and spacing").arg(dim[0]).arg(dim[1]).arg(dim[2]));
}
else {
dim[0] = dimension.x();
dim[1] = dimension.y();
dim[2] = dimension.z();
}
colorImage->SetDimensions(dim);
colorImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);
......@@ -160,8 +168,6 @@ Action::ApplyStatus MeshToImageStencil::process(MeshComponent* comp) {
vtkSmartPointer<vtkImageStencil> imgstenc = vtkSmartPointer<vtkImageStencil>::New();
imgstenc->SetInputData(colorImage);
imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());
imgstenc->ReverseStencilOff();
imgstenc->SetBackgroundValue(outval);
imgstenc->Update();
......
......@@ -189,7 +189,11 @@ Action::ApplyStatus WarpOut::apply() {
for (vtkIdType i = 0; i < connectivityFilter->GetOutput()->GetNumberOfPoints(); i++) {
// get the id of the point in the original point set
#if VTK_MAJOR_VERSION == 8
pointId->GetTypedTuple(i, &id);
#else
pointId->GetTupleValue(i, &id);
#endif
// get the initial point position
resultPointSet->GetPoint(id, pos);
// get the normal
......
......@@ -28,8 +28,6 @@
#include "DefaultGUIText.h"
#include <Log.h>
// Qt files
#include <QFileDialog>
......
......@@ -142,7 +142,7 @@ set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DCEP_IMAGING=TRUE -DCEP
include("${CTEST_SOURCE_DIRECTORY}/CTestConfig.cmake")
# append only if not a configure stage (at configure stage a new timestamp should be generated)
if (NOT ${CI_STAGE} MATCHES "Configure")
if (NOT ${CI_STAGE} MATCHES "Configure")
set(CI_APPEND "APPEND")
endif()
......
......@@ -15,13 +15,13 @@
# -DCI_MODE="$CAMITK_CI_MODE" \
# -DCI_ID="$CAMITK_CI_ID" \
# -DCI_BRANCH=$CAMITK_CI_BRANCH \
# -DCI_BUILD_SETTINGS="$COMPILER_CONFIG" \
# -DCI_BUILD_SETTINGS="$CAMITK_BUILD_SETTINGS" \
# -DCTEST_SOURCE_DIRECTORY="$CAMITK_SOURCE_DIR" \
# -DCTEST_BINARY_DIRECTORY="$CAMITK_BUILD_DIR" \
# -S $CAMITK_SOURCE_DIR/sdk/cmake/ctest/ci-test.cmake > test.log 2>&1
#
# It will submit a new report in the "configure" section of the dashboard
# identified as $SITE and $COMPILER_CONFIG.
# identified as $SITE and $CAMITK_BUILD_SETTINGS.
#
# What this script does ?
# 1. INFORMATION STEP
......@@ -30,7 +30,9 @@
# 2. RUN TEST
# Run test for each CAMITK_TARGET of CamiTK
set(CI_STAGE "Test")
if (NOT CI_STAGE)
set(CI_STAGE "Test")
endif()
# ------------------------ STEP 1: information step ------------------------
include("${CTEST_SOURCE_DIRECTORY}/sdk/cmake/ctest/ci-setup.cmake")
......
......@@ -151,12 +151,24 @@ if(MSVC)
# CAMITK_VTK_LIBRARIES = VTK input libraries at linkage
foreach(VTK_LIBRARY ${VTK_LIBRARIES})
# Clear some errors on VTK configuration
# rename correctly verdict -> vtkverdict library
# rename correctly verdict -> vtkverdict, vtkproj -> vtklibproj, vtkhdf5_hl -> vtkhdf5_hl_src, vtkhdf5 -> vtkhdf5_src libraries
if(${VTK_LIBRARY} STREQUAL "verdict")
set(VTK_LIBRARY "vtkverdict")
endif()
if("${VTK_VERSION}" VERSION_GREATER_EQUAL 8.2)
if(${VTK_LIBRARY} STREQUAL "vtkhdf5_hl_src")
set(VTK_LIBRARY "vtkhdf5_hl")
endif()
if(${VTK_LIBRARY} STREQUAL "vtkhdf5_src")
set(VTK_LIBRARY "vtkhdf5")
endif()
if(${VTK_LIBRARY} STREQUAL "vtklibproj")
set(VTK_LIBRARY "vtkproj")
endif()
endif()
set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/${VTK_LIBRARY}-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/${VTK_LIBRARY}-${CAMITK_VTK_VERSION}.lib)
endforeach()
# add missing vtkIOExport, vtkImagingStencil, vtkIOImport, vtkImagingMath library
set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkIOExport-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkIOExport-${CAMITK_VTK_VERSION}.lib)
set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkImagingStencil-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkImagingStencil-${CAMITK_VTK_VERSION}.lib)
......
......@@ -163,7 +163,7 @@ macro(camitk_extension)
# if this extension is enabled, do everything needed
# otherwise... do nothing
if (${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE})
if (${${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}})
# TARGET NAME
# The target name is composed of the following: [action / component]-name
......@@ -965,7 +965,7 @@ macro(camitk_extension)
camitk_add_integration_test()
endif()
endif() # endif(${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE})
endif() # ${TYPE_EXTENSION_CMAKE}_${EXTENSION_NAME_CMAKE}_ENABLED
endmacro()
......
......@@ -125,7 +125,6 @@ Geometry::Geometry(QString label, vtkSmartPointer<vtkPointSet> pointSetPtr, cons
//-- init mapper
mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(customPipelineOutput);
mapper->ImmediateModeRenderingOn();
mapper->SetResolveCoincidentTopologyToPolygonOffset();
// set the rainbow lookup table from blue to red
......
......@@ -151,7 +151,7 @@ void Slice::setOriginalVolume(vtkSmartPointer<vtkImageData> volume) {
void Slice::initActors() {
imgToMapFilter->SetInputData(originalVolume);
if (nullptr == lut) {
if (lut == nullptr) {
imgToMapFilter->SetLookupTable(nullptr);
}
else {
......
......@@ -48,9 +48,7 @@
#include <vtkPiecewiseFunction.h>
#include <vtkColorTransferFunction.h>
#include <vtkVolumeProperty.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkImageCast.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#include <vtkVolume.h>
#include <vtkCellArray.h>
......@@ -379,7 +377,6 @@ vtkSmartPointer<vtkImageData> ImageComponent::getImageDataWithFrameTransform() {
// -------------------- initLookupTable --------------------
void ImageComponent::initLookupTable() {
// TODO set in a betterway information about the lut thanks to image data
if (this->originalImageData->GetNumberOfScalarComponents() == 1) {
// Default values for grey level lut
......@@ -392,7 +389,6 @@ void ImageComponent::initLookupTable() {
lut->SetWindow(getActualNumberOfColors());
lut->SetRampToSCurve();
lut->Build(); // effective build
}
else {
// For colored image, we need to extract the information from the image
......@@ -509,48 +505,25 @@ QString ImageComponent::getImageName() const {
void ImageComponent::update3DViewer() {
bool viewIn3D = property("Display Image in 3D Viewer").toBool();
if (viewIn3D) {
if (axialSlices) {
axialSlices->setViewSliceIn3D(true);
}
if (coronalSlices) {
coronalSlices->setViewSliceIn3D(true);
}
if (sagittalSlices) {
sagittalSlices->setViewSliceIn3D(true);
}
if (arbitrarySlices) {
// by default not visible in 3D
arbitrarySlices->setViewSliceIn3D(false);
}
if (volumeRenderingChild) {
volumeRenderingChild->setVisibility(InteractiveViewer::get3DViewer(), true);
}
if (axialSlices) {
axialSlices->setViewSliceIn3D(viewIn3D);
}
else {
if (axialSlices) {
axialSlices->setViewSliceIn3D(false);
}
if (coronalSlices) {
coronalSlices->setViewSliceIn3D(false);
}
if (coronalSlices) {
coronalSlices->setViewSliceIn3D(viewIn3D);
}
if (sagittalSlices) {
sagittalSlices->setViewSliceIn3D(false);
}
if (sagittalSlices) {
sagittalSlices->setViewSliceIn3D(viewIn3D);
}
if (arbitrarySlices) {
arbitrarySlices->setViewSliceIn3D(false);
}
if (arbitrarySlices) {
// by default never visible in 3D
arbitrarySlices->setViewSliceIn3D(false);
}
if (volumeRenderingChild) {
volumeRenderingChild->setVisibility(InteractiveViewer::get3DViewer(), false);
}
if (volumeRenderingChild) {
volumeRenderingChild->setVisibility(InteractiveViewer::get3DViewer(), viewIn3D);
}
}
......
......@@ -78,6 +78,7 @@
#include <vtkExtractSelectedFrustum.h>
#include <vtkPointData.h>
namespace camitk {
// ---------------------- singleton ----------------------------
/// the register containing all the viewers (static instantiation, global variable, but global only for this file)
......
......@@ -35,6 +35,7 @@
// -- VTK stuff
#include <vtkVersion.h>
#include <QVTKInteractor.h>
#if VTK_MAJOR_VERSION == 6
#include <QVTKWidget2.h>
......@@ -43,23 +44,20 @@
#elif VTK_MAJOR_VERSION == 7
#include <QVTKWidget.h>
// additional needed headers for QVTKWidget
#include <QWindow>
#else
#error "Invalid VTK version: not (yet) supported."
// for VTK8, check for instance https://www.slicer.org/wiki/Documentation/Labs/Qt5-and-VTK8#Qt5:_QVTKOpenGLWidget
#endif
#elif VTK_MAJOR_VERSION == 8
#include <QVTKOpenGLWidget.h>
#include <vtkSmartPointer.h>
#include <vtkInteractorStyle.h>
#include <vtkRenderWindowInteractor.h>
#include <QVTKInteractor.h>
#include <utility>
#else
#error "Invalid VTK version: not (yet) supported."
#endif
// -- VTK stuff classes
class vtkRenderer;
class vtkInteractorStyle;
class vtkRenderer;
class vtkPicker;
class vtkProp;
class vtkActor;
......@@ -71,53 +69,14 @@ class vtkCamera;
class vtkAxesActor;
class vtkAnnotatedCubeActor;
class vtkScalarBarWidget;
class vtkUnsignedCharArray;
class vtkTextMapper;
class vtkAbstractPropPicker;
namespace camitk {
// -- Core stuff classes
class GeometricObject;
/// Interactor used when we are in picking mode
class vtkInteractorStylePick : public vtkInteractorStyle {
public:
static vtkInteractorStylePick* New();
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
void PrintSelf(ostream& os, vtkIndent indent) override;
void SetAreaPicking(bool b);
void OnLeftButtonDown() override;
void OnLeftButtonUp() override;
void OnMouseMove() override;
protected:
vtkInteractorStylePick();
~vtkInteractorStylePick() override = default;
virtual void Pick();
void RedrawRubberBand();
int startPosition[2];
int endPosition[2];
int moving;
vtkSmartPointer<vtkUnsignedCharArray> pixelArray;
bool areaPicking;
};
namespace camitk {
}
class vtkInteractorStylePick;
namespace camitk {
/**
* @ingroup group_sdk_libraries_core_viewer
*
......@@ -142,6 +101,9 @@ class CAMITK_API RendererWidget : public QVTKWidget2 {
#elif VTK_MAJOR_VERSION == 7
class CAMITK_API RendererWidget : public QVTKWidget {
#elif VTK_MAJOR_VERSION == 8
class CAMITK_API RendererWidget : public QVTKOpenGLWidget {
#else
#error "Invalid VTK version: not (yet) supported."
#endif
......@@ -517,7 +479,7 @@ protected :
bool pickingDiverter;
/// picking interactor
vtkSmartPointer<vtkInteractorStylePick> pickInteractorStyle;
vtkSmartPointer<camitk::vtkInteractorStylePick> pickInteractorStyle;
///@}
......
This diff is collapsed.
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef VTKINTERACTORSTYLEPICK_H
#define VTKINTERACTORSTYLEPICK_H
#include <vtkInteractorStyle.h>
#include <vtkSmartPointer.h>
class vtkUnsignedCharArray;
namespace camitk {
/// Specific backward compatible interactor for CamiTK RendererWidget
/// Interactor used when we are in picking mode
///
class vtkInteractorStylePick : public vtkInteractorStyle {
public:
static vtkInteractorStylePick* New();
vtkTypeMacro(vtkInteractorStylePick, vtkInteractorStyle);
void PrintSelf(ostream& os, vtkIndent indent) override;
void SetAreaPicking(bool b);
void OnLeftButtonDown() override;
void OnLeftButtonUp() override;
void OnMouseMove() override;
protected:
vtkInteractorStylePick();
~vtkInteractorStylePick() override = default;
virtual void Pick();
void RedrawRubberBand();
int startPosition[2];
int endPosition[2];
int moving;
vtkSmartPointer<vtkUnsignedCharArray> pixelArray;
bool areaPicking;
};
}
#endif //VTKINTERACTORSTYLEPICK_H
......@@ -237,10 +237,16 @@ void FancyMainWindow::refresh() {
if (Application::getTopLevelComponents().size() > 0) {
ImageComponent* comp = dynamic_cast<ImageComponent*>(Application::getTopLevelComponents().last());
if (comp) {
if (comp != nullptr && comp->getAxialSlices() != nullptr) {
comp->getAxialSlices()->setVisibility(viewer3D, true);
}
if (comp != nullptr && comp->getSagittalSlices() != nullptr) {
comp->getSagittalSlices()->setVisibility(viewer3D, true);
}
if (comp != nullptr && comp->getCoronalSlices() != nullptr) {
comp->getCoronalSlices()->setVisibility(viewer3D, true);
}
if (comp != nullptr && comp->getArbitrarySlices() != nullptr) {
comp->getArbitrarySlices()->setVisibility(viewer3D, true);
}
}
......
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