EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Polyhedron.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Polyhedron.cpp
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 
10 
13 
14 #include <algorithm>
15 
17  size_t cvert = vertices.size();
18  vertices.insert(vertices.end(), other.vertices.begin(), other.vertices.end());
20  auto join = [&](std::vector<FaceType>& existing,
21  const std::vector<FaceType>& additional) -> void {
22  for (const auto& aface : additional) {
23  FaceType nface = aface;
24  std::transform(nface.begin(), nface.end(), nface.begin(),
25  [&](size_t x) { return (x + cvert); });
26  existing.push_back(nface);
27  }
28  };
29  // For faces and triangular mesh
30  join(faces, other.faces);
31  join(triangularMesh, other.triangularMesh);
32 }
33 
35  for_each(vertices.begin(), vertices.end(),
36  [&](auto& v) { v = transform * v; });
37 }
38 
40  Extent extent;
41  auto vtxs = vertices;
42  std::transform(vtxs.begin(), vtxs.end(), vtxs.begin(), [&](auto& v) {
43  auto vt = (transform * v);
44  extent.check(vt);
45  return (vt);
46  });
47 
48  // Special checks of binR for hyper plane surfaces
50  // Check inclusion of origin (i.e. convex around origin)
51  Vector3D origin = transform * Vector3D(0., 0., extent.medium(binZ));
52  for (const auto& face : faces) {
53  std::vector<Vector3D> tface;
54  tface.reserve(face.size());
55  for (auto f : face) {
56  tface.push_back(vtxs[f]);
57  }
58  if (detail::VerticesHelper::isInsidePolygon(origin, tface)) {
59  extent.ranges[binR].first = 0.;
60  extent.ranges[binPhi].first = -M_PI;
61  extent.ranges[binPhi].second = M_PI;
62  break;
63  }
64  }
65  if (exact) {
66  // Check for radial extend in 2D
67  auto radialDistance = [&](const Vector3D& pos1,
68  const Vector3D& pos2) -> double {
69  Vector2D O(0, 0);
70  Vector2D p1p2 = (pos2.block<2, 1>(0, 0) - pos1.block<2, 1>(0, 0));
71  double L = p1p2.norm();
72  Vector2D p1O = (O - pos1.block<2, 1>(0, 0));
73 
74  // Don't try parallel lines
75  if (L < 1e-7) {
77  }
78  double f = p1p2.dot(p1O) / L;
79 
80  // Clamp to [0, |p1p2|]
81  f = std::min(L, std::max(0., f));
82  Vector2D closest = f * p1p2.normalized() + pos1.block<2, 1>(0, 0);
83  double dist = (closest - O).norm();
84  return dist;
85  };
86 
87  for (size_t iv = 1; iv < vtxs.size() + 1; ++iv) {
88  size_t fpoint = iv < vtxs.size() ? iv : 0;
89  double testR = radialDistance(vtxs[fpoint], vtxs[iv - 1]);
90  extent.ranges[binR].first = std::min(extent.ranges[binR].first, testR);
91  }
92  }
93  }
94  return extent;
95 }