Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding cuboid portal shell #4047

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
172 changes: 172 additions & 0 deletions Core/include/Acts/Geometry/CuboidPortalShell.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// 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 "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/CuboidVolumeBounds.hpp"
#include "Acts/Geometry/PortalShell.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Utilities/AxisDefinitions.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <array>
#include <memory>
#include <vector>

namespace Acts {

/// @class CuboidPortalShell
/// Base class for cuboid shaped portal shells, e.g. shells for cuboid
/// volumes
class CuboidPortalShell : public PortalShellBase {
public:
using Face = CuboidVolumeBounds::Face;

using enum CuboidVolumeBounds::Face;

/// Retrieve the portal associated to the given face. Can be nullptr if unset.
/// @param face The face to retrieve the portal for
/// @return The portal associated to the face
virtual Portal* portal(Face face) = 0;

/// Retrieve a shared_ptr for the portal associated to the given face. Can be
/// nullptr if unset.
/// @param face The face to retrieve the portal for
/// @return The portal associated to the face
virtual std::shared_ptr<Portal> portalPtr(Face face) = 0;

/// Set the portal associated to the given face.
/// @param portal The portal to set
/// @param face The face to set the portal
virtual void setPortal(std::shared_ptr<Portal> portal, Face face) = 0;

/// @copydoc PortalShellBase::fill
void fill(TrackingVolume& volume) override;

virtual const Transform3& transform() const = 0;
};

/// Output stream operator for the CuboidPortalShell::Face enum
/// @param os The output stream
/// @param face The face to output
/// @return The output stream
std::ostream& operator<<(std::ostream& os, CuboidPortalShell::Face face);

/// @class SingleCuboidPortalShell
/// This class describes a cuboid shell containing a single volume.
class SingleCuboidPortalShell : public CuboidPortalShell {
public:
/// Construct a single cuboid portal shell for the given volume
/// @param volume The volume to create the shell for
explicit SingleCuboidPortalShell(TrackingVolume& volume);

/// @copydoc PortalShellBase::size
std::size_t size() const final;

/// @copydoc CuboidPortalShell::portal
Portal* portal(Face face) final;

/// @copydoc CuboidPortalShell::portalPtr
std::shared_ptr<Portal> portalPtr(Face face) final;

/// @copydoc CuboidPortalShell::setPortal
void setPortal(std::shared_ptr<Portal> portal, Face face) final;

/// @copydoc PortalShellBase::applyToVolume
void applyToVolume() override;

/// @copydoc PortalShellBase::isValid
bool isValid() const override;

/// @copydoc PortalShellBase::label
std::string label() const override;

const Transform3& transform() const override {
return m_volume->transform();
};

private:
std::array<std::shared_ptr<Portal>, 6> m_portals{};

TrackingVolume* m_volume;
};

/// @class CuboidStackPortalShell
/// This class describes a cuboid shell containing multiple volumes.
class CuboidStackPortalShell : public CuboidPortalShell {
public:
/// Construct the portal shell stack from the given shells
/// @param gctx The geometry context
/// @param shells The shells to stack
/// @note The shells must be ordered in the given direction
/// @param direction The stacking direction in local stack coordinates
/// @param logger A logging instance for debugging
CuboidStackPortalShell(const GeometryContext& gctx,
std::vector<CuboidPortalShell*> shells,
AxisDirection axis,
const Logger& logger = getDummyLogger());

/// Construct the portal shell stack from the given shells
/// @param gctx The geometry context
/// @param shells The shells to stack
/// @note The shells must be ordered in the given direction
/// @param direction The stacking direction in global coordinates
/// @param logger A logging instance for debugging
CuboidStackPortalShell(const GeometryContext& gctx,
std::vector<CuboidPortalShell*> shells,
const Vector3& direction,
const Logger& logger = getDummyLogger());

/// @copydoc PortalShellBase::size
std::size_t size() const final;

/// @copydoc CuboidPortalShell::portal
Portal* portal(Face face) final;

/// @copydoc CuboidPortalShell::portalPtr
std::shared_ptr<Portal> portalPtr(Face face) final;

/// @copydoc CuboidPortalShell::setPortal
void setPortal(std::shared_ptr<Portal> portal, Face face) final;

void applyToVolume() override {
// No-op, because it's a composite portal shell
}

/// @copydoc PortalShellBase::isValid
bool isValid() const override;

/// @copydoc PortalShellBase::label
std::string label() const override;

/// Return the stack's group transform
const Transform3& transform() const override;

/// Convert a global vector to an axis direction in local stack coordinates
/// @param dir is the global direction to convert
static AxisDirection directionToAxis(const Vector3& dir);

private:
void stackShell(const GeometryContext& gctx, const Logger& logger);

/// Shell stacking direction in global coordinates
Vector3 m_direction;
ssdetlab marked this conversation as resolved.
Show resolved Hide resolved

/// Shell stacking direction in local stack coordinates
AxisDirection m_axis;

///
CuboidVolumeBounds::Face m_frontFace;
CuboidVolumeBounds::Face m_backFace;
std::array<CuboidVolumeBounds::Face, 4> m_sideFaces;

std::vector<CuboidPortalShell*> m_shells;
};

} // namespace Acts
25 changes: 24 additions & 1 deletion Core/include/Acts/Geometry/CuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/BoundarySurfaceFace.hpp"
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Geometry/VolumeBounds.hpp"
#include "Acts/Utilities/AxisDefinitions.hpp"
Expand Down Expand Up @@ -58,6 +59,18 @@ class CuboidVolumeBounds : public VolumeBounds {
eSize
};

