From 11aa3392f65175f6c73bbad0c16e281d66b2d7d5 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Wed, 17 Jan 2024 14:25:06 +0100
Subject: [PATCH] Correctly handle quadrilinear facets in tessellated shapes.

---
 DDCAD/include/DDCAD/Utilities.h | 20 --------------------
 DDCAD/src/ASSIMPReader.cpp      |  7 ++++++-
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/DDCAD/include/DDCAD/Utilities.h b/DDCAD/include/DDCAD/Utilities.h
index 1b0a86f08..a7e8f511d 100644
--- a/DDCAD/include/DDCAD/Utilities.h
+++ b/DDCAD/include/DDCAD/Utilities.h
@@ -54,25 +54,6 @@ namespace dd4hep {
     }
     // Determine if the facet is degenerated by calculating its determinant
     inline bool facetIsDegenerated(std::vector<ROOT::Geom::Vertex_t> const& vertices){
-#if 0
-      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 = std::numeric_limits<double>::epsilon();
-      // 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 std::fabs(det) < epsilon;
-#else
       using ROOT::Geom::Vertex_t;
       // Compute normal using non-zero segments
       constexpr double kTolerance = 1.e-20;
@@ -99,7 +80,6 @@ namespace dd4hep {
           break;
       }
       return degenerated;
-#endif
     }
   }
 }
diff --git a/DDCAD/src/ASSIMPReader.cpp b/DDCAD/src/ASSIMPReader.cpp
index 78e9e7f5c..03b9166f5 100644
--- a/DDCAD/src/ASSIMPReader.cpp
+++ b/DDCAD/src/ASSIMPReader.cpp
@@ -117,7 +117,12 @@ ASSIMPReader::readVolumes(const std::string& source, double unit_length)  const
       ///       assigns the proper indices to the facet.
       for(unsigned int i=0; i < mesh->mNumFaces; i++)  {
         const unsigned int* idx  = mesh->mFaces[i].mIndices;
-        bool degenerated = dd4hep::cad::facetIsDegenerated({vertices[idx[0]], vertices[idx[1]], vertices[idx[2]]});
+        bool degenerated = false;
+        if ( mesh->mFaces[i].mNumIndices == 3 )
+          degenerated = dd4hep::cad::facetIsDegenerated({vertices[idx[0]], vertices[idx[1]], vertices[idx[2]]});
+        else if ( mesh->mFaces[i].mNumIndices == 4 )
+          degenerated = dd4hep::cad::facetIsDegenerated({vertices[idx[0]], vertices[idx[1]], vertices[idx[2]], vertices[idx[3]]});
+        
         if ( degenerated )   {
           printout(DEBUG, "ASSIMPReader", "+++ %s: Drop degenerated facet: %d %d %d",
                    name.c_str(), idx[0], idx[1], idx[2]);
-- 
GitLab