From: tbaudier Date: Mon, 1 Feb 2016 13:26:20 +0000 (+0100) Subject: Ensure the compilation with Qt4 and Qt5 X-Git-Tag: v1.4.0~72^2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=6543794d0c4718aaa344b28acc77ca18d423f1f3;p=clitk.git Ensure the compilation with Qt4 and Qt5 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bbeb0e..8030908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,13 +5,13 @@ cmake_minimum_required(VERSION 2.8) cmake_policy(VERSION 2.8) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) + #cmake_policy(SET CMP0007 NEW) endif(COMMAND cmake_policy) if(NOT DEFINED CLITK_SOURCE_DIR) set(CLITK_SOURCE_DIR ${PROJECT_SOURCE_DIR}) endif(NOT DEFINED CLITK_SOURCE_DIR) #========================================================= -SET(QT_MIN_VERSION "5.0.0") -SET(VTK_MIN_VERSION "6.0.0") + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) if(MSVC) diff --git a/cmake/build_opt.cmake b/cmake/build_opt.cmake index 4a2ca00..48ba5a6 100644 --- a/cmake/build_opt.cmake +++ b/cmake/build_opt.cmake @@ -24,7 +24,14 @@ option(CLITK_BUILD_SEGMENTATION "Build command-line segmentation tools" OFF) option(CLITK_BUILD_REGISTRATION "Build command-line registration tools" OFF) option(CLITK_BUILD_VV "Build vv the 4D visualizer (requires VTK and QT)" ON) + if(CLITK_BUILD_VV) + set(vv_QT_VERSION "4" CACHE STRING "Expected Qt version") + set_property(CACHE vv_QT_VERSION PROPERTY STRINGS 4 5) + if(NOT (vv_QT_VERSION VERSION_EQUAL "4" OR vv_QT_VERSION VERSION_EQUAL "5")) + message(FATAL_ERROR "Expected value for vv_QT_VERSION is either '4' or '5'") + endif() + add_subdirectory(${CLITK_SOURCE_DIR}/vv ${PROJECT_BINARY_DIR}/vv) endif(CLITK_BUILD_VV) diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 4b0932d..3b72002 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.4) # To avoid warning with some version if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) + #cmake_policy(SET CMP0007 NEW) endif(COMMAND cmake_policy) #========================================================= @@ -109,6 +110,7 @@ set(vv_SRCS #========================================================= # Qt related commands +if(vv_QT_VERSION VERSION_GREATER "4") find_package(Qt5Widgets REQUIRED) find_package(Qt5Network REQUIRED) find_package(Qt5Designer REQUIRED) @@ -186,6 +188,81 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) +else() +find_package(Qt4 REQUIRED) +link_directories(${QT_LIBRARY_DIR}) + + +QT4_WRAP_CPP(vv_SRCS + vvMainWindowBase.h + QTreePushButton.h + vvDocumentation.h + vvHelpDialog.h + vvQDicomSeriesSelector.h + vvSlicerManager.h + vvStructureSetActor.h + vvROIActor.h + vvToolCreatorBase.h + ) + +QT4_WRAP_UI(vv_UI_CXX + qt_ui/vvHelpDialog.ui + qt_ui/vvDocumentation.ui + qt_ui/vvDicomSeriesSelector.ui + qt_ui/vvDummyWindow.ui #For testing + ) + +QT4_ADD_RESOURCES(vv_SRCS vvIcons.qrc) + +# Add the autotools in the header vvToolsList.h for initialization of the dummy +# variables in vv.cxx for the tools contained in vvLib +if(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h) + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h) + foreach(tool ${vv_TOOLS}) + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "#include \"${tool}.h\"\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "extern const vvToolCreator<${tool}> *dummy${tool};\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "const vvToolCreator<${tool}> *dummy${tool}2 = dummy${tool};\n\n") + endforeach(tool) +endif(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h) + +# Add the autotools and the common files ui +foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI}) + set(vv_SRCS ${vv_SRCS} ${tool}.cxx) + QT4_WRAP_CPP(vv_SRCS ${tool}.h) + QT4_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui) +endforeach(tool) + +# Add the common source files +foreach(tool ${vv_COMMON}) + set(vv_SRCS ${vv_SRCS} ${tool}.cxx) + QT4_WRAP_CPP(vv_SRCS ${tool}.h) +endforeach(tool) + +# if Windows and Qt was built as a static lib then don't set QT_DLL flag +set(QT_STATIC 0) +if(WIN32) + if(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl) + file(READ ${QT_LIBRARY_DIR}/QtCore.prl QT_CORE_PRL) + if(${QT_CORE_PRL} MATCHES "static") + set(QT_STATIC 1) + endif(${QT_CORE_PRL} MATCHES "static") + endif(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl) +endif(WIN32) +if(NOT QT_STATIC) + add_definitions(-DQT_DLL) +endif(NOT QT_STATIC) + +add_definitions(-DQT_THREAD_SUPPORT) + +include_directories( + ${QT_INCLUDES} + ${QT_INCLUDE_DIR} + ${QT_QTGUI_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} +) +endif() #========================================================= #========================================================= @@ -213,8 +290,11 @@ endforeach(tool) #========================================================= #Add Foundation Libraries (this should be after our libraries, since we depend #on them) -#set(foundationLibraries clitkCommon ${ITK_LIBRARIES} QVTK vtkHybrid) +if(vv_QT_VERSION VERSION_GREATER "4") set(foundationLibraries clitkCommon ${ITK_LIBRARIES} ${VTK_LIBRARIES}) +else() +set(foundationLibraries clitkCommon ${ITK_LIBRARIES} QVTK vtkHybrid) +endif() #========================================================= # Use CxImage to create animated gifs @@ -244,8 +324,11 @@ if(APPLE) endif() #========================================================= #Create binary and libs for tests -#set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} ${Qt5Widgets_LIBRARIES_DIRS} ${Qt5Network_LIBRARIES_DIRS} ${APPLE_FRAMEWORKS}) +if(vv_QT_VERSION VERSION_GREATER "4") set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} Qt5::Widgets Qt5::Network Qt5::Designer ${APPLE_FRAMEWORKS}) +else() +set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ${APPLE_FRAMEWORKS}) +endif() # QtNetwork is required by vvRegisterForm add_library(vvLib ${vv_SRCS} ${vv_UI_CXX}) diff --git a/vv/vvIntensityValueSlider.h b/vv/vvIntensityValueSlider.h index 4e2bfb3..2984663 100644 --- a/vv/vvIntensityValueSlider.h +++ b/vv/vvIntensityValueSlider.h @@ -19,7 +19,11 @@ #define VVINTENSITYVALUESLIDER_H // qt +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include // clitk diff --git a/vv/vvLabelImageLoaderWidget.h b/vv/vvLabelImageLoaderWidget.h index ff74464..94b591c 100644 --- a/vv/vvLabelImageLoaderWidget.h +++ b/vv/vvLabelImageLoaderWidget.h @@ -23,7 +23,11 @@ #include "vvImage.h" // qt +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include #include "ui_vvLabelImageLoaderWidget.h" diff --git a/vv/vvRegisterForm.cxx b/vv/vvRegisterForm.cxx index dab97ad..2d6057e 100644 --- a/vv/vvRegisterForm.cxx +++ b/vv/vvRegisterForm.cxx @@ -20,7 +20,9 @@ #include "vvRegisterForm.h" #include #include +#if QT_VERSION >= 0x050000 #include +#endif #include #include "clitkConfiguration.h" #include "vvConfiguration.h" @@ -34,6 +36,18 @@ vvRegisterForm::vvRegisterForm(QUrl url, QString path, QSettings::Format format) void vvRegisterForm::sendData(){ QUrl url2(url); + +#if QT_VERSION < 0x050000 + url2.addQueryItem("name", firstName->text().toUtf8()); + url2.addQueryItem("lastName", lastName->text().toUtf8()); + url2.addQueryItem("email", email->text().toUtf8()); + url2.addQueryItem("group", group->text().toUtf8()); + url2.addQueryItem("os", OS_NAME); + url2.addQueryItem("vvVersion", VV_VERSION); + url2.addQueryItem("architecture", ARCHITECTURE); + url2.addQueryItem("adressing", QString::number(sizeof(char*)*8)+"-bit"); + url2.addQueryItem("compilationDate", QString(__DATE__) + ", " + QString(__TIME__) ); +#else QUrlQuery url2Query; url2Query.addQueryItem("name", firstName->text().toUtf8()); @@ -46,6 +60,7 @@ void vvRegisterForm::sendData(){ url2Query.addQueryItem("adressing", QString::number(sizeof(char*)*8)+"-bit"); url2Query.addQueryItem("compilationDate", QString(__DATE__) + ", " + QString(__TIME__) ); url2.setQuery(url2Query); +#endif manager->get(QNetworkRequest(url2)); } diff --git a/vv/vvSegmentationDialog.h b/vv/vvSegmentationDialog.h index 07f1fdc..cf248d9 100644 --- a/vv/vvSegmentationDialog.h +++ b/vv/vvSegmentationDialog.h @@ -32,7 +32,11 @@ #include "vtkPolyData.h" #include +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include //==================================================================== diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index d7caa17..1bf7f13 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -1084,7 +1084,11 @@ void vvSlicer::UpdateDisplayExtent() // Local copy of extent int w_ext[6]; +#if VTK_MAJOR_VERSION <= 5 + int* ext = GetExtent(); +#else int* ext = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()); +#endif copyExtent(ext, w_ext); if (mUseReducedExtent) { copyExtent(mReducedExtent, w_ext); @@ -1107,10 +1111,11 @@ void vvSlicer::UpdateDisplayExtent() if (mOverlay && mOverlayVisibility) { AdjustResliceToSliceOrientation(mOverlayReslice); int overExtent[6]; - this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent); #if VTK_MAJOR_VERSION <= 5 + this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent); bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent()); #else + this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent); bool out = ClipDisplayedExtent(overExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); #endif mOverlayActor->SetVisibility(!out); @@ -1127,10 +1132,11 @@ void vvSlicer::UpdateDisplayExtent() if (mFusion && mFusionVisibility) { AdjustResliceToSliceOrientation(mFusionReslice); int fusExtent[6]; - this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent); #if VTK_MAJOR_VERSION <= 5 + this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent); bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent()); #else + this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent); bool out = ClipDisplayedExtent(fusExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); #endif mFusionActor->SetVisibility(!out); @@ -1164,13 +1170,11 @@ void vvSlicer::UpdateDisplayExtent() int vfExtent[6]; #if VTK_MAJOR_VERSION <= 5 mVF->GetVTKImages()[0]->UpdateInformation(); + this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent); + bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent()); #else //this->UpdateInformation(); -#endif this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mVF->GetVTKImages()[0], vfExtent); -#if VTK_MAJOR_VERSION <= 5 - bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent()); -#else bool out = ClipDisplayedExtent(vfExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); #endif mVFActor->SetVisibility(!out); @@ -1251,6 +1255,29 @@ void vvSlicer::ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, con } //---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6], + vtkImageData *targetImage, int targetExtent[6]) +{ + double dExtents[6]; + for(unsigned int i=0; i<6; i++) { + // From source voxel coordinates to world coordinates + dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i]; + + // From world coordinates to floating point target voxel coordinates + dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2]; + + // Round to current slice or larger extent + if(i/2==this->GetOrientation()) + targetExtent[i] = itk::Math::Round(dExtents[i]); + else if(i%2==1) + targetExtent[i] = itk::Math::Ceil(dExtents[i]); + else + targetExtent[i] = itk::Math::Floor(dExtents[i]); + } +} +//---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- bool vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6]) { diff --git a/vv/vvSlicer.h b/vv/vvSlicer.h index 43e0854..5b317b4 100644 --- a/vv/vvSlicer.h +++ b/vv/vvSlicer.h @@ -288,6 +288,8 @@ private: void UpdateDisplayExtent(); void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6], vtkImageData *targetImage, int targetExtent[6]); + void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6], + vtkImageData *targetImage, int targetExtent[6]); ///Sets the surfaces to be cut on the image slice: update the vtkCutter void SetContourSlice(); diff --git a/vv/vvSurfaceViewerDialog.h b/vv/vvSurfaceViewerDialog.h index fe9848e..ff9f0be 100644 --- a/vv/vvSurfaceViewerDialog.h +++ b/vv/vvSurfaceViewerDialog.h @@ -23,7 +23,11 @@ class vtkPolyDataMapper; class vtkActor; class vtkOBJReader; +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include //==================================================================== diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index 5c47732..0ab816e 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -18,7 +18,11 @@ #ifndef VVTOOLBINARIZE_H #define VVTOOLBINARIZE_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolCropImage.h b/vv/vvToolCropImage.h index 2f28630..579ac86 100644 --- a/vv/vvToolCropImage.h +++ b/vv/vvToolCropImage.h @@ -19,7 +19,11 @@ #define VVTOOLCROPIMAGE_H //qt +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include #include // vv diff --git a/vv/vvToolImageArithm.h b/vv/vvToolImageArithm.h index 93d79f4..7e558f3 100644 --- a/vv/vvToolImageArithm.h +++ b/vv/vvToolImageArithm.h @@ -17,7 +17,12 @@ ===========================================================================**/ #ifndef VVTOOLImageArithm_H #define VVTOOLImageArithm_H + +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolInputSelectorWidget.h b/vv/vvToolInputSelectorWidget.h index ab0e05b..c0a4920 100644 --- a/vv/vvToolInputSelectorWidget.h +++ b/vv/vvToolInputSelectorWidget.h @@ -19,7 +19,11 @@ #define VVTOOLINPUTSELECTORWIDGET_H // qt +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include // vv diff --git a/vv/vvToolMIP.h b/vv/vvToolMIP.h index 4691e2e..d3c6f7c 100644 --- a/vv/vvToolMIP.h +++ b/vv/vvToolMIP.h @@ -47,7 +47,11 @@ along with this program. If not, see . #include +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "vvToolBase.h" #include "QWidget" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolMedianFilter.h b/vv/vvToolMedianFilter.h index ef99df0..ff8dafe 100644 --- a/vv/vvToolMedianFilter.h +++ b/vv/vvToolMedianFilter.h @@ -44,8 +44,12 @@ #ifndef VVTOOLMedianFilter_H #define VVTOOLMedianFilter_H - + +#if QT_VERSION < 0x050000 + #include +#else #include +#endif #include "vvToolBase.h" #include "QWidget" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h index 1f5d6c9..b17bd5c 100644 --- a/vv/vvToolProfile.h +++ b/vv/vvToolProfile.h @@ -18,7 +18,11 @@ #ifndef VVTOOLPROFILE_H #define VVTOOLPROFILE_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolROIManager.h b/vv/vvToolROIManager.h index 1c5fa20..5c93de3 100644 --- a/vv/vvToolROIManager.h +++ b/vv/vvToolROIManager.h @@ -19,7 +19,11 @@ #ifndef VVTOOLROIMANAGER_H #define VVTOOLROIMANAGER_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include #include "vvToolBase.h" diff --git a/vv/vvToolResample.h b/vv/vvToolResample.h index a522e3d..3cb12ef 100644 --- a/vv/vvToolResample.h +++ b/vv/vvToolResample.h @@ -31,7 +31,11 @@ #include "vvToolBase.h" // qt +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include //------------------------------------------------------------------------------ diff --git a/vv/vvToolSegmentation.h b/vv/vvToolSegmentation.h index 93b9f3f..ba5eb5b 100644 --- a/vv/vvToolSegmentation.h +++ b/vv/vvToolSegmentation.h @@ -18,7 +18,11 @@ #ifndef VVTOOLSEGMENTATION_H #define VVTOOLSEGMENTATION_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolSimpleInputSelectorWidget.h b/vv/vvToolSimpleInputSelectorWidget.h index d80f5bf..fccc714 100644 --- a/vv/vvToolSimpleInputSelectorWidget.h +++ b/vv/vvToolSimpleInputSelectorWidget.h @@ -17,7 +17,11 @@ ===========================================================================**/ #ifndef VVTOOLSIMPLEINPUTSELECTORWIDGET_H #define VVTOOLSIMPLEINPUTSELECTORWIDGET_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include #include "ui_vvToolSimpleInputSelectorWidget.h" diff --git a/vv/vvToolWidgetBase.h b/vv/vvToolWidgetBase.h index d9bd2f3..915600e 100644 --- a/vv/vvToolWidgetBase.h +++ b/vv/vvToolWidgetBase.h @@ -19,7 +19,11 @@ #ifndef VVTOOLWIDGETBASE_H #define VVTOOLWIDGETBASE_H +#if QT_VERSION < 0x050000 +#include +#else #include +#endif #include "ui_vvToolWidgetBase.h" #include "clitkImageToImageGenericFilter.h"