STIR  6.2.0
BasicCoordinate.h
Go to the documentation of this file.
1 #ifndef __stir_BasicCoordinate_H__
2 #define __stir_BasicCoordinate_H__
3 //
4 //
5 /*
6  Copyright (C) 2000 PARAPET partners
7  Copyright (C) 2000 - 2011-01-04, Hammersmith Imanet Ltd
8  Copyright (C) 2012-06-01 - 2013, Kris Thielemans
9  This file is part of STIR.
10 
11  SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
12 
13  See STIR/LICENSE.txt for details
14 */
15 
33 #include "stir/common.h"
34 #include <boost/operators.hpp>
35 #include <iterator>
36 
37 START_NAMESPACE_STIR
52 template <int num_dimensions, typename coordT>
54  : boost::partially_ordered<BasicCoordinate<num_dimensions, coordT>, // have operator>, <= etc for free
55  boost::equality_comparable<BasicCoordinate<num_dimensions, coordT> // have operator!= for free
56  >>
57 {
58 
59 public:
61 
62  typedef std::random_access_iterator_tag iterator_category;
63  typedef coordT value_type;
64  typedef value_type& reference;
65  typedef const value_type& const_reference;
66  typedef value_type* iterator;
67  typedef value_type* pointer;
68  typedef const value_type* const_iterator;
69  typedef std::ptrdiff_t difference_type;
70  typedef std::size_t size_type;
72 
74  inline BasicCoordinate();
76  explicit inline BasicCoordinate(const coordT&);
77 #if 0
78  /* disabled. It overlaps with the constructor below and VC 6.0 can't sort it out.
79  We don't seem to need it anyway
80  */
82  inline BasicCoordinate(const BasicCoordinate& c);
83 #endif
84 
86  // Note implementation here for VC 6.0
87  template <typename coordT2>
89  {
90  for (int i = 1; i <= num_dimensions; ++i)
91  (*this)[i] = static_cast<coordT>(c[i]);
92  }
93  // virtual destructor, not implemented at the moment
94  // It's only needed whenever there is a chance that an object will be deleted
95  // through a pointer to its base class and derived classes have extra
96  // data members
97  // virtual ~BasicCoordinate() {}
98 
100  inline BasicCoordinate& operator=(const BasicCoordinate& c);
101 
103  inline bool operator==(const BasicCoordinate& c) const;
104 
106  inline bool operator<(const BasicCoordinate& c) const;
107 
108  // access to elements
110  inline coordT& operator[](const int d);
112 
118  inline coordT const& operator[](const int d) const;
119 
121  inline coordT& at(const int d);
124  inline coordT const& at(const int d) const;
125 
126  // check if the coordinate is empty (always returns false)
127  inline bool empty() const
128  {
129  return false;
130  }
131 
133 
134  inline static int get_min_index();
135  inline static int get_max_index();
136  inline static unsigned size();
138  inline void fill(const coordT&);
140 
142 
143  inline BasicCoordinate& operator+=(const BasicCoordinate& c);
144  inline BasicCoordinate& operator-=(const BasicCoordinate& c);
145  inline BasicCoordinate& operator*=(const BasicCoordinate& c);
146  inline BasicCoordinate& operator/=(const BasicCoordinate& c);
147 
148  inline BasicCoordinate& operator+=(const coordT& a);
149  inline BasicCoordinate& operator-=(const coordT& a);
150  inline BasicCoordinate& operator*=(const coordT& a);
151  inline BasicCoordinate& operator/=(const coordT& a);
153 
155 
156  inline BasicCoordinate operator+(const BasicCoordinate& c) const;
157  inline BasicCoordinate operator-(const BasicCoordinate& c) const;
158  inline BasicCoordinate operator*(const BasicCoordinate& c) const;
159  inline BasicCoordinate operator/(const BasicCoordinate& c) const;
161 
163 
164  inline BasicCoordinate operator+(const coordT& a) const;
165  inline BasicCoordinate operator-(const coordT& a) const;
166  inline BasicCoordinate operator*(const coordT& a) const;
167  inline BasicCoordinate operator/(const coordT& a) const;
168  inline BasicCoordinate operator-() const;
170 
172 
173  inline iterator begin();
174  inline const_iterator begin() const;
175  inline iterator end();
176  inline const_iterator end() const;
178 
179 private:
181 
182  coordT coords[num_dimensions];
183 };
184 
196 
197 template <class T>
198 inline BasicCoordinate<1, T> make_coordinate(const T& a1);
199 
200 template <class T>
201 inline BasicCoordinate<2, T> make_coordinate(const T& a1, const T& a2);
202 
203 template <class T>
204 inline BasicCoordinate<3, T> make_coordinate(const T& a1, const T& a2, const T& a3);
205 
206 template <class T>
207 inline BasicCoordinate<4, T> make_coordinate(const T& a1, const T& a2, const T& a3, const T& a4);
208 
209 template <class T>
210 inline BasicCoordinate<5, T> make_coordinate(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5);
211 
212 template <class T>
213 inline BasicCoordinate<6, T> make_coordinate(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6);
214 
216 
217 /*
218  General functions on BasicCoordinate objects, like in ArrayFunction.h
219 */
220 
222 
225 template <int num_dimensions, typename coordT>
228 
231 template <int num_dimensions, typename coordT>
234 
237 template <int num_dimensions, typename coordT>
238 inline double norm(const BasicCoordinate<num_dimensions, coordT>& p1);
240 
243 template <int num_dimensions, typename coordT>
245 
247 
250 template <int num_dimensions, typename coordT>
252 
253 // Note: gcc 2.8.1 bug:
254 // It cannot call 'join' (it generates a bad mangled name for the function)
256 
257 template <int num_dimensions, typename coordT>
259 
261 
262 template <int num_dimensions, class coordT>
264 
266 
267 template <int num_dimensions, class coordT>
268 inline BasicCoordinate<num_dimensions - 1, coordT> cut_last_dimension(const BasicCoordinate<num_dimensions, coordT>& c);
269 
271 
272 template <int num_dimensions, typename coordT>
273 inline BasicCoordinate<num_dimensions - 1, coordT> cut_first_dimension(const BasicCoordinate<num_dimensions, coordT>& c);
274 
276 
277 template <int num_dimensions>
279 
280 END_NAMESPACE_STIR
281 
282 #include "stir/BasicCoordinate.inl"
283 
284 #endif
BasicCoordinate< num_dimensions, float > convert_int_to_float(const BasicCoordinate< num_dimensions, int > &cint)
converts a BasicCoordinate<int> to BasicCoordinate<float>
Definition: BasicCoordinate.inl:486
BasicCoordinate< num_dimensions+1, coordT > join(const BasicCoordinate< num_dimensions, coordT > &c, const coordT &a)
make a longer BasicCoordinate, by appending the coordT to c
Definition: BasicCoordinate.inl:466
BasicCoordinate< num_dimensions - 1, coordT > cut_last_dimension(const BasicCoordinate< num_dimensions, coordT > &c)
make a shorter BasicCoordinate, by cutting the last element from c
Definition: BasicCoordinate.inl:458
double angle(const BasicCoordinate< num_dimensions, coordT > &p1, const BasicCoordinate< num_dimensions, coordT > &p2)
compute angle between 2 directions
Definition: BasicCoordinate.inl:440
BasicCoordinate< num_dimensions - 1, coordT > cut_first_dimension(const BasicCoordinate< num_dimensions, coordT > &c)
make a shorter BasicCoordinate, by cutting the first element from c
Definition: BasicCoordinate.inl:477
BasicCoordinate(const BasicCoordinate< num_dimensions, coordT2 > &c)
constructor from different type of coordT
Definition: BasicCoordinate.h:88
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition: BasicCoordinate.inl:415
coordT inner_product(const BasicCoordinate< num_dimensions, coordT > &p1, const BasicCoordinate< num_dimensions, coordT > &p2)
compute sum_i p1[i] * p2[i]
Definition: BasicCoordinate.inl:408
double cos_angle(const BasicCoordinate< num_dimensions, coordT > &p1, const BasicCoordinate< num_dimensions, coordT > &p2)
compute cos of the angle between 2 directions
Definition: BasicCoordinate.inl:433
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition: BasicCoordinate.inl:426
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition: BasicCoordinate.h:53
basic configuration include file
(inline) implementations for stir::BasicCoordinate
Boost class to define all comparison operators given only 2 (see operators.hpp)
Definition: doxygen_doc_for_boost.h:57