File indexing completed on 2025-01-18 09:55:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDCAD_UTILITIES_H
0014 #define DDCAD_UTILITIES_H
0015
0016 #include <vector>
0017 #include <cmath>
0018 #include <limits>
0019
0020 #include <TGeoTessellated.h>
0021 #include <TGeoVector3.h>
0022
0023
0024 namespace dd4hep {
0025
0026
0027 namespace cad {
0028
0029 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1)
0030 inline std::string streamFacet(TGeoFacet const& facet,
0031 TGeoTessellated const& shape) {
0032 using ::operator<<;
0033 std::stringstream str;
0034 str << "{";
0035 for (int i = 0; i < facet.GetNvert(); ++i) {
0036 str << shape.GetVertex(facet[i]);
0037 if (i != facet.GetNvert() - 1)
0038 str << ", ";
0039 }
0040 str << "}";
0041 return str.str();
0042 }
0043 #else
0044 inline std::string streamFacet(TGeoFacet const& facet,
0045 TGeoTessellated const& ) {
0046 using ::operator<<;
0047 std::stringstream str;
0048 str << facet;
0049 return str.str();
0050 }
0051 #endif
0052
0053 inline std::string streamVertices(ROOT::Geom::Vertex_t const& v1,
0054 ROOT::Geom::Vertex_t const& v2,
0055 ROOT::Geom::Vertex_t const& v3) {
0056 using ::operator<<;
0057 std::stringstream str;
0058 str << "{" << v1 << ", " << v2 << ", " << v3 << "}";
0059 return str.str();
0060 }
0061
0062 inline bool facetIsDegenerated(std::vector<ROOT::Geom::Vertex_t> const& vertices){
0063 using ROOT::Geom::Vertex_t;
0064
0065 constexpr double kTolerance = 1.e-20;
0066 bool degenerated = true;
0067 Vertex_t normal;
0068 int fNvert = int(vertices.size());
0069 for (int i = 0; i < fNvert - 1; ++i) {
0070 Vertex_t e1 = vertices[i + 1] - vertices[i];
0071 if (e1.Mag2() < kTolerance)
0072 continue;
0073 for (int j = i + 1; j < fNvert; ++j) {
0074 Vertex_t e2 = vertices[(j + 1) % fNvert] - vertices[j];
0075 if (e2.Mag2() < kTolerance)
0076 continue;
0077 normal = Vertex_t::Cross(e1, e2);
0078
0079 if (normal.Mag2() < kTolerance)
0080 continue;
0081 normal.Normalize();
0082 degenerated = false;
0083 break;
0084 }
0085 if (!degenerated)
0086 break;
0087 }
0088 return degenerated;
0089 }
0090 }
0091 }
0092 #endif