Skip to content

Commit

Permalink
Use proto volumes and proto detector in the svgtools illistrator and …
Browse files Browse the repository at this point in the history
…cleanup the styling and naming
  • Loading branch information
niermann999 committed Nov 20, 2023
1 parent fcb1c85 commit e2b02cd
Show file tree
Hide file tree
Showing 27 changed files with 575 additions and 446 deletions.
6 changes: 6 additions & 0 deletions core/include/detray/core/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ class detector {
return _surfaces[bcd.index()];
}

/// @returns a surface using its index - const
DETRAY_HOST_DEVICE
constexpr auto surface(dindex sf_idx) const -> const surface_type & {
return _surfaces[sf_idx];
}

/// @returns the overall number of surfaces in the detector
DETRAY_HOST_DEVICE
constexpr auto n_surfaces() const -> dindex {
Expand Down
10 changes: 10 additions & 0 deletions core/include/detray/geometry/detail/surface_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ struct surface_kernels {
}
};

/// A functor to retrieve the masks shape name
struct get_shape_name {
template <typename mask_group_t, typename index_t>
DETRAY_HOST inline std::string operator()(const mask_group_t&,
const index_t&) const {

return mask_group_t::value_type::shape::name;
}
};

/// A functor to run the mask self check. Puts error messages into @param os
struct mask_self_check {
template <typename mask_group_t, typename index_t>
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/geometry/detector_volume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class detector_volume {
/// Constructor from detector @param det and volume index @param vol_idx in
/// that detector.
constexpr detector_volume(const detector_t &det, const dindex vol_idx)
: detector_volume(det, det.volume_by_index(vol_idx)) {}
: detector_volume(det, det.volumes()[vol_idx]) {}

/// Equality operator
///
Expand Down
11 changes: 11 additions & 0 deletions core/include/detray/geometry/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class surface {
constexpr surface(const detector_t &det, const geometry::barcode bcd)
: surface(det, det.surface(bcd)) {}

/// Constructor from detector @param det and surface index @param sf_idx
DETRAY_HOST_DEVICE
constexpr surface(const detector_t &det, const dindex sf_idx)
: surface(det, det.surface(sf_idx)) {}

/// Conversion to surface interface around constant detector type
template <typename detector_type = detector_t,
std::enable_if_t<!std::is_const_v<detector_type>, bool> = true>
Expand Down Expand Up @@ -133,6 +138,12 @@ class surface {
return visit_mask<typename kernels::get_volume_link>();
}

/// @returns the mask shape name
DETRAY_HOST
std::string shape_name() const {
return visit_mask<typename kernels::get_shape_name>();
}

/// @returns the coordinate transform matrix of the surface
DETRAY_HOST_DEVICE
constexpr auto transform(const context &ctx) const -> const transform3 & {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** 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/geometry/detector_volume.hpp"
#include "detray/plugins/svgtools/conversion/volume.hpp"

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

namespace detray::svgtools::conversion {

/// @brief Generates the proto detector object
///
/// @param context The geometry context.
/// @param detector The detector object.
/// @param hide_portals whether to display portals.
/// @param hide_passives whether to display passive surfaces.
///
/// @returns An actsvg proto volume representing the volume.
template <typename point3_container_t, typename detector_t, typename view_t>
auto detector(const typename detector_t::geometry_context& context,
const detector_t& detector, const view_t& view,
bool hide_portals = false, bool hide_passives = false,
bool hide_grids = false) {

actsvg::proto::detector<point3_container_t> p_detector;

for (const auto& vol_desc : detector.volumes()) {

p_detector._volumes.push_back(
svgtools::conversion::volume<point3_container_t>(
context, detector, detector_volume{detector, vol_desc}, view,
hide_portals, hide_passives, hide_grids));
}

return p_detector;
}

} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ inline auto grid_type_and_edges(const grid_t& grid, const view_t&) {
dvector<scalar_t> edges_r{r, r};

if constexpr (std::is_same_v<view_t, actsvg::views::x_y>) {
return std::tuple(actsvg::proto::grid::e_r_phi, edges_r, edges_phi);
return std::tuple(actsvg::proto::grid::e_r_phi, r, edges_r, edges_phi);
}
if constexpr (std::is_same_v<view_t, actsvg::views::z_r>) {
return std::tuple(actsvg::proto::grid::e_x_y, edges_z, edges_r);
return std::tuple(actsvg::proto::grid::e_x_y, r, edges_z, edges_r);
}
if constexpr (std::is_same_v<view_t, actsvg::views::z_phi>) {
return std::tuple(actsvg::proto::grid::e_z_phi, edges_z, edges_phi);
return std::tuple(actsvg::proto::grid::e_z_phi, r, edges_z, edges_phi);
}
if constexpr (std::is_same_v<view_t, typename actsvg::views::z_rphi>) {
return std::tuple(actsvg::proto::grid::e_z_phi, edges_z, edges_rphi);
return std::tuple(actsvg::proto::grid::e_z_phi, r, edges_z, edges_rphi);
}

return std::tuple(actsvg::proto::grid::e_x_y, dvector<scalar_t>{},
return std::tuple(actsvg::proto::grid::e_x_y, r, dvector<scalar_t>{},
dvector<scalar_t>{});
}

Expand All @@ -91,12 +91,14 @@ inline auto grid_type_and_edges(const grid_t& grid, const view_t&) {

auto edges_r = grid.template get_axis<axis_label::e_r>().bin_edges();
auto edges_phi = grid.template get_axis<axis_label::e_phi>().bin_edges();
// The axes are always sorted
scalar_t r{edges_r.back()};

if constexpr (std::is_same_v<view_t, typename actsvg::views::x_y>) {
return std::tuple(actsvg::proto::grid::e_r_phi, edges_r, edges_phi);
return std::tuple(actsvg::proto::grid::e_r_phi, r, edges_r, edges_phi);
}

return std::tuple(actsvg::proto::grid::e_x_y, dvector<scalar_t>{},
return std::tuple(actsvg::proto::grid::e_x_y, r, dvector<scalar_t>{},
dvector<scalar_t>{});
}

Expand All @@ -116,8 +118,9 @@ struct type_and_edge_getter {
return grid_type_and_edges(group[index], view);
}

return std::tuple(actsvg::proto::grid::e_x_y, dvector<scalar_t>{},
dvector<scalar_t>{});
return std::tuple(actsvg::proto::grid::e_x_y,
detray::detail::invalid_value<scalar_t>(),
dvector<scalar_t>{}, dvector<scalar_t>{});
}
};

Expand All @@ -143,12 +146,13 @@ std::optional<actsvg::proto::grid> grid(const detector_t& detector,
actsvg::proto::grid p_grid;

if (not link.is_invalid()) {
const auto [type, edges0, edges1] =
const auto [type, r, edges0, edges1] =
detector.accelerator_store()
.template visit<detail::type_and_edge_getter<d_scalar_t>>(link,
view);

p_grid._type = type;
p_grid._reference_r = static_cast<a_scalar_t>(r);

std::transform(edges0.cbegin(), edges0.cend(),
std::back_inserter(p_grid._edges_0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ inline auto information_section(
const detray::surface<detector_t>& d_surface) {
svgtools::meta::proto::information_section<point3_t> is;
is._title = d_surface.is_portal() ? "Portal" : "Surface";
const auto position = d_surface.center(context);
const auto position =
d_surface.transform(context).point_to_global(d_surface.centroid());
is._info = {"Idx: " + std::to_string(d_surface.index()),
point_to_string(position)};
is._position = svgtools::conversion::point<point3_t>(position);
return is;
}

} // namespace detray::svgtools::conversion
} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ namespace detray::svgtools::conversion {
template <typename point3_container_t, typename detector_t>
auto portal(const typename detector_t::geometry_context& context,
const detector_t& detector,
const detray::surface<detector_t>& d_portal) {
const detray::surface<detector_t>& d_portal,
bool hide_links = false) {
assert(d_portal.is_portal());

using p_portal_t = actsvg::proto::portal<point3_container_t>;

p_portal_t p_portal;
if (svgtools::utils::is_not_world_portal(d_portal)) {
p_portal._name = "portal_" + std::to_string(d_portal.index());
if (!hide_links && svgtools::utils::is_not_world_portal(d_portal)) {
p_portal._volume_links = {
svgtools::conversion::link<point3_container_t>(context, detector,
d_portal)};
}
p_portal._surface =
svgtools::conversion::surface<point3_container_t>(context, d_portal);

return p_portal;
}

} // namespace detray::svgtools::conversion
} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ struct surface_converter {
template <typename point3_container_t, typename detector_t>
auto surface(const typename detector_t::geometry_context& context,
const detray::surface<detector_t>& d_surface) {
return d_surface.template visit_mask<surface_converter<point3_container_t>>(
d_surface.transform(context));

auto p_surface =
d_surface.template visit_mask<surface_converter<point3_container_t>>(
d_surface.transform(context));

p_surface._name = "surface_" + std::to_string(d_surface.index());

return p_surface;
}

} // namespace detray::svgtools::conversion
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,63 @@

// Project include(s)
#include "detray/geometry/detector_volume.hpp"
#include "detray/geometry/surface.hpp"
#include "detray/plugins/svgtools/conversion/grid.hpp"
#include "detray/plugins/svgtools/conversion/portal.hpp"
#include "detray/plugins/svgtools/conversion/surface.hpp"
#include "detray/plugins/svgtools/utils/volume_utils.hpp"

// Actsvg include(s)
#include "actsvg/proto/portal.hpp"
#include "actsvg/proto/surface.hpp"
#include "actsvg/proto/volume.hpp"

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

namespace detray::svgtools::conversion {

/// @brief Calculates the proto volume of a collection of detray surfaces.
/// @brief Generates the proto volume of a detray volume.
///
/// @param context The context.
/// @param d_surfaces The detray surfaces.
/// @param context The geometry context.
/// @param detector The detractor the volume belongs to.
/// @param d_volume The detray volume.
/// @param hide_portals whether to display the volumes portals.
/// @param hide_passives whether to display the contained passive surfaces.
///
/// @returns An actsvg proto volume representing the volume.
template <typename point3_container_t, typename detector_t>
template <typename point3_container_t, typename detector_t, typename view_t>
auto volume(const typename detector_t::geometry_context& context,
const detector_t& detector,
const std::vector<detray::surface<detector_t>>& d_surfaces) {
using p_volume_t = actsvg::proto::volume<point3_container_t>;
using p_portal_t = actsvg::proto::portal<point3_container_t>;
using p_surface_t = actsvg::proto::surface<point3_container_t>;
p_volume_t p_volume;
std::vector<p_surface_t> surfaces;
std::vector<p_portal_t> portals;
for (const auto& item : d_surfaces) {
if (item.is_portal()) {
auto portal = svgtools::conversion::portal<point3_container_t>(
context, detector, item);
portals.push_back(portal);
} else {
auto surface = svgtools::conversion::surface<point3_container_t>(
context, item);
surfaces.push_back(surface);
const detray::detector_volume<detector_t>& d_volume,
const view_t& view, bool hide_portals = false,
bool hide_passives = false, bool hide_grids = false) {

actsvg::proto::volume<point3_container_t> p_volume;
p_volume._index = d_volume.index();

for (const auto& desc :
svgtools::utils::surface_lookup(detector, d_volume)) {

const auto sf = detray::surface{detector, desc};

if (sf.is_portal()) {
if (!hide_portals) {
auto portal = svgtools::conversion::portal<point3_container_t>(
context, detector, sf, false);
p_volume._portals.push_back(portal);
}
} else if (!(sf.is_passive() && hide_passives)) {
auto surface =
svgtools::conversion::surface<point3_container_t>(context, sf);
p_volume._v_surfaces.push_back(surface);
}
}
p_volume._v_surfaces = surfaces;
p_volume._portals = portals;
return p_volume;
}

/// @brief Calculates the proto volume of a detray volume.
///
/// @param context The context.
/// @param d_volume The detray volume.
///
/// @returns An actsvg proto volume representing the volume.
template <typename point3_container_t, typename detector_t>
auto volume(const typename detector_t::geometry_context& context,
const detector_t& detector,
const detray::detector_volume<detector_t>& d_volume) {
std::vector<detray::surface<detector_t>> surfaces{};
const auto descriptors =
svgtools::utils::surface_lookup(detector, d_volume);
for (const auto& desc : descriptors) {
surfaces.push_back(detray::surface{detector, desc});
// Convert grid, if present
if (!hide_grids) {
if (auto p_grid_ptr = svgtools::conversion::grid<actsvg::scalar>(
detector, p_volume._index, view)) {
p_volume._surface_grid = *p_grid_ptr;
}
}
return svgtools::conversion::volume<point3_container_t>(context, detector,
surfaces);

return p_volume;
}

} // namespace detray::svgtools::conversion
Loading

0 comments on commit e2b02cd

Please sign in to comment.