-
Notifications
You must be signed in to change notification settings - Fork 97
Axial bucket projection issue #1375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KrisThielemans
merged 10 commits into
UCL:master
from
robbietuk:axial_bucket_projection_issue
Feb 15, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a4a7f5c
run_back_projection_test_with_axial_buckets
robbietuk d5e958e
Add a guard for axial crystals per bucket being a factor of num_rings
robbietuk 8cd047d
[ci skip] Refactor and renaming
bab0cdd
[ci skip] Remove duplicate test and access volume array without Pixel…
robbietuk 4c4c857
Require GeometryBlocksOnCylindrical to check scanner consistency and …
robbietuk 815c75e
Fix a logic bug with get_scanner_geometry() == "Generic"
robbietuk 65ae1f8
Fix an axial_block_spacing issue with a downsampled_scanner test
robbietuk 57fb97b
[ci skip] Allow test to run and reduce code duplication
robbietuk 070c06a
Add GeometryBlocksOnCylindricalTests
robbietuk 1bb2af0
[ci skip] Small fixes
robbietuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,151 @@ | ||
/*! | ||
|
||
\file | ||
\ingroup recontest | ||
|
||
\brief Test program to ensure the axial coordinates of blocks on cylindrical are monotonic with axial indices | ||
|
||
\author Robert Twyman | ||
|
||
Copyright (C) 2024, Prescient Imaging | ||
This file is part of STIR. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
|
||
See STIR/LICENSE.txt for details | ||
*/ | ||
|
||
#include "stir/recon_buildblock/ProjMatrixByBinUsingRayTracing.h" | ||
#include "stir/ExamInfo.h" | ||
#include "stir/Verbosity.h" | ||
#include "stir/LORCoordinates.h" | ||
#include "stir/ProjDataInfoGenericNoArcCorr.h" | ||
#include "stir/Succeeded.h" | ||
#include "stir/RunTests.h" | ||
#include "stir/Scanner.h" | ||
#include "stir/HighResWallClockTimer.h" | ||
#include "stir/GeometryBlocksOnCylindrical.h" | ||
#include "stir/IO/write_to_file.h" | ||
#include <cmath> | ||
|
||
START_NAMESPACE_STIR | ||
|
||
/*! | ||
\ingroup test | ||
\brief Test class for BlocksOnCylindrical geometry | ||
*/ | ||
class GeometryBlocksOnCylindricalTests : public RunTests | ||
{ | ||
public: | ||
void run_tests() override; | ||
|
||
private: | ||
/*! \brief Tests multiple axial blocks/bucket configurations to ensure the detector map's axial indices and coordinates | ||
* are monotonic | ||
*/ | ||
void run_monotonic_axial_coordinates_in_detector_map_test(); | ||
//! Tests the axial indices and coordinates are monotonic in the detector map | ||
static Succeeded monotonic_axial_coordinates_in_detector_map_test(const shared_ptr<Scanner>& scanner_sptr); | ||
}; | ||
|
||
void | ||
GeometryBlocksOnCylindricalTests::run_monotonic_axial_coordinates_in_detector_map_test() | ||
{ | ||
auto scanner_sptr = std::make_shared<Scanner>(Scanner::SAFIRDualRingPrototype); | ||
scanner_sptr->set_scanner_geometry("BlocksOnCylindrical"); | ||
scanner_sptr->set_transaxial_block_spacing(scanner_sptr->get_transaxial_crystal_spacing() | ||
* scanner_sptr->get_num_transaxial_crystals_per_block()); | ||
int num_axial_buckets = 1; // TODO add for loop when support is added | ||
|
||
for (int num_axial_crystals_per_blocks = 1; num_axial_crystals_per_blocks < 3; ++num_axial_crystals_per_blocks) | ||
for (int num_axial_blocks_per_bucket = 1; num_axial_blocks_per_bucket < 3; ++num_axial_blocks_per_bucket) | ||
{ | ||
scanner_sptr->set_num_axial_crystals_per_block(num_axial_crystals_per_blocks); | ||
scanner_sptr->set_num_axial_blocks_per_bucket(num_axial_blocks_per_bucket); | ||
scanner_sptr->set_num_rings(scanner_sptr->get_num_axial_crystals_per_bucket() * num_axial_buckets); | ||
scanner_sptr->set_axial_block_spacing(scanner_sptr->get_axial_crystal_spacing() | ||
* (scanner_sptr->get_num_axial_crystals_per_block() + 0.5)); | ||
|
||
if (monotonic_axial_coordinates_in_detector_map_test(scanner_sptr) == Succeeded::no) | ||
{ | ||
warning(boost::format("Monothonic axial coordinates test failed for:\n" | ||
"\taxial_crystal_per_block =\t%1%\n" | ||
"\taxial_blocks_per_bucket =\t%2%\n" | ||
"\tnum_axial_buckets =\t\t\t%3%") | ||
% num_axial_crystals_per_blocks % num_axial_blocks_per_bucket % num_axial_buckets); | ||
everything_ok = false; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
Succeeded | ||
GeometryBlocksOnCylindricalTests::monotonic_axial_coordinates_in_detector_map_test(const shared_ptr<Scanner>& scanner_sptr) | ||
{ | ||
if (scanner_sptr->get_scanner_geometry() != "BlocksOnCylindrical") | ||
{ | ||
warning("monotonic_axial_coordinates_in_detector_map_test is only for the BlocksOnCylindrical geometry"); | ||
return Succeeded::no; | ||
} | ||
|
||
shared_ptr<DetectorCoordinateMap> detector_map_sptr; | ||
try | ||
{ | ||
detector_map_sptr.reset(new GeometryBlocksOnCylindrical(*scanner_sptr)); | ||
} | ||
catch (const std::runtime_error& e) | ||
{ | ||
warning(boost::format("Caught runtime_error while creating GeometryBlocksOnCylindrical: %1%\n" | ||
"Failing the test.") | ||
% e.what()); | ||
return Succeeded::no; | ||
} | ||
|
||
unsigned min_axial_pos = 0; | ||
float prev_min_axial_coord = -std::numeric_limits<float>::max(); | ||
|
||
for (unsigned axial_idx = 0; axial_idx < detector_map_sptr->get_num_axial_coords(); ++axial_idx) | ||
for (unsigned tangential_idx = 0; tangential_idx < detector_map_sptr->get_num_tangential_coords(); ++tangential_idx) | ||
for (unsigned radial_idx = 0; radial_idx < detector_map_sptr->get_num_radial_coords(); ++radial_idx) | ||
{ | ||
const DetectionPosition<> det_pos = DetectionPosition<>(tangential_idx, axial_idx, radial_idx); | ||
CartesianCoordinate3D<float> coord = detector_map_sptr->get_coordinate_for_det_pos(det_pos); | ||
if (coord.z() > prev_min_axial_coord) | ||
{ | ||
min_axial_pos = axial_idx; | ||
prev_min_axial_coord = coord.z(); | ||
} | ||
else if (coord.z() < prev_min_axial_coord) | ||
{ | ||
float delta = coord.z() - prev_min_axial_coord; | ||
warning(boost::format("Axial Coordinates are not monotonic.\n" | ||
"Next axial index =\t\t%1%, Next axial coord (mm) =\t\t%2% (%3%)\n" | ||
"Previous axial index =\t%4%, Previous axial coord (mm) =\t%5%") | ||
% axial_idx % coord.z() % delta % min_axial_pos % prev_min_axial_coord); | ||
return Succeeded::no; | ||
} | ||
} | ||
|
||
return Succeeded::yes; | ||
} | ||
|
||
void | ||
GeometryBlocksOnCylindricalTests::run_tests() | ||
{ | ||
HighResWallClockTimer timer; | ||
timer.start(); | ||
run_monotonic_axial_coordinates_in_detector_map_test(); | ||
timer.stop(); | ||
} | ||
END_NAMESPACE_STIR | ||
|
||
USING_NAMESPACE_STIR | ||
|
||
int | ||
main() | ||
{ | ||
Verbosity::set(1); | ||
GeometryBlocksOnCylindricalTests tests; | ||
tests.run_tests(); | ||
return tests.main_return_value(); | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.