Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FacesHelper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FacesHelper.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
13 
14 #include <numeric>
15 #include <utility>
16 #include <vector>
17 
18 namespace Acts {
19 
20 namespace detail {
21 
23 struct FacesHelper {
24  using FaceVector = std::vector<Polyhedron::FaceType>;
25 
34  static std::pair<FaceVector, FaceVector> convexFaceMesh(
35  const std::vector<Vector3>& vertices, bool centerLast = false) {
36  FaceVector faces;
37  FaceVector triangularMesh;
38  // Write the face
39  unsigned int offset = centerLast ? 1 : 0;
40  std::vector<size_t> face(vertices.size() - offset);
41  std::iota(face.begin(), face.end(), 0);
42  faces.push_back(face);
44  unsigned int anker = centerLast ? vertices.size() - 1 : 0;
45  for (unsigned int it = 2 - offset; it < vertices.size() - offset; ++it) {
46  triangularMesh.push_back({anker, it - 1, it});
47  }
48  // Close for centered reference point
49  if (centerLast) {
50  triangularMesh.push_back({anker, vertices.size() - 2, 0});
51  }
52  return {faces, triangularMesh};
53  }
54 
66  static std::pair<FaceVector, FaceVector> cylindricalFaceMesh(
67  const std::vector<Vector3>& vertices, bool fullTwoPi = true) {
68  FaceVector faces;
69  FaceVector triangularMesh;
70  size_t nqfaces = static_cast<size_t>(0.5 * vertices.size());
71  size_t reduce = (not fullTwoPi) ? 1 : 0;
72  for (size_t iface = 0; iface < nqfaces - reduce; ++iface) {
73  size_t p2 = (iface + 1 == nqfaces) ? 0 : iface + 1;
74  std::vector<size_t> face = {iface, p2, p2 + nqfaces, nqfaces + iface};
75  faces.push_back(face);
76  std::vector<size_t> triA = {iface, p2, p2 + nqfaces};
77  triangularMesh.push_back(triA);
78  std::vector<size_t> triB = {p2 + nqfaces, nqfaces + iface, iface};
79  triangularMesh.push_back(triB);
80  }
81  return {faces, triangularMesh};
82  }
83 };
84 
85 } // namespace detail
86 
87 } // namespace Acts