|
| 1 | +// This file is part of the ACTS project. |
| 2 | +// |
| 3 | +// Copyright (C) 2016 CERN for the benefit of the ACTS project |
| 4 | +// |
| 5 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include "Acts/Definitions/Algebra.hpp" |
| 12 | +#include "Acts/Definitions/Units.hpp" |
| 13 | + |
| 14 | +namespace Acts::detail { |
| 15 | +/// @brief Auxiliary class to coherently sort Transforms and Vectors such that |
| 16 | +/// a strict ordering between two objects may be defined and hence |
| 17 | +/// a sorted map or set of these objects becomes possible. In the case of |
| 18 | +/// Vectors, the sorter compares the differences of each component. As |
| 19 | +/// soon as a difference exceeds the predefined translational tolerance |
| 20 | +/// threshold the < operator is assigned based on this difference. In the |
| 21 | +/// case of rotations, the three Euler angles of the rotation matrix are |
| 22 | +/// evaluated and compared in an analogous way |
| 23 | +class TransformComparator { |
| 24 | + public: |
| 25 | + /// @brief Default constructor setting the predefined tolerance values |
| 26 | + /// for translation & rotation |
| 27 | + TransformComparator() = default; |
| 28 | + /// @brief Constructor with an adaption of the translation & rotTolerance |
| 29 | + /// @param transTolerance: Tolerance value within the difference of the |
| 30 | + /// i-th component between two vectors is considered to be 0 |
| 31 | + /// @param rotTolerance: Tolerance value within the difference of the |
| 32 | + /// i-th Euler angle between two Rotations is considered to be 0 |
| 33 | + TransformComparator(const double transTolerance, const double rotTolerance); |
| 34 | + /// @brief Generic comparison function between two kSize-dimensional vectors |
| 35 | + /// Returns 0 if all components agree within the translational |
| 36 | + /// tolerance. As soon as one component differs, 1 is returned if the |
| 37 | + /// component from vector a is larger and otherwise -1 |
| 38 | + /// @param a: Reference to the first vector to compare |
| 39 | + /// @param b: Reference to the second vector to compare |
| 40 | + template <unsigned int kSize> |
| 41 | + int compare(const Acts::ActsVector<kSize>& a, |
| 42 | + const Acts::ActsVector<kSize>& b) const { |
| 43 | + for (unsigned int i = 0; i < kSize; ++i) { |
| 44 | + const double diff = a[i] - b[i]; |
| 45 | + if (std::abs(diff) > m_tolTrans) { |
| 46 | + return diff > 0 ? 1 : -1; |
| 47 | + } |
| 48 | + } |
| 49 | + return 0; |
| 50 | + } |
| 51 | + /// @brief Brief compares the three Euler angles of the two rotation matrices |
| 52 | + /// If all angles agree within the rotational tolerance, 0 is returned. |
| 53 | + /// Otherwise, -1 or 1 is returned depending on whether the first |
| 54 | + /// differing i-th angle from a or b is larger. |
| 55 | + /// @param a: Reference to the first rotation matrix to compare |
| 56 | + /// @param b: Reference to the second rotation matrix to compare |
| 57 | + int compare(const Acts::RotationMatrix3& a, |
| 58 | + const Acts::RotationMatrix3& b) const; |
| 59 | + /// @brief Compares two transforms. First, it's checked whether the translational |
| 60 | + /// components between the two differ and if not the comparison between |
| 61 | + /// the two rotation matrices is returned |
| 62 | + /// @param a: Reference to the first transform to compare |
| 63 | + /// @param b: Reference to the second transform to compare |
| 64 | + int compare(const Acts::Transform3& a, const Acts::Transform3& b) const; |
| 65 | + |
| 66 | + /// @brief Implementation of the < operator for Transforms |
| 67 | + bool operator()(const Acts::Transform3& a, const Acts::Transform3& b) const; |
| 68 | + /// @brief Implementation of the < operator for RotationMatrices |
| 69 | + bool operator()(const Acts::RotationMatrix3& a, |
| 70 | + const Acts::RotationMatrix3& b) const; |
| 71 | + /// @brief Implementation of the < operator for 3-vectors |
| 72 | + bool operator()(const Acts::Vector3& a, const Acts::Vector3& b) const; |
| 73 | + /// @brief Implementation of the < operator for 2-vectors |
| 74 | + bool operator()(const Acts::Vector2& a, const Acts::Vector2& b) const; |
| 75 | + |
| 76 | + private: |
| 77 | + /** @brief Maximum tolerance per translational vector component */ |
| 78 | + double m_tolTrans{0.1 * Acts::UnitConstants::um}; |
| 79 | + /** @brief Maximum tolerance per euler angle */ |
| 80 | + double m_tolRot{0.01 * Acts::UnitConstants::mrad}; |
| 81 | +}; |
| 82 | +} // namespace Acts::detail |
0 commit comments