26#include "GeoModelKernel/GeoShapeShift.h"
27#include "GeoModelKernel/GeoShapeUnion.h"
28#include "GeoModelKernel/GeoTrd.h"
34 return std::make_unique<Amg::Transform3D>(trf);
37std::pair<bool, std::unique_ptr<Trk::Volume>>
52 if (std::abs((
a0.cross(a1).unit()).dot(b0.cross(b1).unit())) < 1.e-3) {
53 if (std::abs((
a0.cross(a1).unit()).dot(b1)) < 1.e-3)
55 else if (std::abs((
a0.cross(a1).unit()).dot(b0)) < 1.e-3)
61 if (std::abs(std::abs((
a0.cross(a1).unit()).dot(b0.cross(b1).unit())) -
63 return std::make_pair(
false,
nullptr);
91 return std::make_pair(
true,
nullptr);
95 std::unique_ptr<Trk::Volume> overlap;
97 auto spb = std::make_shared<Trk::SimplePolygonBrepVolumeBounds>(
result.xyVertices, 0.5 * (
result.maxZ -
result.minZ));
100 overlap = std::make_unique<Trk::Volume>(makeTransform(transf), spb);
102 return std::make_pair(
true, std::move(overlap));
105 return std::make_pair(
false,
nullptr);
113 pgA.
xyVertices.emplace_back(vtx.x(), vtx.y());
116 pgB.
xyVertices.emplace_back(vtx.x(), vtx.y());
119 for (
const std::pair<double, double>& vtx : pgA.
xyVertices) {
122 for (
const std::pair<double, double>& vtx : pgB.
xyVertices) {
126 for (
int ia = 0; ia < pgA.
nVtx; ia++) {
127 pgA.
edges.emplace_back(
131 for (
int ib = 0; ib < pgB.
nVtx; ib++) {
132 pgB.
edges.emplace_back(
137 std::vector<Trk::EdgeCross> edge_cross;
138 for (
int ia = 0; ia < pgA.
nVtx; ia++) {
139 for (
int ib = 0; ib < pgB.
nVtx; ib++) {
145 if (
rs == 0 && rpq == 0) {
157 if (
t0 > 0 &&
t0 < 1.)
158 edge_cross.emplace_back(
159 std::make_pair(ia, ib), std::make_pair(
t0, -1));
160 if (t1 > 0 && t1 < 1.)
161 edge_cross.emplace_back(
162 std::make_pair(ia, ib), std::make_pair(t1, -1));
163 }
else if (
rs != 0 && qps /
rs > 0 && qps /
rs < 1 &&
164 rpq /
rs > 0 && rpq /
rs < 1) {
165 edge_cross.emplace_back(std::make_pair(ia, ib),
166 std::make_pair(qps /
rs, rpq /
rs));
171 std::vector<Trk::EdgeCross> setVtx;
172 for (
int ia = 0; ia < pgA.
nVtx; ia++) {
174 setVtx.emplace_back(std::make_pair(ia, -1),
175 std::make_pair(0., -1.));
177 if (ie.edge_id.first == ia) {
178 if (!setVtx.empty() && setVtx.back().edge_id.first == ia &&
179 setVtx.back().edge_pos.first > ie.edge_pos.first)
180 setVtx.insert(setVtx.end() - 1, ie);
182 setVtx.push_back(ie);
187 for (
int ib = 0; ib < pgB.
nVtx; ib++) {
189 int nlow = ib == 0 ? pgB.
nVtx : ib - 1;
191 std::vector<Trk::EdgeCross>::iterator it = setVtx.begin();
192 std::vector<Trk::EdgeCross>::iterator itb = setVtx.end();
193 while (it != setVtx.end()) {
194 if ((*it).edge_id.second == nlow) {
195 if (itb == setVtx.end() ||
196 (*it).edge_pos.second > (*itb).edge_pos.second)
203 std::make_pair(ib, -2),
215 pgon.
nVtx = setVtx.size() < 3 ? 0 : setVtx.size();
220 for (
auto vtx : setVtx) {
221 if (vtx.edge_id.second == -1)
223 else if (vtx.edge_id.second == -2)
229 pgA.
edges[vtx.edge_id.first].second};
231 pgon.
xyVertices.emplace_back(vint.x(), vint.y());
254 bool isPolygon = (box || trd || prism || spb || trdd);
262 std::vector<Amg::Vector3D> vtxLocal;
292 }
else if (
swap == 2) {
322 cache.
vertices.push_back(std::move(vtx));
364 const std::vector<std::pair<double, double>> vtcs = prism->
xyVertices();
365 for (
const auto& vtc : vtcs)
366 vtxLocal.emplace_back(vtc.first, vtc.second, prism->
halflengthZ());
367 cache.
nVtx = vtcs.size();
370 const std::vector<std::pair<double, double>> vtcs = spb->
xyVertices();
371 for (
const auto& vtc : vtcs)
372 vtxLocal.emplace_back(vtc.first, vtc.second, spb->
halflengthZ());
373 cache.
nVtx = vtcs.size();
381 cache.
vertices.push_back(std::move(vtx));
388 const std::pair<double, double>& vtx,
389 const std::vector<std::pair<double, double>>& pgon) {
393 size_t nv = pgon.size();
394 for (
size_t i = 0, k = nv - 1; i < nv; k = i++) {
395 if ((pgon[i].second > vtx.second) != (pgon[k].second > vtx.second)) {
396 double ctg = (pgon[k].first - pgon[i].first) /
397 (pgon[k].second - pgon[i].second);
399 (vtx.second - pgon[i].second) * ctg + pgon[i].first);
406 const std::pair<double, double>& b,
410 return (
a.first * b.first +
a.second * b.second);
412 return (
a.first * b.second -
a.second * b.first);
415std::pair<bool, std::unique_ptr<Trk::Volume>>
433 double distance_center = (volA.
center() - volB.
center()).norm();
434 if (distance_center >
437 return std::make_pair(
true,
nullptr);
447 if (std::abs((b0.cross(b1).unit()).dot(
a0.cross(a1).unit())) < 1.e-3) {
448 if (std::abs((b0.cross(b1).unit()).dot(a1)) < 1.e-3)
450 else if (std::abs((b0.cross(b1).unit()).dot(
a0)) < 1.e-3)
456 if (std::abs(std::abs((b0.cross(b1).unit()).dot(
a0.cross(a1).unit())) -
458 return std::make_pair(
false,
nullptr);
463 if (norm.z() != 1.) {
487 return std::make_pair(
true,
nullptr);
491 std::unique_ptr<Trk::Volume> overlap{};
493 auto spb = std::make_shared<Trk::SimplePolygonBrepVolumeBounds>(
result.xyVertices,
497 overlap = std::make_unique<Trk::Volume>(makeTransform(transf), spb);
499 return std::make_pair(
true, std::move(overlap));
502 return std::make_pair(
false,
nullptr);
void swap(DataVector< T > &a, DataVector< T > &b)
See DataVector<T, BASE>::swap().
Bounds for a cubical Volume, the decomposeToSurfaces method creates a vector of 6 surfaces:
double halflengthX() const
This method returns the halflength in local x.
double halflengthY() const
This method returns the halflength in local y.
double halflengthZ() const
This method returns the halflength in local z.
Bounds for a cylindrical Volume, the decomposeToSurfaces method creates a vector of up to 6 surfaces:
double halflengthZ() const
This method returns the halflengthZ.
double outerRadius() const
This method returns the outer radius.
Bounds for a double trapezoidal shaped Volume, the decomposeToSurfaces method creates a vector of 8 s...
double minHalflengthX() const
This method returns the X halflength at minimal Y.
double halflengthZ() const
This method returns the halflength in local z.
double halflengthY1() const
This method returns the halflength1 in local y.
double halflengthY2() const
This method returns the halflength2 in local y.
double maxHalflengthX() const
This method returns the X halflength at maximal Y (local coordinates)
double medHalflengthX() const
This method returns the (maximal) halflength in local x.
Bounds for the transcript of triangular prism.
const std::vector< std::pair< double, double > > & xyVertices() const
This method returns the set of xy generating vertices.
double halflengthZ() const
This method returns the halflength in local z.
Bounds for the exact transcript of the GeoSimplePolygonBrep; volume defined by combination of symm....
double halflengthZ() const
This method returns the halflength in local z.
const std::vector< std::pair< double, double > > & xyVertices() const
This method returns the set of xy generating vertices.
Bounds for a trapezoidal shaped Volume, the decomposeToSurfaces method creates a vector of 6 surfaces...
double halflengthZ() const
This method returns the halflength in local z.
double minHalflengthX() const
This method returns the minimal halflength in local x.
double halflengthY() const
This method returns the halflength in local y.
double maxHalflengthX() const
This method returns the maximal halflength in local x.
static std::pair< bool, std::unique_ptr< Trk::Volume > > intersect(const Volume &volA, const Volume &volB)
static std::pair< bool, std::unique_ptr< Trk::Volume > > intersectApproximative(const Volume &volA, const Volume &volB)
static Trk::PolygonCache intersectPgon(Trk::PolygonCache &, Trk::PolygonCache &)
static PolygonCache polygonXY(const Volume &inVol, int swap=0)
static double det(const std::pair< double, double > &a, const std::pair< double, double > &b, bool)
static bool inside(const std::pair< double, double > &vtx, const std::vector< std::pair< double, double > > &pgon)
Base class for all volumes inside the tracking realm, it defines the interface for inherited Volume c...
const Amg::Vector3D & center() const
returns the center of the volume
const Amg::Transform3D & transform() const
Return methods for geometry transform.
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
Eigen::AngleAxisd AngleAxis3D
Amg::Transform3D getRotateZ3D(double angle)
get a rotation transformation around Z-axis
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Amg::Transform3D getRotateY3D(double angle)
get a rotation transformation around Y-axis
Eigen::Translation< double, 3 > Translation3D
std::unique_ptr< Amg::Transform3D > makeTransform(const Amg::Transform3D &trf)
std::vector< std::pair< double, double > > xyVertices
std::vector< Amg::Vector3D > vertices
std::vector< std::pair< double, double > > edges
std::vector< bool > commonVertices