Back to home page

EIC code displayed by LXR

 
 

    


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/Geometry/Polyhedron.hpp"
0013 
0014 #include <numeric>
0015 #include <utility>
0016 #include <vector>
0017 
0018 namespace Acts::detail {
0019 
0020 /// @brief Helper for writing out faces for polyhedron representation
0021 struct FacesHelper {
0022   using FaceVector = std::vector<Polyhedron::FaceType>;
0023 
0024   /// @brief This method words for all convex type surface setups
0025   /// It includes:
0026   ///
0027   /// Rectangle / Triangle / Polygon
0028   /// Full disc, ellipse, half ring
0029   /// @param vertices The vector of vertices
0030   /// @param centerLast Boolean indicator if the center is given for
0031   /// a better triangulation method as last element of the vector
0032   static std::pair<FaceVector, FaceVector> convexFaceMesh(
0033       const std::vector<Vector3>& vertices, bool centerLast = false) {
0034     FaceVector faces;
0035     FaceVector triangularMesh;
0036     // Write the face
0037     unsigned int offset = centerLast ? 1 : 0;
0038     std::vector<std::size_t> face(vertices.size() - offset);
0039     std::iota(face.begin(), face.end(), 0);
0040     faces.push_back(face);
0041     /// Triangular mesh construction
0042     unsigned int anker = centerLast ? vertices.size() - 1 : 0;
0043     for (unsigned int it = 2 - offset; it < vertices.size() - offset; ++it) {
0044       triangularMesh.push_back({anker, it - 1, it});
0045     }
0046     // Close for centered reference point
0047     if (centerLast) {
0048       triangularMesh.push_back({anker, vertices.size() - 2, 0});
0049     }
0050     return {faces, triangularMesh};
0051   }
0052 
0053   /// @brief This method works for all concentric type surface setups
0054   /// It includes :
0055   ///
0056   /// - Cylinder (concentric bows on each side, separated by z)
0057   /// - Cut-off cone
0058   ///
0059   /// The single requirement is that the #vertices are equal and the input
0060   /// vector is splittable in half into the two bows.
0061   ///
0062   /// @param vertices The vector of vertices
0063   /// @param fullTwoPi The indicator if the concentric face is closed
0064   static std::pair<FaceVector, FaceVector> cylindricalFaceMesh(
0065       const std::vector<Vector3>& vertices, bool fullTwoPi = true) {
0066     FaceVector faces;
0067     FaceVector triangularMesh;
0068     std::size_t nqfaces = static_cast<std::size_t>(0.5 * vertices.size());
0069     std::size_t reduce = (!fullTwoPi) ? 1 : 0;
0070     for (std::size_t iface = 0; iface < nqfaces - reduce; ++iface) {
0071       std::size_t p2 = (iface + 1 == nqfaces) ? 0 : iface + 1;
0072       std::vector<std::size_t> face = {iface, p2, p2 + nqfaces,
0073                                        nqfaces + iface};
0074       faces.push_back(face);
0075       std::vector<std::size_t> triA = {iface, p2, p2 + nqfaces};
0076       triangularMesh.push_back(triA);
0077       std::vector<std::size_t> triB = {p2 + nqfaces, nqfaces + iface, iface};
0078       triangularMesh.push_back(triB);
0079     }
0080     return {faces, triangularMesh};
0081   }
0082 };
0083 
0084 }  // namespace Acts::detail