/// Enum describing the possible faces of a cuboid volume
/// @note These values are synchronized with the BoundarySurfaceFace enum.
/// Once Gen1 is removed, this can be changed.
enum class Face : unsigned int {
negativeXYPlane = BoundarySurfaceFace::negativeFaceXY,
positiveXYPlane = BoundarySurfaceFace::positiveFaceXY,
negativeYZPlane = BoundarySurfaceFace::negativeFaceYZ,
positiveYZPlane = BoundarySurfaceFace::positiveFaceYZ,
negativeZXPlane = BoundarySurfaceFace::negativeFaceZX,
positiveZXPlane = BoundarySurfaceFace::positiveFaceZX
ssdetlab marked this conversation as resolved.
Show resolved Hide resolved
};

CuboidVolumeBounds() = delete;

/// Constructor - the box boundaries
Expand Down Expand Up @@ -156,7 +169,17 @@ class CuboidVolumeBounds : public VolumeBounds {
/// Convert axis direction to a corresponding bound value
/// in local coordinate convention
/// @param direction the axis direction to convert
static BoundValues fromAxisDirection(AxisDirection direction);
static BoundValues boundsFromAxisDirection(AxisDirection direction);

/// Convert axis direction to a set of corresponding cuboid faces
/// in local coordinate convention
/// @param direction the axis direction to convert
/// @return A tuple of cuboid faces with the following ordering convention:
/// (1) negative face orthogonal to the axis direction
/// (2) positive face orthogonal to the axis direction
/// (3) list of side faces parallel to the axis direction
static std::tuple<Face, Face, std::array<Face, 4>> facesFromAxisDirection(
AxisDirection direction);

/// Output Method for std::ostream
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#pragma once

#include "Acts/Geometry/BlueprintNode.hpp"
#include "Acts/Geometry/CylinderPortalShell.hpp"
#include "Acts/Geometry/CylinderVolumeStack.hpp"
#include "Acts/Geometry/PortalShell.hpp"
#include "Acts/Geometry/VolumeAttachmentStrategy.hpp"
#include "Acts/Geometry/VolumeResizeStrategy.hpp"
#include "Acts/Utilities/AxisDefinitions.hpp"
Expand Down
Loading
Loading