1+ /*
2+ Copyright (C) 2024, 2025 University College London
3+
4+ SPDX-License-Identifier: Apache-2.0
5+ */
6+ #ifndef __petsird_helpers_geometry_h__
7+ #define __petsird_helpers_geometry_h__
8+
19#include < xtensor/xarray.hpp>
210#include < xtensor/xview.hpp>
311#include < xtensor/xio.hpp>
412#include < xtensor-blas/xlinalg.hpp>
513#include < vector>
614#include " generated/types.h"
15+ #include " petsird_helpers.h"
716
817namespace petsird_helpers
918{
@@ -12,40 +21,40 @@ namespace geometry
1221
1322// ! Convert RigidTransformation to 4x4 matrix
1423inline xt::xarray<float >
15- transform_to_mat44 (const RigidTransformation& transform)
24+ transform_to_mat44 (const petsird:: RigidTransformation& transform)
1625{
1726 xt::xarray<float > bottom_row = { { 0 .0f , 0 .0f , 0 .0f , 1 .0f } };
1827 return xt::concatenate (xt::xtuple (transform.matrix , bottom_row), 0 );
1928}
2029
2130// ! Convert 4x4 matrix to RigidTransformation
22- inline RigidTransformation
31+ inline petsird:: RigidTransformation
2332mat44_to_transform (const xt::xarray<float >& mat)
2433{
25- RigidTransformation transform;
34+ petsird:: RigidTransformation transform;
2635 transform.matrix = xt::view (mat, xt::range (0 , 3 ), xt::all ());
2736 return transform;
2837}
2938
3039// ! Convert Coordinate to homogeneous vector
3140inline xt::xarray<float >
32- coordinate_to_homogeneous (const Coordinate& coord)
41+ coordinate_to_homogeneous (const petsird:: Coordinate& coord)
3342{
3443 return xt::concatenate (xt::xtuple (coord.c , xt::xarray<float >{ 1 .0f }), 0 );
3544}
3645
3746// ! Convert homogeneous vector to Coordinate
38- inline Coordinate
47+ inline petsird:: Coordinate
3948homogeneous_to_coordinate (const xt::xarray<float >& hom_coord)
4049{
41- Coordinate coord;
50+ petsird:: Coordinate coord;
4251 coord.c = xt::view (hom_coord, xt::range (0 , 3 ));
4352 return coord;
4453}
4554
4655// ! Multiply a list of transformations
47- inline RigidTransformation
48- mult_transforms (const std::vector<RigidTransformation>& transforms)
56+ inline petsird:: RigidTransformation
57+ mult_transforms (const std::vector<petsird:: RigidTransformation>& transforms)
4958{
5059 xt::xarray<float > mat = xt::eye<float >(4 );
5160 for (auto it = transforms.rbegin (); it != transforms.rend (); ++it)
@@ -56,18 +65,18 @@ mult_transforms(const std::vector<RigidTransformation>& transforms)
5665}
5766
5867// ! Apply transformations to a coordinate
59- inline Coordinate
60- mult_transforms_coord (const std::vector<RigidTransformation>& transforms, const Coordinate& coord)
68+ inline petsird:: Coordinate
69+ mult_transforms_coord (const std::vector<petsird:: RigidTransformation>& transforms, const petsird:: Coordinate& coord)
6170{
6271 xt::xarray<float > hom = xt::linalg::dot (transform_to_mat44 (mult_transforms (transforms)), coordinate_to_homogeneous (coord));
6372 return homogeneous_to_coordinate (hom);
6473}
6574
6675// ! Transform a BoxShape
67- inline BoxShape
68- transform_BoxShape (const RigidTransformation& transform, const BoxShape& box_shape)
76+ inline petsird:: BoxShape
77+ transform_BoxShape (const petsird:: RigidTransformation& transform, const petsird:: BoxShape& box_shape)
6978{
70- BoxShape new_box;
79+ petsird:: BoxShape new_box;
7180 for (size_t i = 0 ; i < box_shape.corners .size (); ++i)
7281 {
7382 new_box.corners [i] = mult_transforms_coord ({ transform }, box_shape.corners [i]);
@@ -76,9 +85,9 @@ transform_BoxShape(const RigidTransformation& transform, const BoxShape& box_sha
7685}
7786
7887// ! find the BoxShape corresponding to a ExpandedDetectionBin
79- inline BoxShape
80- get_detecting_box (const ScannerInformation& scanner, const TypeOfModule& type_of_module,
81- const ExpandedDetectionBin& expanded_detection_bin)
88+ inline petsird:: BoxShape
89+ get_detecting_box (const petsird:: ScannerInformation& scanner, const petsird:: TypeOfModule& type_of_module,
90+ const petsird:: ExpandedDetectionBin& expanded_detection_bin)
8291{
8392 const auto & rep_module = scanner.scanner_geometry .replicated_modules [type_of_module];
8493 const auto & det_els = rep_module.object .detecting_elements ;
@@ -88,11 +97,13 @@ get_detecting_box(const ScannerInformation& scanner, const TypeOfModule& type_of
8897}
8998
9099// ! find the BoxShape corresponding to a DetectionBin
91- inline BoxShape
92- get_detecting_box (const ScannerInformation& scanner, const TypeOfModule& type_of_module, const DetectionBin& detection_bin)
100+ inline petsird::BoxShape
101+ get_detecting_box (const petsird::ScannerInformation& scanner, const petsird::TypeOfModule& type_of_module,
102+ const petsird::DetectionBin& detection_bin)
93103{
94104 return get_detecting_box (scanner, type_of_module, expand_detection_bin (scanner, type_of_module, detection_bin));
95105}
96106
97107} // namespace geometry
98108} // namespace petsird_helpers
109+ #endif
0 commit comments