SIRF  3.4.0
GeometricalInfo.h
1 /*
2  SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3  Copyright 2018 Commonwealth Scientific and Industrial Research Organisation's
4  Australian eHealth Research Organisation
5  Copyright 2020 Rutherford Appleton Laboratory STFC
6  Copyright 2019 - 2020 University College London
7 
8  This is software developed for the Collaborative Computational
9  Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
10  (http://www.ccpsynerbi.ac.uk/).
11 
12  Licensed under the Apache License, Version 2.0 (the "License");
13  you may not use this file except in compliance with the License.
14  You may obtain a copy of the License at
15  http://www.apache.org/licenses/LICENSE-2.0
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 */
22 
23 #ifndef SIRF_GEOMETRICAL_INFO_TYPE
24 #define SIRF_GEOMETRICAL_INFO_TYPE
25 
26 #include <array>
27 #include <string>
28 
29 namespace sirf {
30 
31 template <int num_physical_dimensions, int num_index_dimensions>
33 public:
34  typedef std::array<float, num_physical_dimensions> Coordinate;
35  typedef std::array<unsigned int, num_index_dimensions> Index;
36  // Eventually something here like
37  // Coordinate transform_index_to_physical_point(Index)
38  // Index transform_physical_point_to_index(Coordinate)
39 
40  virtual bool operator==(const GeometricalInfo& vgi) const = 0;
41  virtual bool operator!=(const GeometricalInfo& vgi) const = 0;
43  virtual void print_info() const = 0;
44  virtual std::string get_info() const = 0;
45 };
46 
47 
48 template <int num_dimensions>
50  public GeometricalInfo<num_dimensions, num_dimensions> {
51 private:
53 
54 public:
55  // TODO: Why to I have to define these again?
56  typedef typename BaseType::Coordinate Coordinate;
57  typedef typename BaseType::Index Index;
58 
63  typedef Coordinate Offset;
67  typedef Coordinate Spacing;
71  typedef Index Size;
76  typedef std::array<Coordinate, num_dimensions> DirectionMatrix;
81  typedef std::array<std::array<float, num_dimensions+1>, num_dimensions+1>
83 
84 
86  const Offset& _offset, const Spacing& _spacing,
87  const Size& _size, const DirectionMatrix& _direction);
88  virtual ~VoxelisedGeometricalInfo() {};
89 
90  virtual bool operator==(const GeometricalInfo<num_dimensions, num_dimensions>& gi) const
91  {
92  const VoxelisedGeometricalInfo& vgi = (const VoxelisedGeometricalInfo&)gi;
93  const float eps = 0.01F;
94  const float delta = 0.1F;
95  return
96  near_(_offset, vgi.get_offset(), eps) &&
97  near_(_spacing, vgi.get_spacing(), eps) &&
98  _size == vgi.get_size() &&
99  near_(_direction, vgi.get_direction(), delta);
100  }
101  virtual bool operator!=(const GeometricalInfo<num_dimensions, num_dimensions>& gi) const
102  {
103  const VoxelisedGeometricalInfo& vgi = (const VoxelisedGeometricalInfo&)gi;
104  return !(*this == vgi);
105  }
106  const Offset get_offset() const;
107  const Spacing get_spacing() const;
108  const Size get_size() const;
109  const DirectionMatrix get_direction() const;
110 
111  const TransformMatrix calculate_index_to_physical_point_matrix() const;
112 
114  virtual void print_info() const;
115  virtual std::string get_info() const;
116 
117 private:
118  Offset _offset;
119  Spacing _spacing;
120  Size _size;
121  DirectionMatrix _direction;
122  static bool near_(const Coordinate& x, const Coordinate& y, float eps)
123  {
124  float t = 0;
125  for (int i = 0; i < num_dimensions; i++) {
126  float xi = x[i];
127  float yi = y[i];
128  t = std::max(t, std::abs(xi - yi));
129  }
130  return t <= eps;
131  }
132  static bool near_(const DirectionMatrix& x, const DirectionMatrix& y, float eps)
133  {
134  float t = 0;
135  for (int i = 0; i < num_dimensions; i++) {
136  for (int j = 0; j < num_dimensions; j++) {
137  float xij = x[i][j];
138  float yij = y[i][j];
139  t = std::max(t, std::abs(xij - yij));
140  }
141  }
142  return t <= eps;
143  }
144 };
145 
148 typedef VoxelisedGeometricalInfo<3>::TransformMatrix TransformMatrix3D;
149 
150 }
151 
152 #endif
Definition: GeometricalInfo.h:49
Coordinate Offset
Definition: GeometricalInfo.h:63
virtual void print_info() const =0
Print info.
Abstract data container.
Definition: GeometricalInfo.cpp:141
Coordinate Spacing
Definition: GeometricalInfo.h:67
Definition: GeometricalInfo.h:32
std::array< std::array< float, num_dimensions+1 >, num_dimensions+1 > TransformMatrix
Definition: GeometricalInfo.h:82
Index Size
Definition: GeometricalInfo.h:71
std::array< Coordinate, num_dimensions > DirectionMatrix
Definition: GeometricalInfo.h:76