21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/SystemOfUnits.h"
34 , m_combinedVolume(nullptr)
43 std::vector<std::pair<float, float>> xyVtx,
50 , m_combinedVolume(nullptr)
55 double xmin = xyVtx[0].first;
57 double ymin = xyVtx[0].second;
59 for (
unsigned int i = 0;
i < xyVtx.size();
i++) {
62 xmin = xyVtx[
i].first;
64 xmax = xyVtx[
i].first;
66 ymin = xyVtx[
i].second;
68 ymax = xyVtx[
i].second;
85 std::vector<std::pair<double, double>> xyVtx,
92 , m_combinedVolume(nullptr)
97 double xmin = xyVtx[0].first;
99 double ymin = xyVtx[0].second;
101 for (
unsigned int i = 0;
i < xyVtx.size();
i++) {
104 xmin = xyVtx[
i].first;
106 xmax = xyVtx[
i].first;
108 ymin = xyVtx[
i].second;
110 ymax = xyVtx[
i].second;
112 double ehalfX = 0.5 * (
xmax -
xmin);
113 double ehalfY = 0.5 * (
ymax -
ymin);
129 , m_halfX(trabo.m_halfX)
130 , m_halfY(trabo.m_halfY)
131 , m_halfZ(trabo.m_halfZ)
132 , m_ordering(trabo.m_ordering)
133 , m_combinedVolume(trabo.m_combinedVolume->
clone())
134 , m_envelope(trabo.m_envelope->
clone())
135 , m_objectAccessor(trabo.m_objectAccessor)
138 for (
unsigned int i = 0;
i <
m_xyVtx.size();
i++)
144 delete m_combinedVolume;
152 if (
this != &trabo) {
157 m_xyVtx.resize(trabo.
m_xyVtx.size());
158 for (
unsigned int i = 0;
i < m_xyVtx.size();
i++)
160 delete m_combinedVolume;
169 const std::vector<const Trk::Surface*>*
173 std::vector<const Trk::Surface*>* retsf =
174 new std::vector<const Trk::Surface*>;
197 for (
unsigned int iv = 0; iv < m_xyVtx.size(); iv++) {
198 if (iv != m_xyVtx.size() - 1)
199 retsf->push_back(sideSurf(
transform, iv, iv + 1));
201 retsf->push_back(sideSurf(
transform, iv, 0));
212 unsigned int iv2)
const
216 double xdif = m_xyVtx[iv2].first - m_xyVtx[iv1].first;
217 double ydif = m_xyVtx[iv2].second - m_xyVtx[iv1].second;
218 double xsize = sqrt(xdif * xdif + ydif * ydif);
220 double ori = m_ordering > 0 ? -1. : 1.;
223 0.5 * (m_xyVtx[iv1].
first + m_xyVtx[iv2].
first),
226 double phi = ori * ydif < 0 ?
M_PI / 2 : -
M_PI / 2;
227 if (ori > 0 && ydif > 0)
229 if (std::abs(xdif) > 1
e-6) {
258 return (m_combinedVolume->inside(
pos, tol));
266 #ifdef TRKDETDESCR_USEFLOATPRECISON
269 std::vector<std::pair<double, double>> triangles = TriangulatePolygonCheck(
271 std::vector<std::pair<double, double>> vertices;
272 #ifdef TRKDETDESCR_USEFLOATPRECISON
275 for (
unsigned int i = 0;
i < triangles.size();
i =
i + 3) {
276 vertices.push_back(triangles[
i]);
277 vertices.push_back(triangles[
i + 1]);
278 vertices.push_back(triangles[
i + 2]);
288 m_combinedVolume = cVol;
295 std::stringstream temp_sl;
296 temp_sl << std::setiosflags(std::ios::fixed);
297 temp_sl << std::setprecision(7);
298 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
299 temp_sl <<
"( " << m_halfZ <<
")";
300 for (
const auto & xyVtx : m_xyVtx)
301 temp_sl <<
"(" << xyVtx.first <<
"," << xyVtx.second <<
")";
309 std::stringstream temp_sl;
310 temp_sl << std::setiosflags(std::ios::fixed);
311 temp_sl << std::setprecision(7);
312 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
313 temp_sl <<
"( " << m_halfZ <<
")";
314 for (
const auto & myVtx : m_xyVtx)
315 temp_sl <<
"(" << myVtx.first <<
"," << myVtx.second <<
")";
333 #ifdef TRKDETDESCR_USEFLOATPRECISON
339 std::pair<double, double>
a,
340 std::pair<double, double>
b,
341 std::pair<double, double>
c)
const
345 double CrossZ = (
b.first -
a.first) * (
c.second -
a.second) -
346 (
c.first -
a.first) * (
b.second -
a.second);
348 return (CrossZ >= 0.);
350 return (CrossZ < 0.);
356 std::pair<double, double>
a,
357 std::pair<double, double>
b,
358 std::pair<double, double>
c,
359 std::pair<double, double>
d)
const
363 return Xor(Left(
a,
b,
c), Left(
a,
b,
d)) && Xor(Left(
c,
d,
a), Left(
c,
d,
b));
370 const std::vector<std::pair<double, double>>& inputVertices)
const
374 int iPlus1 = (
i + 1) % inputVertices.size();
375 int iMinus1 = (
i + inputVertices.size() - 1) % inputVertices.size();
378 if (Left(inputVertices[iMinus1], inputVertices[
i], inputVertices[iPlus1]))
379 return Left(inputVertices[
i], inputVertices[j], inputVertices[iMinus1]) &&
380 Left(inputVertices[j], inputVertices[
i], inputVertices[iPlus1]);
386 Left(inputVertices[
i], inputVertices[j], inputVertices[iPlus1]) &&
387 Left(inputVertices[j], inputVertices[
i], inputVertices[iMinus1]));
394 const std::vector<std::pair<double, double>>& inputVertices)
const
400 for (
int k = 0;
k < (
int)inputVertices.size();
k++) {
402 int kPlus1 = (
k + 1) % inputVertices.size();
405 if ((
k !=
i) && (kPlus1 !=
i) && (
k != j) && (kPlus1 != j))
410 inputVertices[kPlus1]))
420 const std::vector<std::pair<double, double>>& inputVertices)
const
425 return InCone(
i, j, inputVertices) && Diagonalie(
i, j, inputVertices);
428 std::vector<std::pair<double, double>>
430 const std::vector<std::pair<double, double>>&
Vertices)
const
444 std::vector<std::pair<double, double>> outTriangles;
445 std::vector<std::pair<double, double>> inputVertices;
446 inputVertices.reserve(NSize);
447 for (
int i = 0;
i < NSize;
i++)
458 return inputVertices;
461 int VerticesLeft = NSize;
462 while (VerticesLeft > 3) {
464 bool bCornerCut =
false;
465 for (
int i = 0;
i < VerticesLeft;
i++) {
468 if (iPlus1 == VerticesLeft)
470 int iPlus2 = (iPlus1 + 1);
471 if (iPlus2 == VerticesLeft)
474 if (Diagonal(
i, iPlus2, inputVertices)) {
476 outTriangles.push_back(inputVertices[
i]);
477 outTriangles.push_back(inputVertices[iPlus1]);
478 outTriangles.push_back(inputVertices[iPlus2]);
480 inputVertices.erase(inputVertices.begin() + iPlus1);
488 std::vector<std::pair<double, double>>
out;
493 if (VerticesLeft == 3) {
494 outTriangles.push_back(inputVertices[0]);
495 outTriangles.push_back(inputVertices[1]);
496 outTriangles.push_back(inputVertices[2]);
497 inputVertices.erase(inputVertices.begin() + 1);
504 std::vector<std::pair<double, double>>
506 const std::vector<std::pair<double, double>>&
Vertices)
513 if (m_ordering == -1)
515 std::vector<std::pair<double, double>> outTriangles =
517 if (outTriangles.empty()) {
518 m_ordering = -m_ordering + 1;
519 outTriangles = TriangulatePolygon(
Vertices);
524 #ifdef TRKDETDESCR_USEFLOATPRECISON