21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/SystemOfUnits.h"
43 const std::vector<std::pair<float, float>>& xyVtx,
55 double xmin = xyVtx[0].first;
57 double ymin = xyVtx[0].second;
59 for (
unsigned int i = 0; i < xyVtx.size(); i++) {
61 if (xyVtx[i].first <
xmin)
62 xmin = xyVtx[i].first;
63 if (xyVtx[i].first >
xmax)
64 xmax = xyVtx[i].first;
65 if (xyVtx[i].second <
ymin)
66 ymin = xyVtx[i].second;
67 if (xyVtx[i].second >
ymax)
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,
97 double xmin = xyVtx[0].first;
99 double ymin = xyVtx[0].second;
101 for (
unsigned int i = 0; i < xyVtx.size(); i++) {
103 if (xyVtx[i].first <
xmin)
104 xmin = xyVtx[i].first;
105 if (xyVtx[i].first >
xmax)
106 xmax = xyVtx[i].first;
107 if (xyVtx[i].second <
ymin)
108 ymin = xyVtx[i].second;
109 if (xyVtx[i].second >
ymax)
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));
138 for (
unsigned int i = 0; i <
m_xyVtx.size(); i++)
152 if (
this != &trabo) {
158 for (
unsigned int i = 0; i <
m_xyVtx.size(); i++)
169std::vector<std::unique_ptr<Trk::Surface>>
173 auto retsf = std::vector<std::unique_ptr<Trk::Surface>>();
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));
196 volExcl = std::make_shared<const Trk::VolumeExcluder>(
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++) {
206 retsf.push_back(
sideSurf(transform, iv, iv + 1));
208 retsf.push_back(
sideSurf(transform, iv, 0));
215std::unique_ptr<Trk::PlaneSurface>
219 unsigned int iv2)
const
221 std::unique_ptr<Trk::PlaneSurface> plane =
nullptr;
225 double xsize = sqrt(xdif * xdif + ydif * ydif);
233 double phi = ori * ydif < 0 ?
M_PI / 2 : -
M_PI / 2;
234 if (ori > 0 && ydif > 0)
236 if (std::abs(xdif) > 1e-6) {
237 phi = std::atan(ydif / xdif);
246 plane = std::make_unique<Trk::PlaneSurface>(tr, std::make_shared<Trk::RectangleBounds>(0.5 * xsize,
m_halfZ));
271 std::unique_ptr<Trk::Volume> cVol;
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);
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
429std::vector<std::pair<double, double>>
431 const std::vector<std::pair<double, double>>& Vertices)
const
444 int NSize = Vertices.size();
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++)
449 inputVertices.push_back((Vertices)[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);
505std::vector<std::pair<double, double>>
507 const std::vector<std::pair<double, double>>& Vertices)
516 std::vector<std::pair<double, double>> outTriangles =
518 if (outTriangles.empty()) {
525#ifdef TRKDETDESCR_USEFLOATPRECISON
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
Bounds for the exact transcript of the GeoSimplePolygonBrep; volume defined by combination of symm....
double m_halfZ
halflength in z
double m_halfX
halflength in x - to define enclosing rectangle
int m_ordering
-1 not set/ 1 anticlockwise / 0 clockwise
SimplePolygonBrepVolumeBounds * clone() const override final
Virtual constructor.
std::vector< std::pair< double, double > > TriangulatePolygon(const std::vector< std::pair< double, double > > &Vertices) const
static bool Xor(bool x, bool y)
std::unique_ptr< Trk::PlaneSurface > sideSurf(const Amg::Transform3D &, unsigned int, unsigned int) const
virtual std::vector< std::unique_ptr< Trk::Surface > > decomposeToSurfaces(const Amg::Transform3D &transform) override final
Method to decompose the Bounds into Surfaces.
MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
SimplePolygonBrepVolumeBounds()
Default Constructor.
bool Diagonalie(int i, int j, const std::vector< std::pair< double, double > > &inputVertices) const
bool Diagonal(int i, int j, const std::vector< std::pair< double, double > > &inputVertices) const
bool Left(std::pair< double, double > a, std::pair< double, double > b, std::pair< double, double > c) const
Trk::EightObjectsAccessor m_objectAccessor
There's only one single object Acessor for the moment has to be implemented if Cuboids are used more ...
virtual ~SimplePolygonBrepVolumeBounds()
Destructor.
const Trk::Volume * m_envelope
simplified envelope
const Trk::Volume * m_combinedVolume
triangulated polygon
bool inside(const Amg::Vector3D &, double tol=0.) const override final
This method checks if position in the 3D volume frame is inside the volume.
std::vector< std::pair< double, double > > TriangulatePolygonCheck(const std::vector< std::pair< double, double > > &Vertices)
double m_halfY
halflength in y - to define enclosing rectangle
std::vector< std::pair< double, double > > m_xyVtx
generating xy vertices
SimplePolygonBrepVolumeBounds & operator=(const SimplePolygonBrepVolumeBounds &bobo)
Assignment operator.
bool InCone(int i, int j, const std::vector< std::pair< double, double > > &inputVertices) const
bool Intersect(std::pair< double, double > a, std::pair< double, double > b, std::pair< double, double > c, std::pair< double, double > d) const
VolumeBounds()
Default Constructor.
Base class for all volumes inside the tracking realm, it defines the interface for inherited Volume c...
virtual Volume * clone() const
polymorpic deep copy
Eigen::AngleAxisd AngleAxis3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D