Skip to content

Commit

Permalink
AssimWriter: implement facetIsDegenerated function
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed Jan 15, 2024
1 parent 7b4b564 commit 2eb23a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions DDCAD/include/DDCAD/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions DDCAD/src/ASSIMPWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2eb23a0

Please sign in to comment.