21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/SystemOfUnits.h"
34 , m_combinedVolume(nullptr)
43 const 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;
78 std::make_unique<Amg::Transform3D>(transXY),
79 std::make_shared<Trk::CuboidVolumeBounds>(ehalfX, ehalfY,
m_halfZ));
85 const 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);
120 std::make_unique<Amg::Transform3D>(transXY),
121 std::make_shared<Trk::CuboidVolumeBounds>(ehalfX, ehalfY,
m_halfZ));
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 std::vector<std::unique_ptr<Trk::Surface>>
173 auto retsf = std::vector<std::unique_ptr<Trk::Surface>>();
180 std::make_shared<Trk::RectangleBounds>(m_halfX, m_halfY));
182 std::make_shared<const Trk::VolumeExcluder>(
183 std::make_unique<Trk::Volume>(
189 retsf.push_back(std::make_unique<Trk::SubtractedPlaneSurface>(xymPlane, std::move(volExcl),
true));
193 std::make_shared<Trk::RectangleBounds>(m_halfX, m_halfY)
196 volExcl = std::make_shared<const Trk::VolumeExcluder>(
197 std::make_unique<Trk::Volume>(*m_combinedVolume,
201 retsf.push_back(std::make_unique<Trk::SubtractedPlaneSurface>(xyPlane, std::move(volExcl),
true));
204 for (
unsigned int iv = 0; iv < m_xyVtx.size(); iv++) {
205 if (iv != m_xyVtx.size() - 1)
206 retsf.push_back(sideSurf(
transform, iv, iv + 1));
208 retsf.push_back(sideSurf(
transform, iv, 0));
215 std::unique_ptr<Trk::PlaneSurface>
219 unsigned int iv2)
const
221 std::unique_ptr<Trk::PlaneSurface> plane =
nullptr;
223 double xdif = m_xyVtx[iv2].first - m_xyVtx[iv1].first;
224 double ydif = m_xyVtx[iv2].second - m_xyVtx[iv1].second;
225 double xsize = sqrt(xdif * xdif + ydif * ydif);
227 double ori = m_ordering > 0 ? -1. : 1.;
230 0.5 * (m_xyVtx[iv1].
first + m_xyVtx[iv2].
first),
233 double phi = ori * ydif < 0 ?
M_PI / 2 : -
M_PI / 2;
234 if (ori > 0 && ydif > 0)
236 if (std::abs(xdif) > 1
e-6) {
246 plane = std::make_unique<Trk::PlaneSurface>(tr, std::make_shared<Trk::RectangleBounds>(0.5 * xsize, m_halfZ));
264 return (m_combinedVolume->inside(
pos, tol));
271 std::unique_ptr<Trk::Volume> cVol;
272 std::vector<std::pair<double, double>> triangles = TriangulatePolygonCheck(m_xyVtx);
273 std::vector<std::pair<double, double>> vertices;
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]);
278 auto newVol = std::make_unique<Trk::Volume>(
nullptr, std::make_shared<Trk::PrismVolumeBounds>(vertices, m_halfZ));
280 cVol = std::make_unique<Trk::Volume>(
nullptr, std::make_shared<Trk::CombinedVolumeBounds>(std::move(cVol),
285 cVol = std::move(newVol);
289 m_combinedVolume = cVol.release();
296 std::stringstream temp_sl;
297 temp_sl << std::setiosflags(std::ios::fixed);
298 temp_sl << std::setprecision(7);
299 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
300 temp_sl <<
"( " << m_halfZ <<
")";
301 for (
const auto & xyVtx : m_xyVtx)
302 temp_sl <<
"(" << xyVtx.first <<
"," << xyVtx.second <<
")";
310 std::stringstream temp_sl;
311 temp_sl << std::setiosflags(std::ios::fixed);
312 temp_sl << std::setprecision(7);
313 temp_sl <<
"Trk::SimplePolygonBrepVolumeBounds: (halfZ, xy vertices) = ";
314 temp_sl <<
"( " << m_halfZ <<
")";
315 for (
const auto & myVtx : m_xyVtx)
316 temp_sl <<
"(" << myVtx.first <<
"," << myVtx.second <<
")";
334 #ifdef TRKDETDESCR_USEFLOATPRECISON
340 std::pair<double, double>
a,
341 std::pair<double, double>
b,
342 std::pair<double, double>
c)
const
346 double CrossZ = (
b.first -
a.first) * (
c.second -
a.second) -
347 (
c.first -
a.first) * (
b.second -
a.second);
349 return (CrossZ >= 0.);
351 return (CrossZ < 0.);
357 std::pair<double, double>
a,
358 std::pair<double, double>
b,
359 std::pair<double, double>
c,
360 std::pair<double, double>
d)
const
364 return Xor(Left(
a,
b,
c), Left(
a,
b,
d)) && Xor(Left(
c,
d,
a), Left(
c,
d,
b));
371 const std::vector<std::pair<double, double>>& inputVertices)
const
375 int iPlus1 = (
i + 1) % inputVertices.size();
376 int iMinus1 = (
i + inputVertices.size() - 1) % inputVertices.size();
379 if (Left(inputVertices[iMinus1], inputVertices[
i], inputVertices[iPlus1]))
380 return Left(inputVertices[
i], inputVertices[j], inputVertices[iMinus1]) &&
381 Left(inputVertices[j], inputVertices[
i], inputVertices[iPlus1]);
387 Left(inputVertices[
i], inputVertices[j], inputVertices[iPlus1]) &&
388 Left(inputVertices[j], inputVertices[
i], inputVertices[iMinus1]));
395 const std::vector<std::pair<double, double>>& inputVertices)
const
401 for (
int k = 0;
k < (
int)inputVertices.size();
k++) {
403 int kPlus1 = (
k + 1) % inputVertices.size();
406 if ((
k !=
i) && (kPlus1 !=
i) && (
k != j) && (kPlus1 != j))
411 inputVertices[kPlus1]))
421 const std::vector<std::pair<double, double>>& inputVertices)
const
426 return InCone(
i, j, inputVertices) && Diagonalie(
i, j, inputVertices);
429 std::vector<std::pair<double, double>>
431 const std::vector<std::pair<double, double>>&
Vertices)
const
445 std::vector<std::pair<double, double>> outTriangles;
446 std::vector<std::pair<double, double>> inputVertices;
447 inputVertices.reserve(NSize);
448 for (
int i = 0;
i < NSize;
i++)
459 return inputVertices;
462 int VerticesLeft = NSize;
463 while (VerticesLeft > 3) {
465 bool bCornerCut =
false;
466 for (
int i = 0;
i < VerticesLeft;
i++) {
469 if (iPlus1 == VerticesLeft)
471 int iPlus2 = (iPlus1 + 1);
472 if (iPlus2 == VerticesLeft)
475 if (Diagonal(
i, iPlus2, inputVertices)) {
477 outTriangles.push_back(inputVertices[
i]);
478 outTriangles.push_back(inputVertices[iPlus1]);
479 outTriangles.push_back(inputVertices[iPlus2]);
481 inputVertices.erase(inputVertices.begin() + iPlus1);
489 std::vector<std::pair<double, double>>
out;
494 if (VerticesLeft == 3) {
495 outTriangles.push_back(inputVertices[0]);
496 outTriangles.push_back(inputVertices[1]);
497 outTriangles.push_back(inputVertices[2]);
498 inputVertices.erase(inputVertices.begin() + 1);
505 std::vector<std::pair<double, double>>
507 const std::vector<std::pair<double, double>>&
Vertices)
514 if (m_ordering == -1)
516 std::vector<std::pair<double, double>> outTriangles =
518 if (outTriangles.empty()) {
519 m_ordering = -m_ordering + 1;
520 outTriangles = TriangulatePolygon(
Vertices);
525 #ifdef TRKDETDESCR_USEFLOATPRECISON