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: Add closest point and distance computation to SurfaceBounds #3990

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
87106e9
tmp
andiwand Dec 12, 2024
4d5d10d
tmp
andiwand Dec 13, 2024
9bcc7f6
tmp
andiwand Dec 17, 2024
e6e0cc2
draft
andiwand Dec 17, 2024
bdf87b6
clean annulus
andiwand Dec 18, 2024
f856077
tmp
andiwand Dec 18, 2024
7f29993
tmp
andiwand Dec 18, 2024
a595467
tmp
andiwand Dec 18, 2024
793c950
includes
andiwand Dec 18, 2024
0c965e7
tmp
andiwand Dec 18, 2024
7a1c005
tmp
andiwand Dec 18, 2024
79ada20
make compile
andiwand Dec 18, 2024
17db365
tmp
andiwand Dec 18, 2024
289109a
jacobians
andiwand Dec 18, 2024
a034c42
Merge branch 'main' of github.com:acts-project/acts into tmp-distance…
andiwand Dec 18, 2024
edb6882
metric
andiwand Dec 19, 2024
a2bf8be
remove some unintended changes
andiwand Dec 19, 2024
43c7d23
default inside impl; fix compilation
andiwand Dec 19, 2024
26e68b3
Merge branch 'main' of github.com:acts-project/acts into tmp-distance…
andiwand Dec 19, 2024
7ea4115
deduplicate inside
andiwand Dec 19, 2024
890b472
remove bounds check helpers
andiwand Dec 19, 2024
c30f1cc
Merge branch 'main' of github.com:acts-project/acts into tmp-distance…
andiwand Dec 19, 2024
b9e2168
doc
andiwand Dec 19, 2024
cf9a545
rename tolerance mode
andiwand Dec 19, 2024
ef18a08
fix doc
andiwand Dec 19, 2024
c1de29d
rename tolerance mode
andiwand Dec 19, 2024
5032c8b
simplify distance
andiwand Dec 19, 2024
bf236b4
fix and docs
andiwand Dec 19, 2024
217b138
small fix
andiwand Dec 19, 2024
a0d665d
remove cartesian to bound jacobians
andiwand Dec 19, 2024
529a109
fix doc; tolerance less annulus inside check
andiwand Dec 19, 2024
97c568e
deal with different coordinate systems in annulus bounds
andiwand Dec 19, 2024
385c66d
try fix annulus closest point
andiwand Dec 19, 2024
cd13630
minor
andiwand Dec 19, 2024
c8be68f
minor
andiwand Dec 19, 2024
5727270
Merge branch 'main' of github.com:acts-project/acts into tmp-distance…
andiwand Dec 19, 2024
c6a4219
fixes and ref updates
andiwand Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Core/include/Acts/Geometry/TrapezoidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#include "Acts/Geometry/VolumeBounds.hpp"

#include <array>
#include <iomanip>
#include <iosfwd>
#include <memory>
#include <ostream>
#include <stdexcept>
#include <vector>

