Skip to content

Commit

Permalink
Helper/generator fixes (#56)
Browse files Browse the repository at this point in the history
* fix module_id order

Fixes #54

* fix conversion from detector_id to mod/el

follow agreed order

fixes #55

* simplify id generation
  • Loading branch information
KrisThielemans authored Nov 7, 2024
1 parent 265cf60 commit f8616f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cpp/petsird_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ constexpr uint32_t NUMBER_OF_ENERGY_BINS = 3;
constexpr uint32_t NUMBER_OF_TOF_BINS = 300;
constexpr float RADIUS = 400.F;
constexpr std::array<float, 3> CRYSTAL_LENGTH{ 20.F, 4.F, 4.F };
constexpr std::array<float, 3> NUM_CRYSTALS_PER_MODULE{ 2, 4, 5 };
constexpr std::array<float, 3> NUM_CRYSTALS_PER_MODULE{ 2, 4, 7 };
constexpr uint32_t NUM_MODULES_ALONG_RING{ 20 };
constexpr uint32_t NUM_MODULES_ALONG_AXIS{ 2 };
constexpr float MODULE_AXIS_SPACING{ (NUM_CRYSTALS_PER_MODULE[2] + 4) * CRYSTAL_LENGTH[2] };
Expand Down Expand Up @@ -64,6 +64,7 @@ get_detector_module()
constexpr auto N0 = NUM_CRYSTALS_PER_MODULE[0];
constexpr auto N1 = NUM_CRYSTALS_PER_MODULE[1];
constexpr auto N2 = NUM_CRYSTALS_PER_MODULE[2];
unsigned id = 0;
for (int rep0 = 0; rep0 < N0; ++rep0)
for (int rep1 = 0; rep1 < N1; ++rep1)
for (int rep2 = 0; rep2 < N2; ++rep2)
Expand All @@ -72,7 +73,7 @@ get_detector_module()
{ 0.0, 1.0, 0.0, (rep1 - N1 / 2) * CRYSTAL_LENGTH[1] },
{ 0.0, 0.0, 1.0, (rep2 - N2 / 2) * CRYSTAL_LENGTH[2] } } };
rep_volume.transforms.push_back(transform);
rep_volume.ids.push_back(rep0 + N0 * (rep1 + N1 * rep2));
rep_volume.ids.push_back(id++);
}
}

Expand Down
6 changes: 4 additions & 2 deletions python/petsird_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
RADIUS = 400
CRYSTAL_LENGTH = (20, 4, 4)
# num crystals in a module
NUM_CRYSTALS_PER_MODULE = (2, 4,5)
NUM_CRYSTALS_PER_MODULE = (2, 4, 7)
NUM_MODULES_ALONG_RING = 20
NUM_MODULES_ALONG_AXIS = 2
MODULE_AXIS_SPACING = (NUM_CRYSTALS_PER_MODULE[2] + 4) * CRYSTAL_LENGTH[2]
Expand Down Expand Up @@ -55,6 +55,7 @@ def get_detector_module() -> petsird.DetectorModule:
N0 = NUM_CRYSTALS_PER_MODULE[0]
N1 = NUM_CRYSTALS_PER_MODULE[1]
N2 = NUM_CRYSTALS_PER_MODULE[2]
id = 0
for rep0 in range(N0):
for rep1 in range(N1):
for rep2 in range(N2):
Expand All @@ -69,7 +70,8 @@ def get_detector_module() -> petsird.DetectorModule:
)
)
rep_volume.transforms.append(transform)
rep_volume.ids.append(rep0 + N0 * (rep1 + N1 * rep2))
rep_volume.ids.append(id)
id += 1

return petsird.DetectorModule(
detecting_elements=[rep_volume], detecting_element_ids=[0]
Expand Down
7 changes: 5 additions & 2 deletions python/petsird_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ def get_module_and_element(
assert len(scanner_geometry.replicated_modules) == 1
rep_module = scanner_geometry.replicated_modules[0]
assert len(rep_module.object.detecting_elements) == 1
num_modules = len(rep_module.transforms)
num_el_per_module = len(
rep_module.object.detecting_elements[0].ids
)

return [
ModuleAndElement(module=det % num_modules, el=det // num_modules)
ModuleAndElement(module=det // num_el_per_module, el=det % num_el_per_module)
for det in scanner_det_ids
]

Expand Down

0 comments on commit f8616f8

Please sign in to comment.