File indexing completed on 2025-01-18 09:11:25
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<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::referencePosition(const GeometryContext& ,
0037 AxisDirection aDir) const {
0038
0039
0040 if (aDir == AxisDirection::AxisR || aDir == AxisDirection::AxisRPhi) {
0041
0042 return (center() + m_volumeBounds->referenceOffset(aDir));
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, double 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<VolumeBounds> volbounds) {
0078 update(std::move(volbounds));
0079 }
0080
0081 void Volume::update(std::shared_ptr<VolumeBounds> volbounds,
0082 std::optional<Transform3> transform,
0083 const Logger& ) {
0084 if (volbounds) {
0085 m_volumeBounds = std::move(volbounds);
0086 }
0087 if (transform.has_value()) {
0088 setTransform(*transform);
0089 }
0090 }
0091
0092 const Transform3& Volume::transform() const {
0093 return m_transform;
0094 }
0095
0096 const Transform3& Volume::itransform() const {
0097 return m_itransform;
0098 }
0099
0100 const Vector3& Volume::center() const {
0101 return m_center;
0102 }
0103
0104 const VolumeBounds& Volume::volumeBounds() const {
0105 return *m_volumeBounds;
0106 }
0107
0108 VolumeBounds& Volume::volumeBounds() {
0109 return *m_volumeBounds;
0110 }
0111
0112 std::shared_ptr<const VolumeBounds> Volume::volumeBoundsPtr() const {
0113 return m_volumeBounds;
0114 }
0115
0116 std::shared_ptr<VolumeBounds> Volume::volumeBoundsPtr() {
0117 return m_volumeBounds;
0118 }
0119
0120 void Volume::setTransform(const Transform3& transform) {
0121 m_transform = transform;
0122 m_itransform = m_transform.inverse();
0123 m_center = m_transform.translation();
0124 }
0125
0126 bool Volume::operator==(const Volume& other) const {
0127 return (m_transform.matrix() == other.m_transform.matrix()) &&
0128 (*m_volumeBounds == *other.m_volumeBounds);
0129 }
0130
0131 void Volume::visualize(IVisualization3D& helper, const GeometryContext& gctx,
0132 const ViewConfig& viewConfig) const {
0133 auto bSurfaces = volumeBounds().orientedSurfaces(transform());
0134 for (const auto& bs : bSurfaces) {
0135 bs.surface->visualize(helper, gctx, viewConfig);
0136 }
0137 }
0138
0139 }