Skip to content

Commit

Permalink
updates after PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Oct 22, 2024
1 parent 3c9b37d commit bbdc5b0
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 228 deletions.
12 changes: 9 additions & 3 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Material/IVolumeMaterial.hpp"
#include "Acts/Navigation/NavigationDelegate.hpp"
#include "Acts/Navigation/NavigationStream.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceArray.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
Expand Down Expand Up @@ -501,10 +502,15 @@ class TrackingVolume : public Volume {
/// @param policy is the navigation policy to be registered
void setNavigationPolicy(std::unique_ptr<INavigationPolicy> policy);

/// Update the navigation state for this volume. Internally, this consults the
/// registered navigation policy, where the default is a noop.
/// Populate the navigation stream with navigation candidates from this
/// volume. Internally, this consults the registered navigation policy, where
/// the default is a noop.
/// @param args are the navigation arguments
void updateNavigationState(const NavigationArguments& args) const;
/// @param stream is the navigation stream to be updated
/// @param logger is the logger
void initializeNavigationCandidates(const NavigationArguments& args,
AppendOnlyNavigationStream& stream,
const Logger& logger) const;

private:
void connectDenseBoundarySurfaces(
Expand Down
12 changes: 9 additions & 3 deletions Core/include/Acts/Navigation/INavigationPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Navigation/NavigationDelegate.hpp"
#include "Acts/Navigation/NavigationStream.hpp"
#include "Acts/Utilities/DelegateChainBuilder.hpp"

#include <type_traits>
Expand All @@ -26,7 +27,9 @@ concept NavigationPolicyConcept = requires {
requires std::is_base_of_v<INavigationPolicy, T>;
// Has a conforming update method
requires requires(T policy, const NavigationArguments& args) {
{ policy.updateState(args) };
policy.initializeCandidates(args,
std::declval<AppendOnlyNavigationStream&>(),
std::declval<const Logger&>());
};
};

Expand All @@ -39,7 +42,9 @@ class INavigationPolicy {
public:
/// Noop update function that is suitable as a default for default navigation
/// delegates.
static void noopUpdate(const NavigationArguments& /*unused*/) {}
static void noopInitializeCandidates(const NavigationArguments& /*unused*/,
AppendOnlyNavigationStream& /*unused*/,
const Logger& /*unused*/) {}

/// Virtual destructor so policies can be held through this base class.
virtual ~INavigationPolicy() = default;
Expand All @@ -60,7 +65,8 @@ class INavigationPolicy {
void connectDefault(NavigationDelegate& delegate) const {
// This cannot be a concept because we use it in CRTP below
const auto* self = static_cast<const T*>(this);
DelegateChainBuilder{delegate}.add<&T::updateState>(self).store(delegate);
DelegateChainBuilder{delegate}.add<&T::initializeCandidates>(self).store(
delegate);
}
};

Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Navigation/MultiNavigationPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class MultiNavigationPolicy final : public MultiNavigationPolicyBase {
using policy_type = std::tuple_element_t<I, decltype(m_policies)>;
auto* policy = &std::get<I>(m_policies);

auto added = factory.template add<&policy_type::updateState>(policy);
auto added =
factory.template add<&policy_type::initializeCandidates>(policy);

if constexpr (sizeof...(Is) > 0) {
return add<Is...>(added);
Expand Down
7 changes: 3 additions & 4 deletions Core/include/Acts/Navigation/NavigationDelegate.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/Navigation/NavigationStream.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Utilities/Delegate.hpp"

Expand All @@ -20,17 +21,15 @@ class Logger;
/// Struct that serves as the argument to the navigation delegate.
/// It is not supposed to be used as an lvalue.
struct NavigationArguments {
NavigationStream& main;
Vector3 position;
Vector3 direction;

BoundaryTolerance tolerance = BoundaryTolerance::None();

const Logger& logger;
};

/// Central alias for the navigation delegate. This type is owning to support
/// (type-erased) navigation delegate chains (i.e. multiple policies).
using NavigationDelegate = OwningDelegate<void(const NavigationArguments&)>;
using NavigationDelegate = OwningDelegate<void(
const NavigationArguments&, AppendOnlyNavigationStream&, const Logger&)>;

} // namespace Acts
10 changes: 10 additions & 0 deletions Core/include/Acts/Navigation/NavigationStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ class NavigationStream {
std::size_t m_currentIndex = 0u;
};

struct AppendOnlyNavigationStream {
explicit AppendOnlyNavigationStream(NavigationStream& stream);
void addSurfaceCandidate(const Surface& surface,
const BoundaryTolerance& bTolerance);
void addPortalCandidate(const Portal& portal);

private:
NavigationStream* m_stream;
};

} // namespace Acts
12 changes: 9 additions & 3 deletions Core/include/Acts/Navigation/SurfaceArrayNavigationPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// 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/SurfaceArrayCreator.hpp"
#include "Acts/Navigation/INavigationPolicy.hpp"
#include "Acts/Surfaces/SurfaceArray.hpp"

#pragma once

namespace Acts {

class SurfaceArray;

/// A navigation policy that internally uses the Gen1 @c SurfaceArray class
class SurfaceArrayNavigationPolicy : public INavigationPolicy {
public:
Expand Down Expand Up @@ -44,7 +44,11 @@ class SurfaceArrayNavigationPolicy : public INavigationPolicy {

/// Update the navigation state from the surface array
/// @param args The navigation arguments
void updateState(const NavigationArguments& args) const;
/// @param stream The navigation stream to update
/// @param logger The logger
void initializeCandidates(const NavigationArguments& args,
AppendOnlyNavigationStream& stream,
const Logger& logger) const;

/// Connect this policy with a navigation delegate
/// @param delegate The navigation delegate to connect to
Expand Down Expand Up @@ -74,4 +78,6 @@ class SurfaceArrayNavigationPolicy : public INavigationPolicy {
const TrackingVolume& m_volume;
};

static_assert(NavigationPolicyConcept<SurfaceArrayNavigationPolicy>);

} // namespace Acts
72 changes: 0 additions & 72 deletions Core/include/Acts/Navigation/TryAllNavigationPolicies.hpp

This file was deleted.

57 changes: 57 additions & 0 deletions Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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/Navigation/INavigationPolicy.hpp"
#include "Acts/Navigation/NavigationStream.hpp"

namespace Acts {

class TrackingVolume;
class GeometryContext;
class Logger;

/// Policy which adds **all** candidates of the configured type to the
/// stream
class TryAllNavigationPolicy final : public INavigationPolicy {
public:
struct Config {
bool portals = true;
bool sensitives = true;
};

/// Constructor from a volume
/// @param config The configuration for the policy
/// @param gctx is the geometry context
/// @param volume is the volume to navigate
/// @param logger is the logger
TryAllNavigationPolicy(const Config& config, const GeometryContext& gctx,
const TrackingVolume& volume, const Logger& logger);

TryAllNavigationPolicy(const GeometryContext& gctx,
const TrackingVolume& volume, const Logger& logger);

/// Update the navigation state with all volume portals.
/// @param args are the navigation arguments
void initializeCandidates(const NavigationArguments& args,
AppendOnlyNavigationStream& stream,
const Logger& logger) const;

/// Connect the policy to a navigation delegate
/// @param delegate is the navigation delegate
void connect(NavigationDelegate& delegate) const override;

private:
Config m_cfg;
const TrackingVolume* m_volume;
};

static_assert(NavigationPolicyConcept<TryAllNavigationPolicy>);

} // namespace Acts
10 changes: 6 additions & 4 deletions Core/src/Geometry/TrackingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Acts/Material/IVolumeMaterial.hpp"
#include "Acts/Material/ProtoVolumeMaterial.hpp"
#include "Acts/Navigation/INavigationPolicy.hpp"
#include "Acts/Navigation/NavigationStream.hpp"
#include "Acts/Propagator/Navigator.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -52,7 +53,7 @@ TrackingVolume::TrackingVolume(
connectDenseBoundarySurfaces(denseVolumeVector);

DelegateChainBuilder{m_navigationDelegate}
.add<&INavigationPolicy::noopUpdate>()
.add<&INavigationPolicy::noopInitializeCandidates>()
.store(m_navigationDelegate);
}

Expand Down Expand Up @@ -754,9 +755,10 @@ void TrackingVolume::setNavigationPolicy(
m_navigationPolicy->connect(m_navigationDelegate);
}

void TrackingVolume::updateNavigationState(
const NavigationArguments& args) const {
m_navigationDelegate(args);
void TrackingVolume::initializeNavigationCandidates(
const NavigationArguments& args, AppendOnlyNavigationStream& stream,
const Logger& logger) const {
m_navigationDelegate(args, stream, logger);
}

} // namespace Acts
2 changes: 1 addition & 1 deletion Core/src/Navigation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ target_sources(
ActsCore
PRIVATE
NavigationStream.cpp
TryAllNavigationPolicies.cpp
TryAllNavigationPolicy.cpp
SurfaceArrayNavigationPolicy.cpp
)
Loading

0 comments on commit bbdc5b0

Please sign in to comment.