File indexing completed on 2025-08-05 08:09:35
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0010
0011 #include "Acts/Definitions/Direction.hpp"
0012 #include "Acts/Surfaces/PlaneSurface.hpp"
0013 #include "Acts/Surfaces/RectangleBounds.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/BoundingBox.hpp"
0016
0017 #include <utility>
0018
0019 namespace Acts {
0020
0021 CuboidVolumeBounds::CuboidVolumeBounds(ActsScalar halex, ActsScalar haley,
0022 ActsScalar halez)
0023 : VolumeBounds(), m_values({halex, haley, halez}) {
0024 checkConsistency();
0025 buildSurfaceBounds();
0026 }
0027
0028 CuboidVolumeBounds::CuboidVolumeBounds(
0029 const std::array<ActsScalar, eSize>& values)
0030 : m_values(values) {
0031 checkConsistency();
0032 buildSurfaceBounds();
0033 }
0034
0035 std::vector<Acts::OrientedSurface> Acts::CuboidVolumeBounds::orientedSurfaces(
0036 const Transform3& transform) const {
0037 std::vector<OrientedSurface> oSurfaces;
0038 oSurfaces.reserve(6);
0039
0040
0041 auto sf = Surface::makeShared<PlaneSurface>(
0042 transform * Translation3(0., 0., -get(eHalfLengthZ)), m_xyBounds);
0043 oSurfaces.push_back(OrientedSurface{std::move(sf), Direction::AlongNormal});
0044
0045 sf = Surface::makeShared<PlaneSurface>(
0046 transform * Translation3(0., 0., get(eHalfLengthZ)), m_xyBounds);
0047 oSurfaces.push_back(
0048 OrientedSurface{std::move(sf), Direction::OppositeNormal});
0049
0050
0051 sf = Surface::makeShared<PlaneSurface>(
0052 transform * Translation3(-get(eHalfLengthX), 0., 0.) * s_planeYZ,
0053 m_yzBounds);
0054 oSurfaces.push_back(OrientedSurface{std::move(sf), Direction::AlongNormal});
0055
0056 sf = Surface::makeShared<PlaneSurface>(
0057 transform * Translation3(get(eHalfLengthX), 0., 0.) * s_planeYZ,
0058 m_yzBounds);
0059 oSurfaces.push_back(
0060 OrientedSurface{std::move(sf), Direction::OppositeNormal});
0061
0062
0063 sf = Surface::makeShared<PlaneSurface>(
0064 transform * Translation3(0., -get(eHalfLengthY), 0.) * s_planeZX,
0065 m_zxBounds);
0066 oSurfaces.push_back(OrientedSurface{std::move(sf), Direction::AlongNormal});
0067
0068 sf = Surface::makeShared<PlaneSurface>(
0069 transform * Translation3(0., get(eHalfLengthY), 0.) * s_planeZX,
0070 m_zxBounds);
0071 oSurfaces.push_back(
0072 OrientedSurface{std::move(sf), Direction::OppositeNormal});
0073
0074 return oSurfaces;
0075 }
0076
0077 std::ostream& CuboidVolumeBounds::toStream(std::ostream& os) const {
0078 os << std::setiosflags(std::ios::fixed);
0079 os << std::setprecision(5);
0080 os << "Acts::CuboidVolumeBounds: (halfLengthX, halfLengthY, halfLengthZ) = ";
0081 os << "(" << get(eHalfLengthX) << ", " << get(eHalfLengthY) << ", "
0082 << get(eHalfLengthZ) << ")";
0083 return os;
0084 }
0085
0086 Volume::BoundingBox CuboidVolumeBounds::boundingBox(
0087 const Transform3* trf, const Vector3& envelope,
0088 const Volume* entity) const {
0089 Vector3 vmin(-get(eHalfLengthX), -get(eHalfLengthY), -get(eHalfLengthZ));
0090 Vector3 vmax(get(eHalfLengthX), get(eHalfLengthY), get(eHalfLengthZ));
0091
0092 Volume::BoundingBox box(entity, vmin - envelope, vmax + envelope);
0093 return trf == nullptr ? box : box.transformed(*trf);
0094 }
0095
0096 void CuboidVolumeBounds::buildSurfaceBounds() {
0097 m_xyBounds = std::make_shared<const RectangleBounds>(get(eHalfLengthX),
0098 get(eHalfLengthY));
0099 m_yzBounds = std::make_shared<const RectangleBounds>(get(eHalfLengthY),
0100 get(eHalfLengthZ));
0101 m_zxBounds = std::make_shared<const RectangleBounds>(get(eHalfLengthZ),
0102 get(eHalfLengthX));
0103 }
0104
0105 ActsScalar CuboidVolumeBounds::binningBorder(BinningValue bValue) const {
0106 if (bValue <= binZ) {
0107 return m_values[bValue];
0108 }
0109 if (bValue == binR) {
0110 return std::sqrt(m_values[binX] * m_values[binX] +
0111 m_values[binY] * m_values[binY]);
0112 }
0113 return 0.0;
0114 }
0115
0116 bool CuboidVolumeBounds::inside(const Vector3& pos, ActsScalar tol) const {
0117 return (std::abs(pos.x()) <= get(eHalfLengthX) + tol &&
0118 std::abs(pos.y()) <= get(eHalfLengthY) + tol &&
0119 std::abs(pos.z()) <= get(eHalfLengthZ) + tol);
0120 }
0121
0122 std::vector<ActsScalar> CuboidVolumeBounds::values() const {
0123 std::vector<ActsScalar> valvector;
0124 valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
0125 return valvector;
0126 }
0127
0128 void CuboidVolumeBounds::checkConsistency() noexcept(false) {
0129 if (get(eHalfLengthX) <= 0 || get(eHalfLengthY) <= 0 ||
0130 get(eHalfLengthZ) <= 0.) {
0131 throw std::invalid_argument(
0132 "CuboidVolumeBounds: invalid input, zero or negative.");
0133 }
0134 }
0135
0136 void CuboidVolumeBounds::set(BoundValues bValue, ActsScalar value) {
0137 set({{bValue, value}});
0138 }
0139
0140 void CuboidVolumeBounds::set(
0141 std::initializer_list<std::pair<BoundValues, ActsScalar>> keyValues) {
0142 std::array<ActsScalar, eSize> previous = m_values;
0143 for (const auto& [key, value] : keyValues) {
0144 m_values[key] = value;
0145 }
0146 try {
0147 checkConsistency();
0148 buildSurfaceBounds();
0149 } catch (std::invalid_argument& e) {
0150 m_values = previous;
0151 throw e;
0152 }
0153 }
0154
0155 }