From 06f3a1a303351c946cf33a92fea37216693ec948 Mon Sep 17 00:00:00 2001 From: ssdetlab Date: Wed, 22 Jan 2025 14:27:49 +0200 Subject: [PATCH] idx fixes, strategies, bounds --- .../Acts/Geometry/CuboidVolumeBounds.hpp | 9 + .../Acts/Geometry/CuboidVolumeStack.hpp | 76 ++-- .../CylinderContainerBlueprintNode.hpp | 26 +- .../Acts/Geometry/CylinderVolumeStack.hpp | 52 +-- .../detail/VolumeAttachmentStrategy.hpp | 32 ++ .../Geometry/detail/VolumeResizeStrategy.hpp | 25 ++ Core/src/Geometry/CMakeLists.txt | 2 + Core/src/Geometry/CuboidVolumeBounds.cpp | 40 +++ Core/src/Geometry/CuboidVolumeStack.cpp | 240 ++++++------- .../CylinderContainerBlueprintNode.cpp | 12 +- Core/src/Geometry/CylinderVolumeStack.cpp | 94 ++--- .../detail/VolumeAttachmentStrategy.cpp | 30 ++ .../Geometry/detail/VolumeResizeStrategy.cpp | 25 ++ Examples/Python/src/Blueprint.cpp | 11 +- Examples/Python/src/Geometry.cpp | 19 +- .../Core/Geometry/BlueprintApiTests.cpp | 16 +- .../Core/Geometry/BlueprintTests.cpp | 3 +- .../Core/Geometry/CuboidVolumeBoundsTests.cpp | 11 + .../Core/Geometry/CuboidVolumeStackTests.cpp | 337 ++++++++---------- .../Geometry/CylinderVolumeStackTests.cpp | 152 ++++---- 20 files changed, 631 insertions(+), 581 deletions(-) create mode 100644 Core/include/Acts/Geometry/detail/VolumeAttachmentStrategy.hpp create mode 100644 Core/include/Acts/Geometry/detail/VolumeResizeStrategy.hpp create mode 100644 Core/src/Geometry/detail/VolumeAttachmentStrategy.cpp create mode 100644 Core/src/Geometry/detail/VolumeResizeStrategy.cpp diff --git a/Core/include/Acts/Geometry/CuboidVolumeBounds.hpp b/Core/include/Acts/Geometry/CuboidVolumeBounds.hpp index 39344352eda..8bc5cac731e 100644 --- a/Core/include/Acts/Geometry/CuboidVolumeBounds.hpp +++ b/Core/include/Acts/Geometry/CuboidVolumeBounds.hpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -71,6 +72,9 @@ class CuboidVolumeBounds : public VolumeBounds { /// @param values iw the bound values CuboidVolumeBounds(const std::array& values); + CuboidVolumeBounds( + std::initializer_list> keyValues); + /// Copy Constructor /// /// @param bobo is the source volume bounds to be copied @@ -149,6 +153,11 @@ class CuboidVolumeBounds : public VolumeBounds { /// @param keyValues the initializer list of key value pairs void set(std::initializer_list> keyValues); + /// Convert axis direction to a corresponding bound value + /// in local coordinate convetion + /// @param direction the axis direction to convert + static BoundValues fromAxisDirection(AxisDirection direction); + /// Output Method for std::ostream /// /// @param os is ostream operator to be dumped into diff --git a/Core/include/Acts/Geometry/CuboidVolumeStack.hpp b/Core/include/Acts/Geometry/CuboidVolumeStack.hpp index ea8ae133656..d29feaa9308 100644 --- a/Core/include/Acts/Geometry/CuboidVolumeStack.hpp +++ b/Core/include/Acts/Geometry/CuboidVolumeStack.hpp @@ -10,9 +10,12 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Geometry/Volume.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/Logger.hpp" +#include #include namespace Acts { @@ -30,29 +33,6 @@ namespace Acts { /// @note The size adjustment convention is that volumes are never shrunk class CuboidVolumeStack : public Volume { public: - /// The attachment strategy defines how the volumes are attached - /// Attachment always happens pair-wise - enum class AttachmentStrategy { - /// Given two volumes, the *left* one, i.e. the one with the lower **local** - /// x, y, or z value is extended - First, - /// Given two volumes, the *right* one, i.e. the one with the higher - /// **local** x, y, or z value is extended - Second, - /// Given two volumes, the *midpoint* between the two volumes is found - Midpoint, - /// A gap volume is created to fit between the two volumes - Gap, - }; - - /// The resize strategy defines how the volumes are resized - enum class ResizeStrategy { - /// Extend the volume connected to the respective edge to fit the new bounds - Expand, - /// Create a gap volume at the respective edge to fit the new bounds - Gap, - }; - /// Constructor from a vector of volumes and direction /// @param volumes is the vector of volumes /// @param direction is the axis direction @@ -69,10 +49,11 @@ class CuboidVolumeStack : public Volume { /// in @c x or @c y. /// @pre The volumes all need to have @c CuboidVolumeBounds /// @note Preconditions are checked on construction - CuboidVolumeStack(std::vector& volumes, AxisDirection direction, - AttachmentStrategy strategy = AttachmentStrategy::Midpoint, - ResizeStrategy resizeStrategy = ResizeStrategy::Expand, - const Logger& logger = Acts::getDummyLogger()); + CuboidVolumeStack( + std::vector& volumes, AxisDirection direction, + VolumeAttachmentStrategy strategy = VolumeAttachmentStrategy::Midpoint, + VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand, + const Logger& logger = Acts::getDummyLogger()); /// Constructor from a vector of volumes and direction /// @param volumes is the vector of volumes @@ -90,10 +71,11 @@ class CuboidVolumeStack : public Volume { /// in @c x or @c y. /// @pre The volumes all need to have @c CuboidVolumeBounds /// @note Preconditions are checked on construction - CuboidVolumeStack(std::vector& volumes, const Vector3& direction, - AttachmentStrategy strategy = AttachmentStrategy::Midpoint, - ResizeStrategy resizeStrategy = ResizeStrategy::Expand, - const Logger& logger = Acts::getDummyLogger()); + CuboidVolumeStack( + std::vector& volumes, const Vector3& direction, + VolumeAttachmentStrategy strategy = VolumeAttachmentStrategy::Midpoint, + VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand, + const Logger& logger = Acts::getDummyLogger()); /// Update the volume bounds and transform. This /// will update the bounds of all volumes in the stack @@ -113,6 +95,17 @@ class CuboidVolumeStack : public Volume { /// @return the vector of gap volumes const std::vector>& gaps() const; + /// Conert axis direction to an array index according to + /// stack convention. For example, AxisX --> 0 + /// @param direction is the axis direction to convert + static std::size_t axisToIndex(AxisDirection direction); + + /// Get axis directions orthogonal to the given one according + /// to stack convention. For example AxisX --> + /// @param direction is the axis direction to find the orthogonal for + static std::pair getOrthogonalAxes( + AxisDirection direction); + private: /// Helper to get the first volume in the input, and throw an exception if /// there is not one. @@ -124,7 +117,8 @@ class CuboidVolumeStack : public Volume { /// internal attachment and produces the overall outer volume bounds. /// @param strategy is the attachment strategy /// @param logger is the logger - void initializeOuterVolume(AttachmentStrategy strategy, const Logger& logger); + void initializeOuterVolume(VolumeAttachmentStrategy strategy, + const Logger& logger); struct VolumeTuple; @@ -157,7 +151,7 @@ class CuboidVolumeStack : public Volume { /// @param logger is the logger /// @return vector of gap volumes. Can be empty if none were created. std::vector checkOverlapAndAttach( - std::vector& volumes, AttachmentStrategy strategy, + std::vector& volumes, VolumeAttachmentStrategy strategy, const Logger& logger); /// Helper function to synchronize the bounds of the volumes @@ -184,24 +178,10 @@ class CuboidVolumeStack : public Volume { AxisDirection m_dirOrth1{}; AxisDirection m_dirOrth2{}; - ResizeStrategy m_resizeStrategy{}; + VolumeResizeStrategy m_resizeStrategy{}; Transform3 m_groupTransform{}; std::vector> m_gaps{}; std::vector& m_volumes; }; -/// Output operator for the attachment strategy -/// @param os is the output stream -/// @param strategy is the attachment strategy -/// @return the output stream -std::ostream& operator<<(std::ostream& os, - CuboidVolumeStack::AttachmentStrategy strategy); - -/// Output operator for the resize strategy -/// @param os is the output stream -/// @param strategy is the resize strategy -/// @return the output stream -std::ostream& operator<<(std::ostream& os, - CuboidVolumeStack::ResizeStrategy strategy); - } // namespace Acts diff --git a/Core/include/Acts/Geometry/CylinderContainerBlueprintNode.hpp b/Core/include/Acts/Geometry/CylinderContainerBlueprintNode.hpp index decd92facd9..d05bdac55e4 100644 --- a/Core/include/Acts/Geometry/CylinderContainerBlueprintNode.hpp +++ b/Core/include/Acts/Geometry/CylinderContainerBlueprintNode.hpp @@ -11,6 +11,8 @@ #include "Acts/Geometry/BlueprintNode.hpp" #include "Acts/Geometry/CylinderVolumeStack.hpp" #include "Acts/Geometry/PortalShell.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/Logger.hpp" @@ -37,10 +39,10 @@ class CylinderContainerBlueprintNode final : public BlueprintNode { /// see documentation of that class for more information CylinderContainerBlueprintNode( const std::string& name, AxisDirection direction, - CylinderVolumeStack::AttachmentStrategy attachmentStrategy = - CylinderVolumeStack::AttachmentStrategy::Midpoint, - CylinderVolumeStack::ResizeStrategy resizeStrategy = - CylinderVolumeStack::ResizeStrategy::Expand); + VolumeAttachmentStrategy attachmentStrategy = + VolumeAttachmentStrategy::Midpoint, + VolumeResizeStrategy resizeStrategy = + VolumeResizeStrategy::Expand); /// @copydoc BlueprintNode::name const std::string& name() const override; @@ -101,13 +103,13 @@ class CylinderContainerBlueprintNode final : public BlueprintNode { /// @param attachmentStrategy The attachment strategy /// @return This node for chaining CylinderContainerBlueprintNode& setAttachmentStrategy( - CylinderVolumeStack::AttachmentStrategy attachmentStrategy); + VolumeAttachmentStrategy attachmentStrategy); /// Setter for the resize strategy /// @param resizeStrategy The resize strategy /// @return This node for chaining CylinderContainerBlueprintNode& setResizeStrategy( - CylinderVolumeStack::ResizeStrategy resizeStrategy); + VolumeResizeStrategy resizeStrategy); /// Accessor to the stacking direction /// @return The stacking direction @@ -115,11 +117,11 @@ class CylinderContainerBlueprintNode final : public BlueprintNode { /// Accessor to the attachment strategy /// @return The attachment strategy - CylinderVolumeStack::AttachmentStrategy attachmentStrategy() const; + VolumeAttachmentStrategy attachmentStrategy() const; /// Accessor to the resize strategy /// @return The resize strategy - CylinderVolumeStack::ResizeStrategy resizeStrategy() const; + VolumeResizeStrategy resizeStrategy() const; private: /// @copydoc BlueprintNode::addToGraphviz @@ -138,11 +140,11 @@ class CylinderContainerBlueprintNode final : public BlueprintNode { AxisDirection m_direction = AxisDirection::AxisZ; - CylinderVolumeStack::AttachmentStrategy m_attachmentStrategy{ - CylinderVolumeStack::AttachmentStrategy::Midpoint}; + VolumeAttachmentStrategy m_attachmentStrategy{ + VolumeAttachmentStrategy::Midpoint}; - CylinderVolumeStack::ResizeStrategy m_resizeStrategy{ - CylinderVolumeStack::ResizeStrategy::Expand}; + VolumeResizeStrategy m_resizeStrategy{ + VolumeResizeStrategy::Expand}; // Is only initialized during `build` std::vector m_childVolumes; diff --git a/Core/include/Acts/Geometry/CylinderVolumeStack.hpp b/Core/include/Acts/Geometry/CylinderVolumeStack.hpp index 5cfa24d0ad2..f669f7d9daa 100644 --- a/Core/include/Acts/Geometry/CylinderVolumeStack.hpp +++ b/Core/include/Acts/Geometry/CylinderVolumeStack.hpp @@ -11,6 +11,8 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Geometry/Volume.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/Logger.hpp" @@ -32,29 +34,6 @@ namespace Acts { /// result in overlaps of the resulting volumes bounds. class CylinderVolumeStack : public Volume { public: - /// The attachment strategy defines how the volumes are attached - /// Attachment always happens pair-wise - enum class AttachmentStrategy { - /// Given two volumes, the *left* one, i.e. the one with the lower **local** - /// z or r value is extended - First, - /// Given two volumes, the *right* one, i.e. the one with the higher - /// **local** z or r value is extended - Second, - /// Given two volumes, the *midpoint* between the two volumes is found - Midpoint, - /// A gap volume is created to fit between the two volumes - Gap, - }; - - /// The resize strategy defines how the volumes are resized - enum class ResizeStrategy { - /// Extend the volume connected to the respective edge to fit the new bounds - Expand, - /// Create a gap volume at the respective edge to fit the new bounds - Gap, - }; - /// Constructor from a vector of volumes and direction /// @param volumes is the vector of volumes /// @param direction is the binning direction @@ -74,8 +53,8 @@ class CylinderVolumeStack : public Volume { /// @note Preconditions are checked on construction CylinderVolumeStack( std::vector& volumes, AxisDirection direction, - AttachmentStrategy strategy = AttachmentStrategy::Midpoint, - ResizeStrategy resizeStrategy = ResizeStrategy::Expand, + VolumeAttachmentStrategy strategy = VolumeAttachmentStrategy::Midpoint, + VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand, const Logger& logger = Acts::getDummyLogger()); /// Update the volume bounds and transform. This @@ -109,7 +88,8 @@ class CylinderVolumeStack : public Volume { /// @param strategy is the attachment strategy /// @param logger is the logger void initializeOuterVolume(AxisDirection direction, - AttachmentStrategy strategy, const Logger& logger); + VolumeAttachmentStrategy strategy, + const Logger& logger); struct VolumeTuple; @@ -142,7 +122,7 @@ class CylinderVolumeStack : public Volume { /// @param logger is the logger /// @return vector of gap volumes. Can be empty if none were created. std::vector checkOverlapAndAttachInZ( - std::vector& volumes, AttachmentStrategy strategy, + std::vector& volumes, VolumeAttachmentStrategy strategy, const Logger& logger); /// Helper function to synchronize the r bounds of the volumes @@ -158,7 +138,7 @@ class CylinderVolumeStack : public Volume { /// @param logger is the logger /// @return vector of gap volumes. Can be empty if none were created. std::vector checkOverlapAndAttachInR( - std::vector& volumes, AttachmentStrategy strategy, + std::vector& volumes, VolumeAttachmentStrategy strategy, const Logger& logger); /// Helper function to synchronize the z bounds of the volumes @@ -183,24 +163,10 @@ class CylinderVolumeStack : public Volume { const Transform3& transform, const std::shared_ptr& bounds); AxisDirection m_direction{}; - ResizeStrategy m_resizeStrategy{}; + VolumeResizeStrategy m_resizeStrategy{}; Transform3 m_groupTransform{}; std::vector> m_gaps{}; std::vector& m_volumes; }; -/// Output operator for the attachment strategy -/// @param os is the output stream -/// @param strategy is the attachment strategy -/// @return the output stream -std::ostream& operator<<(std::ostream& os, - CylinderVolumeStack::AttachmentStrategy strategy); - -/// Output operator for the resize strategy -/// @param os is the output stream -/// @param strategy is the resize strategy -/// @return the output stream -std::ostream& operator<<(std::ostream& os, - CylinderVolumeStack::ResizeStrategy strategy); - } // namespace Acts diff --git a/Core/include/Acts/Geometry/detail/VolumeAttachmentStrategy.hpp b/Core/include/Acts/Geometry/detail/VolumeAttachmentStrategy.hpp new file mode 100644 index 00000000000..68af1b14026 --- /dev/null +++ b/Core/include/Acts/Geometry/detail/VolumeAttachmentStrategy.hpp @@ -0,0 +1,32 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once + +#include + +namespace Acts { + +/// The attachment strategy defines how the volumes are attached +/// Attachment always happens pair-wise +enum class VolumeAttachmentStrategy { + /// Given two volumes, the *left* one, i.e. the one with the lower **local** + /// x, y, or z value is extended + First, + /// Given two volumes, the *right* one, i.e. the one with the higher + /// **local** x, y, or z value is extended + Second, + /// Given two volumes, the *midpoint* between the two volumes is found + Midpoint, + /// A gap volume is created to fit between the two volumes + Gap, +}; + +std::ostream& operator<<(std::ostream& os, VolumeAttachmentStrategy strategy); + +} // namespace Acts diff --git a/Core/include/Acts/Geometry/detail/VolumeResizeStrategy.hpp b/Core/include/Acts/Geometry/detail/VolumeResizeStrategy.hpp new file mode 100644 index 00000000000..3124de68b6c --- /dev/null +++ b/Core/include/Acts/Geometry/detail/VolumeResizeStrategy.hpp @@ -0,0 +1,25 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once + +#include + +namespace Acts { + +/// The resize strategy defines how the volumes are resized +enum class VolumeResizeStrategy { + /// Extend the volume connected to the respective edge to fit the new bounds + Expand, + /// Create a gap volume at the respective edge to fit the new bounds + Gap, +}; + +std::ostream& operator<<(std::ostream& os, VolumeResizeStrategy strategy); + +} // namespace Acts diff --git a/Core/src/Geometry/CMakeLists.txt b/Core/src/Geometry/CMakeLists.txt index 18a58033eaa..19585591c45 100644 --- a/Core/src/Geometry/CMakeLists.txt +++ b/Core/src/Geometry/CMakeLists.txt @@ -51,4 +51,6 @@ target_sources( StaticBlueprintNode.cpp LayerBlueprintNode.cpp MaterialDesignatorBlueprintNode.cpp + detail/VolumeAttachmentStrategy.cpp + detail/VolumeResizeStrategy.cpp ) diff --git a/Core/src/Geometry/CuboidVolumeBounds.cpp b/Core/src/Geometry/CuboidVolumeBounds.cpp index 9b01eb54ae8..90d66e7eff1 100644 --- a/Core/src/Geometry/CuboidVolumeBounds.cpp +++ b/Core/src/Geometry/CuboidVolumeBounds.cpp @@ -9,11 +9,15 @@ #include "Acts/Geometry/CuboidVolumeBounds.hpp" #include "Acts/Definitions/Direction.hpp" +#include "Acts/Surfaces/LineSurface.hpp" #include "Acts/Surfaces/PlaneSurface.hpp" #include "Acts/Surfaces/RectangleBounds.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/BoundingBox.hpp" +#include +#include +#include #include namespace Acts { @@ -30,6 +34,24 @@ CuboidVolumeBounds::CuboidVolumeBounds(const std::array& values) buildSurfaceBounds(); } +CuboidVolumeBounds::CuboidVolumeBounds( + std::initializer_list> keyValues) { + // Consistency check will fail if + // not all the bounds are constructed + std::array values = {-1, -1, -1}; + for (const auto& [key, value] : keyValues) { + values[key] = value; + } + if (std::any_of(values.begin(), values.end(), + [](const auto& val) { return val == -1; })) { + throw std::logic_error("Missing bound values"); + } + + m_values = values; + checkConsistency(); + buildSurfaceBounds(); +} + std::vector CuboidVolumeBounds::values() const { return {m_values.begin(), m_values.end()}; } @@ -150,4 +172,22 @@ void CuboidVolumeBounds::set( } } +CuboidVolumeBounds::BoundValues CuboidVolumeBounds::fromAxisDirection( + AxisDirection direction) { + using enum AxisDirection; + switch (direction) { + case AxisX: + return BoundValues::eHalfLengthX; + break; + case AxisY: + return BoundValues::eHalfLengthY; + break; + case AxisZ: + return BoundValues::eHalfLengthZ; + break; + default: + throw std::invalid_argument("Invalid axis direction"); + } +} + } // namespace Acts diff --git a/Core/src/Geometry/CuboidVolumeStack.cpp b/Core/src/Geometry/CuboidVolumeStack.cpp index 0b0c6d7f506..b06214886b5 100644 --- a/Core/src/Geometry/CuboidVolumeStack.cpp +++ b/Core/src/Geometry/CuboidVolumeStack.cpp @@ -15,11 +15,13 @@ #include "Acts/Utilities/Logger.hpp" #include -#include #include +#include #include #include +#include #include +#include #include namespace Acts { @@ -43,11 +45,10 @@ struct CuboidVolumeStack::VolumeTuple { } double mid(AxisDirection direction) const { - return localTransform.translation()[static_cast(direction)]; + return localTransform.translation()[axisToIndex(direction)]; } double halfLength(AxisDirection direction) const { - return updatedBounds->get( - static_cast(direction)); + return updatedBounds->get(CuboidVolumeBounds::fromAxisDirection(direction)); } double min(AxisDirection direction) const { return mid(direction) - halfLength(direction); @@ -85,47 +86,74 @@ struct CuboidVolumeStack::VolumeTuple { } }; +std::size_t CuboidVolumeStack::axisToIndex(AxisDirection direction) { + switch (direction) { + case AxisDirection::AxisX: + return 0; + break; + case AxisDirection::AxisY: + return 1; + break; + case AxisDirection::AxisZ: + return 2; + break; + default: + throw std::invalid_argument("Invalid axis direction"); + } +} + +std::pair CuboidVolumeStack::getOrthogonalAxes( + AxisDirection direction) { + switch (direction) { + case AxisDirection::AxisX: + return {AxisDirection::AxisY, AxisDirection::AxisZ}; + break; + case AxisDirection::AxisY: + return {AxisDirection::AxisZ, AxisDirection::AxisX}; + break; + case AxisDirection::AxisZ: + return {AxisDirection::AxisX, AxisDirection::AxisY}; + break; + default: + throw std::invalid_argument("Invalid axis direction"); + } +} + CuboidVolumeStack::CuboidVolumeStack(std::vector& volumes, AxisDirection direction, - AttachmentStrategy strategy, - ResizeStrategy resizeStrategy, + VolumeAttachmentStrategy strategy, + VolumeResizeStrategy resizeStrategy, const Logger& logger) : Volume(initialVolume(volumes)), m_dir(direction), m_resizeStrategy(resizeStrategy), m_volumes(volumes) { - auto dirIdx = static_cast(m_dir); - m_dirOrth1 = static_cast((dirIdx + 1) % 3); - m_dirOrth2 = static_cast((dirIdx + 2) % 3); + std::tie(m_dirOrth1, m_dirOrth2) = getOrthogonalAxes(m_dir); initializeOuterVolume(strategy, logger); } CuboidVolumeStack::CuboidVolumeStack(std::vector& volumes, const Vector3& direction, - AttachmentStrategy strategy, - ResizeStrategy resizeStrategy, + VolumeAttachmentStrategy strategy, + VolumeResizeStrategy resizeStrategy, const Logger& logger) : Volume(initialVolume(volumes)), m_resizeStrategy(resizeStrategy), m_volumes(volumes) { - // TODO: What's a good tolerance here? - const auto& tolerance = s_onSurfaceTolerance; Vector3 localDirVector = m_volumes.front()->transform().rotation().inverse() * direction; - if ((localDirVector - Vector3::UnitX()).norm() < tolerance) { + if ((localDirVector - Vector3::UnitX()).norm() < 1e-4) { m_dir = AxisDirection::AxisX; - } else if ((localDirVector - Vector3::UnitY()).norm() < tolerance) { + } else if ((localDirVector - Vector3::UnitY()).norm() < 1e-4) { m_dir = AxisDirection::AxisY; - } else if ((localDirVector - Vector3::UnitZ()).norm() < tolerance) { + } else if ((localDirVector - Vector3::UnitZ()).norm() < 1e-4) { m_dir = AxisDirection::AxisZ; } else { throw std::invalid_argument("CuboidVolumeStack: Invalid axis direction"); } - auto dirIdx = static_cast(m_dir); - m_dirOrth1 = static_cast((dirIdx + 1) % 3); - m_dirOrth2 = static_cast((dirIdx + 2) % 3); + std::tie(m_dirOrth1, m_dirOrth2) = getOrthogonalAxes(m_dir); initializeOuterVolume(strategy, logger); } @@ -138,7 +166,7 @@ Volume& CuboidVolumeStack::initialVolume(const std::vector& volumes) { return *volumes.front(); } -void CuboidVolumeStack::initializeOuterVolume(AttachmentStrategy strategy, +void CuboidVolumeStack::initializeOuterVolume(VolumeAttachmentStrategy strategy, const Logger& logger) { ACTS_DEBUG("Creating CuboidVolumeStack from " << m_volumes.size() << " volumes in direction " @@ -192,9 +220,9 @@ void CuboidVolumeStack::initializeOuterVolume(AttachmentStrategy strategy, ACTS_VERBOSE("Checking volume alignment"); checkVolumeAlignment(volumeTuples, logger); - auto dirIdx = static_cast(m_dir); + auto dirIdx = axisToIndex(m_dir); ACTS_VERBOSE("Sorting by volume " << axisDirectionName(m_dir) << " position"); - std::ranges::sort(volumeTuples, {}, [&dirIdx](const auto& v) { + std::ranges::sort(volumeTuples, {}, [dirIdx](const auto& v) { return v.localTransform.translation()[dirIdx]; }); ACTS_VERBOSE("Checking for overlaps and attaching volumes in " @@ -245,18 +273,17 @@ void CuboidVolumeStack::initializeOuterVolume(AttachmentStrategy strategy, double min = volumeTuples.front().min(m_dir); double max = volumeTuples.back().max(m_dir); - double mid = (min + max) / 2.0; - double hl = (max - min) / 2.0; + double mid = std::midpoint(min, max); + double hl = std::midpoint(max, -min); Translation3 translation(Vector3::Unit(dirIdx) * mid); m_transform = m_groupTransform * translation; - std::array bounds{}; - bounds.at(dirIdx) = hl; - bounds.at(static_cast(m_dirOrth1)) = hl1; - bounds.at(static_cast(m_dirOrth2)) = hl2; - - Volume::update(std::make_shared(bounds), std::nullopt, - logger); + auto bounds = std::make_shared( + std::initializer_list>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), hl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), hl1}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), hl2}}); + Volume::update(bounds, std::nullopt, logger); ACTS_DEBUG("Outer bounds are:\n" << volumeBounds()); ACTS_DEBUG("Outer transform / new group transform is:\n" << m_transform.matrix()); @@ -292,12 +319,12 @@ void CuboidVolumeStack::overlapPrint(const CuboidVolumeStack::VolumeTuple& a, } std::vector -CuboidVolumeStack::checkOverlapAndAttach( - std::vector& volumes, - CuboidVolumeStack::AttachmentStrategy strategy, const Logger& logger) { +CuboidVolumeStack::checkOverlapAndAttach(std::vector& volumes, + VolumeAttachmentStrategy strategy, + const Logger& logger) { // Preconditions: volumes are sorted along stacking direction - auto dirIdx = static_cast(m_dir); - auto dirBoundIdx = static_cast(m_dir); + auto dirIdx = axisToIndex(m_dir); + auto dirBoundIdx = CuboidVolumeBounds::fromAxisDirection(m_dir); std::vector gapVolumes; for (std::size_t i = 0; i < volumes.size() - 1; i++) { @@ -327,7 +354,7 @@ CuboidVolumeStack::checkOverlapAndAttach( << axisDirectionName(m_dir) << " with strategy: " << strategy); switch (strategy) { - case AttachmentStrategy::Midpoint: { + case VolumeAttachmentStrategy::Midpoint: { ACTS_VERBOSE(" -> Strategy: Expand both volumes to midpoint"); double aMidNew = (a.min(m_dir) + a.max(m_dir)) / 2.0 + gapWidth / 4.0; @@ -362,7 +389,7 @@ CuboidVolumeStack::checkOverlapAndAttach( break; } - case AttachmentStrategy::First: { + case VolumeAttachmentStrategy::First: { ACTS_VERBOSE(" -> Strategy: Expand first volume"); double aMidNew = (a.min(m_dir) + b.min(m_dir)) / 2.0; double aHlNew = (b.min(m_dir) - a.min(m_dir)) / 2.0; @@ -381,7 +408,7 @@ CuboidVolumeStack::checkOverlapAndAttach( break; } - case AttachmentStrategy::Second: { + case VolumeAttachmentStrategy::Second: { ACTS_VERBOSE(" -> Strategy: Expand second volume"); double bMidNew = (a.max(m_dir) + b.max(m_dir)) / 2.0; double bHlNew = (b.max(m_dir) - a.max(m_dir)) / 2.0; @@ -399,7 +426,7 @@ CuboidVolumeStack::checkOverlapAndAttach( b.updatedBounds->set(dirBoundIdx, bHlNew); break; } - case AttachmentStrategy::Gap: { + case VolumeAttachmentStrategy::Gap: { ACTS_VERBOSE(" -> Strategy: Create a gap volume"); double gapHl = (b.min(m_dir) - a.max(m_dir)) / 2.0; double gapMid = (b.min(m_dir) + a.max(m_dir)) / 2.0; @@ -419,13 +446,14 @@ CuboidVolumeStack::checkOverlapAndAttach( Transform3 gapLocalTransform{gapTranslation}; Transform3 gapGlobalTransform = m_groupTransform * gapLocalTransform; - std::array gapBoundsVals{}; - gapBoundsVals[dirIdx] = gapHl; - gapBoundsVals[static_cast(m_dirOrth1)] = - (max1 - min1) / 2; - gapBoundsVals[static_cast(m_dirOrth2)] = - (max2 - min2) / 2; - auto gapBounds = std::make_shared(gapBoundsVals); + auto gapBounds = std::make_shared( + std::initializer_list< + std::pair>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), gapHl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), + (max1 - min1) / 2}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), + (max2 - min2) / 2}}); auto gap = addGapVolume(gapGlobalTransform, gapBounds); gapVolumes.emplace_back(*gap, m_groupTransform); @@ -471,9 +499,9 @@ void CuboidVolumeStack::printVolumeSequence( void CuboidVolumeStack::checkVolumeAlignment( const std::vector& volumes, const Logger& logger) const { std::size_t n = 0; - auto dirIdx = static_cast(m_dir); - auto dirOrth1Idx = static_cast(m_dirOrth1); - auto dirOrth2Idx = static_cast(m_dirOrth2); + auto dirIdx = axisToIndex(m_dir); + auto dirOrth1Idx = axisToIndex(m_dirOrth1); + auto dirOrth2Idx = axisToIndex(m_dirOrth2); for (auto& vt : volumes) { ACTS_VERBOSE("Checking volume #" @@ -516,19 +544,19 @@ void CuboidVolumeStack::checkVolumeAlignment( std::pair CuboidVolumeStack::synchronizeBounds( std::vector& volumes, const Logger& logger) { - auto boundDirOrth1 = static_cast(m_dirOrth1); - auto boundDirOrth2 = static_cast(m_dirOrth2); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(m_dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(m_dirOrth2); const double maxHl1 = std::max_element(volumes.begin(), volumes.end(), - [&boundDirOrth1](const auto& a, const auto& b) { + [boundDirOrth1](const auto& a, const auto& b) { return a.bounds->get(boundDirOrth1) < b.bounds->get(boundDirOrth1); }) ->bounds->get(boundDirOrth1); const double maxHl2 = std::max_element(volumes.begin(), volumes.end(), - [&boundDirOrth2](const auto& a, const auto& b) { + [boundDirOrth2](const auto& a, const auto& b) { return a.bounds->get(boundDirOrth2) < b.bounds->get(boundDirOrth2); }) @@ -658,7 +686,7 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, ACTS_VERBOSE("Resize all volumes to new " << axisDirectionName(dir) << " bounds"); for (auto& volume : volumeTuples) { - volume.set({{static_cast(dir), + volume.set({{CuboidVolumeBounds::fromAxisDirection(dir), newVolume.halfLength(dir)}}); } ACTS_VERBOSE("*** Volume configuration after " << axisDirectionName(dir) @@ -675,11 +703,9 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, ACTS_VERBOSE("Halflength " << axisDirectionName(m_dir) << "is the same, no " << axisDirectionName(m_dir) << "resize needed"); } else { - auto dirIdx = static_cast(m_dir); - auto dirOrth1Idx = static_cast(m_dirOrth1); - auto dirOrth2Idx = static_cast(m_dirOrth2); - auto boundDirIdx = static_cast(m_dir); - if (m_resizeStrategy == ResizeStrategy::Expand) { + auto dirIdx = axisToIndex(m_dir); + auto boundDirIdx = CuboidVolumeBounds::fromAxisDirection(m_dir); + if (m_resizeStrategy == VolumeResizeStrategy::Expand) { if (newVolume.min(m_dir) < oldVolume.min(m_dir)) { ACTS_VERBOSE("Expanding first volume to new " << axisDirectionName(m_dir) << "bounds"); @@ -717,7 +743,7 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, last.set({{boundDirIdx, newHlLast}}); last.setLocalTransform(Transform3{translation}, m_groupTransform); } - } else if (m_resizeStrategy == ResizeStrategy::Gap) { + } else if (m_resizeStrategy == VolumeResizeStrategy::Gap) { ACTS_VERBOSE("Creating gap volumes to fill the new " << axisDirectionName(m_dir) << " bounds"); @@ -745,19 +771,21 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, << axisDirectionName(m_dir)); gap1Hl = candidate.bounds->get( - static_cast(m_dir)) + + CuboidVolumeBounds::fromAxisDirection(m_dir)) + gap1Hl; gap1Max = gap1Min + gap1Hl * 2; gap1P = (gap1Max + gap1Min) / 2.0; printGapDimensions(candidate, " before"); - std::array gap1BoundsVals{}; - gap1BoundsVals[dirIdx] = gap1Hl; - gap1BoundsVals[dirOrth1Idx] = newVolume.halfLength(m_dirOrth1); - gap1BoundsVals[dirOrth2Idx] = newVolume.halfLength(m_dirOrth2); - auto gap1Bounds = - std::make_shared(gap1BoundsVals); + auto gap1Bounds = std::make_shared( + std::initializer_list< + std::pair>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), gap1Hl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), + newVolume.halfLength(m_dirOrth1)}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), + newVolume.halfLength(m_dirOrth2)}}); Translation3 gap1Translation(Vector3::Unit(dirIdx) * gap1P); Transform3 gap1Transform = m_groupTransform * gap1Translation; candidate.volume->update(std::move(gap1Bounds), gap1Transform); @@ -767,12 +795,14 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, } else { ACTS_VERBOSE("~> Creating new gap volume at negative "); - std::array gap1BoundsVals{}; - gap1BoundsVals[dirIdx] = gap1Hl; - gap1BoundsVals[dirOrth1Idx] = newVolume.halfLength(m_dirOrth1); - gap1BoundsVals[dirOrth2Idx] = newVolume.halfLength(m_dirOrth2); - auto gap1Bounds = - std::make_shared(gap1BoundsVals); + auto gap1Bounds = std::make_shared( + std::initializer_list< + std::pair>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), gap1Hl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), + newVolume.halfLength(m_dirOrth1)}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), + newVolume.halfLength(m_dirOrth2)}}); Translation3 gap1Translation(Vector3::Unit(dirIdx) * gap1P); Transform3 gap1Transform = m_groupTransform * gap1Translation; auto gap1 = addGapVolume(gap1Transform, std::move(gap1Bounds)); @@ -795,17 +825,19 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, ACTS_VERBOSE("~> Reusing existing gap volume at positive "); gap2Hl = candidate.bounds->get( - static_cast(m_dir)) + + CuboidVolumeBounds::fromAxisDirection(m_dir)) + gap2Hl; gap2Min = newVolume.max(m_dir) - gap2Hl * 2; gap2P = (gap2Max + gap2Min) / 2.0; - std::array gap2BoundsVals{}; - gap2BoundsVals[dirIdx] = gap2Hl; - gap2BoundsVals[dirOrth1Idx] = newVolume.halfLength(m_dirOrth1); - gap2BoundsVals[dirOrth2Idx] = newVolume.halfLength(m_dirOrth2); - auto gap2Bounds = - std::make_shared(gap2BoundsVals); + auto gap2Bounds = std::make_shared( + std::initializer_list< + std::pair>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), gap2Hl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), + newVolume.halfLength(m_dirOrth1)}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), + newVolume.halfLength(m_dirOrth2)}}); Translation3 gap2Translation(Vector3::Unit(dirIdx) * gap2P); Transform3 gap2Transform = m_groupTransform * gap2Translation; @@ -814,12 +846,14 @@ void CuboidVolumeStack::update(std::shared_ptr volbounds, printGapDimensions(candidate, " after "); } else { ACTS_VERBOSE("~> Creating new gap volume at positive "); - std::array gap2BoundsVals{}; - gap2BoundsVals[dirIdx] = gap2Hl; - gap2BoundsVals[dirOrth1Idx] = newVolume.halfLength(m_dirOrth1); - gap2BoundsVals[dirOrth2Idx] = newVolume.halfLength(m_dirOrth2); - auto gap2Bounds = - std::make_shared(gap2BoundsVals); + auto gap2Bounds = std::make_shared( + std::initializer_list< + std::pair>{ + {CuboidVolumeBounds::fromAxisDirection(m_dir), gap2Hl}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth1), + newVolume.halfLength(m_dirOrth1)}, + {CuboidVolumeBounds::fromAxisDirection(m_dirOrth2), + newVolume.halfLength(m_dirOrth2)}}); Translation3 gap2Translation(Vector3::Unit(dirIdx) * gap2P); Transform3 gap2Transform = m_groupTransform * gap2Translation; auto gap2 = addGapVolume(gap2Transform, std::move(gap2Bounds)); @@ -858,36 +892,4 @@ const std::vector>& CuboidVolumeStack::gaps() const { return m_gaps; } -std::ostream& operator<<(std::ostream& os, - CuboidVolumeStack::AttachmentStrategy strategy) { - switch (strategy) { - case CuboidVolumeStack::AttachmentStrategy::First: - os << "First"; - break; - case CuboidVolumeStack::AttachmentStrategy::Second: - os << "Second"; - break; - case CuboidVolumeStack::AttachmentStrategy::Midpoint: - os << "Midpoint"; - break; - case CuboidVolumeStack::AttachmentStrategy::Gap: - os << "Gap"; - break; - } - return os; -} - -std::ostream& operator<<(std::ostream& os, - CuboidVolumeStack::ResizeStrategy strategy) { - switch (strategy) { - case CuboidVolumeStack::ResizeStrategy::Expand: - os << "Expand"; - break; - case CuboidVolumeStack::ResizeStrategy::Gap: - os << "Gap"; - break; - } - return os; -} - } // namespace Acts diff --git a/Core/src/Geometry/CylinderContainerBlueprintNode.cpp b/Core/src/Geometry/CylinderContainerBlueprintNode.cpp index 0da0e409c0b..aef3461a57b 100644 --- a/Core/src/Geometry/CylinderContainerBlueprintNode.cpp +++ b/Core/src/Geometry/CylinderContainerBlueprintNode.cpp @@ -24,8 +24,8 @@ namespace Acts { CylinderContainerBlueprintNode::CylinderContainerBlueprintNode( const std::string& name, AxisDirection direction, - CylinderVolumeStack::AttachmentStrategy attachmentStrategy, - CylinderVolumeStack::ResizeStrategy resizeStrategy) + VolumeAttachmentStrategy attachmentStrategy, + VolumeResizeStrategy resizeStrategy) : m_name(name), m_direction(direction), m_attachmentStrategy(attachmentStrategy), @@ -207,7 +207,7 @@ CylinderContainerBlueprintNode& CylinderContainerBlueprintNode::setDirection( CylinderContainerBlueprintNode& CylinderContainerBlueprintNode::setAttachmentStrategy( - CylinderVolumeStack::AttachmentStrategy attachmentStrategy) { + VolumeAttachmentStrategy attachmentStrategy) { if (m_stack != nullptr) { throw std::runtime_error("Cannot change direction after build"); } @@ -217,7 +217,7 @@ CylinderContainerBlueprintNode::setAttachmentStrategy( CylinderContainerBlueprintNode& CylinderContainerBlueprintNode::setResizeStrategy( - CylinderVolumeStack::ResizeStrategy resizeStrategy) { + VolumeResizeStrategy resizeStrategy) { if (m_stack != nullptr) { throw std::runtime_error("Cannot change direction after build"); } @@ -244,12 +244,12 @@ AxisDirection CylinderContainerBlueprintNode::direction() const { return m_direction; } -CylinderVolumeStack::AttachmentStrategy +VolumeAttachmentStrategy CylinderContainerBlueprintNode::attachmentStrategy() const { return m_attachmentStrategy; } -CylinderVolumeStack::ResizeStrategy +VolumeResizeStrategy CylinderContainerBlueprintNode::resizeStrategy() const { return m_resizeStrategy; } diff --git a/Core/src/Geometry/CylinderVolumeStack.cpp b/Core/src/Geometry/CylinderVolumeStack.cpp index 61696bd61af..888216352d1 100644 --- a/Core/src/Geometry/CylinderVolumeStack.cpp +++ b/Core/src/Geometry/CylinderVolumeStack.cpp @@ -86,8 +86,8 @@ struct CylinderVolumeStack::VolumeTuple { CylinderVolumeStack::CylinderVolumeStack(std::vector& volumes, AxisDirection direction, - AttachmentStrategy strategy, - ResizeStrategy resizeStrategy, + VolumeAttachmentStrategy strategy, + VolumeResizeStrategy resizeStrategy, const Logger& logger) : Volume(initialVolume(volumes)), m_direction(direction), @@ -105,9 +105,9 @@ Volume& CylinderVolumeStack::initialVolume( return *volumes.front(); } -void CylinderVolumeStack::initializeOuterVolume(AxisDirection direction, - AttachmentStrategy strategy, - const Logger& logger) { +void CylinderVolumeStack::initializeOuterVolume( + AxisDirection direction, VolumeAttachmentStrategy strategy, + const Logger& logger) { ACTS_DEBUG("Creating CylinderVolumeStack from " << m_volumes.size() << " volumes in direction " << axisDirectionName(direction)); @@ -300,26 +300,24 @@ void CylinderVolumeStack::overlapPrint( ACTS_VERBOSE("Checking overlap between"); if (direction == AxisDirection::AxisZ) { - ss << " - " - << " z: [ " << std::setw(w) << a.minZ() << " <- " << std::setw(w) - << a.midZ() << " -> " << std::setw(w) << a.maxZ() << " ]"; + ss << " - " << " z: [ " << std::setw(w) << a.minZ() << " <- " + << std::setw(w) << a.midZ() << " -> " << std::setw(w) << a.maxZ() + << " ]"; ACTS_VERBOSE(ss.str()); ss.str(""); - ss << " - " - << " z: [ " << std::setw(w) << b.minZ() << " <- " << std::setw(w) - << b.midZ() << " -> " << std::setw(w) << b.maxZ() << " ]"; + ss << " - " << " z: [ " << std::setw(w) << b.minZ() << " <- " + << std::setw(w) << b.midZ() << " -> " << std::setw(w) << b.maxZ() + << " ]"; ACTS_VERBOSE(ss.str()); } else { - ss << " - " - << " r: [ " << std::setw(w) << a.minR() << " <-> " << std::setw(w) - << a.maxR() << " ]"; + ss << " - " << " r: [ " << std::setw(w) << a.minR() << " <-> " + << std::setw(w) << a.maxR() << " ]"; ACTS_VERBOSE(ss.str()); ss.str(""); - ss << " - " - << " r: [ " << std::setw(w) << b.minR() << " <-> " << std::setw(w) - << b.maxR() << " ]"; + ss << " - " << " r: [ " << std::setw(w) << b.minR() << " <-> " + << std::setw(w) << b.maxR() << " ]"; ACTS_VERBOSE(ss.str()); } } @@ -328,7 +326,8 @@ void CylinderVolumeStack::overlapPrint( std::vector CylinderVolumeStack::checkOverlapAndAttachInZ( std::vector& volumes, - CylinderVolumeStack::AttachmentStrategy strategy, const Logger& logger) { + VolumeAttachmentStrategy strategy, + const Logger& logger) { // Preconditions: volumes are sorted by z std::vector gapVolumes; for (std::size_t i = 0; i < volumes.size() - 1; i++) { @@ -354,7 +353,7 @@ CylinderVolumeStack::checkOverlapAndAttachInZ( ACTS_VERBOSE("Synchronizing bounds in z with strategy: " << strategy); switch (strategy) { - case AttachmentStrategy::Midpoint: { + case VolumeAttachmentStrategy::Midpoint: { ACTS_VERBOSE(" -> Strategy: Expand both volumes to midpoint"); double aZMidNew = (a.minZ() + a.maxZ()) / 2.0 + gapWidth / 4.0; @@ -389,7 +388,7 @@ CylinderVolumeStack::checkOverlapAndAttachInZ( break; } - case AttachmentStrategy::First: { + case VolumeAttachmentStrategy::First: { ACTS_VERBOSE(" -> Strategy: Expand first volume"); double aZMidNew = (a.minZ() + b.minZ()) / 2.0; double aHlZNew = (b.minZ() - a.minZ()) / 2.0; @@ -408,7 +407,7 @@ CylinderVolumeStack::checkOverlapAndAttachInZ( break; } - case AttachmentStrategy::Second: { + case VolumeAttachmentStrategy::Second: { ACTS_VERBOSE(" -> Strategy: Expand second volume"); double bZMidNew = (a.maxZ() + b.maxZ()) / 2.0; double bHlZNew = (b.maxZ() - a.maxZ()) / 2.0; @@ -426,7 +425,7 @@ CylinderVolumeStack::checkOverlapAndAttachInZ( b.updatedBounds->set(CylinderVolumeBounds::eHalfLengthZ, bHlZNew); break; } - case AttachmentStrategy::Gap: { + case VolumeAttachmentStrategy::Gap: { ACTS_VERBOSE(" -> Strategy: Create a gap volume"); double gapHlZ = (b.minZ() - a.maxZ()) / 2.0; double gapMidZ = (b.minZ() + a.maxZ()) / 2.0; @@ -463,7 +462,8 @@ CylinderVolumeStack::checkOverlapAndAttachInZ( std::vector CylinderVolumeStack::checkOverlapAndAttachInR( std::vector& volumes, - CylinderVolumeStack::AttachmentStrategy strategy, const Logger& logger) { + VolumeAttachmentStrategy strategy, + const Logger& logger) { std::vector gapVolumes; for (std::size_t i = 0; i < volumes.size() - 1; i++) { std::size_t j = i + 1; @@ -488,7 +488,7 @@ CylinderVolumeStack::checkOverlapAndAttachInR( ACTS_VERBOSE("Synchronizing bounds in r with strategy: " << strategy); switch (strategy) { - case AttachmentStrategy::Midpoint: { + case VolumeAttachmentStrategy::Midpoint: { ACTS_VERBOSE(" -> Strategy: Expand both volumes to midpoint"); a.set({{CylinderVolumeBounds::eMaxR, a.maxR() + gapWidth / 2.0}}); @@ -496,21 +496,21 @@ CylinderVolumeStack::checkOverlapAndAttachInR( break; } - case AttachmentStrategy::First: { + case VolumeAttachmentStrategy::First: { ACTS_VERBOSE(" -> Strategy: Expand first volume"); a.set({{CylinderVolumeBounds::eMaxR, b.minR()}}); break; } - case AttachmentStrategy::Second: { + case VolumeAttachmentStrategy::Second: { ACTS_VERBOSE(" -> Strategy: Expand second volume"); b.set({{CylinderVolumeBounds::eMinR, a.maxR()}}); break; } - case AttachmentStrategy::Gap: { + case VolumeAttachmentStrategy::Gap: { ACTS_VERBOSE(" -> Strategy: Create a gap volume"); auto gapBounds = std::make_shared( @@ -789,7 +789,7 @@ void CylinderVolumeStack::update(std::shared_ptr volbounds, if (same(newHlZ, oldHlZ)) { ACTS_VERBOSE("Halflength z is the same, no z resize needed"); } else { - if (m_resizeStrategy == ResizeStrategy::Expand) { + if (m_resizeStrategy == VolumeResizeStrategy::Expand) { if (newMinZ < oldMinZ) { ACTS_VERBOSE("Expanding first volume to new z bounds"); @@ -823,7 +823,7 @@ void CylinderVolumeStack::update(std::shared_ptr volbounds, last.setLocalTransform(Transform3{Translation3{0, 0, newMidZLast}}, m_groupTransform); } - } else if (m_resizeStrategy == ResizeStrategy::Gap) { + } else if (m_resizeStrategy == VolumeResizeStrategy::Gap) { ACTS_VERBOSE("Creating gap volumes to fill the new z bounds"); auto printGapDimensions = [&](const VolumeTuple& gap, @@ -948,7 +948,7 @@ void CylinderVolumeStack::update(std::shared_ptr volbounds, if (oldMinR == newMinR && oldMaxR == newMaxR) { ACTS_VERBOSE("Radii are the same, no r resize needed"); } else { - if (m_resizeStrategy == ResizeStrategy::Expand) { + if (m_resizeStrategy == VolumeResizeStrategy::Expand) { if (oldMinR > newMinR) { // expand innermost volume auto& first = volumeTuples.front(); @@ -971,7 +971,7 @@ void CylinderVolumeStack::update(std::shared_ptr volbounds, << last.minR() << " <-> " << last.maxR() << " ]"); } - } else if (m_resizeStrategy == ResizeStrategy::Gap) { + } else if (m_resizeStrategy == VolumeResizeStrategy::Gap) { auto printGapDimensions = [&](const VolumeTuple& gap, const std::string& prefix = "") { ACTS_VERBOSE(" -> gap" << prefix << ": [ " << gap.minZ() << " <- " @@ -1092,36 +1092,4 @@ const std::vector>& CylinderVolumeStack::gaps() const { return m_gaps; } -std::ostream& operator<<(std::ostream& os, - CylinderVolumeStack::AttachmentStrategy strategy) { - switch (strategy) { - case CylinderVolumeStack::AttachmentStrategy::First: - os << "First"; - break; - case CylinderVolumeStack::AttachmentStrategy::Second: - os << "Second"; - break; - case CylinderVolumeStack::AttachmentStrategy::Midpoint: - os << "Midpoint"; - break; - case CylinderVolumeStack::AttachmentStrategy::Gap: - os << "Gap"; - break; - } - return os; -} - -std::ostream& operator<<(std::ostream& os, - CylinderVolumeStack::ResizeStrategy strategy) { - switch (strategy) { - case CylinderVolumeStack::ResizeStrategy::Expand: - os << "Expand"; - break; - case CylinderVolumeStack::ResizeStrategy::Gap: - os << "Gap"; - break; - } - return os; -} - } // namespace Acts diff --git a/Core/src/Geometry/detail/VolumeAttachmentStrategy.cpp b/Core/src/Geometry/detail/VolumeAttachmentStrategy.cpp new file mode 100644 index 00000000000..8f6c55e9884 --- /dev/null +++ b/Core/src/Geometry/detail/VolumeAttachmentStrategy.cpp @@ -0,0 +1,30 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" + +namespace Acts { +std::ostream& operator<<(std::ostream& os, VolumeAttachmentStrategy strategy) { + switch (strategy) { + case VolumeAttachmentStrategy::First: + os << "First"; + break; + case VolumeAttachmentStrategy::Second: + os << "Second"; + break; + case VolumeAttachmentStrategy::Midpoint: + os << "Midpoint"; + break; + case VolumeAttachmentStrategy::Gap: + os << "Gap"; + break; + } + return os; +} + +} // namespace Acts \ No newline at end of file diff --git a/Core/src/Geometry/detail/VolumeResizeStrategy.cpp b/Core/src/Geometry/detail/VolumeResizeStrategy.cpp new file mode 100644 index 00000000000..bb289d8ce2f --- /dev/null +++ b/Core/src/Geometry/detail/VolumeResizeStrategy.cpp @@ -0,0 +1,25 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" + +namespace Acts { + +std::ostream& operator<<(std::ostream& os, VolumeResizeStrategy strategy) { + switch (strategy) { + case VolumeResizeStrategy::Expand: + os << "Expand"; + break; + case VolumeResizeStrategy::Gap: + os << "Gap"; + break; + } + return os; +} + +} // namespace Acts diff --git a/Examples/Python/src/Blueprint.cpp b/Examples/Python/src/Blueprint.cpp index c0ebdd4f5e8..0fc16095e21 100644 --- a/Examples/Python/src/Blueprint.cpp +++ b/Examples/Python/src/Blueprint.cpp @@ -15,6 +15,8 @@ #include "Acts/Geometry/LayerBlueprintNode.hpp" #include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp" #include "Acts/Geometry/StaticBlueprintNode.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" @@ -339,13 +341,10 @@ void addBlueprint(Context& ctx) { std::shared_ptr>( m, "CylinderContainerBlueprintNode") .def(py::init(), + VolumeAttachmentStrategy, VolumeResizeStrategy>(), py::arg("name"), py::arg("direction"), - py::arg("attachmentStrategy") = - CylinderVolumeStack::AttachmentStrategy::Gap, - py::arg("resizeStrategy") = - CylinderVolumeStack::ResizeStrategy::Gap) + py::arg("attachmentStrategy") = VolumeAttachmentStrategy::Gap, + py::arg("resizeStrategy") = VolumeResizeStrategy::Gap) .def_property( "attachmentStrategy", &Acts::CylinderContainerBlueprintNode::attachmentStrategy, diff --git a/Examples/Python/src/Geometry.cpp b/Examples/Python/src/Geometry.cpp index ec15814e940..1cc85e4583d 100644 --- a/Examples/Python/src/Geometry.cpp +++ b/Examples/Python/src/Geometry.cpp @@ -34,6 +34,8 @@ #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/Volume.hpp" #include "Acts/Geometry/VolumeBounds.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Material/ISurfaceMaterial.hpp" #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Surfaces/Surface.hpp" @@ -294,16 +296,15 @@ void addGeometry(Context& ctx) { { auto cylStack = py::class_(m, "CylinderVolumeStack"); - py::enum_(cylStack, - "AttachmentStrategy") - .value("Gap", CylinderVolumeStack::AttachmentStrategy::Gap) - .value("First", CylinderVolumeStack::AttachmentStrategy::First) - .value("Second", CylinderVolumeStack::AttachmentStrategy::Second) - .value("Midpoint", CylinderVolumeStack::AttachmentStrategy::Midpoint); + py::enum_(cylStack, "AttachmentStrategy") + .value("Gap", VolumeAttachmentStrategy::Gap) + .value("First", VolumeAttachmentStrategy::First) + .value("Second", VolumeAttachmentStrategy::Second) + .value("Midpoint", VolumeAttachmentStrategy::Midpoint); - py::enum_(cylStack, "ResizeStrategy") - .value("Gap", CylinderVolumeStack::ResizeStrategy::Gap) - .value("Expand", CylinderVolumeStack::ResizeStrategy::Expand); + py::enum_(cylStack, "ResizeStrategy") + .value("Gap", VolumeResizeStrategy::Gap) + .value("Expand", VolumeResizeStrategy::Expand); } addBlueprint(ctx); diff --git a/Tests/UnitTests/Core/Geometry/BlueprintApiTests.cpp b/Tests/UnitTests/Core/Geometry/BlueprintApiTests.cpp index dd42e620a17..1617efa50d2 100644 --- a/Tests/UnitTests/Core/Geometry/BlueprintApiTests.cpp +++ b/Tests/UnitTests/Core/Geometry/BlueprintApiTests.cpp @@ -23,6 +23,8 @@ #include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" #include "Acts/Geometry/TrackingVolume.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Navigation/INavigationPolicy.hpp" #include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Surfaces/RectangleBounds.hpp" @@ -271,13 +273,12 @@ BOOST_AUTO_TEST_CASE(NodeApiTestContainers) { mat.addCylinderContainer("Detector", AxisDirection::AxisR, [&](auto& det) { det.addCylinderContainer("Pixel", AxisDirection::AxisZ, [&](auto& cyl) { - cyl.setAttachmentStrategy(CylinderVolumeStack::AttachmentStrategy::Gap) - .setResizeStrategy(CylinderVolumeStack::ResizeStrategy::Gap); + cyl.setAttachmentStrategy(VolumeAttachmentStrategy::Gap) + .setResizeStrategy(VolumeResizeStrategy::Gap); cyl.addCylinderContainer( "PixelNegativeEndcap", AxisDirection::AxisZ, [&](auto& ec) { - ec.setAttachmentStrategy( - CylinderVolumeStack::AttachmentStrategy::Gap); + ec.setAttachmentStrategy(VolumeAttachmentStrategy::Gap); auto makeLayer = [&](const Transform3& trf, auto& layer) { std::vector> surfaces; @@ -308,9 +309,8 @@ BOOST_AUTO_TEST_CASE(NodeApiTestContainers) { cyl.addCylinderContainer( "PixelBarrel", AxisDirection::AxisR, [&](auto& brl) { - brl.setAttachmentStrategy( - CylinderVolumeStack::AttachmentStrategy::Gap) - .setResizeStrategy(CylinderVolumeStack::ResizeStrategy::Gap); + brl.setAttachmentStrategy(VolumeAttachmentStrategy::Gap) + .setResizeStrategy(VolumeResizeStrategy::Gap); auto makeLayer = [&](const std::string& name, double r, std::size_t nStaves, int nSensorsPerStave) { @@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE(NodeApiTestContainers) { auto& ec = cyl.addCylinderContainer("PixelPosWrapper", AxisDirection::AxisR); - ec.setResizeStrategy(CylinderVolumeStack::ResizeStrategy::Gap); + ec.setResizeStrategy(VolumeResizeStrategy::Gap); ec.addStaticVolume(std::make_unique( base * Translation3{Vector3{0, 0, 600_mm}}, std::make_shared(150_mm, 390_mm, 200_mm), diff --git a/Tests/UnitTests/Core/Geometry/BlueprintTests.cpp b/Tests/UnitTests/Core/Geometry/BlueprintTests.cpp index 6d7a1a30fb9..33973661c9a 100644 --- a/Tests/UnitTests/Core/Geometry/BlueprintTests.cpp +++ b/Tests/UnitTests/Core/Geometry/BlueprintTests.cpp @@ -22,6 +22,7 @@ #include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp" #include "Acts/Geometry/StaticBlueprintNode.hpp" #include "Acts/Geometry/TrackingVolume.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" #include "Acts/Material/BinnedSurfaceMaterial.hpp" #include "Acts/Material/ProtoSurfaceMaterial.hpp" #include "Acts/Surfaces/RectangleBounds.hpp" @@ -214,7 +215,7 @@ BOOST_AUTO_TEST_CASE(CylinderContainer) { auto root = std::make_unique(cfg); auto& cyl = root->addCylinderContainer("Container", AxisDirection::AxisZ); - cyl.setAttachmentStrategy(CylinderVolumeStack::AttachmentStrategy::Gap); + cyl.setAttachmentStrategy(VolumeAttachmentStrategy::Gap); double z0 = -200_mm; double hlZ = 30_mm; diff --git a/Tests/UnitTests/Core/Geometry/CuboidVolumeBoundsTests.cpp b/Tests/UnitTests/Core/Geometry/CuboidVolumeBoundsTests.cpp index 79688dad718..126a803ca73 100644 --- a/Tests/UnitTests/Core/Geometry/CuboidVolumeBoundsTests.cpp +++ b/Tests/UnitTests/Core/Geometry/CuboidVolumeBoundsTests.cpp @@ -38,6 +38,12 @@ BOOST_AUTO_TEST_CASE(CuboidVolumeConstruction) { // Test Construction CuboidVolumeBounds box(hx, hy, hz); + // Test initilizer list construction + CuboidVolumeBounds init( + {{CuboidVolumeBounds::BoundValues::eHalfLengthX, hx}, + {CuboidVolumeBounds::BoundValues::eHalfLengthY, hy}, + {CuboidVolumeBounds::BoundValues::eHalfLengthZ, hz}}); + // Test copy construction CuboidVolumeBounds copied(box); BOOST_CHECK_EQUAL(box, copied); @@ -71,6 +77,11 @@ BOOST_AUTO_TEST_CASE(CuboidVolumeException) { BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, -hz), std::logic_error); // Other iterations : all BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, -hz), std::logic_error); + // Initilizer list with missing bound values + BOOST_CHECK_THROW( + CuboidVolumeBounds({{CuboidVolumeBounds::BoundValues::eHalfLengthX, hx}, + {CuboidVolumeBounds::BoundValues::eHalfLengthZ, hz}}), + std::logic_error); } BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) { diff --git a/Tests/UnitTests/Core/Geometry/CuboidVolumeStackTests.cpp b/Tests/UnitTests/Core/Geometry/CuboidVolumeStackTests.cpp index cd24dd7b1a9..1ff76615757 100644 --- a/Tests/UnitTests/Core/Geometry/CuboidVolumeStackTests.cpp +++ b/Tests/UnitTests/Core/Geometry/CuboidVolumeStackTests.cpp @@ -19,6 +19,8 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Geometry/CuboidVolumeBounds.hpp" #include "Acts/Geometry/CuboidVolumeStack.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" #include "Acts/Utilities/Logger.hpp" @@ -26,7 +28,9 @@ #include "Acts/Utilities/Zip.hpp" #include +#include #include +#include using namespace Acts::UnitLiterals; @@ -46,16 +50,16 @@ struct Fixture { BOOST_FIXTURE_TEST_SUITE(Geometry, Fixture) -static const std::vector strategies = { - CuboidVolumeStack::AttachmentStrategy::Gap, - CuboidVolumeStack::AttachmentStrategy::First, - CuboidVolumeStack::AttachmentStrategy::Second, - CuboidVolumeStack::AttachmentStrategy::Midpoint, +static const std::vector strategies = { + VolumeAttachmentStrategy::Gap, + VolumeAttachmentStrategy::First, + VolumeAttachmentStrategy::Second, + VolumeAttachmentStrategy::Midpoint, }; -static const std::vector resizeStrategies = { - CuboidVolumeStack::ResizeStrategy::Expand, - CuboidVolumeStack::ResizeStrategy::Gap, +static const std::vector resizeStrategies = { + VolumeResizeStrategy::Expand, + VolumeResizeStrategy::Gap, }; BOOST_AUTO_TEST_SUITE(CuboidVolumeStackTest) @@ -76,34 +80,32 @@ BOOST_DATA_TEST_CASE(BaselineLocal, angle, rotate, shift, offset, strategy, dir) { double halfDir = 400_mm; - std::size_t dirIdx = static_cast(dir); - std::size_t dirOrth1Idx = (dirIdx + 1) % 3; - std::size_t dirOrth2Idx = (dirIdx + 2) % 3; + auto [dirOrth1, dirOrth2] = CuboidVolumeStack::getOrthogonalAxes(dir); - auto dirOrth1 = static_cast(dirOrth1Idx); - auto dirOrth2 = static_cast(dirOrth2Idx); + auto dirIdx = CuboidVolumeStack::axisToIndex(dir); + auto dirOrth1Idx = CuboidVolumeStack::axisToIndex(dirOrth1); - auto boundDir = static_cast(dir); - auto boundDirOrth1 = static_cast(dirOrth1); - auto boundDirOrth2 = static_cast(dirOrth2); + auto boundDir = CuboidVolumeBounds::fromAxisDirection(dir); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(dirOrth2); - std::array bounds1Vals{}; - bounds1Vals.at(boundDir) = halfDir; - bounds1Vals.at(boundDirOrth1) = 100_mm; - bounds1Vals.at(boundDirOrth2) = 400_mm; - auto bounds1 = std::make_shared(bounds1Vals); + auto bounds1 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 400_mm}}); - std::array bounds2Vals{}; - bounds2Vals.at(boundDir) = halfDir; - bounds2Vals.at(boundDirOrth1) = 200_mm; - bounds2Vals.at(boundDirOrth2) = 600_mm; - auto bounds2 = std::make_shared(bounds2Vals); + auto bounds2 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 200_mm}, + {boundDirOrth2, 600_mm}}); - std::array bounds3Vals{}; - bounds3Vals.at(boundDir) = halfDir; - bounds3Vals.at(boundDirOrth1) = 300_mm; - bounds3Vals.at(boundDirOrth2) = 500_mm; - auto bounds3 = std::make_shared(bounds3Vals); + auto bounds3 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 300_mm}, + {boundDirOrth2, 500_mm}}); Transform3 base = AngleAxis3(angle * 1_degree, Vector3::Unit(dirOrth1Idx)) * Translation3(offset); @@ -129,20 +131,19 @@ BOOST_DATA_TEST_CASE(BaselineLocal, std::transform(volumes.begin(), volumes.end(), std::back_inserter(originalBounds), [](const auto& vol) { const auto* res = - static_cast(&vol->volumeBounds()); + dynamic_cast(&vol->volumeBounds()); throw_assert(res != nullptr, ""); return *res; }); if (shift < 1.0) { - BOOST_CHECK_THROW( - CuboidVolumeStack(volumes, dir, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger), - std::invalid_argument); + BOOST_CHECK_THROW(CuboidVolumeStack(volumes, dir, strategy, + VolumeResizeStrategy::Gap, *logger), + std::invalid_argument); return; } - CuboidVolumeStack stack(volumes, dir, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + CuboidVolumeStack stack(volumes, dir, strategy, VolumeResizeStrategy::Gap, + *logger); auto stackBounds = dynamic_cast(&stack.volumeBounds()); @@ -187,7 +188,7 @@ BOOST_DATA_TEST_CASE(BaselineLocal, BOOST_CHECK_EQUAL(newBounds->get(boundDir), bounds.get(boundDir)); } } else { - if (strategy == CuboidVolumeStack::AttachmentStrategy::Gap) { + if (strategy == VolumeAttachmentStrategy::Gap) { // Gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 5); auto gap1 = volumes.at(1); @@ -231,7 +232,7 @@ BOOST_DATA_TEST_CASE(BaselineLocal, BOOST_CHECK_EQUAL(vol1->transform().matrix(), transform1.matrix()); BOOST_CHECK_EQUAL(vol2->transform().matrix(), transform2.matrix()); BOOST_CHECK_EQUAL(vol3->transform().matrix(), transform3.matrix()); - } else if (strategy == CuboidVolumeStack::AttachmentStrategy::First) { + } else if (strategy == VolumeAttachmentStrategy::First) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -266,7 +267,7 @@ BOOST_DATA_TEST_CASE(BaselineLocal, Transform3 expectedTransform3 = base * expectedTranslation3; CHECK_CLOSE_OR_SMALL(vol3->transform().matrix(), expectedTransform3.matrix(), 1e-10, 1e-14); - } else if (strategy == CuboidVolumeStack::AttachmentStrategy::Second) { + } else if (strategy == VolumeAttachmentStrategy::Second) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -301,7 +302,7 @@ BOOST_DATA_TEST_CASE(BaselineLocal, Transform3 expectedTransform3 = base * expectedTranslation3; CHECK_CLOSE_OR_SMALL(vol3->transform().matrix(), expectedTransform3.matrix(), 1e-10, 1e-14); - } else if (strategy == CuboidVolumeStack::AttachmentStrategy::Midpoint) { + } else if (strategy == VolumeAttachmentStrategy::Midpoint) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -387,11 +388,10 @@ BOOST_DATA_TEST_CASE(BaselineGlobal, volumesAxisDirection.end()); CuboidVolumeStack stackOrientation(volumesOrientation, orientation, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, - *logger); - CuboidVolumeStack stackAxisDirection( - volumesAxisDirection, AxisDirection::AxisZ, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + VolumeResizeStrategy::Gap, *logger); + CuboidVolumeStack stackAxisDirection(volumesAxisDirection, + AxisDirection::AxisZ, strategy, + VolumeResizeStrategy::Gap, *logger); auto stackBoundsOrientation = dynamic_cast(&stackOrientation.volumeBounds()); @@ -419,34 +419,31 @@ BOOST_DATA_TEST_CASE(Asymmetric, double halfDir3 = 400_mm; double pDir3 = 850_mm; - std::size_t dirIdx = static_cast(dir); - std::size_t dirOrth1Idx = (dirIdx + 1) % 3; - std::size_t dirOrth2Idx = (dirIdx + 2) % 3; + auto [dirOrth1, dirOrth2] = CuboidVolumeStack::getOrthogonalAxes(dir); - auto dirOrth1 = static_cast(dirOrth1Idx); - auto dirOrth2 = static_cast(dirOrth2Idx); + auto dirIdx = CuboidVolumeStack::axisToIndex(dir); - auto boundDir = static_cast(dir); - auto boundDirOrth1 = static_cast(dirOrth1); - auto boundDirOrth2 = static_cast(dirOrth2); + auto boundDir = CuboidVolumeBounds::fromAxisDirection(dir); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(dirOrth2); - std::array bounds1Vals{}; - bounds1Vals[dirIdx] = halfDir1; - bounds1Vals[dirOrth1Idx] = 100_mm; - bounds1Vals[dirOrth2Idx] = 400_mm; - auto bounds1 = std::make_shared(bounds1Vals); + auto bounds1 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir1}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 400_mm}}); - std::array bounds2Vals{}; - bounds2Vals[dirIdx] = halfDir2; - bounds2Vals[dirOrth1Idx] = 200_mm; - bounds2Vals[dirOrth2Idx] = 600_mm; - auto bounds2 = std::make_shared(bounds2Vals); + auto bounds2 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir2}, + {boundDirOrth1, 200_mm}, + {boundDirOrth2, 600_mm}}); - std::array bounds3Vals{}; - bounds3Vals[dirIdx] = halfDir3; - bounds3Vals[dirOrth1Idx] = 300_mm; - bounds3Vals[dirOrth2Idx] = 500_mm; - auto bounds3 = std::make_shared(bounds3Vals); + auto bounds3 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir3}, + {boundDirOrth1, 300_mm}, + {boundDirOrth2, 500_mm}}); Translation3 translation1(Vector3::Unit(dirIdx) * pDir1); Transform3 transform1(translation1); @@ -462,9 +459,8 @@ BOOST_DATA_TEST_CASE(Asymmetric, std::vector volumes = {vol2.get(), vol1.get(), vol3.get()}; - CuboidVolumeStack stack(volumes, dir, - CuboidVolumeStack::AttachmentStrategy::Gap, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + CuboidVolumeStack stack(volumes, dir, VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 5); auto stackBounds = @@ -498,34 +494,32 @@ BOOST_DATA_TEST_CASE(UpdateStack, angle, offset, zshift, strategy, dir) { double halfDir = 400_mm; - std::size_t dirIdx = static_cast(dir); - std::size_t dirOrth1Idx = (dirIdx + 1) % 3; - std::size_t dirOrth2Idx = (dirIdx + 2) % 3; + auto [dirOrth1, dirOrth2] = CuboidVolumeStack::getOrthogonalAxes(dir); - auto dirOrth1 = static_cast(dirOrth1Idx); - auto dirOrth2 = static_cast(dirOrth2Idx); + auto dirIdx = CuboidVolumeStack::axisToIndex(dir); + auto dirOrth1Idx = CuboidVolumeStack::axisToIndex(dirOrth1); - auto boundDir = static_cast(dir); - auto boundDirOrth1 = static_cast(dirOrth1); - auto boundDirOrth2 = static_cast(dirOrth2); + auto boundDir = CuboidVolumeBounds::fromAxisDirection(dir); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(dirOrth2); - std::array bounds1Vals{}; - bounds1Vals[dirIdx] = halfDir; - bounds1Vals[dirOrth1Idx] = 100_mm; - bounds1Vals[dirOrth2Idx] = 600_mm; - auto bounds1 = std::make_shared(bounds1Vals); + auto bounds1 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 600_mm}}); - std::array bounds2Vals{}; - bounds2Vals[dirIdx] = halfDir; - bounds2Vals[dirOrth1Idx] = 100_mm; - bounds2Vals[dirOrth2Idx] = 600_mm; - auto bounds2 = std::make_shared(bounds2Vals); + auto bounds2 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 600_mm}}); - std::array bounds3Vals{}; - bounds3Vals[dirIdx] = halfDir; - bounds3Vals[dirOrth1Idx] = 100_mm; - bounds3Vals[dirOrth2Idx] = 600_mm; - auto bounds3 = std::make_shared(bounds3Vals); + auto bounds3 = std::make_shared( + std::initializer_list>{ + {boundDir, halfDir}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 600_mm}}); Vector3 shift = Vector3::Unit(dirIdx) * zshift; Transform3 base = AngleAxis3(angle * 1_degree, Vector3::Unit(dirOrth1Idx)) * @@ -548,11 +542,10 @@ BOOST_DATA_TEST_CASE(UpdateStack, std::vector originalTransforms = {transform1, transform2, transform3}; - CuboidVolumeStack stack( - volumes, dir, - CuboidVolumeStack::AttachmentStrategy::Gap, // should not make a - // difference - strategy, *logger); + CuboidVolumeStack stack(volumes, dir, + VolumeAttachmentStrategy::Gap, // should not make a + // difference + strategy, *logger); const auto* originalBounds = dynamic_cast(&stack.volumeBounds()); @@ -679,7 +672,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(updatedBounds->get(boundDirOrth1), 700_mm); BOOST_CHECK_EQUAL(updatedBounds->get(boundDirOrth2), 700_mm); - if (strategy == CuboidVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -708,7 +701,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, Transform3 expectedTransform3 = base * expectedTranslation3; BOOST_CHECK_EQUAL(vol3->transform().matrix(), expectedTransform3.matrix()); - } else if (strategy == CuboidVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // Gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 5); @@ -751,34 +744,33 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_DATA_TEST_CASE( UpdateStackOneSided, ((boost::unit_test::data::make(-1.0, 1.0) ^ - boost::unit_test::data::make(CuboidVolumeStack::ResizeStrategy::Gap, - CuboidVolumeStack::ResizeStrategy::Expand)) * + boost::unit_test::data::make(VolumeResizeStrategy::Gap, + VolumeResizeStrategy::Expand)) * boost::unit_test::data::make(Acts::AxisDirection::AxisX, Acts::AxisDirection::AxisY, Acts::AxisDirection::AxisZ)), f, strategy, dir) { - std::size_t dirIdx = static_cast(dir); - std::size_t dirOrth1Idx = (dirIdx + 1) % 3; - std::size_t dirOrth2Idx = (dirIdx + 2) % 3; + auto [dirOrth1, dirOrth2] = CuboidVolumeStack::getOrthogonalAxes(dir); - auto dirOrth1 = static_cast(dirOrth1Idx); - auto dirOrth2 = static_cast(dirOrth2Idx); + auto dirIdx = CuboidVolumeStack::axisToIndex(dir); + auto dirOrth1Idx = CuboidVolumeStack::axisToIndex(dirOrth1); + auto dirOrth2Idx = CuboidVolumeStack::axisToIndex(dirOrth2); - auto boundDir = static_cast(dir); - auto boundDirOrth1 = static_cast(dirOrth1); - auto boundDirOrth2 = static_cast(dirOrth2); + auto boundDir = CuboidVolumeBounds::fromAxisDirection(dir); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(dirOrth2); - std::array bounds1Vals{}; - bounds1Vals[dirIdx] = 400_mm; - bounds1Vals[dirOrth1Idx] = 100_mm; - bounds1Vals[dirOrth2Idx] = 300_mm; - auto bounds1 = std::make_shared(bounds1Vals); + auto bounds1 = std::make_shared( + std::initializer_list>{ + {boundDir, 400_mm}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 300_mm}}); - std::array bounds2Vals{}; - bounds2Vals[dirIdx] = 400_mm; - bounds2Vals[dirOrth1Idx] = 100_mm; - bounds2Vals[dirOrth2Idx] = 300_mm; - auto bounds2 = std::make_shared(bounds2Vals); + auto bounds2 = std::make_shared( + std::initializer_list>{ + {boundDir, 400_mm}, + {boundDirOrth1, 100_mm}, + {boundDirOrth2, 300_mm}}); auto trf = Transform3::Identity(); @@ -792,8 +784,7 @@ BOOST_DATA_TEST_CASE( std::vector volumes = {vol1.get(), vol2.get()}; - CuboidVolumeStack stack{volumes, dir, - CuboidVolumeStack::AttachmentStrategy::Gap, strategy, + CuboidVolumeStack stack{volumes, dir, VolumeAttachmentStrategy::Gap, strategy, *logger}; const auto* originalBounds = dynamic_cast(&stack.volumeBounds()); @@ -857,7 +848,7 @@ BOOST_DATA_TEST_CASE( BOOST_CHECK_EQUAL(volBounds->get(boundDirOrth2), 300_mm); } - if (strategy == CuboidVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gaps were added, there was one gap initially BOOST_CHECK_EQUAL(volumes.size(), 3); const Volume* vol = nullptr; @@ -874,7 +865,7 @@ BOOST_DATA_TEST_CASE( BOOST_REQUIRE(volBounds != nullptr); BOOST_CHECK_EQUAL(volBounds->get(boundDir), 450_mm); BOOST_CHECK_EQUAL(vol->center()[dirIdx], f * 550_mm); - } else if (strategy == CuboidVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // One gap volume was added BOOST_CHECK_EQUAL(volumes.size(), 4); @@ -926,42 +917,32 @@ BOOST_DATA_TEST_CASE(ResizeGapMultiple, Acts::AxisDirection::AxisY, Acts::AxisDirection::AxisZ), dir) { - std::size_t dirIdx = static_cast(dir); - std::size_t dirOrth1Idx = (dirIdx + 1) % 3; - std::size_t dirOrth2Idx = (dirIdx + 2) % 3; - - auto dirOrth1 = static_cast(dirOrth1Idx); - auto dirOrth2 = static_cast(dirOrth2Idx); + auto [dirOrth1, dirOrth2] = CuboidVolumeStack::getOrthogonalAxes(dir); - auto boundDir = static_cast(dir); - auto boundDirOrth1 = static_cast(dirOrth1); - auto boundDirOrth2 = static_cast(dirOrth2); + auto dirIdx = CuboidVolumeStack::axisToIndex(dir); - std::array boundsVals{}; - boundsVals[dirIdx] = 100; - boundsVals[dirOrth1Idx] = 70; - boundsVals[dirOrth2Idx] = 100; - auto bounds = std::make_shared(boundsVals); + auto boundDir = CuboidVolumeBounds::fromAxisDirection(dir); + auto boundDirOrth1 = CuboidVolumeBounds::fromAxisDirection(dirOrth1); + auto boundDirOrth2 = CuboidVolumeBounds::fromAxisDirection(dirOrth2); + auto bounds = std::make_shared( + std::initializer_list>{ + {boundDir, 100}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); Transform3 trf = Transform3::Identity(); Volume vol{trf, bounds}; BOOST_TEST_CONTEXT("Positive") { std::vector volumes = {&vol}; - CuboidVolumeStack stack(volumes, dir, - CuboidVolumeStack::AttachmentStrategy::Gap, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + CuboidVolumeStack stack(volumes, dir, VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); - std::array newBounds1Vals{}; - newBounds1Vals[dirIdx] = 200; - newBounds1Vals[dirOrth1Idx] = 70; - newBounds1Vals[dirOrth2Idx] = 100; - auto newBounds1 = std::make_shared(newBounds1Vals); - newBounds1->set( - {{boundDir, 200}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); + auto newBounds1 = std::make_shared( + std::initializer_list< + std::pair>{ + {boundDir, 200}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); stack.update(newBounds1, trf * Translation3{Vector3::Unit(dirIdx) * 100}, *logger); BOOST_CHECK_EQUAL(volumes.size(), 2); @@ -973,13 +954,10 @@ BOOST_DATA_TEST_CASE(ResizeGapMultiple, BOOST_REQUIRE_NE(updatedBounds, nullptr); BOOST_CHECK_EQUAL(updatedBounds->get(boundDir), 100.0); - std::array newBounds2Vals{}; - newBounds2Vals[dirIdx] = 300; - newBounds2Vals[dirOrth1Idx] = 70; - newBounds2Vals[dirOrth2Idx] = 100; - auto newBounds2 = std::make_shared(newBounds2Vals); - newBounds2->set( - {{boundDir, 300}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); + auto newBounds2 = std::make_shared( + std::initializer_list< + std::pair>{ + {boundDir, 300}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); stack.update(newBounds2, trf * Translation3{Vector3::Unit(dirIdx) * 200}, *logger); @@ -996,20 +974,16 @@ BOOST_DATA_TEST_CASE(ResizeGapMultiple, BOOST_TEST_CONTEXT("Negative") { std::vector volumes = {&vol}; - CuboidVolumeStack stack(volumes, dir, - CuboidVolumeStack::AttachmentStrategy::Gap, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + CuboidVolumeStack stack(volumes, dir, VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); - std::array newBounds1Vals{}; - newBounds1Vals[dirIdx] = 200; - newBounds1Vals[dirOrth1Idx] = 70; - newBounds1Vals[dirOrth2Idx] = 100; - auto newBounds1 = std::make_shared(newBounds1Vals); - newBounds1->set( - {{boundDir, 200}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); + auto newBounds1 = std::make_shared( + std::initializer_list< + std::pair>{ + {boundDir, 200}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); stack.update(newBounds1, trf * Translation3{Vector3::Unit(dirIdx) * -100}, *logger); BOOST_CHECK_EQUAL(volumes.size(), 2); @@ -1021,13 +995,10 @@ BOOST_DATA_TEST_CASE(ResizeGapMultiple, BOOST_REQUIRE_NE(updatedBounds, nullptr); BOOST_CHECK_EQUAL(updatedBounds->get(boundDir), 100.0); - std::array newBounds2Vals{}; - newBounds2Vals[dirIdx] = 300; - newBounds2Vals[dirOrth1Idx] = 70; - newBounds2Vals[dirOrth2Idx] = 100; - auto newBounds2 = std::make_shared(newBounds2Vals); - newBounds2->set( - {{boundDir, 300}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); + auto newBounds2 = std::make_shared( + std::initializer_list< + std::pair>{ + {boundDir, 300}, {boundDirOrth1, 70}, {boundDirOrth2, 100}}); stack.update(newBounds2, trf * Translation3{Vector3::Unit(dirIdx) * -200}, *logger); @@ -1093,10 +1064,9 @@ BOOST_DATA_TEST_CASE(InvalidInput, std::make_shared(100_mm, 400_mm, 400_mm)); volumes.push_back(vol2.get()); - BOOST_CHECK_THROW( - CuboidVolumeStack(volumes, direction, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger), - std::invalid_argument); + BOOST_CHECK_THROW(CuboidVolumeStack(volumes, direction, strategy, + VolumeResizeStrategy::Gap, *logger), + std::invalid_argument); } } @@ -1115,10 +1085,9 @@ BOOST_DATA_TEST_CASE(InvalidInput, std::make_shared(100_mm, 400_mm, 400_mm)); volumes.push_back(vol2.get()); - BOOST_CHECK_THROW( - CuboidVolumeStack(volumes, direction, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger), - std::invalid_argument); + BOOST_CHECK_THROW(CuboidVolumeStack(volumes, direction, strategy, + VolumeResizeStrategy::Gap, *logger), + std::invalid_argument); } } } @@ -1137,7 +1106,7 @@ BOOST_DATA_TEST_CASE(JoinCuboidVolumeSingle, std::vector volumes{vol.get()}; CuboidVolumeStack stack(volumes, direction, strategy, - CuboidVolumeStack::ResizeStrategy::Gap, *logger); + VolumeResizeStrategy::Gap, *logger); // Cuboid stack has the same transform as bounds as the single input // volume diff --git a/Tests/UnitTests/Core/Geometry/CylinderVolumeStackTests.cpp b/Tests/UnitTests/Core/Geometry/CylinderVolumeStackTests.cpp index 59987bfb42e..2935410ba6e 100644 --- a/Tests/UnitTests/Core/Geometry/CylinderVolumeStackTests.cpp +++ b/Tests/UnitTests/Core/Geometry/CylinderVolumeStackTests.cpp @@ -19,6 +19,8 @@ #include "Acts/Definitions/Units.hpp" #include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Geometry/CylinderVolumeStack.hpp" +#include "Acts/Geometry/detail/VolumeAttachmentStrategy.hpp" +#include "Acts/Geometry/detail/VolumeResizeStrategy.hpp" #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Logger.hpp" @@ -44,17 +46,16 @@ struct Fixture { BOOST_FIXTURE_TEST_SUITE(Geometry, Fixture) -static const std::vector strategies = { - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::AttachmentStrategy::First, - CylinderVolumeStack::AttachmentStrategy::Second, - CylinderVolumeStack::AttachmentStrategy::Midpoint, +static const std::vector strategies = { + VolumeAttachmentStrategy::Gap, + VolumeAttachmentStrategy::First, + VolumeAttachmentStrategy::Second, + VolumeAttachmentStrategy::Midpoint, }; -static const std::vector resizeStrategies = - { - CylinderVolumeStack::ResizeStrategy::Expand, - CylinderVolumeStack::ResizeStrategy::Gap, +static const std::vector resizeStrategies = { + VolumeResizeStrategy::Expand, + VolumeResizeStrategy::Gap, }; BOOST_AUTO_TEST_SUITE(CylinderVolumeStackTest) @@ -109,13 +110,12 @@ BOOST_DATA_TEST_CASE(Baseline, if (shift < 1.0) { BOOST_CHECK_THROW( CylinderVolumeStack(volumes, AxisDirection::AxisZ, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, *logger), + VolumeResizeStrategy::Gap, *logger), std::invalid_argument); return; } CylinderVolumeStack cylStack(volumes, AxisDirection::AxisZ, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeResizeStrategy::Gap, *logger); auto stackBounds = dynamic_cast(&cylStack.volumeBounds()); @@ -162,7 +162,7 @@ BOOST_DATA_TEST_CASE(Baseline, bounds.get(CylinderVolumeBounds::eHalfLengthZ)); } } else { - if (strategy == CylinderVolumeStack::AttachmentStrategy::Gap) { + if (strategy == VolumeAttachmentStrategy::Gap) { // Gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 5); auto gap1 = volumes.at(1); @@ -207,7 +207,7 @@ BOOST_DATA_TEST_CASE(Baseline, BOOST_CHECK_EQUAL(vol2->transform().matrix(), transform2.matrix()); BOOST_CHECK_EQUAL(vol3->transform().matrix(), transform3.matrix()); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::First) { + } else if (strategy == VolumeAttachmentStrategy::First) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -242,7 +242,7 @@ BOOST_DATA_TEST_CASE(Baseline, Transform3 expectedTransform3 = base * Translation3{0_mm, 0_mm, pZ3}; CHECK_CLOSE_OR_SMALL(vol3->transform().matrix(), expectedTransform3.matrix(), 1e-10, 1e-14); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Second) { + } else if (strategy == VolumeAttachmentStrategy::Second) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -277,7 +277,7 @@ BOOST_DATA_TEST_CASE(Baseline, Transform3 expectedTransform3 = base * Translation3{0_mm, 0_mm, pZ3}; CHECK_CLOSE_OR_SMALL(vol3->transform().matrix(), expectedTransform3.matrix(), 1e-10, 1e-14); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Midpoint) { + } else if (strategy == VolumeAttachmentStrategy::Midpoint) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -342,9 +342,8 @@ BOOST_AUTO_TEST_CASE(Asymmetric) { std::vector volumes = {vol2.get(), vol1.get(), vol3.get()}; CylinderVolumeStack cylStack(volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 5); auto stackBounds = @@ -385,8 +384,7 @@ BOOST_DATA_TEST_CASE(RotationInZ, boost::unit_test::data::make(strategies), std::vector volumes = {vol1.get(), vol2.get()}; CylinderVolumeStack cylStack(volumes, AxisDirection::AxisZ, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeResizeStrategy::Gap, *logger); auto stackBounds = dynamic_cast(&cylStack.volumeBounds()); @@ -406,13 +404,13 @@ BOOST_DATA_TEST_CASE(RotationInZ, boost::unit_test::data::make(strategies), BOOST_CHECK_EQUAL(bounds->get(CylinderVolumeBounds::eMaxR), 400_mm); } - if (strategy == CylinderVolumeStack::AttachmentStrategy::Gap) { + if (strategy == VolumeAttachmentStrategy::Gap) { // Volumes stayed at the same position, not resized BOOST_CHECK_EQUAL(vol1->center()[eZ], -hlZ - gap / 2.0 + shift); BOOST_CHECK_EQUAL(vol2->center()[eZ], hlZ + gap / 2.0 + shift); BOOST_CHECK_EQUAL(newBounds1->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); BOOST_CHECK_EQUAL(newBounds2->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::First) { + } else if (strategy == VolumeAttachmentStrategy::First) { // Left volume moved, got resized BOOST_CHECK_EQUAL(vol1->center()[eZ], -hlZ + shift); BOOST_CHECK_EQUAL(newBounds1->get(CylinderVolumeBounds::eHalfLengthZ), @@ -420,7 +418,7 @@ BOOST_DATA_TEST_CASE(RotationInZ, boost::unit_test::data::make(strategies), // Right volume stayed the same BOOST_CHECK_EQUAL(vol2->center()[eZ], hlZ + gap / 2.0 + shift); BOOST_CHECK_EQUAL(newBounds2->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Second) { + } else if (strategy == VolumeAttachmentStrategy::Second) { // Left volume stayed the same BOOST_CHECK_EQUAL(vol1->center()[eZ], -hlZ - gap / 2.0 + shift); BOOST_CHECK_EQUAL(newBounds1->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); @@ -428,7 +426,7 @@ BOOST_DATA_TEST_CASE(RotationInZ, boost::unit_test::data::make(strategies), BOOST_CHECK_EQUAL(vol2->center()[eZ], hlZ + shift); BOOST_CHECK_EQUAL(newBounds2->get(CylinderVolumeBounds::eHalfLengthZ), hlZ + gap / 2.0); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Midpoint) { + } else if (strategy == VolumeAttachmentStrategy::Midpoint) { // Left volume moved, got resized BOOST_CHECK_EQUAL(vol1->center()[eZ], -hlZ - gap / 4.0 + shift); BOOST_CHECK_EQUAL(newBounds1->get(CylinderVolumeBounds::eHalfLengthZ), @@ -481,8 +479,8 @@ BOOST_DATA_TEST_CASE(UpdateStack, CylinderVolumeStack cylStack( volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, // should not make a - // difference + VolumeAttachmentStrategy::Gap, // should not make a + // difference strategy, *logger); const auto* originalBounds = @@ -621,7 +619,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eMinR), 50_mm); BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eMaxR), 700_mm); - if (strategy == CylinderVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -651,7 +649,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, base * Translation3{0_mm, 0_mm, 2 * hlZ + hlZ / 2.0}; BOOST_CHECK_EQUAL(vol3->transform().matrix(), expectedTransform3.matrix()); - } else if (strategy == CylinderVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // Gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 5); @@ -696,8 +694,8 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_DATA_TEST_CASE( UpdateStackOneSided, (boost::unit_test::data::make(-1.0, 1.0) ^ - boost::unit_test::data::make(CylinderVolumeStack::ResizeStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Expand)), + boost::unit_test::data::make(VolumeResizeStrategy::Gap, + VolumeResizeStrategy::Expand)), f, strategy) { auto trf = Transform3::Identity(); @@ -712,8 +710,8 @@ BOOST_DATA_TEST_CASE( std::vector volumes = {vol1.get(), vol2.get()}; CylinderVolumeStack cylStack{volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - strategy, *logger}; + VolumeAttachmentStrategy::Gap, strategy, + *logger}; const auto* originalBounds = dynamic_cast(&cylStack.volumeBounds()); @@ -778,7 +776,7 @@ BOOST_DATA_TEST_CASE( BOOST_CHECK_EQUAL(volBounds->get(CylinderVolumeBounds::eMaxR), 300_mm); } - if (strategy == CylinderVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gaps were added, there was one gap initially BOOST_CHECK_EQUAL(volumes.size(), 3); const Volume* vol = nullptr; @@ -796,7 +794,7 @@ BOOST_DATA_TEST_CASE( BOOST_CHECK_EQUAL(volBounds->get(CylinderVolumeBounds::eHalfLengthZ), 450_mm); BOOST_CHECK_EQUAL(vol->center()[eZ], f * 550_mm); - } else if (strategy == CylinderVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // One gap volume was added BOOST_CHECK_EQUAL(volumes.size(), 4); @@ -824,8 +822,8 @@ BOOST_AUTO_TEST_CASE(ResizeReproduction1) { std::vector volumes = {&vol1}; CylinderVolumeStack stack(volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); Transform3 trf2 = Transform3::Identity() * Translation3{Vector3::UnitZ() * -1500}; @@ -850,8 +848,8 @@ BOOST_AUTO_TEST_CASE(ResizeReproduction2) { std::vector volumes = {&vol1}; CylinderVolumeStack stack(volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); Transform3 trf2 = Transform3::Identity() * Translation3{Vector3::UnitZ() * 260.843}; @@ -903,9 +901,8 @@ BOOST_AUTO_TEST_CASE(ResizeGapMultiple) { BOOST_TEST_CONTEXT("Positive") { std::vector volumes = {&vol}; CylinderVolumeStack stack(volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); @@ -940,9 +937,8 @@ BOOST_AUTO_TEST_CASE(ResizeGapMultiple) { BOOST_TEST_CONTEXT("Negative") { std::vector volumes = {&vol}; CylinderVolumeStack stack(volumes, AxisDirection::AxisZ, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); @@ -1036,14 +1032,13 @@ BOOST_DATA_TEST_CASE(Baseline, if (f < 0.0) { BOOST_CHECK_THROW( CylinderVolumeStack(volumes, AxisDirection::AxisR, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, *logger), + VolumeResizeStrategy::Gap, *logger), std::invalid_argument); return; } CylinderVolumeStack cylStack(volumes, AxisDirection::AxisR, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeResizeStrategy::Gap, *logger); auto stackBounds = dynamic_cast(&cylStack.volumeBounds()); @@ -1125,7 +1120,7 @@ BOOST_DATA_TEST_CASE(Baseline, dynamic_cast(&vol2->volumeBounds()); const auto* newBounds3 = dynamic_cast(&vol3->volumeBounds()); - if (strategy == CylinderVolumeStack::AttachmentStrategy::Gap) { + if (strategy == VolumeAttachmentStrategy::Gap) { // Two gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 5); @@ -1160,7 +1155,7 @@ BOOST_DATA_TEST_CASE(Baseline, BOOST_CHECK_EQUAL(gapBounds2->get(CylinderVolumeBounds::eMaxR), fInner * 600_mm); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::First) { + } else if (strategy == VolumeAttachmentStrategy::First) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1182,7 +1177,7 @@ BOOST_DATA_TEST_CASE(Baseline, BOOST_CHECK_EQUAL(newBounds3->get(CylinderVolumeBounds::eMaxR), fOuter * 900_mm); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Second) { + } else if (strategy == VolumeAttachmentStrategy::Second) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1203,7 +1198,7 @@ BOOST_DATA_TEST_CASE(Baseline, fOuter * 600_mm); BOOST_CHECK_EQUAL(newBounds3->get(CylinderVolumeBounds::eMaxR), fOuter * 900_mm); - } else if (strategy == CylinderVolumeStack::AttachmentStrategy::Midpoint) { + } else if (strategy == VolumeAttachmentStrategy::Midpoint) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1278,8 +1273,8 @@ BOOST_DATA_TEST_CASE(UpdateStack, cylStack = std::make_unique( volumes, AxisDirection::AxisR, - CylinderVolumeStack::AttachmentStrategy::Gap, // should not make a - // difference + VolumeAttachmentStrategy::Gap, // should not make a + // difference strategy, *logger); originalOuterBounds = @@ -1367,7 +1362,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eMaxR), 900_mm); BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); - if (strategy == CylinderVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1389,7 +1384,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(*newBounds3, originalBounds[2]); BOOST_CHECK_EQUAL(vol3->transform().matrix(), base.matrix()); - } else if (strategy == CylinderVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // One gap volume was added BOOST_CHECK_EQUAL(volumes.size(), 4); @@ -1424,7 +1419,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eMinR), 100_mm); BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); - if (strategy == CylinderVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1446,7 +1441,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(*newBounds2, originalBounds[1]); BOOST_CHECK_EQUAL(vol2->transform().matrix(), base.matrix()); - } else if (strategy == CylinderVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // One gap volume was added BOOST_CHECK_EQUAL(volumes.size(), 4); @@ -1485,7 +1480,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eMinR), 0_mm); BOOST_CHECK_EQUAL(cylBounds->get(CylinderVolumeBounds::eHalfLengthZ), hlZ); - if (strategy == CylinderVolumeStack::ResizeStrategy::Expand) { + if (strategy == VolumeResizeStrategy::Expand) { // No gap volumes were added BOOST_CHECK_EQUAL(volumes.size(), 3); @@ -1509,7 +1504,7 @@ BOOST_DATA_TEST_CASE(UpdateStack, // Position stayed the same BOOST_CHECK_EQUAL(vol3->transform().matrix(), base.matrix()); - } else if (strategy == CylinderVolumeStack::ResizeStrategy::Gap) { + } else if (strategy == VolumeResizeStrategy::Gap) { // One gap volume was added BOOST_CHECK_EQUAL(volumes.size(), 5); @@ -1581,8 +1576,8 @@ BOOST_DATA_TEST_CASE(UpdateStack, BOOST_DATA_TEST_CASE( UpdateStackOneSided, (boost::unit_test::data::make(-1.0, 1.0) ^ - boost::unit_test::data::make(CylinderVolumeStack::ResizeStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Expand)), + boost::unit_test::data::make(VolumeResizeStrategy::Gap, + VolumeResizeStrategy::Expand)), f, strategy) { // Strategy should not affect the sizing here at all @@ -1597,8 +1592,8 @@ BOOST_DATA_TEST_CASE( std::vector volumes = {vol1.get(), vol2.get()}; CylinderVolumeStack cylStack{volumes, AxisDirection::AxisR, - CylinderVolumeStack::AttachmentStrategy::Gap, - strategy, *logger}; + VolumeAttachmentStrategy::Gap, strategy, + *logger}; const auto* originalBounds = dynamic_cast(&cylStack.volumeBounds()); @@ -1673,9 +1668,8 @@ BOOST_AUTO_TEST_CASE(ResizeGapMultiple) { BOOST_TEST_CONTEXT("Outer") { std::vector volumes = {&vol}; CylinderVolumeStack stack(volumes, AxisDirection::AxisR, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); @@ -1708,9 +1702,8 @@ BOOST_AUTO_TEST_CASE(ResizeGapMultiple) { BOOST_TEST_CONTEXT("Inner") { std::vector volumes = {&vol}; CylinderVolumeStack stack(volumes, AxisDirection::AxisR, - CylinderVolumeStack::AttachmentStrategy::Gap, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeAttachmentStrategy::Gap, + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_EQUAL(volumes.size(), 1); BOOST_CHECK(stack.gaps().empty()); @@ -1795,9 +1788,8 @@ BOOST_DATA_TEST_CASE(JoinCylinderVolumesInvalidInput, std::make_shared(100_mm, 400_mm, 400_mm)); volumes.push_back(vol2.get()); - BOOST_CHECK_THROW(CylinderVolumeStack( - volumes, direction, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, *logger), + BOOST_CHECK_THROW(CylinderVolumeStack(volumes, direction, strategy, + VolumeResizeStrategy::Gap, *logger), std::invalid_argument); } } @@ -1816,9 +1808,8 @@ BOOST_DATA_TEST_CASE(JoinCylinderVolumesInvalidInput, std::make_shared(100_mm, 400_mm, 400_mm)); volumes.push_back(vol2.get()); - BOOST_CHECK_THROW(CylinderVolumeStack( - volumes, direction, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, *logger), + BOOST_CHECK_THROW(CylinderVolumeStack(volumes, direction, strategy, + VolumeResizeStrategy::Gap, *logger), std::invalid_argument); } } @@ -1852,8 +1843,7 @@ BOOST_DATA_TEST_CASE(JoinCylinderVolumesInvalidInput, { // have valid stack, try to assign extra CylinderVolumeStack cylStack(volumes, direction, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeResizeStrategy::Gap, *logger); BOOST_CHECK_THROW(cylStack.update(invalid, std::nullopt, *logger), std::invalid_argument); } @@ -1874,8 +1864,7 @@ BOOST_DATA_TEST_CASE(JoinCylinderVolumesInvalidInput, volumes.push_back(vol.get()); BOOST_CHECK_THROW( CylinderVolumeStack(volumes, direction, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger), + VolumeResizeStrategy::Gap, *logger), std::invalid_argument); } } @@ -1896,8 +1885,7 @@ BOOST_DATA_TEST_CASE(JoinCylinderVolumeSingle, std::vector volumes{vol.get()}; CylinderVolumeStack cylStack(volumes, direction, strategy, - CylinderVolumeStack::ResizeStrategy::Gap, - *logger); + VolumeResizeStrategy::Gap, *logger); // Cylinder stack has the same transform as bounds as the single input // volume