Mantid
Loading...
Searching...
No Matches
PositionAndRotationAccumulator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2026 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
9namespace Mantid::Geometry {
10
11void PositionAndRotationAccumulator::setCoordinate(const size_t componentIndex, const std::string &axis,
12 const double value, const Kernel::V3D &currentPosition) {
13 auto &entry = m_positions[componentIndex];
14 if (!entry.seeded) {
15 entry.position = currentPosition;
16 entry.seeded = true;
17 }
18 if (axis == "x") {
19 entry.position.setX(value);
20 } else if (axis == "y") {
21 entry.position.setY(value);
22 } else if (axis == "z") {
23 entry.position.setZ(value);
24 }
25}
26
27void PositionAndRotationAccumulator::setPosition(const size_t componentIndex, const Kernel::V3D &position) {
28 m_positions[componentIndex] = {position, true};
29}
30
31bool PositionAndRotationAccumulator::setRotationAngle(const size_t componentIndex, const std::string &axis,
32 const double degrees) {
33 auto &entry = m_rotations[componentIndex];
34 bool recognised = true;
35 if (axis == "rotx") {
36 entry.x = degrees;
37 } else if (axis == "roty") {
38 entry.y = degrees;
39 } else if (axis == "rotz") {
40 entry.z = degrees;
41 } else {
42 recognised = false;
43 }
44 return recognised;
45}
46
47std::map<size_t, Kernel::V3D> PositionAndRotationAccumulator::positions() const {
48 std::map<size_t, Kernel::V3D> result;
49 for (const auto &[componentIndex, entry] : m_positions) {
50 result.emplace(componentIndex, entry.position);
51 }
52 return result;
53}
54
55std::map<size_t, Kernel::Quat> PositionAndRotationAccumulator::rotations() const {
56 std::map<size_t, Kernel::Quat> result;
57 for (const auto &[componentIndex, entry] : m_rotations) {
58 result.emplace(componentIndex, Kernel::Quat(entry.x, Kernel::V3D(1, 0, 0)) *
59 Kernel::Quat(entry.y, Kernel::V3D(0, 1, 0)) *
60 Kernel::Quat(entry.z, Kernel::V3D(0, 0, 1)));
61 }
62 return result;
63}
64
65} // namespace Mantid::Geometry
double value
The value of the point.
Definition FitMW.cpp:51
double position
Definition GetAllEi.cpp:154
void setCoordinate(const size_t componentIndex, const std::string &axis, const double value, const Kernel::V3D &currentPosition)
Set one coordinate.
void setPosition(const size_t componentIndex, const Kernel::V3D &position)
Set the whole position at once, discarding any coordinates accumulated so far.
std::map< size_t, Kernel::V3D > positions() const
The accumulated position for each component that had any coordinate set.
bool setRotationAngle(const size_t componentIndex, const std::string &axis, const double degrees)
Set one rotation angle, in degrees.
std::map< size_t, Kernel::Quat > rotations() const
The composed rotation for each component that had any angle set.
Class for quaternions.
Definition Quat.h:39
Class for 3D vectors.
Definition V3D.h:34
void setX(const double xx) noexcept
Set is x position.
Definition V3D.h:224