diff --git a/src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h b/src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h index 374ccd9bf..bbf0c257b 100644 --- a/src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h +++ b/src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h @@ -205,7 +205,7 @@ The actual algorithm is described in int estimate_randoms(); void save_randoms() { - std::string filename = output_filename_prefix + "_randoms" + "_f1g1d0b0.hs"; + std::string filename = "randoms_f1g1d0b0.hs"; randoms_sptr->write(filename.c_str()); } std::shared_ptr get_output() @@ -222,6 +222,24 @@ The actual algorithm is described in /// Returns -1 if not found. float get_time_at_which_num_prompts_exceeds_threshold(const unsigned long threshold) const; + void sinograms_and_randoms_from_listmode( + STIRListmodeData& lm_data, double start, double stop, + STIRAcquisitionData& acq_data_template, + std::shared_ptr& sinograms_sptr, + std::shared_ptr& randoms_sptr) + { + ListmodeToSinograms converter; + converter.set_input(lm_data); + converter.set_output("sinograms"); + converter.set_template(acq_data_template); + converter.set_time_interval(start, stop); + converter.set_up(); + converter.process_data(); + sinograms_sptr = converter.get_output(); + converter.estimate_randoms(); + randoms_sptr = converter.get_randoms_sptr(); + } + protected: // variables for ML estimation of singles/randoms int fan_size; diff --git a/src/xSTIR/cSTIR/tests/CMakeLists.txt b/src/xSTIR/cSTIR/tests/CMakeLists.txt index 8c185147b..55fcd697d 100644 --- a/src/xSTIR/cSTIR/tests/CMakeLists.txt +++ b/src/xSTIR/cSTIR/tests/CMakeLists.txt @@ -29,9 +29,15 @@ target_link_libraries(cstir_test6 csirf cstir ${STIR_LIBRARIES}) INSTALL(TARGETS cstir_test6 DESTINATION bin) + add_executable(cstir_test7 test7.cpp ${STIR_REGISTRIES}) + target_link_libraries(cstir_test7 csirf cstir ${STIR_LIBRARIES}) + INSTALL(TARGETS cstir_test7 DESTINATION bin) + ADD_TEST(NAME PET_TESTS_CPLUSPLUS_1 COMMAND cstir_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_SIRF_DATA_PATH(PET_TESTS_CPLUSPLUS_1) ADD_TEST(NAME PET_TESTS_CPLUSPLUS_4 COMMAND cstir_test4 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_SIRF_DATA_PATH(PET_TESTS_CPLUSPLUS_4) ADD_TEST(NAME PET_TESTS_CPLUSPLUS_6 COMMAND cstir_test6 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_SIRF_DATA_PATH(PET_TESTS_CPLUSPLUS_6) +ADD_TEST(NAME PET_TESTS_CPLUSPLUS_7 COMMAND cstir_test7 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_SIRF_DATA_PATH(PET_TESTS_CPLUSPLUS_7) diff --git a/src/xSTIR/cSTIR/tests/test7.cpp b/src/xSTIR/cSTIR/tests/test7.cpp new file mode 100644 index 000000000..230155d81 --- /dev/null +++ b/src/xSTIR/cSTIR/tests/test7.cpp @@ -0,0 +1,80 @@ +/* +SyneRBI Synergistic Image Reconstruction Framework (SIRF) +Copyright 2018 - 2020 Rutherford Appleton Laboratory STFC +Copyright 2018 - 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 PET + +\author Evgueni Ovtchinnikov +\author Richard Brown +\author SyneRBI +*/ +#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 main() +{ + std::cout << "running test7.cpp...\n"; + try { + std::string SIRF_data_path = examples_data_path("PET"); + if (SIRF_data_path.length() < 1) { + std::cout << "cannot find data" << std::endl; + return 1; + } + std::string path = append_path(SIRF_data_path, "mMR"); + std::string f_listmode = append_path(path, "list.l.hdr"); + std::string f_template = append_path(path, "mMR_template_span11_small.hs"); + + STIRAcquisitionDataInMemory::set_as_template(); + + STIRAcquisitionDataInFile acq_data_template(f_template.c_str()); + STIRListmodeData lm_data(f_listmode); + ListmodeToSinograms converter; + + std::shared_ptr sinograms_sptr; + std::shared_ptr randoms_sptr; + converter.sinograms_and_randoms_from_listmode + (lm_data, 0, 10, acq_data_template, sinograms_sptr, randoms_sptr); + + std::cout << sinograms_sptr->norm() << '\n'; + std::cout << randoms_sptr->norm() << '\n'; + + std::cout << "done with test7.cpp...\n"; + return 0; + } + catch (...) + { + return 1; + } +}