Mantid
Loading...
Searching...
No Matches
ReferenceFrame.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <stdexcept>
9
10using namespace Mantid::Kernel;
11
12namespace Mantid::Geometry {
13
14namespace {
21V3D directionToVector(const PointingAlong &direction) {
22 V3D result;
23 if (direction == X) {
24 result = V3D(1, 0, 0);
25 } else if (direction == Y) {
26 result = V3D(0, 1, 0);
27 } else {
28 result = V3D(0, 0, 1);
29 }
30 return result;
31}
32
38std::string directionToString(const PointingAlong &direction) {
39 std::string result;
40 if (direction == X) {
41 result = "X";
42 } else if (direction == Y) {
43 result = "Y";
44 } else {
45 result = "Z";
46 }
47 return result;
48}
49} // namespace
50
55
62ReferenceFrame::ReferenceFrame(PointingAlong up, PointingAlong alongBeam, Handedness handedness, std::string origin)
63 : ReferenceFrame(up, alongBeam, up, handedness, std::move(origin)) {}
64
74 Handedness handedness, std::string origin)
75 : m_up(up), m_alongBeam(alongBeam), m_thetaSign(thetaSign), m_handedness(handedness), m_origin(std::move(origin)) {
76 if (up == alongBeam) {
77 throw std::invalid_argument("Cannot have up direction the same as the beam direction");
78 }
79 if (thetaSign == alongBeam) {
80 throw std::invalid_argument("Scattering angle sign axis cannot be the same as the beam direction");
81 }
82 m_vecPointingUp = directionToVector(m_up);
83 m_vecPointingAlongBeam = directionToVector(m_alongBeam);
84 m_vecThetaSign = directionToVector(m_thetaSign);
85}
86
92
97
102std::string ReferenceFrame::pointingUpAxis() const { return directionToString(m_up); }
103
108std::string ReferenceFrame::pointingAlongBeamAxis() const { return directionToString(m_alongBeam); }
109
115std::string ReferenceFrame::pointingHorizontalAxis() const { return directionToString(pointingHorizontal()); }
116
122 if (m_up == X) {
123 if (m_alongBeam == Y)
124 return Z;
125 else
126 return Y;
127 } else if (m_up == Y) {
128 if (m_alongBeam == Z)
129 return X;
130 else
131 return Z;
132 } else {
133 if (m_alongBeam == Y)
134 return X;
135 else
136 return Y;
137 }
138}
139
144
148std::string ReferenceFrame::origin() const { return m_origin; }
149
155
161
167
172V3D ReferenceFrame::vecPointingHorizontal() const { return directionToVector(pointingHorizontal()); }
173
181 // Normalized (unit) parallel vectors should produce a scalar product of 1
183}
184
185} // namespace Mantid::Geometry
ReferenceFrame : Holds reference frame information from the geometry description file.
std::string origin() const
Gets the origin.
std::string pointingHorizontalAxis() const
Pointing horizontal to beam as a string.
PointingAlong m_up
Pointing up axis.
Mantid::Kernel::V3D vecPointingUp() const
Convert up axis into a 3D direction.
PointingAlong pointingUp() const
Gets the pointing up direction.
Mantid::Kernel::V3D vecPointingHorizontal() const
Convert along horizontal axis into a 3D direction.
Mantid::Kernel::V3D vecThetaSign() const
Convert along the axis defining the 2theta sign.
Handedness m_handedness
Handedness.
PointingAlong pointingHorizontal() const
Gets the pointing horizontal direction, i.e perpendicular to up & along beam.
Mantid::Kernel::V3D m_vecPointingAlongBeam
Vector pointing along the beam.
Handedness getHandedness() const
Gets the handedness.
PointingAlong pointingAlongBeam() const
Gets the beam pointing along direction.
PointingAlong m_alongBeam
Beam pointing along axis.
Mantid::Kernel::V3D m_vecPointingUp
Vector pointing up instrument.
std::string pointingAlongBeamAxis() const
Pointing along beam axis as a string.
PointingAlong m_thetaSign
Axis defining the 2theta sign.
Mantid::Kernel::V3D m_vecThetaSign
Vector denoting the direction defining the 2theta sign.
Mantid::Kernel::V3D vecPointingAlongBeam() const
Convert along beam axis into a 3D direction.
std::string pointingUpAxis() const
Pointing up axis as a string.
ReferenceFrame()
Default constructor.
bool isVectorPointingAlongBeam(const Mantid::Kernel::V3D &v) const
Test whether or not a vector is in the beam direction.
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
Handedness
Type to distingusih between l and r handedness.
PointingAlong
Type to describe pointing along options.
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Definition: V3D.h:341
STL namespace.