diff --git a/DDCAD/include/DDCAD/Utilities.h b/DDCAD/include/DDCAD/Utilities.h index 325a5c408ba8c010e593c6b0a9995b7d3af89341..6e12f04017851e08c82d16600b2e9e636fc60d6e 100644 --- a/DDCAD/include/DDCAD/Utilities.h +++ b/DDCAD/include/DDCAD/Utilities.h @@ -13,8 +13,11 @@ #ifndef DDCAD_UTILITIES_H #define DDCAD_UTILITIES_H +#include <vector> + #include <TGeoTessellated.h> #include <TGeoVector3.h> + /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -47,6 +50,27 @@ namespace dd4hep { str << "{" << v1 << ", " << v2 << ", " << v3 << "}"; return str; } + + // Determine if the facet is degenerated by calculating its determinant + inline bool facetIsDegenerated(std::vector<ROOT::Geom::Vertex_t> const& vertices){ + const ROOT::Geom::Vertex_t& v1 = vertices[0]; + const ROOT::Geom::Vertex_t& v2 = vertices[1]; + const ROOT::Geom::Vertex_t& v3 = vertices[2]; + constexpr double epsilon = 1.e-20; + // v1.x v2.x v3.x v1.x v2.x + // + // v1.y v2.y v3.y v1.y v2.y + // + // v1.z v2.z v3.z v1.z v2.z + double det = 0.0 + + v1.x() * v2.y() * v3.z() + + v2.x() * v3.y() * v1.z() + + v3.x() * v1.y() * v2.z() + - v1.z() * v2.y() * v3.x() + - v2.z() * v3.y() * v1.x() + - v3.z() * v1.y() * v2.x(); + return det < epsilon; + } } } #endif diff --git a/DDCAD/src/ASSIMPWriter.cpp b/DDCAD/src/ASSIMPWriter.cpp index 82c692ded977c2ae389cdc01edefc5a3396f4db0..f31219174ca5e269999362260279efd2744d852c 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -158,15 +158,17 @@ namespace { ++nskip; continue; } -#if ROOT_VERSION_CODE < ROOT_VERSION(6,31,1) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + bool degenerated = dd4hep::cad::facetIsDegenerated(vertices); +#else bool degenerated = true; TGeoFacet f(&vertices, 3, vv0, vv1, vv2); f.ComputeNormal(degenerated); +#endif if ( degenerated ) { ++nskip; continue; } -#endif tes->AddFacet(vv0, vv1, vv2); } #else