Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-02 09:18:43

0001 // This file is part of the actsvg package.
0002 //
0003 // Copyright (C) 2022 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <string>
0012 #include <vector>
0013 
0014 #include "actsvg/core/style.hpp"
0015 #include "actsvg/proto/grid.hpp"
0016 #include "actsvg/proto/portal.hpp"
0017 #include "actsvg/proto/surface.hpp"
0018 #include "actsvg/styles/defaults.hpp"
0019 
0020 namespace actsvg {
0021 
0022 namespace proto {
0023 
0024 /** A proto volume class as a simple translation layer
0025  * from a volume description
0026  *
0027  * @tparam point3_container a vertex description of surfaces
0028  **/
0029 
0030 template <typename point3_container>
0031 struct volume {
0032 
0033     using surface_type = surface<point3_container>;
0034 
0035     using portal_type = portal<point3_container>;
0036 
0037     /// Type enumeration
0038     enum type { e_cylinder = 0, e_cuboid = 1, e_other = 2 };
0039 
0040     // The index of the volume
0041     unsigned int _index = 0u;
0042 
0043     // The depth level of the volume
0044     unsigned int _depth_level = 0u;
0045 
0046     /// Name of the volume
0047     std::string _name = "unnamed_volume";
0048 
0049     // The type of the volume & its parameters
0050     type _type = e_cylinder;
0051     std::vector<scalar> _bound_values;
0052     point3_container _vertices = {};
0053 
0054     // Style parameters
0055     style::fill _fill;
0056     style::stroke _stroke = defaults::__nn_stroke;
0057     style::transform _transform;
0058 
0059     /// Auxiliary information
0060     std::vector<std::string> _info = {};
0061 
0062     /// The contained surfaces as batches - optimised for layer view
0063     std::vector<std::vector<surface<point3_container>>> _surfaces = {};
0064 
0065     /// The container surfaces as flat - opimised for volume view
0066     std::vector<surface<point3_container>> _v_surfaces = {};
0067 
0068     /// The portals
0069     std::vector<portal<point3_container>> _portals = {};
0070 
0071     /// The associated surface grid
0072     grid _surface_grid;
0073 
0074     /** These are the grid associations, when iterating through
0075      * the associataions are also grouped by batch in order to
0076      * split the association view if necessary
0077      *
0078      *  for (auto : batch){
0079      *    size_t i = 0;
0080      *    for (auto: _edges_1){
0081      *      for (auto: _edges_0){
0082      *        auto assoc = _grid_associations[i++];
0083      *        }
0084      *     }
0085      *   }
0086      *
0087      * The entries of the association point to the index in the surface
0088      * container of the volume
0089      **/
0090     std::vector<std::vector<std::vector<size_t>>> _grid_associations = {};
0091 
0092     /// Colorize method
0093     ///
0094     /// @param colors_ are the indexed colors
0095     ///
0096     void colorize(std::vector<style::color>& colors_) {
0097         if (_index < colors_.size()) {
0098             _fill._fc = colors_[_index];
0099         }
0100         // Colorize the portals
0101         for (auto& p : _portals) {
0102             // The portal itself has no fill color
0103             p._surface._fill._fc._rgb = {255, 255, 255};
0104             p._surface._fill._fc._opacity = 1.;
0105             // The links are filled
0106             for (auto& vl : p._volume_links) {
0107                 if (vl._link_index < colors_.size()) {
0108                     vl._stroke._sc = colors_[vl._link_index];
0109                     vl._stroke._sc._opacity = 1.;
0110                     vl._end_marker._fill._fc = colors_[vl._link_index];
0111                     vl._end_marker._fill._fc._opacity = 1.;
0112                     vl._end_marker._stroke = vl._stroke;
0113                 }
0114             }
0115         }
0116         // Colorize the surfaces
0117         for (auto& sbatch : _surfaces) {
0118             for (auto& s : sbatch) {
0119                 s._fill._fc = colors_[_index];
0120                 s._fill._fc._opacity = 0.25;
0121             }
0122         }
0123     }
0124 };
0125 
0126 }  // namespace proto
0127 
0128 }  // namespace actsvg