File indexing completed on 2025-07-12 07:51:58
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/Polyhedron.hpp"
0010
0011 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0012 #include "Acts/Visualization/IVisualization3D.hpp"
0013
0014 #include <algorithm>
0015 #include <limits>
0016 #include <numbers>
0017
0018 namespace Acts {
0019
0020 void Polyhedron::merge(const Polyhedron& other) {
0021 std::size_t cvert = vertices.size();
0022 vertices.insert(vertices.end(), other.vertices.begin(), other.vertices.end());
0023
0024 auto join = [&](std::vector<FaceType>& existing,
0025 const std::vector<FaceType>& additional) -> void {
0026 for (const auto& aface : additional) {
0027 FaceType nface = aface;
0028 std::transform(nface.begin(), nface.end(), nface.begin(),
0029 [&](std::size_t x) { return (x + cvert); });
0030 existing.push_back(nface);
0031 }
0032 };
0033
0034 join(faces, other.faces);
0035 join(triangularMesh, other.triangularMesh);
0036 }
0037
0038 void Polyhedron::move(const Transform3& transform) {
0039 for_each(vertices.begin(), vertices.end(),
0040 [&](auto& v) { v = transform * v; });
0041 }
0042
0043 Extent Polyhedron::extent(const Transform3& transform) const {
0044 Extent extent;
0045 auto vtxs = vertices;
0046 std::transform(vtxs.begin(), vtxs.end(), vtxs.begin(), [&](auto& v) {
0047 auto vt = (transform * v);
0048 extent.extend(vt);
0049 return (vt);
0050 });
0051
0052
0053 if (detail::VerticesHelper::onHyperPlane(vtxs)) {
0054
0055 Vector3 origin =
0056 transform * Vector3(0., 0., extent.medium(AxisDirection::AxisZ));
0057 for (const auto& face : faces) {
0058 std::vector<Vector3> tface;
0059 tface.reserve(face.size());
0060 for (auto f : face) {
0061 tface.push_back(vtxs[f]);
0062 }
0063 if (detail::VerticesHelper::isInsidePolygon(origin, tface)) {
0064 extent.range(AxisDirection::AxisR).setMin(0.);
0065 extent.range(AxisDirection::AxisPhi)
0066 .set(-std::numbers::pi, std::numbers::pi);
0067 break;
0068 }
0069 }
0070 if (exact) {
0071
0072 auto radialDistance = [&](const Vector3& pos1,
0073 const Vector3& pos2) -> double {
0074 Vector2 O(0, 0);
0075 Vector2 p1p2 = (pos2.block<2, 1>(0, 0) - pos1.block<2, 1>(0, 0));
0076 double L = p1p2.norm();
0077 Vector2 p1O = (O - pos1.block<2, 1>(0, 0));
0078
0079
0080 if (L < 1e-7) {
0081 return std::numeric_limits<double>::max();
0082 }
0083 double f = p1p2.dot(p1O) / L;
0084
0085
0086 f = std::min(L, std::max(0., f));
0087 Vector2 closest = f * p1p2.normalized() + pos1.block<2, 1>(0, 0);
0088 double dist = (closest - O).norm();
0089 return dist;
0090 };
0091
0092 for (std::size_t iv = 1; iv < vtxs.size() + 1; ++iv) {
0093 std::size_t fpoint = iv < vtxs.size() ? iv : 0;
0094 double testR = radialDistance(vtxs[fpoint], vtxs[iv - 1]);
0095 extent.range(AxisDirection::AxisR).expandMin(testR);
0096 }
0097 }
0098 }
0099 return extent;
0100 }
0101
0102 void Polyhedron::visualize(IVisualization3D& helper,
0103 const ViewConfig& viewConfig) const {
0104 if (viewConfig.visible) {
0105 if (!viewConfig.triangulate) {
0106 helper.faces(vertices, faces, viewConfig.color);
0107 } else {
0108 helper.faces(vertices, triangularMesh, viewConfig.color);
0109 }
0110 }
0111 }
0112
0113 }