Skip to content

Commit

Permalink
Geometry export to OBJ and PLY
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Nov 15, 2024
1 parent 0c44541 commit ca1ea98
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
35 changes: 24 additions & 11 deletions source/tdis/tracking/ActsGeometryService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Acts/Plugins/Json/MaterialMapJsonConverter.hpp>
#include <Acts/Visualization/GeometryView3D.hpp>
#include <Acts/Visualization/ObjVisualization3D.hpp>
#include <Acts/Visualization/PlyVisualization3D.hpp>
#include <Acts/Visualization/ViewConfig.hpp>
#include <array>
#include <exception>
Expand Down Expand Up @@ -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()));
Expand All @@ -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<const Acts::TrackingGeometry> gGeometry =
gGeometry =
ActsExamples::Telescope::buildDetector(
nominalContext, // gctx is the detector element dependent geometry context
detectorStore, // detectorStore is the store for the detector element
Expand All @@ -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);
Expand Down
66 changes: 44 additions & 22 deletions source/tdis/tracking/ActsGeometryService.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,41 @@
#include <TGeoManager.h>
#include <spdlog/logger.h>

#include "TelescopeDetectorElement.hpp"

#include <Acts/Visualization/GeometryView3D.hpp>
#include <memory>
#include <mutex>

#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 <typename TVis> void DrawTrackingGeometry(TVis& vis_helper,
const Acts::TrackingVolume& tVolume,
const Acts::GeometryContext& gctx);

private:


Parameter<std::string> m_tgeo_file {this, "acts:geometry", "g4sbs_mtpc.root", "TGeo filename with geometry for ACTS"};
Parameter<std::string> m_material_map_file {this, "acts:material_map", "", "JSON/CBOR material map file path"};
Parameter<std::string> m_obj_output_file {this, "acts:output_obj", "", "Output file name to dump ACTS converted geometry as OBJ"};
Parameter<std::string> m_ply_output_file {this, "acts:output_ply", "", "Output file name to dump ACTS converted geometry as PLY"};

Service<tdis::services::LogService> m_service_log {this};
private:
Parameter<std::string> m_tgeo_file{this, "acts:geometry", "g4sbs_mtpc.root","TGeo filename with geometry for ACTS"};
Parameter<std::string> m_material_map_file{this, "acts:material_map", "", "JSON/CBOR material map file path"};
Parameter<std::string> m_obj_output_file{this, "acts:output_obj", "", "Output file name to dump ACTS converted geometry as OBJ"};
Parameter<std::string> m_ply_output_file{this, "acts:output_ply", "", "Output file name to dump ACTS converted geometry as PLY"};

Service<tdis::services::LogService> m_service_log{this};

// General acts log
std::shared_ptr<spdlog::logger> m_log;
Expand All @@ -65,7 +60,34 @@ namespace tdis::tracking {

ActsExamples::Telescope::TelescopeDetectorElement::ContextType nominalContext;

std::vector<std::shared_ptr<ActsExamples::Telescope::TelescopeDetectorElement>> detectorStore;
std::vector<std::shared_ptr<ActsExamples::Telescope::TelescopeDetectorElement>>
detectorStore;

std::shared_ptr<const Acts::TrackingGeometry> gGeometry;
};


template <typename TVis>
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
4 changes: 2 additions & 2 deletions source/tdis/tracking/BuildTelescopeDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ ActsExamples::Telescope::buildDetector(const typename ActsExamples::Telescope::T
std::unique_ptr<Acts::SurfaceArray> 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<Acts::Surface *>(surface.get());
Expand Down

0 comments on commit ca1ea98

Please sign in to comment.