Skip to content

Commit 35c0599

Browse files
Merge pull request #135 from KrisThielemans/cpp_fixes
C++ helper fixes (setting version to 0.7.2)
2 parents 82e6571 + fcad803 commit 35c0599

File tree

9 files changed

+54
-36
lines changed

9 files changed

+54
-36
lines changed

cpp/CMakeLists.txt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.12.0) # older would work, but could give warnings on policy CMP0074
2-
project(petsird VERSION 0.7.1)
2+
project(petsird VERSION 0.7.2)
33

44
set(CMAKE_CXX_STANDARD 17)
55

@@ -15,16 +15,5 @@ if(CCACHE_PROGRAM)
1515
message(STATUS "ccache found, so we will use it.")
1616
endif()
1717

18-
add_executable(petsird_generator petsird_generator.cpp)
19-
target_link_libraries(petsird_generator petsird_generated)
20-
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
21-
# needed for generated PETSIRD files
22-
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/")
23-
24-
add_executable(petsird_analysis petsird_analysis.cpp)
25-
target_link_libraries(petsird_analysis petsird_generated)
26-
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
27-
# needed for generated PETSIRD files
28-
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/")
29-
3018
add_subdirectory(generated)
19+
add_subdirectory(helpers)

cpp/helpers/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
add_executable(petsird_generator petsird_generator.cpp)
3+
target_link_libraries(petsird_generator petsird_generated)
4+
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
5+
# needed for generated PETSIRD files
6+
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/")
7+
8+
add_executable(petsird_analysis petsird_analysis.cpp)
9+
target_link_libraries(petsird_analysis petsird_generated)
10+
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
11+
# needed for generated PETSIRD files
12+
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
SPDX-License-Identifier: Apache-2.0
55
*/
6+
#ifndef __petsird_helpers_h__
7+
#define __petsird_helpers_h__
68

79
#include "generated/types.h"
810
#include <array>
@@ -138,3 +140,5 @@ get_detection_efficiency(const ScannerInformation& scanner, const TypeOfModulePa
138140
}
139141

140142
} // namespace petsird_helpers
143+
144+
#endif

cpp/helpers/include/petsird_helpers/create.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#ifndef __petsird_helpers_create_h__
8+
#define __petsird_helpers_create_h__
9+
710
#include "generated/types.h"
811
#include <array>
912

@@ -12,8 +15,6 @@ namespace petsird_helpers
1215
namespace create
1316
{
1417

15-
using namespace petsird;
16-
1718
//! Helper function to create a std::vector<T>
1819
/*! This function is added to have a 1D analogue construct_2D_nested_vector() */
1920
template <typename T>
@@ -76,3 +77,4 @@ initialize_scanner_information_dimensions(petsird::ScannerInformation& scanner,
7677

7778
} // namespace create
7879
} // namespace petsird_helpers
80+
#endif
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
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

817
namespace petsird_helpers
918
{
@@ -12,40 +21,40 @@ namespace geometry
1221

1322
//! Convert RigidTransformation to 4x4 matrix
1423
inline 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
2332
mat44_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
3140
inline 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
3948
homogeneous_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
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ main(int argc, char const* argv[])
185185
<< "energy_index=" << expanded_detection_bin0.energy_index
186186
<< "), ExpandedDetectionBin(module=" << expanded_detection_bin1.module_index << ", "
187187
<< "el=" << expanded_detection_bin1.element_index << ", "
188-
<< "energy_index=" << expanded_detection_bin0.energy_index << ")]\n";
188+
<< "energy_index=" << expanded_detection_bin1.energy_index << ")]\n";
189189
std::cout << " efficiency:"
190190
<< petsird_helpers::get_detection_efficiency(header.scanner, type_of_module_pair, event) << "\n";
191191
}

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set shell := ['bash', '-ceuo', 'pipefail']
2727

2828
@run-cpp: build-cpp
2929
#!/usr/bin/env bash
30-
cd cpp/build
30+
cd cpp/build/helpers
3131
./petsird_generator testdata.petsird
3232
./petsird_analysis testdata.petsird
3333
rm -f testdata.petsird

matlab/buildfile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function buildToolbox (outdir)
2323

2424
opts.ToolboxName = "PETSIRD";
2525

26-
opts.ToolboxVersion = "0.7.1";
26+
opts.ToolboxVersion = "0.7.2";
2727
opts.OutputFile = fullfile(outdir, sprintf("petsird-%s.mltbx", opts.ToolboxVersion));
2828

2929
opts.Description = "Positron Emission Tomography Standardization Initiative Raw Data (PETSIRD) toolbox for MATLAB";

0 commit comments

Comments
 (0)