namespace Acts {
Expand Down
31 changes: 17 additions & 14 deletions Core/include/Acts/Surfaces/AnnulusBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Tolerance.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/DiscBounds.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"

Expand Down Expand Up @@ -66,27 +65,31 @@ class AnnulusBounds : public DiscBounds {
/// @param values The parameter array
AnnulusBounds(const std::array<double, eSize>& values) noexcept(false);

AnnulusBounds(const AnnulusBounds& source) = default;
BoundsType type() const final { return eAnnulus; }

BoundsType type() const final { return SurfaceBounds::eAnnulus; }
/// @copydoc SurfaceBounds::isCartesian
bool isCartesian() const final { return false; }

/// @copydoc SurfaceBounds::boundToCartesianJacobian
SquareMatrix2 boundToCartesianJacobian(const Vector2& lposition) const final;

/// @copydoc SurfaceBounds::boundToCartesianMetric
SquareMatrix2 boundToCartesianMetric(const Vector2& lposition) const final;

/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;

/// Inside check for the bounds object driven by the boundary check directive
/// Each Bounds has a method inside, which checks if a LocalPosition is inside
/// the bounds Inside can be called without/with tolerances.
///
/// @param lposition Local position (assumed to be in right surface frame)
/// @param boundaryTolerance boundary check directive
/// @return boolean indicator for the success of this operation
bool inside(const Vector2& lposition,
const BoundaryTolerance& boundaryTolerance) const final;
/// @copydoc SurfaceBounds::inside
bool inside(const Vector2& lposition) const final;

/// @copydoc SurfaceBounds::closestPoint
Vector2 closestPoint(const Vector2& lposition,
const std::optional<SquareMatrix2>& metric) const final;

using SurfaceBounds::inside;

/// Outstream operator
///
/// @param sl is the ostream to be dumped into
std::ostream& toStream(std::ostream& sl) const final;

Expand Down
18 changes: 6 additions & 12 deletions Core/include/Acts/Surfaces/BoundaryTolerance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class BoundaryTolerance {
: maxChi2(maxChi2_), weight(weight_) {}
};

enum class ToleranceMode {
Extend, // Extend the boundary
None, // No tolerance
Shrink // Shrink the boundary
enum class Mode {
Extend, //< Extend the boundary
None, //< No tolerance
Shrink //< Shrink the boundary
};
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// Underlying variant type
Expand Down Expand Up @@ -147,8 +147,8 @@ class BoundaryTolerance {
/// Check if the tolerance is chi2 with bound coordinates.
bool hasChi2Bound() const;

/// Check if any tolerance is set.
ToleranceMode toleranceMode() const;
/// Get the tolerance mode.
Mode mode() const;

/// Get the tolerance as absolute bound.
AbsoluteBound asAbsoluteBound(bool isCartesian = false) const;
Expand All @@ -167,12 +167,6 @@ class BoundaryTolerance {
bool isTolerated(const Vector2& distance,
const std::optional<SquareMatrix2>& jacobianOpt) const;

/// Check if there is a metric assigned with this tolerance.
bool hasMetric(bool hasJacobian) const;

/// Get the metric for the tolerance.
SquareMatrix2 getMetric(const std::optional<SquareMatrix2>& jacobian) const;

private:
Variant m_variant;

Expand Down
40 changes: 26 additions & 14 deletions Core/include/Acts/Surfaces/ConeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"

#include <array>
Expand Down Expand Up @@ -71,24 +70,37 @@ class ConeBounds : public SurfaceBounds {
/// @param values The parameter array
ConeBounds(const std::array<double, eSize>& values) noexcept(false);

BoundsType type() const final { return SurfaceBounds::eCone; }
/// @copydoc SurfaceBounds::type
BoundsType type() const final { return eCone; }

/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
/// @copydoc SurfaceBounds::isCartesian
bool isCartesian() const final { return true; }

/// @copydoc SurfaceBounds::boundToCartesianJacobian
SquareMatrix2 boundToCartesianJacobian(const Vector2& lposition) const final {
(void)lposition;
return SquareMatrix2::Identity();
}

/// @copydoc SurfaceBounds::boundToCartesianMetric
SquareMatrix2 boundToCartesianMetric(const Vector2& lposition) const final {
(void)lposition;
return SquareMatrix2::Identity();
}

/// @copydoc SurfaceBounds::values
std::vector<double> values() const final;

/// inside method for local position
///
/// @param lposition is the local position to be checked
/// @param boundaryTolerance is the boundary check directive
/// @return is a boolean indicating if the position is inside
bool inside(const Vector2& lposition,
const BoundaryTolerance& boundaryTolerance =
BoundaryTolerance::None()) const final;
/// @copydoc SurfaceBounds::inside
bool inside(const Vector2& lposition) const final;

/// @copydoc SurfaceBounds::inside
Vector2 closestPoint(const Vector2& lposition,
const std::optional<SquareMatrix2>& metric) const final;

using SurfaceBounds::inside;

/// Output Method for std::ostream
///
/// @param sl is the ostrea into which the dump is done
/// @return is the input object
std::ostream& toStream(std::ostream& sl) const final;
Expand Down
40 changes: 19 additions & 21 deletions Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/PlanarBounds.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"
Expand All @@ -34,8 +33,11 @@ class ConvexPolygonBoundsBase : public PlanarBounds {
/// @param sl is the ostream to be written into
std::ostream& toStream(std::ostream& sl) const final;

/// Return the bounds type of this bounds object.
/// @return The bounds type
BoundsType type() const final { return eConvexPolygon; }

/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;

Expand Down Expand Up @@ -95,15 +97,14 @@ class ConvexPolygonBounds : public ConvexPolygonBoundsBase {
/// @param values The values to build up the vertices
ConvexPolygonBounds(const value_array& values) noexcept(false);

BoundsType type() const final { return SurfaceBounds::eConvexPolygon; }
/// @copydoc SurfaceBounds::inside
bool inside(const Vector2& lposition) const final;

/// @copydoc SurfaceBounds::closestPoint
Vector2 closestPoint(const Vector2& lposition,
const std::optional<SquareMatrix2>& metric) const final;

/// Return whether a local 2D point lies inside of the bounds defined by this
/// object.
/// @param lposition The local position to check
/// @param boundaryTolerance The `BoundaryTolerance` object handling tolerances.
/// @return Whether the points is inside
bool inside(const Vector2& lposition,
const BoundaryTolerance& boundaryTolerance) const final;
using SurfaceBounds::inside;

/// Return the vertices
///
Expand Down Expand Up @@ -144,17 +145,14 @@ class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase {
/// @param vertices The list of vertices.
ConvexPolygonBounds(const std::vector<Vector2>& vertices);

/// Return the bounds type of this bounds object.
/// @return The bounds type
BoundsType type() const final { return SurfaceBounds::eConvexPolygon; }

/// Return whether a local 2D point lies inside of the bounds defined by this
/// object.
/// @param lposition The local position to check
/// @param boundaryTolerance The `BoundaryTolerance` object handling tolerances.
/// @return Whether the points is inside
bool inside(const Vector2& lposition,
const BoundaryTolerance& boundaryTolerance) const final;
/// @copydoc SurfaceBounds::inside
bool inside(const Vector2& lposition) const final;

/// @copydoc SurfaceBounds::closestPoint
Vector2 closestPoint(const Vector2& lposition,
const std::optional<SquareMatrix2>& metric) const final;

using SurfaceBounds::inside;

/// Return the vertices
///
Expand Down
45 changes: 27 additions & 18 deletions Core/include/Acts/Surfaces/ConvexPolygonBounds.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// 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/Surfaces/detail/BoundaryCheckHelper.hpp"
#include "Acts/Surfaces/detail/VerticesHelper.hpp"
#include "Acts/Utilities/ThrowAssert.hpp"

namespace Acts {

template <typename coll_t>
requires std::same_as<typename coll_t::value_type, Acts::Vector2>
void Acts::ConvexPolygonBoundsBase::convex_impl(
const coll_t& vertices) noexcept(false) {
requires std::same_as<typename coll_t::value_type, Vector2>
void ConvexPolygonBoundsBase::convex_impl(const coll_t& vertices) noexcept(
false) {
const std::size_t N = vertices.size();
for (std::size_t i = 0; i < N; i++) {
std::size_t j = (i + 1) % N;
Expand Down Expand Up @@ -48,7 +50,7 @@ void Acts::ConvexPolygonBoundsBase::convex_impl(
}

template <typename coll_t>
Acts::RectangleBounds Acts::ConvexPolygonBoundsBase::makeBoundingBox(
RectangleBounds ConvexPolygonBoundsBase::makeBoundingBox(
const coll_t& vertices) {
Vector2 vmax, vmin;
vmax = vertices[0];
Expand All @@ -63,8 +65,8 @@ Acts::RectangleBounds Acts::ConvexPolygonBoundsBase::makeBoundingBox(
}

template <int N>
Acts::ConvexPolygonBounds<N>::ConvexPolygonBounds(
const std::vector<Acts::Vector2>& vertices) noexcept(false)
ConvexPolygonBounds<N>::ConvexPolygonBounds(
const std::vector<Vector2>& vertices) noexcept(false)
: m_vertices(), m_boundingBox(makeBoundingBox(vertices)) {
throw_assert(vertices.size() == N,
"Size and number of given vertices do not match.");
Expand All @@ -75,15 +77,15 @@ Acts::ConvexPolygonBounds<N>::ConvexPolygonBounds(
}

template <int N>
Acts::ConvexPolygonBounds<N>::ConvexPolygonBounds(
ConvexPolygonBounds<N>::ConvexPolygonBounds(
const vertex_array& vertices) noexcept(false)
: m_vertices(vertices), m_boundingBox(makeBoundingBox(vertices)) {
checkConsistency();
}

template <int N>
Acts::ConvexPolygonBounds<N>::ConvexPolygonBounds(
const value_array& values) noexcept(false)
ConvexPolygonBounds<N>::ConvexPolygonBounds(const value_array& values) noexcept(
false)
: m_vertices(), m_boundingBox(0., 0.) {
for (std::size_t i = 0; i < N; i++) {
m_vertices[i] = Vector2(values[2 * i], values[2 * i + 1]);
Expand All @@ -93,25 +95,32 @@ Acts::ConvexPolygonBounds<N>::ConvexPolygonBounds(
}

template <int N>
bool Acts::ConvexPolygonBounds<N>::inside(
const Acts::Vector2& lposition,
const Acts::BoundaryTolerance& boundaryTolerance) const {
return detail::insidePolygon(m_vertices, boundaryTolerance, lposition,
std::nullopt);
bool ConvexPolygonBounds<N>::inside(const Vector2& lposition) const {
return detail::VerticesHelper::isInsidePolygon(lposition, m_vertices);
}

template <int N>
std::vector<Acts::Vector2> Acts::ConvexPolygonBounds<N>::vertices(
Vector2 ConvexPolygonBounds<N>::closestPoint(
const Vector2& lposition,
const std::optional<SquareMatrix2>& metric) const {
return detail::VerticesHelper::computeClosestPointOnPolygon(
lposition, m_vertices, metric.value_or(SquareMatrix2::Identity()));
}

template <int N>
std::vector<Vector2> ConvexPolygonBounds<N>::vertices(
unsigned int /*ignoredSegments*/) const {
return {m_vertices.begin(), m_vertices.end()};
}

template <int N>
const Acts::RectangleBounds& Acts::ConvexPolygonBounds<N>::boundingBox() const {
const RectangleBounds& ConvexPolygonBounds<N>::boundingBox() const {
return m_boundingBox;
}

template <int N>
void Acts::ConvexPolygonBounds<N>::checkConsistency() const noexcept(false) {
void ConvexPolygonBounds<N>::checkConsistency() const noexcept(false) {
convex_impl(m_vertices);
}

} // namespace Acts
Loading
Loading