From ca1ea9818dae85c9f1da010530c8028b00b063eb Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Fri, 15 Nov 2024 11:31:22 -0500 Subject: [PATCH] Geometry export to OBJ and PLY --- source/tdis/tracking/ActsGeometryService.cc | 35 ++++++---- source/tdis/tracking/ActsGeometryService.h | 66 ++++++++++++------- .../tdis/tracking/BuildTelescopeDetector.cpp | 4 +- 3 files changed, 70 insertions(+), 35 deletions(-) diff --git a/source/tdis/tracking/ActsGeometryService.cc b/source/tdis/tracking/ActsGeometryService.cc index 4f21c57..6ce18a7 100644 --- a/source/tdis/tracking/ActsGeometryService.cc +++ b/source/tdis/tracking/ActsGeometryService.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -357,7 +358,7 @@ void tdis::tracking::ActsGeometryService::Init() { // We just copy it, considering the disks are the same bounds[0] = r_min * Acts::UnitConstants::cm; bounds[1] = r_max * Acts::UnitConstants::cm; - thickness = dz * Acts::UnitConstants::cm * 0.1; + thickness = dz * Acts::UnitConstants::cm * 0.001; m_log->info(fmt::format(" Position: ({:.4f}, {:.4f}, {:>8.4f}) cm, rmin: {:.3f} cm, rmax: {:.3f} cm, dz: {:.4f} cm, Node: '{}', Volume: '{}'", x, y, z, r_min, r_max, dz, node->GetName(), volume->GetName())); @@ -366,14 +367,14 @@ void tdis::tracking::ActsGeometryService::Init() { stereos.push_back(0); } - Acts::ObjVisualization3D objVis; + m_init_log->info("Building ACTS Geometry"); /// Return the telescope detector - std::shared_ptr gGeometry = + gGeometry = ActsExamples::Telescope::buildDetector( nominalContext, // gctx is the detector element dependent geometry context detectorStore, // detectorStore is the store for the detector element @@ -385,20 +386,32 @@ void tdis::tracking::ActsGeometryService::Init() { ActsExamples::Telescope::TelescopeSurfaceType::Disc, // surfaceType is the detector surface type Acts::BinningValue::binZ); - m_log->info("ACTS Detector Elements"); - for(auto &element: detectorStore) { - Acts::GeometryView3D::drawSurface(objVis, element->surface(), m_geometry_context, element->transform(m_geometry_context)); - } + // Visualize ACTS geometry + const Acts::TrackingVolume& tgVolume = *(gGeometry->highestTrackingVolume()); + + // OBJ visualization export + auto obj_file = m_obj_output_file(); if(!m_obj_output_file().empty()) { - m_log->info("ACTS Exporting geometry as view to: {}", m_obj_output_file()); - objVis.write(m_obj_output_file()); + m_log->info("ACTS exporting to OBJ: {}", m_obj_output_file()); + Acts::ObjVisualization3D vis_helper; + DrawTrackingGeometry(vis_helper, tgVolume, m_geometry_context); + vis_helper.write(m_obj_output_file()); } else { - m_log->info("ACTS geometry filename defined by: '{}' is empty. NOT exporting geometry to .obj or whatever ", m_obj_output_file.m_name); + m_log->info("ACTS OBJ Export. Flag '{}' is empty. NOT exporting.", m_obj_output_file.m_name); } - exit(0); + // PLY visualization export + if(!m_ply_output_file().empty()) { + m_log->info("ACTS exporting to PLY: {}", m_ply_output_file()); + Acts::PlyVisualization3D vis_helper; + DrawTrackingGeometry(vis_helper, tgVolume, m_geometry_context); + vis_helper.write(m_ply_output_file()); + } else { + m_log->info("ACTS PLY Export. Flag '{}' is empty. NOT exporting.", m_ply_output_file.m_name); + } + exit(0); // Set ticker back m_app->SetTicker(was_ticker_enabled); diff --git a/source/tdis/tracking/ActsGeometryService.h b/source/tdis/tracking/ActsGeometryService.h index d646766..3f2284a 100644 --- a/source/tdis/tracking/ActsGeometryService.h +++ b/source/tdis/tracking/ActsGeometryService.h @@ -9,46 +9,41 @@ #include #include -#include "TelescopeDetectorElement.hpp" - +#include #include #include #include "ActsGeometryProvider.h" +#include "TelescopeDetectorElement.hpp" #include "services/LogService.hpp" namespace tdis::tracking { - class ActsGeometryService : public JService - { - public: + class ActsGeometryService : public JService { + public: explicit ActsGeometryService() : JService() {} ~ActsGeometryService() override = default; - void Init() override; TGeoManager* GetGeoManager() const { return m_tgeo_manager; } - TGeoVolume * GetTopVolume() const { return m_tgeo_manager->GetTopVolume(); } - - TGeoNode * GetTopNode() const { return m_tgeo_manager->GetTopNode(); } + TGeoVolume* GetTopVolume() const { return m_tgeo_manager->GetTopVolume(); } + TGeoNode* GetTopNode() const { return m_tgeo_manager->GetTopNode(); } - Acts::GeometryContext& GetActsGeometryContext() { - return m_geometry_context; - } + Acts::GeometryContext& GetActsGeometryContext() { return m_geometry_context; } + template void DrawTrackingGeometry(TVis& vis_helper, + const Acts::TrackingVolume& tVolume, + const Acts::GeometryContext& gctx); - private: - - - Parameter m_tgeo_file {this, "acts:geometry", "g4sbs_mtpc.root", "TGeo filename with geometry for ACTS"}; - Parameter m_material_map_file {this, "acts:material_map", "", "JSON/CBOR material map file path"}; - Parameter m_obj_output_file {this, "acts:output_obj", "", "Output file name to dump ACTS converted geometry as OBJ"}; - Parameter m_ply_output_file {this, "acts:output_ply", "", "Output file name to dump ACTS converted geometry as PLY"}; - - Service m_service_log {this}; + private: + Parameter m_tgeo_file{this, "acts:geometry", "g4sbs_mtpc.root","TGeo filename with geometry for ACTS"}; + Parameter m_material_map_file{this, "acts:material_map", "", "JSON/CBOR material map file path"}; + Parameter m_obj_output_file{this, "acts:output_obj", "", "Output file name to dump ACTS converted geometry as OBJ"}; + Parameter m_ply_output_file{this, "acts:output_ply", "", "Output file name to dump ACTS converted geometry as PLY"}; + Service m_service_log{this}; // General acts log std::shared_ptr m_log; @@ -65,7 +60,34 @@ namespace tdis::tracking { ActsExamples::Telescope::TelescopeDetectorElement::ContextType nominalContext; - std::vector> detectorStore; + std::vector> + detectorStore; + std::shared_ptr gGeometry; }; + + + template + void ActsGeometryService::DrawTrackingGeometry(TVis& vis_helper, const Acts::TrackingVolume& tVolume, const Acts::GeometryContext& gctx) { + bool triangulate = false; + + Acts::ViewConfig viewSensitive{.color = {0, 180, 240}, .quarterSegments = 72, .triangulate = triangulate}; + Acts::ViewConfig viewPassive{.color = {240, 280, 0}, .quarterSegments = 72, .triangulate = triangulate}; + Acts::ViewConfig viewVolume{.color = {220, 220, 0}, .quarterSegments = 72, .triangulate = triangulate}; + Acts::ViewConfig viewContainer{.color = {220, 220, 0}, .quarterSegments = 72, .triangulate = triangulate}; + Acts::ViewConfig viewGrid{.color = {220, 0, 0}, .offset = 3., .quarterSegments = 8, .triangulate = triangulate}; + + Acts::GeometryView3D::drawTrackingVolume( + vis_helper, // Visualization helper (templated) + tVolume, // Tracking volume to be drawn + gctx, // Geometry context + viewContainer, // Container volume view configuration + viewVolume, // Navigation level volume view configuration + viewPassive, // Passive surfaces view configuration + viewSensitive, // Sensitive surfaces view configuration + viewGrid, // Grid display view configuration + true, // Write or not + "tdis" // Optional tag + ); + } } // namespace tdis::tracking \ No newline at end of file diff --git a/source/tdis/tracking/BuildTelescopeDetector.cpp b/source/tdis/tracking/BuildTelescopeDetector.cpp index c237127..3f7835c 100644 --- a/source/tdis/tracking/BuildTelescopeDetector.cpp +++ b/source/tdis/tracking/BuildTelescopeDetector.cpp @@ -90,9 +90,9 @@ ActsExamples::Telescope::buildDetector(const typename ActsExamples::Telescope::T std::unique_ptr surArray(new Acts::SurfaceArray(surface)); // Construct the layer if (surfaceType == TelescopeSurfaceType::Plane) { - layers[i] = Acts::PlaneLayer::create(trafo, pBounds, std::move(surArray), 1._mm); + layers[i] = Acts::PlaneLayer::create(trafo, pBounds, std::move(surArray), thickness); } else { - layers[i] = Acts::DiscLayer::create(trafo, rBounds, std::move(surArray), 1._mm); + layers[i] = Acts::DiscLayer::create(trafo, rBounds, std::move(surArray), thickness); } // Associate the layer to the surface auto mutableSurface = const_cast(surface.get());