Skip to content

Commit

Permalink
started moving Challenge nema-data utilities to SIRF
Browse files Browse the repository at this point in the history
  • Loading branch information
evgueni-ovtchinnikov committed Apr 15, 2024
1 parent 2c66faf commit c25c1e0
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/xSTIR/cSTIR/include/sirf/STIR/stir_x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<STIRAcquisitionData> get_output()
Expand All @@ -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<STIRAcquisitionData>& sinograms_sptr,
std::shared_ptr<STIRAcquisitionData>& 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;
Expand Down
6 changes: 6 additions & 0 deletions src/xSTIR/cSTIR/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
80 changes: 80 additions & 0 deletions src/xSTIR/cSTIR/tests/test7.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <cstdlib>

#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<STIRAcquisitionData> sinograms_sptr;
std::shared_ptr<STIRAcquisitionData> 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;
}
}

0 comments on commit c25c1e0

Please sign in to comment.