From dc8bbb6e76490a0dbf583aa84973e964ed122e65 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 12 May 2023 00:52:00 +0100 Subject: [PATCH 1/5] reorganise to cope with DISABLE_* The synergistic library/executables/tests have now been adapted for DISABLE_Gadgetron etc. The work-around in common/utilities.* has therefore been removed. a job with DISABLE_Gadgetron has been added to GHA Fixes #622 --- .github/workflows/build-test.yml | 7 +- CMakeLists.txt | 2 +- data | 2 +- src/CMakeLists.txt | 32 ++++----- src/Synergistic/CMakeLists.txt | 10 ++- src/Synergistic/cSyn/CMakeLists.txt | 10 ++- .../cSyn/include/sirf/Syn/utilities.h | 5 +- src/Synergistic/cSyn/tests/CMakeLists.txt | 7 +- src/Synergistic/cSyn/tests/test_conv_img.cpp | 4 +- src/Synergistic/cSyn/utilities.cpp | 22 +++++-- src/Synergistic/sirf_convert_image_type.cpp | 49 ++++++-------- src/Synergistic/sirf_do_images_match.cpp | 21 ++---- src/Synergistic/sirf_registration.cpp | 17 ++--- src/Synergistic/sirf_resample.cpp | 16 +---- src/Synergistic/tests/CMakeLists.txt | 2 +- src/Synergistic/tests/test_cSynergistic.cpp | 17 ++++- src/common/CMakeLists.txt | 21 +----- src/common/include/sirf/Syn/utilities.h | 56 ---------------- src/common/syn_utilities.cpp | 66 ------------------- 19 files changed, 119 insertions(+), 247 deletions(-) delete mode 100644 src/common/include/sirf/Syn/utilities.h delete mode 100644 src/common/syn_utilities.cpp diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c896b7b8a..ff9a3bbe9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -44,7 +44,12 @@ jobs: DEVEL_BUILD: "ON" EXTRA_BUILD_FLAGS: "-DUSE_ITK=ON" CMAKE_BUILD_TYPE: "Release" - # need to upgrade Gadgetron before we can enable gcc 10 + - os: ubuntu-latest + compiler: gcc + compiler_version: 9 + DEVEL_BUILD: "ON" + EXTRA_BUILD_FLAGS: "-DUSE_ITK=ON -DDISABLE_Gadgetron:BOOL=ON" + CMAKE_BUILD_TYPE: "Release" #- os: ubuntu-latest # compiler: gcc # compiler_version: 10 diff --git a/CMakeLists.txt b/CMakeLists.txt index 57515db14..96b46c8d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ option(DISABLE_Gadgetron "Disable building the SIRF interface to Gadgetron" OFF) if (NOT DISABLE_Gadgetron) set(default_CXX_version 17) else() - message(WARNING "Gadgetron not found. Set gadgetron_DIR if you do have it.") + message(STATUS "Gadgetron disabled.") set (default_CXX_version 11) endif() UseCXX(${default_CXX_version}) diff --git a/data b/data index ef407f7ab..5bd102338 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit ef407f7ab6d4772d1dd04f6b77367dc065b544d1 +Subproject commit 5bd102338ee192edbbd7df3e9343695b20337677 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e40540321..37899826b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,8 +33,11 @@ else() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ISMRMRD_DIR}") find_package(FFTW3 COMPONENTS single REQUIRED) ADD_SUBDIRECTORY(xGadgetron) - set(SIRF_BUILT_WITH_ISMRMRD TRUE PARENT_SCOPE) + set(SIRF_BUILT_WITH_ISMRMRD TRUE) # set for directories "below" + set(SIRF_BUILT_WITH_ISMRMRD TRUE PARENT_SCOPE) # set for directory "above" set(ISMRMRD_VERSION ${ISMRMRD_VERSION} PARENT_SCOPE) + # TODO use target_compile_definitions + add_definitions(-DSIRF_BUILT_WITH_ISMRMRD) endif() @@ -71,7 +74,10 @@ else() endif() ADD_SUBDIRECTORY(Registration) set(SPM_BOOL_STR ${SPM_BOOL_STR} PARENT_SCOPE) + set(SIRF_BUILT_WITH_REGISTRATION TRUE) set(SIRF_BUILT_WITH_REGISTRATION TRUE PARENT_SCOPE) + # TODO use target_compile_definitions + add_definitions(-DSIRF_BUILT_WITH_REGISTRATION) endif() @@ -111,38 +117,26 @@ else() set(Parallelproj_BOOL_STR "0") endif() ADD_SUBDIRECTORY(xSTIR) + set(SIRF_BUILT_WITH_STIR TRUE) set(SIRF_BUILT_WITH_STIR TRUE PARENT_SCOPE) set(STIR_VERSION ${STIR_VERSION} PARENT_SCOPE) + # TODO use target_compile_definitions + add_definitions(-DSIRF_BUILT_WITH_STIR) + endif() set(NiftyPET_BOOL_STR ${NiftyPET_BOOL_STR} PARENT_SCOPE) set(Parallelproj_BOOL_STR ${Parallelproj_BOOL_STR} PARENT_SCOPE) - ########################################################################## # Synergistic # ########################################################################## # Synergistic code currently only works if STIR (with ITK), ISMRMRD and Registration are built +# Currently cannot do this as ImageData.read depends on synergistic/ImageDataWrapper option(DISABLE_Synergistic "Disable building the synergistic code" OFF) if (DISABLE_Synergistic) message(STATUS "Synergistic code disabled.") else() - if ((NOT DISABLE_STIR) AND (NOT DISABLE_Gadgetron) AND (NOT DISABLE_Registration) AND "${STIR_BUILT_WITH_ITK}") - MESSAGE(STATUS "Registration, ISMRMRD and STIR (with ITK) have been built. Building synergistic code.") - ADD_SUBDIRECTORY(Synergistic) - else() - MESSAGE(STATUS "One or more of the following components are missing: Registration, ISMRMRD and STIR (with ITK). Synergistic code will not be built.") - if (DISABLE_STIR) - MESSAGE(STATUS "STIR missing.") - elseif(NOT STIR_BUILT_WITH_ITK) - MESSAGE(STATUS "STIR not built with ITK.") - endif() - if (DISABLE_Gadgetron) - MESSAGE(STATUS "ISMRMRD missing.") - endif() - if (DISABLE_Registration) - MESSAGE(STATUS "Registration missing.") - endif() - endif() + ADD_SUBDIRECTORY(Synergistic) endif() ADD_SUBDIRECTORY(common) diff --git a/src/Synergistic/CMakeLists.txt b/src/Synergistic/CMakeLists.txt index f784a86d8..0cd74906a 100644 --- a/src/Synergistic/CMakeLists.txt +++ b/src/Synergistic/CMakeLists.txt @@ -20,15 +20,19 @@ SET(CMAKE_POSITION_INDEPENDENT_CODE True) # Executables SET(SYN_executables + sirf_convert_image_type + ) +if (SIRF_BUILT_WITH_REGISTRATION) +list(APPEND SYN_executables sirf_registration sirf_do_images_match sirf_resample - sirf_convert_image_type - ) +) +endif() FOREACH(elem ${SYN_executables}) ADD_EXECUTABLE(${elem} ${elem}.cpp ${STIR_REGISTRIES}) - TARGET_LINK_LIBRARIES(${elem} LINK_PUBLIC csirf iutilities cstir cgadgetron Reg) + TARGET_LINK_LIBRARIES(${elem} LINK_PUBLIC csirf csyn) INSTALL(TARGETS ${elem} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) ENDFOREACH(elem ${SYN_executables}) diff --git a/src/Synergistic/cSyn/CMakeLists.txt b/src/Synergistic/cSyn/CMakeLists.txt index 9315cc7f0..f6987af11 100644 --- a/src/Synergistic/cSyn/CMakeLists.txt +++ b/src/Synergistic/cSyn/CMakeLists.txt @@ -28,7 +28,15 @@ target_include_directories(csyn PUBLIC target_include_directories(csyn PUBLIC "$$" ) -target_link_libraries(csyn PUBLIC cgadgetron cstir Reg) +if(SIRF_BUILT_WITH_ISMRMRD) + target_link_libraries(csyn PUBLIC cgadgetron) +endif() +if(SIRF_BUILT_WITH_STIR) + target_link_libraries(csyn PUBLIC cstir) +endif() +if(SIRF_BUILT_WITH_REGISTRATION) + target_link_libraries(csyn PUBLIC Reg) +endif() target_compile_definitions(csyn PRIVATE WIN32_LEAN_AND_MEAN) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" diff --git a/src/Synergistic/cSyn/include/sirf/Syn/utilities.h b/src/Synergistic/cSyn/include/sirf/Syn/utilities.h index 9e1b0a781..fa544dd3b 100644 --- a/src/Synergistic/cSyn/include/sirf/Syn/utilities.h +++ b/src/Synergistic/cSyn/include/sirf/Syn/utilities.h @@ -29,8 +29,11 @@ limitations under the License. */ #pragma once - +#include +#include namespace sirf { + class ImageData; + class ImageDataWrap { public: ImageDataWrap(const std::string &filename, const std::string &engine, bool verbose); diff --git a/src/Synergistic/cSyn/tests/CMakeLists.txt b/src/Synergistic/cSyn/tests/CMakeLists.txt index 229cd9395..f1085ac6d 100644 --- a/src/Synergistic/cSyn/tests/CMakeLists.txt +++ b/src/Synergistic/cSyn/tests/CMakeLists.txt @@ -16,8 +16,8 @@ # #========================================================================= -SET(CMAKE_POSITION_INDEPENDENT_CODE True) +if (SIRF_BUILT_WITH_REGISTRATION) ADD_EXECUTABLE(test_conv_img test_conv_img.cpp ${STIR_REGISTRIES}) TARGET_LINK_LIBRARIES(test_conv_img LINK_PUBLIC cgadgetron csirf iutilities cstir Reg csyn) INSTALL(TARGETS test_conv_img DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) @@ -25,9 +25,14 @@ INSTALL(TARGETS test_conv_img DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) set(MR_vendor_dicom_as_nifti "${CMAKE_SOURCE_DIR}/data/examples/MR/zenodo/dicom_as_nifti.nii") set(MR_SIRF_recon "${CMAKE_SOURCE_DIR}/data/examples/MR/zenodo/SIRF_recon.h5") +if (SIRF_BUILT_WITH_STIR) ADD_TEST(NAME SYN_TEST_STIR_TO_NIFTI_CPLUSPLUS COMMAND test_conv_img ${MR_vendor_dicom_as_nifti} "STIR" "Reg" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() +if (SIRF_BUILT_WITH_ISMRMRD) ADD_TEST(NAME SYN_TEST_GADGETRON_TO_NIFTI_CPLUSPLUS COMMAND test_conv_img ${MR_SIRF_recon} "Gadgetron" "Reg" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() +endif() diff --git a/src/Synergistic/cSyn/tests/test_conv_img.cpp b/src/Synergistic/cSyn/tests/test_conv_img.cpp index 5183f1f6c..563f08fb9 100644 --- a/src/Synergistic/cSyn/tests/test_conv_img.cpp +++ b/src/Synergistic/cSyn/tests/test_conv_img.cpp @@ -22,8 +22,6 @@ limitations under the License. #include #include -#include "sirf/Gadgetron/gadgetron_data_containers.h" -#include "sirf/STIR/stir_data_containers.h" #include "sirf/Reg/NiftiImageData3D.h" #include "sirf/Syn/utilities.h" @@ -57,4 +55,4 @@ int main(int argc, char* argv[]) else std::cout << "engine " << eng_out << " not supported yet\n"; return 1; -} \ No newline at end of file +} diff --git a/src/Synergistic/cSyn/utilities.cpp b/src/Synergistic/cSyn/utilities.cpp index e982b8163..1b2c8bffe 100644 --- a/src/Synergistic/cSyn/utilities.cpp +++ b/src/Synergistic/cSyn/utilities.cpp @@ -1,7 +1,7 @@ /* SyneRBI Synergistic Image Reconstruction Framework (SIRF) Copyright 2020 Rutherford Appleton Laboratory STFC -Copyright 2020 University College London +Copyright 2020, 2023 University College London This is software developed for the Collaborative Computational Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR) @@ -26,34 +26,48 @@ limitations under the License. \author Richard Brown \author Evgueni Ovtchinnikov +\author Kris Thielemans \author SyneRBI */ +#ifdef SIRF_BUILT_WITH_ISMRMRD #include "sirf/Gadgetron/gadgetron_data_containers.h" +#endif +#ifdef SIRF_BUILT_WITH_STIR #include "sirf/STIR/stir_data_containers.h" +#endif +#ifdef SIRF_BUILT_WITH_REGISTRATION #include "sirf/Reg/NiftiImageData3D.h" +#endif #include "sirf/Syn/utilities.h" using namespace sirf; ImageDataWrap::ImageDataWrap(const std::string &filename, const std::string &engine, bool verbose) { + img_sptr_ = 0; +#ifdef SIRF_BUILT_WITH_REGISTRATION if (strcmp(engine.c_str(), "Reg") == 0) { std::shared_ptr > nifti_sptr = std::make_shared >(filename); if (verbose) nifti_sptr->print_header(); img_sptr_ = nifti_sptr; } - else if (strcmp(engine.c_str(), "STIR") == 0) { +#endif +#ifdef SIRF_BUILT_WITH_STIR + if (strcmp(engine.c_str(), "STIR") == 0) { img_sptr_ = std::make_shared(filename); } - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { +#endif +#ifdef SIRF_BUILT_WITH_ISMRMRD + if (strcmp(engine.c_str(), "Gadgetron") == 0) { std::shared_ptr gadgetron_sptr(new GadgetronImagesVector); gadgetron_sptr->read(filename); if (verbose) gadgetron_sptr->print_header(0); img_sptr_ = gadgetron_sptr; } - else +#endif + if (!img_sptr_) throw std::runtime_error("unknown engine - " + engine + ".\n"); // If verbose print geom info diff --git a/src/Synergistic/sirf_convert_image_type.cpp b/src/Synergistic/sirf_convert_image_type.cpp index 8e639e163..78469132a 100644 --- a/src/Synergistic/sirf_convert_image_type.cpp +++ b/src/Synergistic/sirf_convert_image_type.cpp @@ -27,43 +27,28 @@ limitations under the License. \author SyneRBI */ +#include "sirf/Syn/utilities.h" +#ifdef SIRF_BUILT_WITH_REGISTRATION #include "sirf/Reg/NiftiImageData3D.h" +#endif +#ifdef SIRF_BUILT_WITH_ISMRMRD #include "sirf/Gadgetron/gadgetron_data_containers.h" +#endif +#ifdef SIRF_BUILT_WITH_STIR #include "sirf/STIR/stir_data_containers.h" +#endif using namespace sirf; static const std::shared_ptr image_as_sptr(const std::string &filename, const std::string &engine, const bool verbose) { - std::shared_ptr img_sptr; - - if (strcmp(engine.c_str(), "Reg") == 0) { - std::shared_ptr > nifti_sptr = std::make_shared >(filename); - if (verbose) nifti_sptr->print_header(); - img_sptr = nifti_sptr; - } - else if (strcmp(engine.c_str(), "STIR") == 0) { - img_sptr = std::make_shared(filename); - } - - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { - std::shared_ptr gadgetron_sptr(new GadgetronImagesVector); - gadgetron_sptr->read(filename); - if (verbose) gadgetron_sptr->print_header(0); - img_sptr = gadgetron_sptr; - } - else - throw std::runtime_error("unknown engine - " + engine + ".\n"); - - // If verbose print geom info - if (verbose) img_sptr->get_geom_info_sptr()->print_info(); - - // return - return img_sptr; + ImageDataWrap i(filename, engine, verbose); + return i.data_sptr(); } static void convert_and_write_image(const std::string &filename, const std::string &engine, const std::shared_ptr &in_img_sptr, const std::string ¶m_file, const bool verbose) { +#ifdef SIRF_BUILT_WITH_REGISTRATION if (strcmp(engine.c_str(), "Reg") == 0) { NiftiImageData im(*in_img_sptr); im.write(filename); @@ -71,8 +56,11 @@ static void convert_and_write_image(const std::string &filename, const std::stri im.print_header(); im.get_geom_info_sptr()->print_info(); } + return; } - else if (strcmp(engine.c_str(), "STIR") == 0) { +#endif +#ifdef SIRF_BUILT_WITH_STIR + if (strcmp(engine.c_str(), "STIR") == 0) { STIRImageData im(*in_img_sptr); if (param_file.empty()) im.write(filename); @@ -80,12 +68,15 @@ static void convert_and_write_image(const std::string &filename, const std::stri im.write(filename,param_file); if (verbose) im.get_geom_info_sptr()->print_info(); + return; } - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { +#endif +#ifdef SIRF_BUILT_WITH_ISMRMRD + if (strcmp(engine.c_str(), "Gadgetron") == 0) { throw std::runtime_error("Converter to GadgetronImagesVector not yet implemented.\n"); } - else - throw std::runtime_error("unknown engine - " + engine + ".\n"); +#endif + throw std::runtime_error("unknown engine - " + engine + ".\n"); } /// print usage diff --git a/src/Synergistic/sirf_do_images_match.cpp b/src/Synergistic/sirf_do_images_match.cpp index 49cb856db..e3989653e 100644 --- a/src/Synergistic/sirf_do_images_match.cpp +++ b/src/Synergistic/sirf_do_images_match.cpp @@ -28,25 +28,18 @@ limitations under the License. */ #include "sirf/Reg/NiftiImageData3D.h" -#include "sirf/Gadgetron/gadgetron_data_containers.h" -#include "sirf/STIR/stir_data_containers.h" - +#include "sirf/Syn/utilities.h" +#include using namespace sirf; static std::shared_ptr > image_as_sptr(const std::string &filename, const std::string &engine) { - if (strcmp(engine.c_str(), "Nifti") == 0) - return std::make_shared >(filename); - else if (strcmp(engine.c_str(), "STIR") == 0) - return std::make_shared >(STIRImageData(filename)); - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { - std::shared_ptr sptr_img(new GadgetronImagesVector); - sptr_img->read(filename); - return std::make_shared >(*sptr_img); - } - else - throw std::runtime_error("unknown engine - " + engine + ".\n"); + ImageDataWrap i(filename, engine, false); + if (auto cast_sptr = std::dynamic_pointer_cast>(i.data_sptr())) + return cast_sptr; + else + return std::make_shared >(i.data()); } /// print usage diff --git a/src/Synergistic/sirf_registration.cpp b/src/Synergistic/sirf_registration.cpp index 1d38312b4..cf2800b6c 100644 --- a/src/Synergistic/sirf_registration.cpp +++ b/src/Synergistic/sirf_registration.cpp @@ -31,8 +31,7 @@ limitations under the License. #include "sirf/Reg/NiftyF3dSym.h" #include "sirf/Reg/AffineTransformation.h" #include "sirf/Reg/NiftiImageData3D.h" -#include "sirf/Gadgetron/gadgetron_data_containers.h" -#include "sirf/STIR/stir_data_containers.h" +#include "sirf/Syn/utilities.h" #include #ifdef SIRF_SPM #include "sirf/Reg/SPMRegistration.h" @@ -48,18 +47,10 @@ enum Algorithm { static std::shared_ptr image_as_sptr(const std::string &filename, const std::string &engine) { - if (strcmp(engine.c_str(), "Reg") == 0) - return std::make_shared >(filename); - else if (strcmp(engine.c_str(), "STIR") == 0) - return std::make_shared(filename); - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { - std::shared_ptr sptr_img(new GadgetronImagesVector); - sptr_img->read(filename); - return std::move(sptr_img); - } - else - throw std::runtime_error("sirf_registration: unknown image engine - " + engine + ".\n"); + ImageDataWrap i(filename, engine, false); + return i.data_sptr(); } + //reg,algo,is_affine_or_rigid,algo_str static void algo_as_sptr(std::shared_ptr > &algo_sptr, Algorithm &algo, const std::string &algorithm) { diff --git a/src/Synergistic/sirf_resample.cpp b/src/Synergistic/sirf_resample.cpp index ad79db96c..b32f4018f 100644 --- a/src/Synergistic/sirf_resample.cpp +++ b/src/Synergistic/sirf_resample.cpp @@ -32,28 +32,18 @@ If multiple transformations are given, they will be applied in the order they we #include "sirf/Reg/NiftyResampler.h" #include "sirf/Reg/NiftiImageData3D.h" -#include "sirf/Gadgetron/gadgetron_data_containers.h" +#include "sirf/Syn/utilities.h" #include "sirf/Reg/AffineTransformation.h" #include "sirf/Reg/NiftiImageData3DDeformation.h" #include "sirf/Reg/NiftiImageData3DDisplacement.h" -#include "sirf/STIR/stir_data_containers.h" using namespace sirf; static std::shared_ptr image_as_sptr(const std::string &filename, const std::string &engine) { - if (strcmp(engine.c_str(), "Nifti") == 0) - return std::make_shared >(filename); - else if (strcmp(engine.c_str(), "STIR") == 0) - return std::make_shared(filename); - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { - std::shared_ptr sptr_img(new GadgetronImagesVector); - sptr_img->read(filename); - return sptr_img; - } - else - throw std::runtime_error("unknown engine - " + engine + ".\n"); + ImageDataWrap i(filename, engine, false); + return i.data_sptr(); } static std::shared_ptr > algo_as_sptr(const std::string &algorithm) diff --git a/src/Synergistic/tests/CMakeLists.txt b/src/Synergistic/tests/CMakeLists.txt index ed07dd2cb..91b785c0c 100644 --- a/src/Synergistic/tests/CMakeLists.txt +++ b/src/Synergistic/tests/CMakeLists.txt @@ -43,7 +43,7 @@ ADD_EXECUTABLE (SYN_TEST_CPLUSPLUS test_cSynergistic.cpp ${STIR_REGISTRIES}) SET_TARGET_PROPERTIES (SYN_TEST_CPLUSPLUS PROPERTIES FOLDER ${CMAKE_INSTALL_PREFIX}/bin INSTALL_NAME_DIR "Synergistic") -TARGET_LINK_LIBRARIES(SYN_TEST_CPLUSPLUS PUBLIC csirf iutilities cstir cgadgetron Reg) +TARGET_LINK_LIBRARIES(SYN_TEST_CPLUSPLUS PUBLIC csirf csyn) if (DOWNLOAD_ZENODO_TEST_DATA) set(test_data "${CMAKE_SOURCE_DIR}/data/examples/MR/grappa2_1rep.h5" "${MR_vendor_dicom_as_nifti}" "${MR_SIRF_recon}") diff --git a/src/Synergistic/tests/test_cSynergistic.cpp b/src/Synergistic/tests/test_cSynergistic.cpp index e81f66857..9ff633d97 100644 --- a/src/Synergistic/tests/test_cSynergistic.cpp +++ b/src/Synergistic/tests/test_cSynergistic.cpp @@ -27,18 +27,26 @@ limitations under the License. \author SyneRBI */ +#ifdef SIRF_BUILT_WITH_ISMRMRD #include "sirf/Gadgetron/gadgetron_data_containers.h" +#include "sirf/Gadgetron/gadgetron_x.h" +#include "sirf/Gadgetron/gadget_lib.h" +#endif +#ifdef SIRF_BUILT_WITH_STIR #include "sirf/STIR/stir_data_containers.h" +#endif +#ifdef SIRF_BUILT_WITH_REGISTRATION #include "sirf/Reg/NiftiImageData3D.h" #include "sirf/Reg/NiftyResampler.h" #include "sirf/Reg/AffineTransformation.h" -#include "sirf/Gadgetron/gadgetron_x.h" -#include "sirf/Gadgetron/gadget_lib.h" +#endif +#include "sirf/Syn/utilities.h" using namespace sirf; #define ADD_GADGET(X, T) X.push_back(std::make_shared()) +#ifdef SIRF_BUILT_WITH_STIR static void create_stir_output_file_format(const std::string &path) { std::ofstream file(path); @@ -54,6 +62,7 @@ static void create_stir_output_file_format(const std::string &path) file << "End:=\n"; file.close(); } +#endif int main(int argc, char* argv[]) { @@ -70,6 +79,7 @@ int main(int argc, char* argv[]) if (argc > 3) mr_recon_h5_filename = argv[3]; +#ifdef SIRF_BUILT_WITH_STIR // Test STIR -> Nifti { std::cout << "// ----------------------------------------------------------------------- //\n"; @@ -96,7 +106,9 @@ int main(int argc, char* argv[]) std::cout << "// Finished STIRImageData->NiftiImageData test.\n"; std::cout << "//------------------------------------------------------------------------ //\n"; } +#endif +#ifdef SIRF_BUILT_WITH_ISMRMRD // Test Gadgetron -> Nifti if (!mr_recon_h5_filename.empty()) { @@ -310,6 +322,7 @@ int main(int argc, char* argv[]) std::cout << "// Finished GadgetronImageData reorient test.\n"; std::cout << "//------------------------------------------------------------------------ //\n"; } +#endif // Error handling } catch(const std::exception &error) { diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 6877c0fdf..c80e0ee88 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -30,25 +30,10 @@ target_include_directories(csirf PUBLIC target_include_directories(csirf PUBLIC "$$" ) - -if ((NOT DISABLE_STIR) AND (NOT DISABLE_Gadgetron) AND (NOT DISABLE_Registration) AND "${STIR_BUILT_WITH_ITK}") - MESSAGE(STATUS "Registration, ISMRMRD and STIR (with ITK) have been built.") - target_link_libraries(csirf PUBLIC iutilities csyn) -else() - MESSAGE(STATUS "Either Registration or ISMRMRD or STIR (with ITK) have not been built.") - add_library(Syn syn_utilities.cpp) - target_include_directories(Syn PUBLIC - "$$" - ) - target_include_directories(Syn PUBLIC - "$$" +target_include_directories(csirf PUBLIC + "$$" ) - target_link_libraries(Syn PUBLIC cgadgetron cstir Reg) - target_link_libraries(csirf PUBLIC iutilities Syn) - install(TARGETS Syn EXPORT SIRFTargets - COMPONENT Development - DESTINATION lib) -endif() +target_link_libraries(csirf PUBLIC iutilities)# csyn) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" COMPONENT Development diff --git a/src/common/include/sirf/Syn/utilities.h b/src/common/include/sirf/Syn/utilities.h deleted file mode 100644 index 9e1b0a781..000000000 --- a/src/common/include/sirf/Syn/utilities.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -SyneRBI Synergistic Image Reconstruction Framework (SIRF) -Copyright 2020 Rutherford Appleton Laboratory STFC -Copyright 2020 University College London - -This is software developed for the Collaborative Computational -Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR) -(http://www.ccpsynerbi.ac.uk/). - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -*/ - -/*! -\file -\ingroup Synergistic -\brief C++ synergistic utilities. - -\author Evgueni Ovtchinnikov -\author SyneRBI -*/ - -#pragma once - -namespace sirf { - class ImageDataWrap { - public: - ImageDataWrap(const std::string &filename, const std::string &engine, bool verbose); - ImageData& data() - { - return *img_sptr_; - } - const ImageData& data() const - { - return *img_sptr_; - } - std::shared_ptr data_sptr() - { - return img_sptr_; - } - const std::shared_ptr data_sptr() const - { - return img_sptr_; - } - private: - std::shared_ptr img_sptr_; - }; -} diff --git a/src/common/syn_utilities.cpp b/src/common/syn_utilities.cpp deleted file mode 100644 index e982b8163..000000000 --- a/src/common/syn_utilities.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -SyneRBI Synergistic Image Reconstruction Framework (SIRF) -Copyright 2020 Rutherford Appleton Laboratory STFC -Copyright 2020 University College London - -This is software developed for the Collaborative Computational -Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR) -(http://www.ccpsynerbi.ac.uk/). - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -*/ - -/*! -\file -\ingroup Synergistic -\brief C++ synergistic utilities. - -\author Richard Brown -\author Evgueni Ovtchinnikov -\author SyneRBI -*/ - -#include "sirf/Gadgetron/gadgetron_data_containers.h" -#include "sirf/STIR/stir_data_containers.h" -#include "sirf/Reg/NiftiImageData3D.h" -#include "sirf/Syn/utilities.h" - -using namespace sirf; - -ImageDataWrap::ImageDataWrap(const std::string &filename, const std::string &engine, bool verbose) -{ - if (strcmp(engine.c_str(), "Reg") == 0) { - std::shared_ptr > nifti_sptr = - std::make_shared >(filename); - if (verbose) nifti_sptr->print_header(); - img_sptr_ = nifti_sptr; - } - else if (strcmp(engine.c_str(), "STIR") == 0) { - img_sptr_ = std::make_shared(filename); - } - else if (strcmp(engine.c_str(), "Gadgetron") == 0) { - std::shared_ptr gadgetron_sptr(new GadgetronImagesVector); - gadgetron_sptr->read(filename); - if (verbose) gadgetron_sptr->print_header(0); - img_sptr_ = gadgetron_sptr; - } - else - throw std::runtime_error("unknown engine - " + engine + ".\n"); - - // If verbose print geom info - if (verbose) { - std::shared_ptr gi_sptr = - img_sptr_->get_geom_info_sptr(); - if (gi_sptr.get()) - gi_sptr->print_info(); - } -} From f5d424a17d87261bf7119e32c7e9905e2ca01daf Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Thu, 1 Jun 2023 08:21:43 +0100 Subject: [PATCH 2/5] clean-up some include statements - removed some superflous include statements - removed some predeclarations and explicitly include iutilities.h --- src/Registration/cReg/cReg_p.cpp | 8 +------- src/Registration/cReg/include/sirf/Reg/NiftyResample.h | 1 - src/Registration/cReg/include/sirf/Reg/NiftyResampler.h | 1 - src/Registration/cReg/include/sirf/Reg/Resample.h | 1 - src/common/CMakeLists.txt | 3 --- src/xSTIR/cSTIR/cstir_p.cpp | 4 +--- src/xSTIR/cSTIR/tests/test4.cpp | 5 ----- 7 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/Registration/cReg/cReg_p.cpp b/src/Registration/cReg/cReg_p.cpp index 26199559d..cb5fe9bb7 100644 --- a/src/Registration/cReg/cReg_p.cpp +++ b/src/Registration/cReg/cReg_p.cpp @@ -20,6 +20,7 @@ limitations under the License. */ #include "sirf/iUtilities/DataHandle.h" +#include "sirf/iUtilities/iutilities.h" #include "sirf/Reg/cReg_p.h" #include "sirf/Reg/NiftiImageData3D.h" #include "sirf/Reg/Registration.h" @@ -33,13 +34,6 @@ limitations under the License. using namespace sirf; -extern "C" -char* charDataFromHandle(const void* ptr); -extern "C" -int intDataFromHandle(const void* ptr); -extern "C" -float floatDataFromHandle(const void* ptr); - static void* parameterNotFound(const char* name, const char* file, int line) { diff --git a/src/Registration/cReg/include/sirf/Reg/NiftyResample.h b/src/Registration/cReg/include/sirf/Reg/NiftyResample.h index 5136330f0..6515af806 100644 --- a/src/Registration/cReg/include/sirf/Reg/NiftyResample.h +++ b/src/Registration/cReg/include/sirf/Reg/NiftyResample.h @@ -34,7 +34,6 @@ limitations under the License. #include #include #include "sirf/Reg/Resample.h" -#include "sirf/iUtilities/iutilities.h" namespace NiftyMoMo { class BSplineTransformation; diff --git a/src/Registration/cReg/include/sirf/Reg/NiftyResampler.h b/src/Registration/cReg/include/sirf/Reg/NiftyResampler.h index 5136330f0..6515af806 100644 --- a/src/Registration/cReg/include/sirf/Reg/NiftyResampler.h +++ b/src/Registration/cReg/include/sirf/Reg/NiftyResampler.h @@ -34,7 +34,6 @@ limitations under the License. #include #include #include "sirf/Reg/Resample.h" -#include "sirf/iUtilities/iutilities.h" namespace NiftyMoMo { class BSplineTransformation; diff --git a/src/Registration/cReg/include/sirf/Reg/Resample.h b/src/Registration/cReg/include/sirf/Reg/Resample.h index 032400478..bc90783b2 100644 --- a/src/Registration/cReg/include/sirf/Reg/Resample.h +++ b/src/Registration/cReg/include/sirf/Reg/Resample.h @@ -32,7 +32,6 @@ limitations under the License. #include #include #include "sirf/Reg/Transformation.h" -#include "sirf/iUtilities/iutilities.h" namespace sirf { diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index c80e0ee88..2ea8807c4 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -21,9 +21,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE True) set(cSIRF_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") add_library(csirf csirf.cpp ImageData.cpp GeometricalInfo.cpp iequals.cpp utilities.cpp) -target_include_directories(csirf PUBLIC - "$$" - ) target_include_directories(csirf PUBLIC "$$" ) diff --git a/src/xSTIR/cSTIR/cstir_p.cpp b/src/xSTIR/cSTIR/cstir_p.cpp index 914df2377..6eed9fb68 100644 --- a/src/xSTIR/cSTIR/cstir_p.cpp +++ b/src/xSTIR/cSTIR/cstir_p.cpp @@ -24,6 +24,7 @@ limitations under the License. #include "sirf/STIR/stir_types.h" #include "sirf/iUtilities/DataHandle.h" +#include "sirf/iUtilities/iutilities.h" #include "sirf/STIR/cstir_p.h" #include "sirf/STIR/stir_x.h" @@ -36,9 +37,6 @@ using namespace sirf; stir::shared_ptr X; getObjectSptrFromHandle(H, X); #define SIRF_DYNAMIC_CAST(T, X, Y) T& X = dynamic_cast(Y) -extern "C" -char* charDataFromHandle(const void* ptr); - static void* handle_error(const std::string& error_string, const char* file, int line) { diff --git a/src/xSTIR/cSTIR/tests/test4.cpp b/src/xSTIR/cSTIR/tests/test4.cpp index b99923564..6ea1bd587 100644 --- a/src/xSTIR/cSTIR/tests/test4.cpp +++ b/src/xSTIR/cSTIR/tests/test4.cpp @@ -30,17 +30,12 @@ limitations under the License. #include #include -#include "stir/common.h" -#include "stir/IO/stir_ecat_common.h" #include "stir/Verbosity.h" #include "sirf/STIR/stir_x.h" -#include "sirf/common/getenv.h" -#include "sirf/common/iequals.h" #include "sirf/common/utilities.h" using namespace stir; -using namespace ecat; using namespace sirf; int test4() From aee8675a7818503ac132313c3d8e2e21a7f2e4f5 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Thu, 1 Jun 2023 10:35:44 +0100 Subject: [PATCH 3/5] CMake fixes for dependencies - add more conditionals to see if certain things can be built - split csirf library into 2: csirf is now the C++ library, while cinterface-sirf contains the C wrappers. This is probably more logical, but also avoids a circular dependency on ImageDataWrapper (which sits in csyn, but depends on creg etc). ImageDataWrapper is currently not using in csirf, but only in cinterface-sirf (i.e. Python/MATLAB) - remove the option DISABLE_Synergistic when building Python/MATLAB stuff as disabling it would lead to linking errors (as they need ImageDataWrapper) --- data | 2 +- src/CMakeLists.txt | 11 ++++++--- src/Synergistic/pSyn/tests/CMakeLists.txt | 28 +++++++++++++-------- src/common/CMakeLists.txt | 30 ++++++++++++++++++----- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/data b/data index 5bd102338..ef407f7ab 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5bd102338ee192edbbd7df3e9343695b20337677 +Subproject commit ef407f7ab6d4772d1dd04f6b77367dc065b544d1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37899826b..73ae53aa2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,9 +130,14 @@ set(Parallelproj_BOOL_STR ${Parallelproj_BOOL_STR} PARENT_SCOPE) ########################################################################## # Synergistic # ########################################################################## -# Synergistic code currently only works if STIR (with ITK), ISMRMRD and Registration are built -# Currently cannot do this as ImageData.read depends on synergistic/ImageDataWrapper -option(DISABLE_Synergistic "Disable building the synergistic code" OFF) +if (NOT BUILD_PYTHON AND NOT BUILD_MATLAB) + # Currently only disable synergistic library when not using Python/MATLAB, + # as their ImageData.read depends on synergistic/ImageDataWrapper (TODO) + option(DISABLE_Synergistic "Disable building the synergistic code" OFF) +else() + # DISABLE_Synergistic will be not set, which in CMake means it is equivalent to FALSE +endif() + if (DISABLE_Synergistic) message(STATUS "Synergistic code disabled.") else() diff --git a/src/Synergistic/pSyn/tests/CMakeLists.txt b/src/Synergistic/pSyn/tests/CMakeLists.txt index e1029aae4..d2524831c 100644 --- a/src/Synergistic/pSyn/tests/CMakeLists.txt +++ b/src/Synergistic/pSyn/tests/CMakeLists.txt @@ -1,6 +1,7 @@ -#======================================================================== +##======================================================================== # Author: Richard Brown -# Copyright 2018 - 2020 University College London +# Author: Kris Thielemans +# Copyright 2018 - 2020, 2023 University College London # Author: Evgueni Ovtchinnikov # Copyright 2020 UKRI-STFC # @@ -21,12 +22,19 @@ set(MR_vendor_dicom_as_nifti "${CMAKE_SOURCE_DIR}/data/examples/MR/zenodo/dicom_as_nifti.nii") set(MR_SIRF_recon "${CMAKE_SOURCE_DIR}/data/examples/MR/zenodo/SIRF_recon.h5") -ADD_TEST(NAME SYN_TEST_GADGETRON_TO_NIFTI_PYTHON -COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests_syn.py - ${MR_SIRF_recon} "Gadgetron" -WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -ADD_TEST(NAME SYN_TEST_STIR_TO_NIFTI_PYTHON -COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests_syn.py - ${MR_vendor_dicom_as_nifti} "STIR" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +if (SIRF_BUILT_WITH_REGISTRATION) # needed for Nifti + + if (SIRF_BUILT_WITH_ISMRMRD) + ADD_TEST(NAME SYN_TEST_GADGETRON_TO_NIFTI_PYTHON + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests_syn.py + ${MR_SIRF_recon} "Gadgetron" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() + if (SIRF_BUILT_WITH_STIR) + ADD_TEST(NAME SYN_TEST_STIR_TO_NIFTI_PYTHON + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests_syn.py + ${MR_vendor_dicom_as_nifti} "STIR" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() +endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 2ea8807c4..376069ca9 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -20,17 +20,32 @@ set(CMAKE_POSITION_INDEPENDENT_CODE True) set(cSIRF_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") -add_library(csirf csirf.cpp ImageData.cpp GeometricalInfo.cpp iequals.cpp utilities.cpp) +# C++ library +add_library(csirf ImageData.cpp GeometricalInfo.cpp iequals.cpp utilities.cpp) target_include_directories(csirf PUBLIC "$$" ) target_include_directories(csirf PUBLIC "$$" ) -target_include_directories(csirf PUBLIC +# currently necessary for LocalisedException.h and DataHandle.h (and others?) +#target_include_directories(csirf PUBLIC +# "$$" +# ) +target_link_libraries(csirf PUBLIC iutilities) + +# C interface +add_library(cinterface-sirf csirf.cpp) +target_include_directories(cinterface-sirf PUBLIC + "$$" + ) +target_include_directories(cinterface-sirf PUBLIC + "$$" + ) +target_include_directories(cinterface-sirf PUBLIC "$$" ) -target_link_libraries(csirf PUBLIC iutilities)# csyn) +target_link_libraries(cinterface-sirf PUBLIC csirf csyn) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" COMPONENT Development @@ -38,6 +53,9 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" install(TARGETS csirf EXPORT SIRFTargets COMPONENT Development DESTINATION lib) +install(TARGETS cinterface-sirf EXPORT SIRFTargets + COMPONENT Development + DESTINATION lib) if (BUILD_PYTHON) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") @@ -51,7 +69,7 @@ if (BUILD_PYTHON) set(SWIG_MODULE_pysirf_EXTRA_DEPS "${cSIRF_INCLUDE_DIR}/sirf/common/csirf.h") SWIG_ADD_LIBRARY(pysirf LANGUAGE python TYPE MODULE SOURCES pysirf.i ${STIR_REGISTRIES}) TARGET_INCLUDE_DIRECTORIES(${SWIG_MODULE_pysirf_REAL_NAME} PUBLIC ${Python_INCLUDE_DIRS}) - SWIG_LINK_LIBRARIES(pysirf csirf iutilities ${Python_LIBRARIES}) + SWIG_LINK_LIBRARIES(pysirf cinterface-sirf iutilities ${Python_LIBRARIES}) INSTALL(TARGETS ${SWIG_MODULE_pysirf_REAL_NAME} DESTINATION "${PYTHON_DEST}/sirf") INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/pysirf.py" DESTINATION "${PYTHON_DEST}/sirf") #file(GLOB PythonFiles "${CMAKE_CURRENT_LIST_DIR}/*.py") @@ -68,7 +86,7 @@ if (BUILD_MATLAB) set(msirf_h ${CMAKE_CURRENT_BINARY_DIR}/msirf.h) add_executable(gmi_csirf gmi/gmi_csirf.cpp) - target_link_libraries(gmi_csirf mig csirf) + target_link_libraries(gmi_csirf mig cinterface-sirf) # Generate m-files on the fly add_custom_command( OUTPUT ${msirf_c} ${msirf_h} @@ -81,7 +99,7 @@ if (BUILD_MATLAB) add_library(msirf SHARED ${msirf_c}) target_include_directories(msirf PUBLIC ${Matlab_INCLUDE_DIRS}) SET_TARGET_PROPERTIES(msirf PROPERTIES SUFFIX ".${MATLAB_MEX_EXT}" PREFIX "${MATLAB_PREFIX}") - target_link_libraries(msirf csirf iutilities ${Matlab_LIBRARIES}) + target_link_libraries(msirf cinterface-sirf iutilities ${Matlab_LIBRARIES}) INSTALL(TARGETS msirf DESTINATION "${MATLAB_DEST}") INSTALL(FILES ${msirf_h} DESTINATION "${MATLAB_DEST}") From f8b804b82ff3884ee311455b95fca942dd95193a Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Thu, 1 Jun 2023 22:48:29 +0100 Subject: [PATCH 4/5] split cinterface-Reg from cReg lib and fix dependencies cinterface-Reg depends on STIR for TextWriter Also fix some MATLAB things related to TextWriter (untested) --- src/CMakeLists.txt | 87 ++++++++++++++-------------- src/Registration/cReg/CMakeLists.txt | 19 ++++-- src/Registration/mReg/CMakeLists.txt | 4 +- src/Registration/mReg/printer.h | 2 +- src/Registration/pReg/CMakeLists.txt | 2 +- src/xSTIR/mSTIR/printer.h | 2 +- 6 files changed, 63 insertions(+), 53 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 73ae53aa2..1a257dbd4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,48 +40,6 @@ else() add_definitions(-DSIRF_BUILT_WITH_ISMRMRD) endif() - - -########################################################################## -# Registration # -########################################################################## -option(DISABLE_Registration "Disable building the SIRF registration package" OFF) -if (DISABLE_Registration) - message(STATUS "Registration support disabled.") - set(SPM_BOOL_STR "0" PARENT_SCOPE) - set(SIRF_BUILT_WITH_REGISTRATION False PARENT_SCOPE) -else() - FIND_PACKAGE(NIFTYREG 1.5.61 REQUIRED) - # NIFTYREG - FOREACH(NR_lib ${NIFTYREG_LIBRARIES}) - find_library(${NR_lib}_full_path "${NR_lib}" "${NIFTYREG_LIBRARY_DIRS}") - if(NOT ${NR_lib}_full_path) - message(FATAL_ERROR "${NR_lib} not found") - endif() - SET(NR_libs_full_path "${NR_libs_full_path};${${NR_lib}_full_path}") - ENDFOREACH() - # If niftyreg was bulit with OpenMP - if (NIFTYREG_BUILT_WITH_OPENMP) - find_package(OpenMP REQUIRED) - if (OpenMP_CXX_FOUND) - SET(NR_libs_full_path "${NR_libs_full_path};OpenMP::OpenMP_CXX") - endif() - endif() - # If niftyreg was bulit with CUDA - if (NIFTYREG_BUILT_WITH_CUDA) - find_package(CUDA REQUIRED) - SET(NR_libs_full_path "${NR_libs_full_path};${CUDA_CUDA_LIBRARY};${CUDA_CUDART_LIBRARY}") - endif() - ADD_SUBDIRECTORY(Registration) - set(SPM_BOOL_STR ${SPM_BOOL_STR} PARENT_SCOPE) - set(SIRF_BUILT_WITH_REGISTRATION TRUE) - set(SIRF_BUILT_WITH_REGISTRATION TRUE PARENT_SCOPE) - # TODO use target_compile_definitions - add_definitions(-DSIRF_BUILT_WITH_REGISTRATION) -endif() - - - ########################################################################## # STIR # ########################################################################## @@ -127,6 +85,51 @@ endif() set(NiftyPET_BOOL_STR ${NiftyPET_BOOL_STR} PARENT_SCOPE) set(Parallelproj_BOOL_STR ${Parallelproj_BOOL_STR} PARENT_SCOPE) + +########################################################################## +# Registration # +########################################################################## +# Note: +# The Python/MATLAB interface for Reg depends on STIR sadly, so STIR stuff +# needs to come first. We could add some checks here to see if Registration should be +# disabled, but we'll just check it in the cReg/CMakeLists.txt and leave it to the user +# to either enable STIR or disable Registration. +option(DISABLE_Registration "Disable building the SIRF registration package" OFF) +if (DISABLE_Registration) + message(STATUS "Registration support disabled.") + set(SPM_BOOL_STR "0" PARENT_SCOPE) + set(SIRF_BUILT_WITH_REGISTRATION False PARENT_SCOPE) +else() + FIND_PACKAGE(NIFTYREG 1.5.61 REQUIRED) + # NIFTYREG + FOREACH(NR_lib ${NIFTYREG_LIBRARIES}) + find_library(${NR_lib}_full_path "${NR_lib}" "${NIFTYREG_LIBRARY_DIRS}") + if(NOT ${NR_lib}_full_path) + message(FATAL_ERROR "${NR_lib} not found") + endif() + SET(NR_libs_full_path "${NR_libs_full_path};${${NR_lib}_full_path}") + ENDFOREACH() + # If niftyreg was bulit with OpenMP + if (NIFTYREG_BUILT_WITH_OPENMP) + find_package(OpenMP REQUIRED) + if (OpenMP_CXX_FOUND) + SET(NR_libs_full_path "${NR_libs_full_path};OpenMP::OpenMP_CXX") + endif() + endif() + # If niftyreg was bulit with CUDA + if (NIFTYREG_BUILT_WITH_CUDA) + find_package(CUDA REQUIRED) + SET(NR_libs_full_path "${NR_libs_full_path};${CUDA_CUDA_LIBRARY};${CUDA_CUDART_LIBRARY}") + endif() + ADD_SUBDIRECTORY(Registration) + set(SPM_BOOL_STR ${SPM_BOOL_STR} PARENT_SCOPE) + set(SIRF_BUILT_WITH_REGISTRATION TRUE) + set(SIRF_BUILT_WITH_REGISTRATION TRUE PARENT_SCOPE) + # TODO use target_compile_definitions + add_definitions(-DSIRF_BUILT_WITH_REGISTRATION) +endif() + + ########################################################################## # Synergistic # ########################################################################## diff --git a/src/Registration/cReg/CMakeLists.txt b/src/Registration/cReg/CMakeLists.txt index e7d09a50e..6c91c6b61 100644 --- a/src/Registration/cReg/CMakeLists.txt +++ b/src/Registration/cReg/CMakeLists.txt @@ -1,6 +1,9 @@ #======================================================================== +# Author: Evgueni Ovtchinnikov +# Author: Kris Thielemans # Author: Richard Brown -# Copyright 2018 - 2020 University College London +# Copyright 2018-2021, 2023 University College London +# Copyright 2018-2023 Science Technology Facilities Council # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,11 +37,6 @@ SET(SOURCES "NiftiImageData3DDeformation.cpp" "NiftiImageData3DDisplacement.cpp") -# If we're also wrapping to python or matlab, include the c-files -IF(BUILD_PYTHON OR BUILD_MATLAB) - SET(SOURCES ${SOURCES} "cReg.cpp" "cReg_p.cpp") -ENDIF() - # Add SPM source IF(SPM_FOUND) SET(SOURCES ${SOURCES} "SPMRegistration.cpp") @@ -130,4 +128,13 @@ FOREACH(elem ${REG_executables}) INSTALL(TARGETS ${elem} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) ENDFOREACH(elem ${REG_executables}) +IF(BUILD_PYTHON OR BUILD_MATLAB) + ADD_LIBRARY(cinterface-Reg cReg.cpp cReg_p.cpp) + # add dependencies. Note that cstir is required for deleteTextWriter sadly + if (NOT SIRF_BUILT_WITH_STIR) + message(FATAL_ERROR "Python/MATLAB interface for Registration currently depends on STIR.") + endif() + target_link_libraries(cinterface-Reg Reg cstir) +endif() + ADD_SUBDIRECTORY(tests) diff --git a/src/Registration/mReg/CMakeLists.txt b/src/Registration/mReg/CMakeLists.txt index ac7c4fa7c..36b65796f 100644 --- a/src/Registration/mReg/CMakeLists.txt +++ b/src/Registration/mReg/CMakeLists.txt @@ -61,8 +61,8 @@ if(BUILD_MATLAB) target_include_directories(mreg PUBLIC ${Matlab_INCLUDE_DIRS}) # fix output name and link flags SET_TARGET_PROPERTIES(mreg PROPERTIES - SUFFIX ".${MATLAB_MEX_EXT}" PREFIX "${MATLAB_PREFIX}") - target_link_libraries(mreg Reg iutilities csirf cstir ${Matlab_LIBRARIES}) + SUFFIX ".${MATLAB_MEX_EXT}" PREFIX "${MATLAB_PREFIX}") + target_link_libraries(mreg cinterface-Reg ${Matlab_LIBRARIES}) INSTALL(TARGETS mreg DESTINATION "${MATLAB_DEST}") INSTALL(FILES ${mreg_h} DESTINATION "${MATLAB_DEST}") INSTALL(FILES ${SOURCES} DESTINATION "${MATLAB_DEST}/+sirf/+Reg") diff --git a/src/Registration/mReg/printer.h b/src/Registration/mReg/printer.h index fbbea0183..7cfa681ed 100644 --- a/src/Registration/mReg/printer.h +++ b/src/Registration/mReg/printer.h @@ -24,7 +24,7 @@ limitations under the License. #include "stir/TextWriter.h" -class mexTextPrinter : public aTextWriter { +class mexTextPrinter : public stir::aTextWriter { public: virtual void write(const char* text) const { //mexPrintf("mexPrintf is called...\n"); diff --git a/src/Registration/pReg/CMakeLists.txt b/src/Registration/pReg/CMakeLists.txt index 80f66a556..9cd9a9e7a 100644 --- a/src/Registration/pReg/CMakeLists.txt +++ b/src/Registration/pReg/CMakeLists.txt @@ -38,7 +38,7 @@ set(SWIG_MODULE_pyreg_EXTRA_DEPS "${cREG_INCLUDE_DIR}/sirf/Reg/cReg.h") SWIG_ADD_LIBRARY(pyreg LANGUAGE python TYPE MODULE SOURCES pyreg.i) TARGET_INCLUDE_DIRECTORIES(${SWIG_MODULE_pyreg_REAL_NAME} PUBLIC ${Python_INCLUDE_DIRS}) -SWIG_LINK_LIBRARIES(pyreg PUBLIC Reg ${Python_LIBRARIES}) +SWIG_LINK_LIBRARIES(pyreg PUBLIC cinterface-Reg ${Python_LIBRARIES}) INSTALL(TARGETS ${SWIG_MODULE_pyreg_REAL_NAME} DESTINATION "${PYTHON_DEST}/sirf") INSTALL(FILES diff --git a/src/xSTIR/mSTIR/printer.h b/src/xSTIR/mSTIR/printer.h index 78151832e..1799db8ab 100644 --- a/src/xSTIR/mSTIR/printer.h +++ b/src/xSTIR/mSTIR/printer.h @@ -22,7 +22,7 @@ limitations under the License. #include "stir/TextWriter.h" -class mexTextPrinter : public aTextWriter { +class mexTextPrinter : public stir::aTextWriter { public: virtual void write(const char* text) const { //mexPrintf("mexPrintf is called...\n"); From e2f4ca2cfa9e679c6887a3f13cef5f131e9cd117 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Thu, 1 Jun 2023 23:31:28 +0100 Subject: [PATCH 5/5] update CHANGES.md and fix some copyrights --- CHANGES.md | 8 +++++++- CMakeLists.txt | 5 ++++- src/CMakeLists.txt | 7 ++++--- src/common/CMakeLists.txt | 5 ++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4c6a55786..beccbf6a3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,6 @@ # ChangeLog ## v3.5.0 -* GitHub Action: remove temporarily the Ubuntu 20.04 build, #1178 * MR - Re-designed handling of "irregular" ISMRMRD acquisitions, making it user-controlled and more flexible. See https://github.com/SyneRBI/SIRF/pull/1174 for more information - Allow user to set radial, goldenangle, spiral and rpe trajectories @@ -14,6 +13,13 @@ * C++ - added `examples_data_path` and utility functions such as `append_path` in `common/utilities.h` +* Other, including CMake files + - resolve dependencies such that DISABLE_Gadgetron works now + - split some C interfaces into separate libraries, i.e. cinterface-sirf and cinterface-Reg + +* GitHub Action: + - add a build with DISABLE_Gadgetron + ## v3.4.0 * MR: diff --git a/CMakeLists.txt b/CMakeLists.txt index 96b46c8d8..c2277ac0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,10 @@ #======================================================================== # Author: Kris Thielemans -# Copyright 2016 - 2020 University College London +# Author: Evgueni Ovtchinnikov +# Author: Edoardo Pasca +# Author: Richard Brown +# Copyright 2016 - 2023 University College London # Copyright 2016 - 2020 Science Technology Facilities Council # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a257dbd4..cd4b215f6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,9 @@ #======================================================================== # Author: Richard Brown, Kris Thielemans -# Copyright 2016 - 2020 University College London -# Copyright 2016 - 2020 Science Technology Facilities Council +# Author: Evgueni Ovtchinnikov +# Copyright 2016 - 2023 University College London +# Copyright 2016 - 2023 Science Technology Facilities Council # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -134,7 +135,7 @@ endif() # Synergistic # ########################################################################## if (NOT BUILD_PYTHON AND NOT BUILD_MATLAB) - # Currently only disable synergistic library when not using Python/MATLAB, + # Currently only offer to disable synergistic library when not using Python/MATLAB, # as their ImageData.read depends on synergistic/ImageDataWrapper (TODO) option(DISABLE_Synergistic "Disable building the synergistic code" OFF) else() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 376069ca9..223282c9c 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,6 +1,9 @@ #======================================================================== # Author: Evgueni Ovtchinnikov -# Copyright 2020 University College London +# Author: Kris Thielemans +# Author: Richard Brown +# Copyright 2018-2021, 2023 University College London +# Copyright 2018-2023 Science Technology Facilities Council # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.