From 5922c749937ab1e9c1d92537af8aba95177de42f Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Mon, 15 Jan 2024 17:16:27 +0100 Subject: [PATCH] AssimWriter: implement facetIsDegenerated function --- DDCAD/include/DDCAD/Utilities.h | 24 ++++++++++++++++++++++++ DDCAD/src/ASSIMPWriter.cpp | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/DDCAD/include/DDCAD/Utilities.h b/DDCAD/include/DDCAD/Utilities.h index 325a5c408..6e12f0401 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 + #include #include + /// 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 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 82c692ded..f31219174 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