diff --git a/DDCAD/include/DDCAD/Utilities.h b/DDCAD/include/DDCAD/Utilities.h new file mode 100644 index 000000000..6e12f0401 --- /dev/null +++ b/DDCAD/include/DDCAD/Utilities.h @@ -0,0 +1,76 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : A. Sailer +// +//========================================================================== +#ifndef DDCAD_UTILITIES_H +#define DDCAD_UTILITIES_H + +#include + +#include +#include + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for implementation details of the AIDA detector description toolkit + namespace cad { + + inline std::stringstream streamFacet(TGeoFacet const& facet, + TGeoTessellated const& shape) { + using ::operator<<; + std::stringstream str; +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + str << "{"; + for (int i = 0; i < facet.GetNvert(); ++i) { + str << shape.GetVertex(facet[i]); + if (i != facet.GetNvert() - 1) + str << ", "; + } + str << "}"; +#else + str << facet; +#endif + return str; + } + + inline std::stringstream streamVertices(ROOT::Geom::Vertex_t const& v1, + ROOT::Geom::Vertex_t const& v2, + ROOT::Geom::Vertex_t const& v3) { + using ::operator<<; + std::stringstream str; + 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/ASSIMPReader.cpp b/DDCAD/src/ASSIMPReader.cpp index 5accbd731..67a1c37a0 100644 --- a/DDCAD/src/ASSIMPReader.cpp +++ b/DDCAD/src/ASSIMPReader.cpp @@ -16,6 +16,7 @@ #include #include #include +#include /// Open Asset Importer Library #include "assimp/scene.h" @@ -62,8 +63,7 @@ ASSIMPReader::readShapes(const std::string& source, double unit_length) const if ( dump_facets ) { for( size_t i=0, n=shape->GetNfacets(); i < n; ++i ) { const auto& facet = shape->GetFacet(i); - std::stringstream str; - str << facet; + std::stringstream str = dd4hep::cad::streamFacet(facet, shape); printout(ALWAYS,"ASSIMPReader","++ Facet %4ld : %s", i, str.str().c_str()); } @@ -162,8 +162,7 @@ ASSIMPReader::readVolumes(const std::string& source, double unit_length) const if ( dump_facets ) { for( size_t i=0, n=shape->GetNfacets(); i < n; ++i ) { const auto& facet = shape->GetFacet(i); - std::stringstream str; - str << facet; + std::stringstream str = dd4hep::cad::streamFacet(facet, shape); printout(ALWAYS,"ASSIMPReader","++ Facet %4ld : %s", i, str.str().c_str()); } diff --git a/DDCAD/src/ASSIMPWriter.cpp b/DDCAD/src/ASSIMPWriter.cpp index d098098e4..f31219174 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -15,6 +15,7 @@ #include #include #include +#include /// Open Asset Importer Library #include "assimp/postprocess.h" @@ -22,11 +23,11 @@ #include "assimp/scene.h" /// ROOT include files +#include #include +#include #include #include -#include -#include #include /// C/C++ include files @@ -157,9 +158,13 @@ namespace { ++nskip; continue; } +#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; @@ -388,7 +393,11 @@ int ASSIMPWriter::write(const std::string& file_name, for( long j=0, nvx=0, n=tes->GetNfacets(); j < n; ++j ) { bool degenerated = false; const auto& facet = tes->GetFacet(j); +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + tmp = tes->FacetComputeNormal(j, degenerated); +#else tmp = facet.ComputeNormal(degenerated); +#endif if ( !degenerated && facet.GetNvert() > 0 ) { aiFace& face = mesh->mFaces[mesh->mNumFaces]; double u = unit_scale; @@ -397,7 +406,11 @@ int ASSIMPWriter::write(const std::string& file_name, trafo->LocalToMaster(tmp.fVec, norm.fVec); face.mNumIndices = 0; for( long k=0; k < facet.GetNvert(); ++k ) { +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + tmp = tes->GetVertex(facet[k]); +#else tmp = facet.GetVertex(k); +#endif trafo->LocalToMaster(tmp.fVec, vtx.fVec); face.mIndices[face.mNumIndices] = nvx; mesh->mNormals[nvx] = aiVector3D(norm.x(), norm.y(), norm.z()); @@ -408,13 +421,12 @@ int ASSIMPWriter::write(const std::string& file_name, } ++mesh->mNumFaces; if ( dump_facets ) { - stringstream str; const auto* id = face.mIndices; const auto* vv = mesh->mVertices; - TGeoFacet fac(Vertex(vv[id[0]].x,vv[id[0]].y,vv[id[0]].z), - Vertex(vv[id[1]].x,vv[id[1]].y,vv[id[1]].z), - Vertex(vv[id[2]].x,vv[id[2]].y,vv[id[2]].z)); - str << fac; + ROOT::Geom::Vertex_t v1(vv[id[0]].x, vv[id[0]].y, vv[id[0]].z); + ROOT::Geom::Vertex_t v2(vv[id[1]].x, vv[id[1]].y, vv[id[1]].z); + ROOT::Geom::Vertex_t v3(vv[id[2]].x, vv[id[2]].y, vv[id[2]].z); + std::stringstream str = dd4hep::cad::streamVertices(v1, v2, v3); printout(ALWAYS,"ASSIMPWriter","++ Facet %4ld : %s", j, str.str().c_str()); } } diff --git a/DDCore/src/ShapeUtilities.cpp b/DDCore/src/ShapeUtilities.cpp index bfe7a1700..71af25f27 100644 --- a/DDCore/src/ShapeUtilities.cpp +++ b/DDCore/src/ShapeUtilities.cpp @@ -434,7 +434,7 @@ namespace dd4hep { const TGeoFacet& f = sh->GetFacet(i); pars.emplace_back(double(f.GetNvert())); for(int j=0, n=f.GetNvert(); j ROOT_VERSION(6,31,1) +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) int idx = f[j]; pars.emplace_back(double(idx)); #else diff --git a/DDCore/src/plugins/DetectorChecksum.cpp b/DDCore/src/plugins/DetectorChecksum.cpp index 728d80e29..0415aeb5f 100644 --- a/DDCore/src/plugins/DetectorChecksum.cpp +++ b/DDCore/src/plugins/DetectorChecksum.cpp @@ -620,7 +620,12 @@ const DetectorChecksum::entry_t& DetectorChecksum::handleSolid(Solid solid) cons except("DetectorChecksum","+++ TGeoTessellated volume with unsupported number of vertices: %s", solid.name()); } for (int ivertex = 0; ivertex < facet.GetNvert(); ivertex++) { - log << " vertex" << ivertex + 1 << "=\"" << nam << "_v" << facet.GetVertexIndex(ivertex) << "\""; +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + auto vertexIndex = facet[ivertex]; +#else + auto vertexIndex = facet.GetVertexIndex(ivertex); +#endif + log << " vertex" << ivertex + 1 << "=\"" << nam << "_v" << vertexIndex << "\""; } log << " type=\"ABSOLUTE\"/>" << newline; } diff --git a/DDG4/src/Geant4ShapeConverter.cpp b/DDG4/src/Geant4ShapeConverter.cpp index 78855d744..c46644716 100644 --- a/DDG4/src/Geant4ShapeConverter.cpp +++ b/DDG4/src/Geant4ShapeConverter.cpp @@ -259,9 +259,15 @@ namespace dd4hep { for(int i=0; iGetFacet(i); int nv = facet.GetNvert(); +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + const auto& v0 = sh->GetVertex(facet[0]); + const auto& v1 = sh->GetVertex(facet[1]); + const auto& v2 = sh->GetVertex(facet[2]); +#else const auto& v0 = sh->GetVertex(facet.GetVertexIndex(0)); const auto& v1 = sh->GetVertex(facet.GetVertexIndex(1)); const auto& v2 = sh->GetVertex(facet.GetVertexIndex(2)); +#endif G4VFacet* g4f = 0; if ( nv == 3 ) { g4f = new G4TriangularFacet(G4ThreeVector(v0.x() * CM_2_MM, v0.y() * CM_2_MM, v0.z() * CM_2_MM), @@ -270,7 +276,11 @@ namespace dd4hep { ABSOLUTE); } else if ( nv == 4 ) { +#if ROOT_VERSION_CODE >= ROOT_VERSION(6,31,1) + const auto& v3 = sh->GetVertex(facet[3]); +#else const auto& v3 = sh->GetVertex(facet.GetVertexIndex(3)); +#endif g4f = new G4QuadrangularFacet(G4ThreeVector(v0.x() * CM_2_MM, v0.y() * CM_2_MM, v0.z() * CM_2_MM), G4ThreeVector(v1.x() * CM_2_MM, v1.y() * CM_2_MM, v1.z() * CM_2_MM), G4ThreeVector(v2.x() * CM_2_MM, v2.y() * CM_2_MM, v2.z() * CM_2_MM),