ECCE @ 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 
12 
14  size_t cvert = vertices.size();
15  vertices.insert(vertices.end(), other.vertices.begin(), other.vertices.end());
17  auto join = [&](std::vector<FaceType>& existing,
18  const std::vector<FaceType>& additional) -> void {
19  for (const auto& aface : additional) {
20  FaceType nface = aface;
21  std::transform(nface.begin(), nface.end(), nface.begin(),
22  [&](size_t x) { return (x + cvert); });
23  existing.push_back(nface);
24  }
25  };
26  // For faces and triangular mesh
27  join(faces, other.faces);
28  join(triangularMesh, other.triangularMesh);
29 }
30 
32  for_each(vertices.begin(), vertices.end(),
33  [&](auto& v) { v = transform * v; });
34 }
35 
37  Extent extent;
38  for (const auto& vtx : vertices) {
39  extent.check(transform * vtx);
40  }
41  // Special checks for binR:
42  if (std::abs(extent.range(binZ)) < s_onSurfaceTolerance) {
43  // Check inclusion of origin (i.e. convex around origin)
44  Vector3D origin = transform * Vector3D(0., 0., extent.medium(binZ));
45  for (const auto& face : faces) {
46  std::vector<Vector3D> tface;
47  tface.reserve(face.size());
48  for (auto f : face) {
49  tface.push_back(transform * vertices[f]);
50  }
51  if (detail::VerticesHelper::isInsidePolygon(origin, tface)) {
52  extent.ranges[binR].first = 0.;
53  break;
54  }
55  }
56  // Check for radial extent
57  auto radialDistance = [&](const Vector3D& pos1,
58  const Vector3D& pos2) -> double {
59  Vector2D p1(pos1.x(), pos1.y());
60  Vector2D p2(pos2.x(), pos2.y());
61 
62  Vector2D O(0, 0);
63  Vector2D p1p2 = (p2 - p1);
64  double L = p1p2.norm();
65  Vector2D p1O = (O - p1);
66 
67  // don't do division if L is very small
68  if (L < 1e-7) {
70  }
71  double f = p1p2.dot(p1O) / L;
72 
73  // clamp to [0, |p1p2|]
74  f = std::min(L, std::max(0., f));
75 
76  Vector2D closest = f * p1p2.normalized() + p1;
77  double dist = (closest - O).norm();
78 
79  return dist;
80  };
81 
82  for (size_t iv = 1; iv < vertices.size() + 1; ++iv) {
83  size_t fpoint = iv < vertices.size() ? iv : 0;
84  double testR = radialDistance(transform * vertices[fpoint],
85  transform * vertices[iv - 1]);
86  extent.ranges[binR].first = std::min(extent.ranges[binR].first, testR);
87  }
88  }
89  return extent;
90 }