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;
168 const std::vector<const Trk::Surface*>*
172 std::vector<const Trk::Surface*>* retsf =
173 new std::vector<const Trk::Surface*>;
196 for (
unsigned int iv = 0; iv < m_xyVtx.size(); iv++) {
197 if (iv != m_xyVtx.size() - 1)
198 retsf->push_back(sideSurf(
transform, iv, iv + 1));
200 retsf->push_back(sideSurf(
transform, iv, 0));
211 unsigned int iv2)
const
215 double xdif = m_xyVtx[iv2].first - m_xyVtx[iv1].first;
216 double ydif = m_xyVtx[iv2].second - m_xyVtx[iv1].second;
217 double xsize = sqrt(xdif * xdif + ydif * ydif);
219 double ori = m_ordering > 0 ? -1. : 1.;
222 0.5 * (m_xyVtx[iv1].
first + m_xyVtx[iv2].
first),
225 double phi = ori * ydif < 0 ?
M_PI / 2 : -
M_PI / 2;
226 if (ori > 0 && ydif > 0)
228 if (std::abs(xdif) > 1
e-6) {
257 return (m_combinedVolume->inside(
pos, tol));
265 #ifdef TRKDETDESCR_USEFLOATPRECISON
268 std::vector<std::pair<double, double>> triangles = TriangulatePolygonCheck(
270 std::vector<std::pair<double, double>> vertices;
271 #ifdef TRKDETDESCR_USEFLOATPRECISON
274 for (
unsigned int i = 0;
i < triangles.size();
i =
i + 3) {
275 vertices.push_back(triangles[
i]);
276 vertices.push_back(triangles[
i + 1]);
277 vertices.push_back(triangles[
i + 2]);
287 m_combinedVolume = cVol;
294 std::stringstream temp_sl;
295 temp_sl << std::setiosflags(std::ios::fixed);
296 temp_sl << std::setprecision(7);
297 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
298 temp_sl <<
"( " << m_halfZ <<
")";
299 for (
const auto & xyVtx : m_xyVtx)
300 temp_sl <<
"(" << xyVtx.first <<
"," << xyVtx.second <<
")";
308 std::stringstream temp_sl;
309 temp_sl << std::setiosflags(std::ios::fixed);
310 temp_sl << std::setprecision(7);
311 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
312 temp_sl <<
"( " << m_halfZ <<
")";
313 for (
const auto & myVtx : m_xyVtx)
314 temp_sl <<
"(" << myVtx.first <<
"," << myVtx.second <<
")";
332 #ifdef TRKDETDESCR_USEFLOATPRECISON
338 std::pair<double, double>
a,
339 std::pair<double, double>
b,
340 std::pair<double, double>
c)
const
344 double CrossZ = (
b.first -
a.first) * (
c.second -
a.second) -
345 (
c.first -
a.first) * (
b.second -
a.second);
347 return (CrossZ >= 0.);
349 return (CrossZ < 0.);
355 std::pair<double, double>
a,
356 std::pair<double, double>
b,
357 std::pair<double, double>
c,
358 std::pair<double, double>
d)
const
362 return Xor(Left(
a,
b,
c), Left(
a,
b,
d)) && Xor(Left(
c,
d,
a), Left(
c,
d,
b));
369 const std::vector<std::pair<double, double>>& inputVertices)
const
373 int iPlus1 = (
i + 1) % inputVertices.size();
374 int iMinus1 = (
i + inputVertices.size() - 1) % inputVertices.size();
377 if (Left(inputVertices[iMinus1], inputVertices[
i], inputVertices[iPlus1]))
378 return Left(inputVertices[
i], inputVertices[j], inputVertices[iMinus1]) &&
379 Left(inputVertices[j], inputVertices[
i], inputVertices[iPlus1]);
385 Left(inputVertices[
i], inputVertices[j], inputVertices[iPlus1]) &&
386 Left(inputVertices[j], inputVertices[
i], inputVertices[iMinus1]));
393 const std::vector<std::pair<double, double>>& inputVertices)
const
399 for (
int k = 0;
k < (
int)inputVertices.size();
k++) {
401 int kPlus1 = (
k + 1) % inputVertices.size();
404 if ((
k !=
i) && (kPlus1 !=
i) && (
k != j) && (kPlus1 != j))
409 inputVertices[kPlus1]))
419 const std::vector<std::pair<double, double>>& inputVertices)
const
424 return InCone(
i, j, inputVertices) && Diagonalie(
i, j, inputVertices);
427 std::vector<std::pair<double, double>>
429 const std::vector<std::pair<double, double>>&
Vertices)
const
443 std::vector<std::pair<double, double>> outTriangles;
444 std::vector<std::pair<double, double>> inputVertices;
445 inputVertices.reserve(NSize);
446 for (
int i = 0;
i < NSize;
i++)
457 return inputVertices;
460 int VerticesLeft = NSize;
461 while (VerticesLeft > 3) {
463 bool bCornerCut =
false;
464 for (
int i = 0;
i < VerticesLeft;
i++) {
467 if (iPlus1 == VerticesLeft)
469 int iPlus2 = (iPlus1 + 1);
470 if (iPlus2 == VerticesLeft)
473 if (Diagonal(
i, iPlus2, inputVertices)) {
475 outTriangles.push_back(inputVertices[
i]);
476 outTriangles.push_back(inputVertices[iPlus1]);
477 outTriangles.push_back(inputVertices[iPlus2]);
479 inputVertices.erase(inputVertices.begin() + iPlus1);
487 std::vector<std::pair<double, double>>
out;
492 if (VerticesLeft == 3) {
493 outTriangles.push_back(inputVertices[0]);
494 outTriangles.push_back(inputVertices[1]);
495 outTriangles.push_back(inputVertices[2]);
496 inputVertices.erase(inputVertices.begin() + 1);
503 std::vector<std::pair<double, double>>
505 const std::vector<std::pair<double, double>>&
Vertices)
512 if (m_ordering == -1)
514 std::vector<std::pair<double, double>> outTriangles =
516 if (outTriangles.empty()) {
517 m_ordering = -m_ordering + 1;
518 outTriangles = TriangulatePolygon(
Vertices);
523 #ifdef TRKDETDESCR_USEFLOATPRECISON