From f055e771346a84d247aa82895ee6ff289083c2cc Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Sat, 13 Jan 2024 19:52:15 +0100 Subject: [PATCH] ASSIMP: adapt for changes in TGeoTesselated in ROOT --- DDCAD/include/DDCAD/Utilities.h | 52 +++++++++++++++++++++++++ DDCAD/src/ASSIMPReader.cpp | 7 ++-- DDCAD/src/ASSIMPWriter.cpp | 24 ++++++++---- DDCore/src/ShapeUtilities.cpp | 2 +- DDCore/src/plugins/DetectorChecksum.cpp | 7 +++- DDG4/src/Geant4ShapeConverter.cpp | 10 +++++ 6 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 DDCAD/include/DDCAD/Utilities.h diff --git a/DDCAD/include/DDCAD/Utilities.h b/DDCAD/include/DDCAD/Utilities.h new file mode 100644 index 000000000..325a5c408 --- /dev/null +++ b/DDCAD/include/DDCAD/Utilities.h @@ -0,0 +1,52 @@ +//========================================================================== +// 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 <TGeoTessellated.h> +#include <TGeoVector3.h> +/// 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; + } + } +} +#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 <DD4hep/Detector.h> #include <DD4hep/ShapeTags.h> #include <DDCAD/ASSIMPReader.h> +#include <DDCAD/Utilities.h> /// 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..82c692ded 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -15,6 +15,7 @@ #include <DD4hep/Detector.h> #include <DD4hep/Printout.h> #include <DDCAD/ASSIMPWriter.h> +#include <DDCAD/Utilities.h> /// Open Asset Importer Library #include "assimp/postprocess.h" @@ -22,11 +23,11 @@ #include "assimp/scene.h" /// ROOT include files +#include <TBuffer3D.h> #include <TBuffer3DTypes.h> +#include <TClass.h> #include <TGeoBoolNode.h> #include <TGeoMatrix.h> -#include <TBuffer3D.h> -#include <TClass.h> #include <CsgOps.h> /// C/C++ include files @@ -157,6 +158,7 @@ namespace { ++nskip; continue; } +#if ROOT_VERSION_CODE < ROOT_VERSION(6,31,1) bool degenerated = true; TGeoFacet f(&vertices, 3, vv0, vv1, vv2); f.ComputeNormal(degenerated); @@ -164,6 +166,7 @@ namespace { ++nskip; continue; } +#endif tes->AddFacet(vv0, vv1, vv2); } #else @@ -388,7 +391,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 +404,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 +419,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<n; ++j) { -#if ROOT_VERSION_CODE > 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; i<num_facet; ++i) { const TGeoFacet& facet = sh->GetFacet(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), -- GitLab