Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: visualization of grids #552

Merged
merged 118 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
ad2b2dc
Version
fredevb Jun 27, 2023
81f9615
Created and setup subdirectory for actsvg plugins
fredevb Jun 29, 2023
df49f88
Updated actsvg version to 0.4.35
fredevb Jun 29, 2023
5b3a541
actsvg using a detray cyllinder2D
fredevb Jul 3, 2023
d5e2115
Merge branch 'acts-project:main' into main
fredevb Jul 3, 2023
c28f426
Added functor for testing ring2D
fredevb Jul 3, 2023
bc1418a
Local_vertices function for rectangle2D
fredevb Jul 6, 2023
b93b68c
Mask conversion to proto surface
fredevb Jul 10, 2023
9ad801d
Added transform3 conversion from detray to actsvg
fredevb Jul 10, 2023
ab179d6
Added surface conversion (transform conversion not yet tested)
fredevb Jul 10, 2023
aa5ca9d
Merge branch 'acts-project:main' into main
fredevb Jul 10, 2023
d4689e6
Fixed bug in rotation (conversion from radians to degrees)
fredevb Jul 11, 2023
716801f
Changed "array" to "vector" in local_vertices comment
fredevb Jul 12, 2023
2388ab9
Refactor
fredevb Jul 13, 2023
8d0910a
Formatting
fredevb Jul 14, 2023
bd644c6
Comments and refactor
fredevb Jul 14, 2023
965b7d6
Merge branch 'acts-project:main' into main
fredevb Jul 14, 2023
4a25918
portal conversion test
fredevb Jul 17, 2023
aa0f578
Visualization tools (svg conversion, styling, and file writing)
fredevb Jul 17, 2023
e90b1ee
basic demo detector visualization
fredevb Jul 20, 2023
013b3f0
Merge branch 'acts-project:main' into main
fredevb Jul 20, 2023
17a77a7
Detector and volume conversion
fredevb Jul 25, 2023
370e1e1
Merge branch 'acts-project:main' into main
fredevb Jul 26, 2023
12c6e46
Comments
fredevb Jul 26, 2023
bd5975f
Merge branch 'main' into visualization/portals
fredevb Jul 26, 2023
ab969aa
Refactor
fredevb Jul 31, 2023
0ee9bf8
FIxed links
fredevb Jul 31, 2023
46b96bc
Comments
fredevb Jul 31, 2023
156ed47
Clean up
fredevb Aug 1, 2023
f2e6437
Clean up
fredevb Aug 2, 2023
879cda2
Clean up
fredevb Aug 2, 2023
214b7e4
Visualization working.
fredevb Aug 3, 2023
8e0be4b
Implemented remaining
fredevb Aug 4, 2023
9ea9e1f
Refactor
fredevb Aug 5, 2023
a793b2a
links fixed
fredevb Aug 7, 2023
7a7ccd1
Comments
fredevb Aug 8, 2023
fb71d93
Clean up
fredevb Aug 8, 2023
53b0b0f
Suppress ACTSVG warnings
fredevb Aug 8, 2023
ec8ba4b
Merge remote-tracking branch 'upstream/main' into svgviz
fredevb Aug 8, 2023
a547f49
Added conversion from detray surface to actsvg proto surface/portal
fredevb Aug 8, 2023
bb904c3
Formatted
fredevb Aug 8, 2023
c01eeba
Small changes
fredevb Aug 14, 2023
f844028
Refactor
fredevb Aug 15, 2023
7726a87
Added proto volume conversion, svg conversion (surfaces, volumes, and…
fredevb Aug 8, 2023
d5a9248
Merge branch 'acts-project:main' into visualization/surfaces
fredevb Aug 15, 2023
79009ac
Formatting
fredevb Aug 15, 2023
fbf3246
Added basic support for rendering lines
fredevb Aug 15, 2023
9df7414
Removed unused code
fredevb Aug 16, 2023
274d63c
Renamed svg output name
fredevb Aug 16, 2023
36fdb6f
typo
fredevb Aug 16, 2023
0e3f23b
Formatting
fredevb Aug 16, 2023
fb1b6ff
Merge branch 'acts-project:main' into visualization/surfaces
fredevb Aug 16, 2023
c0fb6d6
Removed unused code
fredevb Aug 17, 2023
0592108
Added measures to proto surfaces and fixed a bug in test.
fredevb Aug 17, 2023
53e5e47
Small adjustments
fredevb Aug 17, 2023
0f0bd7c
fix
fredevb Aug 17, 2023
ee0c82c
fix
fredevb Aug 17, 2023
2bfba74
Formatting
fredevb Aug 17, 2023
d026457
small change
fredevb Aug 17, 2023
88eb49a
removed print
fredevb Aug 17, 2023
ab6d7be
Minor comments
fredevb Aug 17, 2023
09876a5
Visualization of detectors and volumes
fredevb Aug 15, 2023
efcd6a0
Formatting
fredevb Aug 16, 2023
7a8a5da
Added proto volume conversion, svg conversion (surfaces, volumes, and…
fredevb Aug 8, 2023
a7c17de
Simple trajectory svg demo
fredevb Aug 9, 2023
5051406
Typo
fredevb Aug 10, 2023
2beec11
Added proto, display, and svg for intersections and records
fredevb Aug 10, 2023
a5608b9
Added copyright statement and comments
fredevb Aug 16, 2023
8949a5a
Formatting
fredevb Aug 23, 2023
57a2dcd
Merge remote-tracking branch 'upstream/main' into visualization/inter…
fredevb Aug 23, 2023
2ed0fad
removed duplicate "private"
fredevb Aug 23, 2023
3a5479f
CI
fredevb Aug 23, 2023
bd45069
fixed typo
fredevb Aug 23, 2023
62efbca
removed ";"
fredevb Aug 23, 2023
f9e2a4d
Test
fredevb Aug 17, 2023
077448b
Demo
fredevb Aug 19, 2023
e232754
Added Information boxes
fredevb Aug 20, 2023
89c672e
Removed old test
fredevb Aug 20, 2023
c2ee6ea
Added trajectory visualization (ray and helix)
fredevb Aug 21, 2023
00cfc13
Added styling
fredevb Aug 23, 2023
f850a4c
CI
fredevb Aug 23, 2023
43186d4
enabled names display
fredevb Aug 23, 2023
8d0f1ff
enabled names
fredevb Aug 23, 2023
2c781fe
CI
fredevb Aug 23, 2023
a77c09a
Formatting
fredevb Aug 23, 2023
4607f40
Grid demo (debug)
fredevb Aug 23, 2023
e18b808
Work in progess
fredevb Aug 23, 2023
fc4d067
Views
fredevb Aug 23, 2023
7f061a1
Refactor
fredevb Aug 28, 2023
86e4109
Added grid visualization
fredevb Aug 28, 2023
55c9e3a
Added comments
fredevb Aug 29, 2023
5944669
Added support for quickly displaying points
fredevb Aug 29, 2023
04a33c8
Adjusted web page svg demo
fredevb Aug 30, 2023
2501265
Merge remote-tracking branch 'upstream/main' into visualization/traje…
fredevb Aug 31, 2023
6330686
Merge remote-tracking branch 'upstream/main' into visualization/traje…
fredevb Sep 1, 2023
ce13461
Merge branch 'visualization/trajectories' into visualization/grids
fredevb Sep 1, 2023
0fdfc8e
rename
fredevb Sep 1, 2023
c5f9599
Added comments and web page test
fredevb Sep 1, 2023
0aa405a
formatting
fredevb Sep 1, 2023
bb1c31b
Merge branch 'visualization/trajectories' into visualization/grids
fredevb Sep 1, 2023
c819398
formatting
fredevb Sep 1, 2023
6ad6e41
updated comment
fredevb Sep 1, 2023
b16e850
small edit
fredevb Sep 1, 2023
7f4015d
Added important comment
fredevb Sep 1, 2023
aab769b
Merge remote-tracking branch 'upstream/main' into visualization/traje…
fredevb Sep 18, 2023
37292a7
Minor changes
fredevb Sep 18, 2023
5df41d7
Formatting
fredevb Sep 18, 2023
b497973
Merge branch 'visualization/trajectories' into visualization/grids
fredevb Sep 18, 2023
3333ee0
Merge remote-tracking branch 'upstream/main' into visualization/grids
fredevb Oct 2, 2023
abfad46
Fixed compile errors
fredevb Oct 2, 2023
db08c55
Merge remote-tracking branch 'upstream/main' into visualization/grids
fredevb Oct 17, 2023
1501467
Clean up
fredevb Oct 17, 2023
36a6d52
Format
fredevb Oct 17, 2023
16d1d72
Minor updates
fredevb Oct 18, 2023
b64ac6b
minor update
fredevb Oct 18, 2023
8b87341
removed unused
fredevb Oct 18, 2023
70ec00e
Merge branch 'main' into visualization/grids
niermann999 Oct 25, 2023
82167e2
fixes after merge
niermann999 Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extern/actsvg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message( STATUS "Building actsvg as part of the Detray project" )
# Declare where to get Actsvg from.
set( DETRAY_ACTSVG_GIT_REPOSITORY "https://github.com/acts-project/actsvg.git"
CACHE STRING "Git repository to take actsvg from" )
set( DETRAY_ACTSVG_GIT_TAG "v0.4.35" CACHE STRING "Version of actsvg to build" )
set( DETRAY_ACTSVG_GIT_TAG "v0.4.37" CACHE STRING "Version of actsvg to build" )
mark_as_advanced( DETRAY_ACTSVG_GIT_REPOSITORY DETRAY_ACTSVG_GIT_TAG )
FetchContent_Declare( actsvg
GIT_REPOSITORY "${DETRAY_ACTSVG_GIT_REPOSITORY}"
Expand Down
165 changes: 165 additions & 0 deletions plugins/svgtools/include/detray/plugins/svgtools/conversion/grid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "detray/core/detector.hpp"
#include "detray/definitions/units.hpp"
#include "detray/grids/axis.hpp"

// Actsvg include(s)
#include "actsvg/proto/grid.hpp"

// System include(s)
#include <algorithm>
#include <optional>
#include <string>
#include <vector>

namespace detray::svgtools::conversion {

/// A functor to access the bin edges.
template <typename scalar_t, detray::n_axis::label axis_label>
struct edge_getter {
template <typename group_t, typename index_t, typename... Args>
DETRAY_HOST_DEVICE inline auto operator()(
[[maybe_unused]] const group_t& group,
[[maybe_unused]] const index_t index) const {
using accel_t = typename group_t::value_type;
if constexpr (detray::detail::is_grid_v<accel_t>) {
const auto grid = group[index];
const auto axis_bin_edges =
grid.axes().template get_axis<axis_label>().bin_edges();
std::vector<scalar_t> edges;
niermann999 marked this conversation as resolved.
Show resolved Hide resolved
std::copy(axis_bin_edges.cbegin(), axis_bin_edges.cend(),
std::back_inserter(edges));
return edges;
}
return std::vector<scalar_t>{};
}
};

/// @return the bin edges of the grid.
template <typename detray::n_axis::label axis_label, typename detector_t,
typename link_t>
auto bin_edges(const detector_t& detector, const link_t& link) {
using d_scalar_t = typename detector_t::scalar_type;
return detector.surface_store()
.template visit<edge_getter<d_scalar_t, axis_label>>(link);
}

// Calculating r under the assumption that the cylinder grid is closed in phi:
// (bin_edge_min - bin_edge_max) / (2*pi).
template <typename d_scalar_t>
auto r_phi_split(const std::vector<d_scalar_t>& edges_rphi) {
const auto r = edges_rphi.back() * detray::constant<d_scalar_t>::inv_pi;
std::vector<d_scalar_t> edges_phi;
std::transform(edges_rphi.cbegin(), edges_rphi.cend(),
std::back_inserter(edges_phi),
[r](d_scalar_t e) { return e / r; });
return std::tuple(edges_phi, r);
}

/// @returns the actsvg grid type and edge values for a detray cylinder
/// grid.
template <typename detector_t, typename link_t, typename view_t>
auto cylinder2_grid_type_and_edges(const detector_t& detector,
const link_t& link, const view_t&) {
assert(link.id() == detector_t::sf_finders::id::e_cylinder2_grid);
auto edges_rphi = bin_edges<detray::n_axis::label::e_rphi>(detector, link);
auto edges_z = bin_edges<detray::n_axis::label::e_cyl_z>(detector, link);
auto [edges_phi, r] = r_phi_split(edges_rphi);
std::vector edges_r{r, r};

if (std::is_same_v<view_t, actsvg::views::x_y>) {
return std::tuple(actsvg::proto::grid::e_r_phi, edges_r, edges_phi);
}
if (std::is_same_v<view_t, actsvg::views::z_r>) {
return std::tuple(actsvg::proto::grid::e_x_y, edges_z, edges_r);
}
if (std::is_same_v<view_t, actsvg::views::z_phi>) {
return std::tuple(actsvg::proto::grid::e_x_y, edges_z, edges_phi);
}
if (std::is_same_v<view_t, typename actsvg::views::z_rphi>) {
return std::tuple(actsvg::proto::grid::e_x_y, edges_z, edges_rphi);
}
using scalar_t = typename detector_t::scalar_type;
return std::tuple(actsvg::proto::grid::e_x_y, std::vector<scalar_t>{},
std::vector<scalar_t>{});
}

/// @returns the actsvg grid type and edge values for a detray disc grid.
template <typename detector_t, typename link_t, typename view_t>
auto disc_grid_type_and_edges(const detector_t& detector, const link_t& link,
const view_t&) {
assert(link.id() == detector_t::sf_finders::id::e_disc_grid);
auto edges_r = bin_edges<detray::n_axis::label::e_r>(detector, link);
auto edges_phi = bin_edges<detray::n_axis::label::e_phi>(detector, link);

if (std::is_same_v<view_t, typename actsvg::views::x_y>) {
return std::tuple(actsvg::proto::grid::e_r_phi, edges_r, edges_phi);
}
using scalar_t = typename detector_t::scalar_type;
return std::tuple(actsvg::proto::grid::e_x_y, std::vector<scalar_t>{},
std::vector<scalar_t>{});
}

/// @returns the detray grids respective actsvg grid type and edge
/// values.
template <typename detector_t, typename link_t,
typename view_t>
auto get_type_and_axes(const detector_t& detector, const link_t& link,
const view_t& view) {
using accel_ids_t = typename detector_t::sf_finders::id;
switch (link.id()) {
fredevb marked this conversation as resolved.
Show resolved Hide resolved
case accel_ids_t::e_cylinder2_grid: {
return cylinder2_grid_type_and_edges(detector, link, view);
}
case accel_ids_t::e_disc_grid: {
return disc_grid_type_and_edges(detector, link, view);
}
default: {
using scalar_t = typename detector_t::scalar_type;
return std::tuple(actsvg::proto::grid::e_x_y,
std::vector<scalar_t>{}, std::vector<scalar_t>{});
}
}
}

/// @brief Converts a detray grid to a actsvg proto grid.
/// @param detector the detector
/// @param index the index of the grid's volume
/// @param view the view
/// @returns a proto grid
template <typename a_scalar_t, typename detector_t, typename view_t>
std::optional<actsvg::proto::grid> grid(const detector_t& detector,
const std::size_t index,
const view_t& view) {
using d_scalar_t = typename detector_t::scalar_type;
using geo_object_ids = typename detector_t::geo_obj_ids;

const auto vol_desc = detector.volumes()[index];
const auto link = vol_desc.template link<geo_object_ids::e_sensitive>();
actsvg::proto::grid p_grid;

if (not link.is_invalid()) {
const auto [type, edges0, edges1] =
get_type_and_axes(detector, link, view);
p_grid._type = type;
std::transform(edges0.cbegin(), edges0.cend(),
std::back_inserter(p_grid._edges_0),
[](d_scalar_t v) { return static_cast<a_scalar_t>(v); });
std::transform(edges1.cbegin(), edges1.cend(),
std::back_inserter(p_grid._edges_1),
[](d_scalar_t v) { return static_cast<a_scalar_t>(v); });
return p_grid;
}
return {};
}

} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace detray::svgtools::conversion {

/// @returns a point as a string.
template <typename point3_t>
inline std::string point_to_string(point3_t point) {

Expand All @@ -33,6 +34,7 @@ inline std::string point_to_string(point3_t point) {
return stream.str();
}

/// @returns the information section for a detray surface.
template <typename point3_t, typename detector_t>
inline auto information_section(
const typename detector_t::geometry_context& context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
#include "detray/intersection/intersection.hpp"
#include "detray/plugins/svgtools/conversion/landmark.hpp"
#include "detray/plugins/svgtools/meta/proto/intersection_record.hpp"
#include "detray/plugins/svgtools/utils/intersection_utils.hpp"

// System include(s)
#include <vector>

namespace detray::svgtools::conversion {

/// @returns The proto intersection record from a list of points
template <typename point3_t, typename container_t>
inline auto intersection_record(const container_t& points) {
using p_intersection_record_t =
svgtools::meta::proto::intersection_record<point3_t>;
p_intersection_record_t p_ir;
for (const auto& point : points) {
const auto p_lm = svgtools::conversion::landmark<point3_t>(point);
p_ir._landmarks.push_back(p_lm);
}
return p_ir;
}

/// @returns The proto intersection record of a detray intersection record.
template <typename point3_t, typename detector_t>
inline auto intersection_record(
Expand All @@ -27,17 +41,13 @@ inline auto intersection_record(
detray::intersection2D<typename detector_t::surface_type,
typename detector_t::transform3>>>&
intersection_record) {
using p_intersection_record_t =
svgtools::meta::proto::intersection_record<point3_t>;
p_intersection_record_t p_ir;
std::vector<typename p_intersection_record_t::landmark_type> landmarks;
std::vector<typename detector_t::point3> points;
for (const auto& record : intersection_record) {
const auto p_lm = svgtools::conversion::landmark<point3_t>(
const auto point = svgtools::utils::intersection_point(
context, detector, record.second);
landmarks.push_back(p_lm);
points.push_back(point);
}
p_ir._landmarks = landmarks;
return p_ir;
return svgtools::conversion::intersection_record<point3_t>(points);
}

} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "detray/intersection/intersection.hpp"
#include "detray/plugins/svgtools/conversion/point.hpp"
#include "detray/plugins/svgtools/meta/proto/landmark.hpp"
#include "detray/plugins/svgtools/utils/intersection_utils.hpp"

namespace detray::svgtools::conversion {

Expand All @@ -23,15 +24,17 @@ inline auto landmark(
const detray::intersection2D<typename detector_t::surface_type,
typename detector_t::transform3>&
d_intersection) {
using p_landmark_t = svgtools::meta::proto::landmark<point3_t>;

const typename detector_t::vector3 dir{};
const detray::surface surface{detector, d_intersection.sf_desc};
const auto position = svgtools::conversion::point<point3_t>(
surface.local_to_global(context, d_intersection.local, dir));
const auto position =
svgtools::utils::intersection_point(context, detector, d_intersection);
return svgtools::conversion::landmark<point3>(position);
}

/// @returns The proto landmark of a detray point.
template <typename point3_t, typename d_point3_t>
inline auto landmark(d_point3_t& position) {
using p_landmark_t = svgtools::meta::proto::landmark<point3_t>;
p_landmark_t p_lm;
p_lm._position = position;
p_lm._position = svgtools::conversion::point<point3_t>(position);
return p_lm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ inline auto link(const typename detector_t::geometry_context& context,

typename detector_t::vector3 dir{};

// Length of link arrow is currently hardcoded to 3.
constexpr double link_length = 3.;
// Length of link arrow is currently hardcoded.
constexpr double link_length = 4.;

const auto [start, end] = svgtools::utils::link_points(
context, detector, d_portal, dir, link_length);
Expand Down
Loading