|
|
|||
File indexing completed on 2025-10-29 07:53:53
0001 // This file is part of the ACTS project. 0002 // 0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project 0004 // 0005 // This Source Code Form is subject to the terms of the Mozilla Public 0006 // License, v. 2.0. If a copy of the MPL was not distributed with this 0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include "Acts/Definitions/Algebra.hpp" 0012 #include "Acts/Surfaces/PlanarBounds.hpp" 0013 #include "Acts/Surfaces/RectangleBounds.hpp" 0014 #include "Acts/Surfaces/SurfaceBounds.hpp" 0015 0016 #include <array> 0017 #include <cstddef> 0018 #include <iosfwd> 0019 #include <span> 0020 #include <vector> 0021 0022 #include <boost/container/small_vector.hpp> 0023 0024 namespace Acts { 0025 0026 /// @brief base class for convex polygon bounds 0027 /// 0028 /// This class serves as a base class for the actual bounds class. 0029 /// The only deriving type is the templated `ConvexPolygonBounds`. 0030 /// 0031 class ConvexPolygonBoundsBase : public PlanarBounds { 0032 public: 0033 /// Output Method for std::ostream 0034 /// @param sl is the ostream to be written into 0035 /// @return Reference to the output stream after writing 0036 std::ostream& toStream(std::ostream& sl) const final; 0037 0038 /// Return the bounds type of this bounds object. 0039 /// @return The bounds type 0040 BoundsType type() const final { return eConvexPolygon; } 0041 0042 /// Return the bound values as dynamically sized vector 0043 /// @return this returns a copy of the internal values 0044 std::vector<double> values() const final; 0045 0046 /// @copydoc SurfaceBounds::center 0047 /// @note For ConvexPolygonBounds: returns average of all vertices (vertex 0048 /// centroid) 0049 Vector2 center() const final; 0050 0051 /// Return a rectangle bounds object that encloses this polygon. 0052 /// @return The rectangular bounds 0053 /// 0054 const RectangleBounds& boundingBox() const final; 0055 0056 protected: 0057 /// Creates a rectangle bounds instance that encloses a set of vertices. 0058 /// @param vertices A collection of vertices to enclose. 0059 void makeBoundingBox(std::span<const Vector2> vertices); 0060 0061 /// Calculates whether a set of vertices forms a convex polygon. This is 0062 /// generic over the number of vertices, so it's factored out of the concrete 0063 /// classes and into this base class. 0064 /// @param vertices A collection of vertices. 0065 /// throws a logic error if this is not the case 0066 template <typename coll_t> 0067 requires std::same_as<typename coll_t::value_type, Acts::Vector2> 0068 static void convex_impl(const coll_t& vertices) noexcept(false); 0069 0070 /// Calculate and cache the center point from vertices 0071 /// @param vertices The vertices to calculate center from 0072 void calculateCenter(std::span<const Vector2> vertices); 0073 0074 /// Return whether this bounds class is in fact convex 0075 /// thorws a logic error if not 0076 /// @param vertices The vertices to check for consistency 0077 static void checkConsistency(std::span<const Vector2> vertices) noexcept( 0078 false); 0079 0080 private: 0081 /// Cached center position 0082 Vector2 m_center{Vector2::Zero()}; 0083 RectangleBounds m_boundingBox{0, 0}; 0084 }; 0085 0086 template <int N> 0087 concept isValidConvexPolygonSize = requires { requires(N >= 3 || N == -1); }; 0088 0089 /// This is the actual implementation of the bounds. 0090 /// It is templated on the number of vertices, but there is a specialization 0091 /// for *dynamic* number of vertices, where the underlying storage is then a 0092 /// vector. 0093 /// 0094 /// @tparam N Number of vertices 0095 template <int N> 0096 requires isValidConvexPolygonSize<N> 0097 class ConvexPolygonBounds : public ConvexPolygonBoundsBase { 0098 public: 0099 /// Expose number of vertices given as template parameter. 0100 static constexpr std::size_t nVertices = N; 0101 0102 /// Expose number of parameters as a template parameter 0103 /// @note The `eSize` name here emulates the size of the *bound values* in other 0104 /// bounds classes. 0105 static constexpr std::size_t eSize = 2 * N; 0106 0107 /// Constructor from a vector of vertices, to facilitate construction. 0108 /// This will throw if the vector size does not match `num_vertices`. 0109 /// This will throw if the vertices do not form a convex polygon. 0110 /// @param vertices The list of vertices. 0111 explicit ConvexPolygonBounds(std::span<const Vector2> vertices) noexcept( 0112 false); 0113 0114 /// Constructor from a fixed size array of parameters 0115 /// This will throw if the vertices do not form a convex polygon. 0116 /// @param values The values to build up the vertices 0117 explicit ConvexPolygonBounds(std::span<const double> values) noexcept(false); 0118 0119 /// @copydoc SurfaceBounds::inside 0120 bool inside(const Vector2& lposition) const final; 0121 0122 /// @copydoc SurfaceBounds::closestPoint 0123 Vector2 closestPoint(const Vector2& lposition, 0124 const SquareMatrix2& metric) const final; 0125 0126 using SurfaceBounds::inside; 0127 0128 /// Return the vertices 0129 /// 0130 /// @param ignoredSegments the number of segments used to approximate 0131 /// and eventually curved line 0132 /// 0133 /// @note the number of segments is ignored in this representation 0134 /// 0135 /// @return vector for vertices in 2D 0136 std::vector<Vector2> vertices(unsigned int ignoredSegments = 0u) const final; 0137 0138 private: 0139 std::array<Vector2, nVertices> m_vertices{}; 0140 }; 0141 0142 /// Tag to trigger specialization of a dynamic polygon 0143 constexpr int PolygonDynamic = -1; 0144 0145 /// This is the specialization handling a polygon with a dynamic number of 0146 /// points. It can accept any number of points. 0147 /// 0148 template <> 0149 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase { 0150 public: 0151 /// Expose number of vertices given as template parameter. 0152 constexpr static int nVertices = PolygonDynamic; 0153 /// Expose number of parameters as a template parameter 0154 /// @note The `eSize` name here emulates the size of the *bound values* in other 0155 /// bounds classes. 0156 constexpr static int eSize = -1; 0157 0158 /// Constructor from a vector of vertices, to facilitate construction. 0159 /// This will throw if the vertices do not form a convex polygon. 0160 /// @param vertices The list of vertices. 0161 explicit ConvexPolygonBounds(std::span<const Vector2> vertices); 0162 0163 /// Constructor from a vector of vertices, to facilitate construction. 0164 /// This will throw if the vertices do not form a convex polygon. 0165 /// @param vertices The list of vertices. 0166 explicit ConvexPolygonBounds(const std::vector<Vector2>& vertices); 0167 0168 /// @copydoc SurfaceBounds::inside 0169 bool inside(const Vector2& lposition) const final; 0170 0171 /// @copydoc SurfaceBounds::closestPoint 0172 Vector2 closestPoint(const Vector2& lposition, 0173 const SquareMatrix2& metric) const final; 0174 0175 using SurfaceBounds::inside; 0176 0177 /// Return the vertices 0178 /// 0179 /// @param lseg the number of segments used to approximate 0180 /// and eventually curved line 0181 /// 0182 /// @note the number of segments is ignored in this representation 0183 /// 0184 /// @return vector for vertices in 2D 0185 std::vector<Vector2> vertices(unsigned int lseg = 1) const final; 0186 0187 private: 0188 boost::container::small_vector<Vector2, 10> m_vertices{}; 0189 }; 0190 0191 } // namespace Acts 0192 0193 #include "Acts/Surfaces/ConvexPolygonBounds.ipp"
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|