STIR 6.4.0
more_interpolators.inl
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2003- 2005, Hammersmith Imanet Ltd
5 For internal GE use only.
6*/
15#include "stir/Coordinate3D.h"
16#include "stir/Array.h"
17#include "stir/round.h"
18#include <cmath>
19
20START_NAMESPACE_STIR
21
22template <class elemT, class positionT>
23elemT
25{
26 // find nearest neighbour
27 const Coordinate3D<int> nearest_neighbour = round(point_in_input_coords);
28
29 if (nearest_neighbour[1] <= in.get_max_index() && nearest_neighbour[1] >= in.get_min_index()
30 && nearest_neighbour[2] <= in[nearest_neighbour[1]].get_max_index()
31 && nearest_neighbour[2] >= in[nearest_neighbour[1]].get_min_index()
32 && nearest_neighbour[3] <= in[nearest_neighbour[1]][nearest_neighbour[2]].get_max_index()
33 && nearest_neighbour[3] >= in[nearest_neighbour[1]][nearest_neighbour[2]].get_min_index())
34 {
35 return in[nearest_neighbour];
36 }
37 else
38 return 0;
39}
40
41template <int num_dimensions, class elemT, class positionT, class valueT>
42void
44 const BasicCoordinate<num_dimensions, positionT>& point_in_output_coords,
45 valueT value)
46{
47 if (value == 0)
48 return;
49 const BasicCoordinate<num_dimensions, int> nearest_neighbour = round(point_in_output_coords);
50
51 if (nearest_neighbour[1] <= out.get_max_index() && nearest_neighbour[1] >= out.get_min_index()
52 && nearest_neighbour[2] <= out[nearest_neighbour[1]].get_max_index()
53 && nearest_neighbour[2] >= out[nearest_neighbour[1]].get_min_index()
54 && nearest_neighbour[3] <= out[nearest_neighbour[1]][nearest_neighbour[2]].get_max_index()
55 && nearest_neighbour[3] >= out[nearest_neighbour[1]][nearest_neighbour[2]].get_min_index())
56 out[nearest_neighbour] += static_cast<elemT>(value);
57}
58
59template <class elemT, class positionT>
60elemT
62{
63 // find left neighbour
64 const Coordinate3D<int> left_neighbour(round(std::floor(point_in_input_coords[1])),
65 round(std::floor(point_in_input_coords[2])),
66 round(std::floor(point_in_input_coords[3])));
67
68 // TODO handle boundary conditions
69 if (left_neighbour[1] < in.get_max_index() && left_neighbour[1] >= in.get_min_index()
70 && left_neighbour[2] < in[left_neighbour[1]].get_max_index() && left_neighbour[2] >= in[left_neighbour[1]].get_min_index()
71 && left_neighbour[3] < in[left_neighbour[1]][left_neighbour[2]].get_max_index()
72 && left_neighbour[3] >= in[left_neighbour[1]][left_neighbour[2]].get_min_index())
73 {
74 const int x1 = left_neighbour[3];
75 const int y1 = left_neighbour[2];
76 const int z1 = left_neighbour[1];
77 const int x2 = left_neighbour[3] + 1;
78 const int y2 = left_neighbour[2] + 1;
79 const int z2 = left_neighbour[1] + 1;
80 const positionT ix = point_in_input_coords[3] - x1;
81 const positionT iy = point_in_input_coords[2] - y1;
82 const positionT iz = point_in_input_coords[1] - z1;
83 const positionT ixc = 1 - ix;
84 const positionT iyc = 1 - iy;
85 const positionT izc = 1 - iz;
86 return static_cast<elemT>(
87 ixc * (iyc * (izc * in[z1][y1][x1] + iz * in[z2][y1][x1]) + iy * (izc * in[z1][y2][x1] + iz * in[z2][y2][x1]))
88 + ix * (iyc * (izc * in[z1][y1][x2] + iz * in[z2][y1][x2]) + iy * (izc * in[z1][y2][x2] + iz * in[z2][y2][x2])));
89 }
90 else
91 return 0;
92}
93
94template <class elemT, class positionT, class valueT>
95void
97{
98 if (value == 0)
99 return;
100 // find left neighbour
101 const Coordinate3D<int> left_neighbour(round(std::floor(point_in_output_coords[1])),
102 round(std::floor(point_in_output_coords[2])),
103 round(std::floor(point_in_output_coords[3])));
104
105 // TODO handle boundary conditions
106 if (left_neighbour[1] < out.get_max_index() && left_neighbour[1] >= out.get_min_index()
107 && left_neighbour[2] < out[left_neighbour[1]].get_max_index() && left_neighbour[2] >= out[left_neighbour[1]].get_min_index()
108 && left_neighbour[3] < out[left_neighbour[1]][left_neighbour[2]].get_max_index()
109 && left_neighbour[3] >= out[left_neighbour[1]][left_neighbour[2]].get_min_index())
110 {
111 const int x1 = left_neighbour[3];
112 const int y1 = left_neighbour[2];
113 const int z1 = left_neighbour[1];
114 const int x2 = left_neighbour[3] + 1;
115 const int y2 = left_neighbour[2] + 1;
116 const int z2 = left_neighbour[1] + 1;
117 const float ix = point_in_output_coords[3] - x1;
118 const float iy = point_in_output_coords[2] - y1;
119 const float iz = point_in_output_coords[1] - z1;
120 const float ixc = 1 - ix;
121 const float iyc = 1 - iy;
122 const float izc = 1 - iz;
123 out[z1][y1][x1] += ixc * iyc * izc * value;
124 out[z2][y1][x1] += ixc * iyc * iz * value;
125 out[z1][y2][x1] += ixc * iy * izc * value;
126 out[z2][y2][x1] += ixc * iy * iz * value;
127 out[z1][y1][x2] += ix * iyc * izc * value;
128 out[z2][y1][x2] += ix * iyc * iz * value;
129 out[z1][y2][x2] += ix * iy * izc * value;
130 out[z2][y2][x2] += ix * iy * iz * value;
131 }
132}
133
134END_NAMESPACE_STIR
defines the stir::Array class for multi-dimensional (numeric) arrays
defines the stir::Coordinate3D<coordT> class
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition BasicCoordinate.h:57
a templated class for 3-dimensional coordinates.
Definition Coordinate3D.h:43
int get_max_index() const
get value of last valid index
Definition VectorWithOffset.inl:131
int get_min_index() const
get value of first valid index
Definition VectorWithOffset.inl:124
elemT pull_linear_interpolate(const Array< 3, elemT > &in, const BasicCoordinate< 3, positionT > &point_in_input_coords)
Returns an interpolated value according to point_in_input_coords.
Definition more_interpolators.inl:61
void push_transpose_linear_interpolate(Array< 3, elemT > &out, const BasicCoordinate< 3, positionT > &point_in_output_coords, valueT value)
Push value into the output array using the transpose of linear interpolation.
Definition more_interpolators.inl:96
void push_nearest_neighbour_interpolate(Array< num_dimensions, elemT > &out, const BasicCoordinate< num_dimensions, positionT > &point_in_output_coords, valueT value)
Push value into the output array using nearest neigbour interpolation.
Definition more_interpolators.inl:43
elemT pull_nearest_neighbour_interpolate(const Array< 3, elemT > &in, const BasicCoordinate< 3, positionT > &point_in_input_coords)
Pull value from the input array using nearest neigbour interpolation.
Definition more_interpolators.inl:24
int round(const float x)
Implements rounding of floating point numbers.
Definition round.inl:59
Declaration of the stir::round functions.