File indexing completed on 2025-08-05 08:09:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/Volume.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/VolumeBounds.hpp"
0013
0014 #include <iostream>
0015 #include <utility>
0016
0017 using namespace Acts::UnitLiterals;
0018
0019 namespace Acts {
0020
0021 Volume::Volume(const Transform3& transform,
0022 std::shared_ptr<const VolumeBounds> volbounds)
0023 : GeometryObject(),
0024 m_transform(transform),
0025 m_itransform(m_transform.inverse()),
0026 m_center(m_transform.translation()),
0027 m_volumeBounds(std::move(volbounds)) {}
0028
0029 Volume::Volume(const Volume& vol, const Transform3& shift)
0030 : GeometryObject(),
0031 m_transform(shift * vol.m_transform),
0032 m_itransform(m_transform.inverse()),
0033 m_center(m_transform.translation()),
0034 m_volumeBounds(vol.m_volumeBounds) {}
0035
0036 Vector3 Volume::binningPosition(const GeometryContext& ,
0037 BinningValue bValue) const {
0038
0039
0040 if (bValue == binR || bValue == binRPhi) {
0041
0042 return (center() + m_volumeBounds->binningOffset(bValue));
0043 }
0044
0045 return center();
0046 }
0047
0048
0049 Volume& Volume::operator=(const Volume& vol) {
0050 if (this != &vol) {
0051 m_transform = vol.m_transform;
0052 m_center = vol.m_center;
0053 m_volumeBounds = vol.m_volumeBounds;
0054 }
0055 return *this;
0056 }
0057
0058 bool Volume::inside(const Vector3& gpos, ActsScalar tol) const {
0059 Vector3 posInVolFrame((transform().inverse()) * gpos);
0060 return (volumeBounds()).inside(posInVolFrame, tol);
0061 }
0062
0063 std::ostream& operator<<(std::ostream& sl, const Volume& vol) {
0064 sl << "Volume with " << vol.volumeBounds() << std::endl;
0065 return sl;
0066 }
0067
0068 Volume::BoundingBox Volume::boundingBox(const Vector3& envelope) const {
0069 return m_volumeBounds->boundingBox(&m_transform, envelope, this);
0070 }
0071
0072 Volume::BoundingBox Volume::orientedBoundingBox() const {
0073 return m_volumeBounds->boundingBox(nullptr, {0.05_mm, 0.05_mm, 0.05_mm},
0074 this);
0075 }
0076
0077 void Volume::assignVolumeBounds(std::shared_ptr<const VolumeBounds> volbounds) {
0078 update(std::move(volbounds));
0079 }
0080
0081 void Volume::update(std::shared_ptr<const VolumeBounds> volbounds,
0082 std::optional<Transform3> transform) {
0083 if (volbounds) {
0084 m_volumeBounds = std::move(volbounds);
0085 }
0086 if (transform.has_value()) {
0087 setTransform(*transform);
0088 }
0089 }
0090
0091 const Transform3& Volume::transform() const {
0092 return m_transform;
0093 }
0094
0095 const Transform3& Volume::itransform() const {
0096 return m_itransform;
0097 }
0098
0099 const Vector3& Volume::center() const {
0100 return m_center;
0101 }
0102
0103 const VolumeBounds& Volume::volumeBounds() const {
0104 return *m_volumeBounds;
0105 }
0106
0107 std::shared_ptr<const VolumeBounds> Volume::volumeBoundsPtr() const {
0108 return m_volumeBounds;
0109 }
0110
0111 void Volume::setTransform(const Transform3& transform) {
0112 m_transform = transform;
0113 m_itransform = m_transform.inverse();
0114 m_center = m_transform.translation();
0115 }
0116
0117 bool Volume::operator==(const Volume& other) const {
0118 return (m_transform.matrix() == other.m_transform.matrix()) &&
0119 (*m_volumeBounds == *other.m_volumeBounds);
0120 }
0121
0122 bool Volume::operator!=(const Volume& other) const {
0123 return !(*this == other);
0124 }
0125 }