-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide C++ tools for accessing examples data (#1166)
* started working on #1163 * [ci skip] made STIR version string available in Python * added path handling utilities in SIRF/common * moved misplaced file utilities.cpp to SIRF/common * added C++ implementation of examples_data_path(), fixes #919 * copied version.h to SIRF/src/common as a quick fix for build errors * replaced quick version.h fix with a proper one * cast NULL to const char* in append_path calls for safety * added missing casts of NULL to const char* * reverted attempted fix in src/common/CMakeLists.txt * replaced hard coded paths in test4.cpp with those provided by new tools * removed unused fix_path_separator and append_path * re-applied quick version.h fix * tested calling STIR's get_STIR_*_dir() functions from a SIRF C++ test * added interfaces to get_STIR_*_dir() to STIR.py * [ci skip] updated CHANGES.md * fix include path for finding version.h and getenv.h * add C++ test on get_STIR_examples_dir * rewrote append_path using variadic templates and clean-up Using va_args etc is not recommended anymore. The replacement is type-safe. Also added some doxygen and removed some obsolete declarations. * replaced Python implementation of examples_data_path with wrapped C++ one --------- Co-authored-by: Kris Thielemans <[email protected]>
- Loading branch information
1 parent
e6e69b4
commit 8ea4cac
Showing
20 changed files
with
273 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule data
updated
from 5bd102 to ef407f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
SyneRBI Synergistic Image Reconstruction Framework (SIRF) | ||
Copyright 2023 Rutherford Appleton Laboratory STFC | ||
Copyright 2023 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 Common | ||
\author Evgueni Ovtchinnikov | ||
\author Kris Thielemans | ||
*/ | ||
#ifndef SIRF_UTILITIES | ||
#define SIRF_UTILITIES | ||
|
||
#include <string> | ||
|
||
namespace sirf { | ||
//! return the path-separator used by the OS | ||
/*! | ||
\ingroup Common | ||
Usually this will return a forward-slash, but it could be a backslash on Windows. | ||
*/ | ||
char path_separator(); | ||
///@{ | ||
//! concatenate path strings | ||
/*! | ||
\ingroup Common | ||
\par Example: | ||
\code | ||
std::string filename = "somefile.txt"; | ||
std:string full_path = append_path("/usr/local", "share", filename); | ||
\endcode | ||
\par warning | ||
The code does not check if there are already trailing path-separators, | ||
nor if the resulting path exists. | ||
*/ | ||
template <typename T> | ||
std::string append_path(std::string path, T a) | ||
{ | ||
return path + path_separator() + std::string(a); | ||
} | ||
template <typename T, typename... Ts> | ||
std::string append_path(std::string path, T a, Ts... args) | ||
{ | ||
return append_path(append_path(path, a), args...); | ||
} | ||
///@{ | ||
//! Returns where the examples are installed | ||
/*! | ||
\ingroup Common | ||
\par Example: | ||
\code | ||
std::string p = examples_data_path("PET"); | ||
\endcode | ||
*/ | ||
std::string examples_data_path(const char* data_type); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
SyneRBI Synergistic Image Reconstruction Framework (SIRF) | ||
Copyright 2023 Rutherford Appleton Laboratory STFC | ||
Copyright 2023 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 Common | ||
\author Evgueni Ovtchinnikov | ||
\author Kris Thielemans | ||
*/ | ||
#include "sirf/common/utilities.h" | ||
#include "sirf/common/version.h" | ||
#include "sirf/common/getenv.h" | ||
#include <sstream> | ||
|
||
namespace sirf { | ||
char path_separator() | ||
{ | ||
std::string filename = __FILE__; | ||
auto found = filename.find_last_of("/\\"); | ||
if (found == std::string::npos) | ||
return '/'; | ||
return filename[found]; | ||
} | ||
|
||
std::string examples_data_path(const char* data_type) | ||
{ | ||
std::string SIRF_data_path = sirf::getenv("SIRF_DATA_PATH"); | ||
if (SIRF_data_path.length() > 0) | ||
return append_path(SIRF_data_path, "examples", data_type); | ||
std::string SIRF_install_path = sirf::getenv("SIRF_INSTALL_PATH"); | ||
if (SIRF_install_path.length() > 0) { | ||
std::stringstream sirf_version; | ||
sirf_version << "SIRF-" << SIRF_VERSION_MAJOR << '.' << SIRF_VERSION_MINOR; | ||
return append_path(SIRF_install_path, "share", sirf_version.str(), "data", "examples", data_type); | ||
} | ||
std::string SIRF_path = sirf::getenv("SIRF_PATH"); | ||
if (SIRF_path.length() > 0) | ||
return append_path(SIRF_path, "data", "examples", data_type); | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.