Skip to content

Commit

Permalink
refactor: simplify volume drawing and lower case variables (#1962)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Mar 22, 2023
1 parent 56aff8b commit 62a5336
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
7 changes: 3 additions & 4 deletions Core/include/Acts/Visualization/GeometryView3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ struct GeometryView3D {
/// @param surface The surface to be drawn
/// @param gctx The geometry context for which it is drawn
/// @param transform An option additional transform
/// @param ViewConfig The drawing configuration
/// @param viewConfig The drawing configuration
static void drawSurface(IVisualization3D& helper, const Surface& surface,
const GeometryContext& gctx,
const Transform3& transform = Transform3::Identity(),
const ViewConfig& ViewConfig = s_viewSensitive);
const ViewConfig& viewConfig = s_viewSensitive);

/// Helper method to draw SurfaceArray objects
///
Expand Down Expand Up @@ -103,15 +103,14 @@ struct GeometryView3D {
/// @param [in,out] helper The visualization helper
/// @param volume The DetectorVolume to be drawn
/// @param gctx The geometry context for which it is drawn
/// @param drawSurfaces switches on/off the drawing of the volumes' surfaces
/// @param transform An option additional transform
/// @param connected The config for connected portals
/// @param unconnected The config for unconnected portals
/// @param viewConfig The drawing configuration
static void drawDetectorVolume(
IVisualization3D& helper,
const Acts::Experimental::DetectorVolume& volume,
const GeometryContext& gctx, bool drawSurfaces,
const GeometryContext& gctx,
const Transform3& transform = Transform3::Identity(),
const ViewConfig& connected = ViewConfig({0, 255, 0}),
const ViewConfig& unconnected = ViewConfig({255, 0, 0}),
Expand Down
58 changes: 20 additions & 38 deletions Core/src/Visualization/GeometryView3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unistd.h>

namespace {

std::string joinPaths(const std::string& a, const std::string& b) {
if (b.substr(0, 1) == "/" || a.empty()) {
return b;
Expand All @@ -50,13 +51,13 @@ std::string getWorkingDirectory() {

void Acts::GeometryView3D::drawPolyhedron(IVisualization3D& helper,
const Polyhedron& polyhedron,
const ViewConfig& ViewConfig) {
if (ViewConfig.visible) {
if (not ViewConfig.triangulate) {
helper.faces(polyhedron.vertices, polyhedron.faces, ViewConfig.color);
const ViewConfig& viewConfig) {
if (viewConfig.visible) {
if (not viewConfig.triangulate) {
helper.faces(polyhedron.vertices, polyhedron.faces, viewConfig.color);
} else {
helper.faces(polyhedron.vertices, polyhedron.triangularMesh,
ViewConfig.color);
viewConfig.color);
}
}
}
Expand All @@ -65,13 +66,13 @@ void Acts::GeometryView3D::drawSurface(IVisualization3D& helper,
const Surface& surface,
const GeometryContext& gctx,
const Transform3& transform,
const ViewConfig& ViewConfig) {
const ViewConfig& viewConfig) {
Polyhedron surfaceHedron =
surface.polyhedronRepresentation(gctx, ViewConfig.nSegments);
surface.polyhedronRepresentation(gctx, viewConfig.nSegments);
if (not transform.isApprox(Transform3::Identity())) {
surfaceHedron.move(transform);
}
drawPolyhedron(helper, surfaceHedron, ViewConfig);
drawPolyhedron(helper, surfaceHedron, viewConfig);
}

void Acts::GeometryView3D::drawSurfaceArray(
Expand Down Expand Up @@ -191,42 +192,23 @@ void Acts::GeometryView3D::drawPortal(IVisualization3D& helper,

void Acts::GeometryView3D::drawDetectorVolume(
IVisualization3D& helper, const Experimental::DetectorVolume& volume,
const GeometryContext& gctx, bool drawSurfaces, const Transform3& transform,
const GeometryContext& gctx, const Transform3& transform,
const ViewConfig& connected, const ViewConfig& unconnected,
const ViewConfig& viewConfig) {
// draw the surfaces of the mother volume
for (auto surface : volume.surfaces()) {
drawSurface(helper, *surface, gctx, transform, viewConfig);
}

// draw the envelope first
auto portals = volume.portals();
for (auto portal : portals) {
for (auto portal : volume.portals()) {
drawPortal(helper, *portal, gctx, transform, connected, unconnected);
}

// draw the surfaces of the mother volume
if (drawSurfaces) {
auto surfaces = volume.surfaces();
for (auto surface : surfaces) {
drawSurface(helper, *surface, gctx, transform, viewConfig);
}
}
// recurse if there are subvolumes, otherwise draw the portals and the
// surfaces if tag is true
auto subvolumes = volume.volumes();
for (auto subvolume : subvolumes) {
if (!subvolume->volumes().empty()) {
drawDetectorVolume(helper, *subvolume, gctx, drawSurfaces, transform,
connected, unconnected, viewConfig);
} else {
auto sub_portals = subvolume->portals();
for (auto sub_portal : sub_portals) {
drawPortal(helper, *sub_portal, gctx, transform, connected,
unconnected);
}
if (drawSurfaces) {
auto sub_surfaces = subvolume->surfaces();
for (auto sub_surface : sub_surfaces) {
drawSurface(helper, *sub_surface, gctx, transform, viewConfig);
}
}
}
// recurse if there are subvolumes
for (auto subvolume : volume.volumes()) {
drawDetectorVolume(helper, *subvolume, gctx, transform, connected,
unconnected, viewConfig);
}
}

Expand Down

0 comments on commit 62a5336

Please sign in to comment.