SIRF  3.6.0
Quaternion.h
Go to the documentation of this file.
1 /*
2 SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3 Copyright 2017 - 2019 University College London
4 
5 This is software developed for the Collaborative Computational
6 Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
7 (http://www.ccpsynerbi.ac.uk/).
8 
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 
19 */
20 
29 #pragma once
30 
31 #include <array>
32 #include <vector>
33 
34 namespace sirf {
35 
36 // Forward declarations
37 template<class dataType> class AffineTransformation;
38 
45 template<class dataType>
47 {
48 public:
49 
51  Quaternion(const dataType in_w, const dataType in_x, const dataType in_y, const dataType in_z) :
52  w(in_w), x(in_x), y(in_y), z(in_z)
53  {}
54 
58 
60  bool operator==(const Quaternion &other) const;
61 
63  bool operator!=(const Quaternion &other) const;
64 
66  static Quaternion get_average(const std::vector<Quaternion> &quaternions);
67 
69  dataType dot(const Quaternion &other) const;
70 
73 
75  Quaternion normalise() const;
76 
78  void print() const;
79 
81  std::array<dataType,4> get_data() const;
82 
84  void set_data(const std::array<dataType,4> &data);
85 
87  std::array<dataType,3> get_Euler_angles() const;
88 
89 private:
90 
92  dataType w, x, y, z;
93 
97  bool is_quaternion_close(const Quaternion &other) const;
98 };
99 }
Class for affine transformations.
Definition: AffineTransformation.h:49
Class for quaternions.
Definition: Quaternion.h:47
bool operator==(const Quaternion &other) const
Equality operator.
Definition: Quaternion.cpp:77
dataType dot(const Quaternion &other) const
Dot product with another quaternion.
Definition: Quaternion.cpp:148
Quaternion(const dataType in_w, const dataType in_x, const dataType in_y, const dataType in_z)
Constructor.
Definition: Quaternion.h:51
static Quaternion get_average(const std::vector< Quaternion > &quaternions)
Average quaternions.
Definition: Quaternion.cpp:95
bool operator!=(const Quaternion &other) const
Equality operator.
Definition: Quaternion.cpp:89
Quaternion normalise() const
Normalise quaternion.
Definition: Quaternion.cpp:131
void set_data(const std::array< dataType, 4 > &data)
Set the data.
Definition: Quaternion.cpp:166
std::array< dataType, 3 > get_Euler_angles() const
Get as Euler angles.
Definition: Quaternion.cpp:175
std::array< dataType, 4 > get_data() const
Get the data.
Definition: Quaternion.cpp:160
void print() const
Print quaternion.
Definition: Quaternion.cpp:154
Quaternion inverse_sign_quaternion() const
Changes the sign of the quaternion components. This is not the same as the inverse.
Definition: Quaternion.cpp:142
Abstract data container.
Definition: GeometricalInfo.cpp:141