Skip to content

Commit

Permalink
reorganise to cope with DISABLE_*
Browse files Browse the repository at this point in the history
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
  • Loading branch information
KrisThielemans committed May 11, 2023
1 parent 802227f commit 4f97a0b
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 247 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion data
Submodule data updated from ef407f to 5bd102
32 changes: 13 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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)
10 changes: 7 additions & 3 deletions src/Synergistic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
10 changes: 9 additions & 1 deletion src/Synergistic/cSyn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ target_include_directories(csyn PUBLIC
target_include_directories(csyn PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>$<INSTALL_INTERFACE:include>"
)
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/"
Expand Down
5 changes: 4 additions & 1 deletion src/Synergistic/cSyn/include/sirf/Syn/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ limitations under the License.
*/

#pragma once

#include <string>
#include <memory>
namespace sirf {
class ImageData;

class ImageDataWrap {
public:
ImageDataWrap(const std::string &filename, const std::string &engine, bool verbose);
Expand Down
7 changes: 6 additions & 1 deletion src/Synergistic/cSyn/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@
#
#=========================================================================

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)

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()
4 changes: 1 addition & 3 deletions src/Synergistic/cSyn/tests/test_conv_img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ limitations under the License.
#include <iostream>
#include <string>

#include "sirf/Gadgetron/gadgetron_data_containers.h"
#include "sirf/STIR/stir_data_containers.h"
#include "sirf/Reg/NiftiImageData3D.h"
#include "sirf/Syn/utilities.h"

Expand Down Expand Up @@ -57,4 +55,4 @@ int main(int argc, char* argv[])
else
std::cout << "engine " << eng_out << " not supported yet\n";
return 1;
}
}
22 changes: 18 additions & 4 deletions src/Synergistic/cSyn/utilities.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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<NiftiImageData<float> > nifti_sptr =
std::make_shared<NiftiImageData3D<float> >(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<STIRImageData>(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<GadgetronImagesVector> 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
Expand Down
49 changes: 20 additions & 29 deletions src/Synergistic/sirf_convert_image_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,56 @@ 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<ImageData> image_as_sptr(const std::string &filename, const std::string &engine, const bool verbose)
{
std::shared_ptr<ImageData> img_sptr;

if (strcmp(engine.c_str(), "Reg") == 0) {
std::shared_ptr<NiftiImageData<float> > nifti_sptr = std::make_shared<NiftiImageData3D<float> >(filename);
if (verbose) nifti_sptr->print_header();
img_sptr = nifti_sptr;
}
else if (strcmp(engine.c_str(), "STIR") == 0) {
img_sptr = std::make_shared<STIRImageData>(filename);
}

else if (strcmp(engine.c_str(), "Gadgetron") == 0) {
std::shared_ptr<GadgetronImagesVector> 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<ImageData> &in_img_sptr, const std::string &param_file, const bool verbose)
{
#ifdef SIRF_BUILT_WITH_REGISTRATION
if (strcmp(engine.c_str(), "Reg") == 0) {
NiftiImageData<float> im(*in_img_sptr);
im.write(filename);
if (verbose) {
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);
else
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
Expand Down
21 changes: 7 additions & 14 deletions src/Synergistic/sirf_do_images_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

using namespace sirf;

static std::shared_ptr<const NiftiImageData3D<float> > image_as_sptr(const std::string &filename, const std::string &engine)
{
if (strcmp(engine.c_str(), "Nifti") == 0)
return std::make_shared<const NiftiImageData3D<float> >(filename);
else if (strcmp(engine.c_str(), "STIR") == 0)
return std::make_shared<const NiftiImageData3D<float> >(STIRImageData(filename));
else if (strcmp(engine.c_str(), "Gadgetron") == 0) {
std::shared_ptr<GadgetronImageData> sptr_img(new GadgetronImagesVector);
sptr_img->read(filename);
return std::make_shared<const NiftiImageData3D<float> >(*sptr_img);
}
else
throw std::runtime_error("unknown engine - " + engine + ".\n");
ImageDataWrap i(filename, engine, false);
if (auto cast_sptr = std::dynamic_pointer_cast<NiftiImageData3D<float>>(i.data_sptr()))
return cast_sptr;
else
return std::make_shared<const NiftiImageData3D<float> >(i.data());
}

/// print usage
Expand Down
Loading

0 comments on commit 4f97a0b

Please sign in to comment.