|
||||
File indexing completed on 2025-01-19 09:23:34
0001 // This file is part of the Acts project. 0002 // 0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include "Acts/Definitions/Algebra.hpp" 0012 #include "Acts/Surfaces/BoundaryCheck.hpp" 0013 #include "Acts/Surfaces/PlanarBounds.hpp" 0014 #include "Acts/Surfaces/RectangleBounds.hpp" 0015 #include "Acts/Surfaces/SurfaceBounds.hpp" 0016 0017 #include <array> 0018 #include <cmath> 0019 #include <cstddef> 0020 #include <exception> 0021 #include <iosfwd> 0022 #include <vector> 0023 0024 #include <boost/container/small_vector.hpp> 0025 0026 namespace Acts { 0027 0028 /// @brief base class for convex polygon bounds 0029 /// 0030 /// This class serves as a base class for the actual bounds class. 0031 /// The only deriving type is the templated `ConvexPolygonBounds`. 0032 /// 0033 class ConvexPolygonBoundsBase : public PlanarBounds { 0034 public: 0035 /// Output Method for std::ostream 0036 /// @param sl is the ostream to be written into 0037 std::ostream& toStream(std::ostream& sl) const final; 0038 0039 /// Return the bound values as dynamically sized vector 0040 /// 0041 /// @return this returns a copy of the internal values 0042 std::vector<double> values() const final; 0043 0044 protected: 0045 /// Return a rectangle bounds instance that encloses a set of vertices. 0046 /// @param vertices A collection of vertices to enclose. 0047 /// @return Enclosing rectangle. 0048 template <typename coll_t> 0049 static RectangleBounds makeBoundingBox(const coll_t& vertices); 0050 0051 /// Calculates whether a set of vertices forms a convex polygon. This is 0052 /// generic over the number of vertices, so it's factored out of the concrete 0053 /// classes and into this base class. 0054 /// @param vertices A collection of vertices. 0055 /// throws a logic error if this is not the case 0056 template <typename coll_t> 0057 static void convex_impl(const coll_t& vertices) noexcept(false); 0058 }; 0059 0060 /// This is the actual implementation of the bounds. 0061 /// It is templated on the number of vertices, but there is a specialization for 0062 /// *dynamic* number of vertices, where the underlying storage is then a vector. 0063 /// 0064 /// @tparam N Number of vertices 0065 template <int N> 0066 class ConvexPolygonBounds : public ConvexPolygonBoundsBase { 0067 public: 0068 /// Expose number of vertices given as template parameter. 0069 /// 0070 static constexpr std::size_t num_vertices = N; 0071 /// Type that's used to store the vertices, in this case a fixed size array. 0072 /// 0073 using vertex_array = std::array<Vector2, num_vertices>; 0074 /// Expose number of parameters as a template parameter 0075 /// 0076 static constexpr std::size_t eSize = 2 * N; 0077 /// Type that's used to store the vertices, in this case a fixed size array. 0078 /// 0079 using value_array = std::array<double, eSize>; 0080 0081 static_assert(N >= 3, "ConvexPolygonBounds needs at least 3 sides."); 0082 0083 ConvexPolygonBounds() = delete; 0084 0085 /// Constructor from a vector of vertices, to facilitate construction. 0086 /// This will throw if the vector size does not match `num_vertices`. 0087 /// This will throw if the vertices do not form a convex polygon. 0088 /// @param vertices The list of vertices. 0089 ConvexPolygonBounds(const std::vector<Vector2>& vertices) noexcept(false); 0090 0091 /// Constructor from a fixed size array of vertices. 0092 /// This will throw if the vertices do not form a convex polygon. 0093 /// @param vertices The vertices 0094 ConvexPolygonBounds(const vertex_array& vertices) noexcept(false); 0095 0096 /// Constructor from a fixed size array of parameters 0097 /// This will throw if the vertices do not form a convex polygon. 0098 /// @param values The values to build up the vertices 0099 ConvexPolygonBounds(const value_array& values) noexcept(false); 0100 0101 ~ConvexPolygonBounds() override = default; 0102 0103 BoundsType type() const final; 0104 0105 /// Return whether a local 2D point lies inside of the bounds defined by this 0106 /// object. 0107 /// @param lposition The local position to check 0108 /// @param bcheck The `BoundaryCheck` object handling tolerances. 0109 /// @return Whether the points is inside 0110 bool inside(const Vector2& lposition, 0111 const BoundaryCheck& bcheck) const final; 0112 0113 /// Return the vertices 0114 /// 0115 /// @param lseg the number of segments used to approximate 0116 /// and eventually curved line 0117 /// 0118 /// @note the number of segments is ignored in this representation 0119 /// 0120 /// @return vector for vertices in 2D 0121 std::vector<Vector2> vertices(unsigned int lseg = 1) const final; 0122 0123 /// Return a rectangle bounds object that encloses this polygon. 0124 /// @return The rectangular bounds 0125 const RectangleBounds& boundingBox() const final; 0126 0127 private: 0128 vertex_array m_vertices; 0129 RectangleBounds m_boundingBox; 0130 0131 /// Return whether this bounds class is in fact convex 0132 /// throws a log error if not 0133 void checkConsistency() const noexcept(false); 0134 }; 0135 0136 /// Tag to trigger specialization of a dynamic polygon 0137 constexpr int PolygonDynamic = -1; 0138 0139 /// This is the specialization handling a polygon with a dynamic number of 0140 /// points. It can accept any number of points. 0141 /// 0142 template <> 0143 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase { 0144 public: 0145 constexpr static int eSize = -1; 0146 0147 /// Default constructor, deleted 0148 ConvexPolygonBounds() = delete; 0149 0150 /// Defaulted destructor 0151 ~ConvexPolygonBounds() override = default; 0152 0153 /// Constructor from a vector of vertices, to facilitate construction. 0154 /// This will throw if the vertices do not form a convex polygon. 0155 /// @param vertices The list of vertices. 0156 ConvexPolygonBounds(const std::vector<Vector2>& vertices); 0157 0158 /// Return the bounds type of this bounds object. 0159 /// @return The bounds type 0160 BoundsType type() const final; 0161 0162 /// Return whether a local 2D point lies inside of the bounds defined by this 0163 /// object. 0164 /// @param lposition The local position to check 0165 /// @param bcheck The `BoundaryCheck` object handling tolerances. 0166 /// @return Whether the points is inside 0167 bool inside(const Vector2& lposition, 0168 const BoundaryCheck& bcheck) const final; 0169 0170 /// Return the vertices 0171 /// 0172 /// @param lseg the number of segments used to approximate 0173 /// and eventually curved line 0174 /// 0175 /// @note the number of segments is ignored in this representation 0176 /// 0177 /// @return vector for vertices in 2D 0178 std::vector<Vector2> vertices(unsigned int lseg = 1) const final; 0179 0180 /// 0181 /// Return a rectangle bounds object that encloses this polygon. 0182 /// @return The rectangular bounds 0183 /// 0184 const RectangleBounds& boundingBox() const final; 0185 0186 private: 0187 boost::container::small_vector<Vector2, 10> m_vertices; 0188 RectangleBounds m_boundingBox; 0189 0190 /// Return whether this bounds class is in fact convex 0191 /// thorws a logic error if not 0192 void checkConsistency() const noexcept(false); 0193 }; 0194 0195 } // namespace Acts 0196 0197 #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 |