Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-21 09:19:52

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 <map>
0012 #include <optional>
0013 #include <string>
0014 #include <utility>
0015 #include <vector>
0016 
0017 #include "actsvg/core/style.hpp"
0018 #include "actsvg/proto/material.hpp"
0019 #include "actsvg/styles/defaults.hpp"
0020 #include "grid.hpp"
0021 
0022 namespace actsvg {
0023 
0024 namespace proto {
0025 
0026 /** A proto surface class as a simple translation layer
0027  * from a surface description
0028  *
0029  * @tparam point3_container a vertex description of surfaces
0030  **/
0031 
0032 template <typename point3_container>
0033 struct surface {
0034 
0035     using point3 = typename point3_container::value_type;
0036 
0037     /// A transform3 structure before placement
0038     struct transform3 {
0039         // original translation
0040         point3 _translation = {0., 0., 0.};
0041         // original rotation
0042         std::array<point3, 3u> _rotation = {
0043             point3{1., 0., 0.}, point3{0., 1., 0.}, point3{0., 0., 1.}};
0044         // Rotate a point to the global frame
0045         point3 rotate(const point3& p_) const {
0046 
0047             point3 ret{0.f, 0.f, 0.f};
0048 
0049             ret[0] += _rotation[0][0] * p_[0];
0050             ret[1] += _rotation[1][0] * p_[0];
0051             ret[2] += _rotation[2][0] * p_[0];
0052 
0053             ret[0] += _rotation[0][1] * p_[1];
0054             ret[1] += _rotation[1][1] * p_[1];
0055             ret[2] += _rotation[2][1] * p_[1];
0056 
0057             ret[0] += _rotation[0][2] * p_[2];
0058             ret[1] += _rotation[1][2] * p_[2];
0059             ret[2] += _rotation[2][2] * p_[2];
0060 
0061             return ret;
0062         }
0063 
0064         /// Apply the translation and rotation
0065         point3 point_to_global(const point3& p_) const {
0066             // Apply the rotation
0067             point3 ret = rotate(p_);
0068             ret[0] += _translation[0];
0069             ret[1] += _translation[1];
0070             ret[2] += _translation[2];
0071             return ret;
0072         }
0073 
0074         // The identity transform
0075         static transform3 identity() { return transform3{}; }
0076     };
0077 
0078     enum class type {
0079         e_annulus,
0080         e_cylinder,
0081         e_diamond,
0082         e_disc,
0083         e_polygon,
0084         e_rectangle,
0085         e_straw,
0086         e_trapez
0087     };
0088 
0089     enum class sf_type { e_portal, e_sensitive, e_passive };
0090 
0091     enum class boolean { e_clipping, e_union, e_subtraction, e_none };
0092 
0093     /// Name of the surface
0094     std::string _name = "unnamed_surface";
0095 
0096     /// Auxiliary information as container map
0097     std::map<std::string, std::vector<std::string>> _aux_info = {};
0098 
0099     /// The contained vertices - for polygon surfaces
0100     point3_container _vertices = {};
0101 
0102     /// This is the optional surface transform - to be applied at the
0103     /// vertices before the view is created
0104     std::optional<transform3> _surface_transform = std::nullopt;
0105 
0106     /// Dedicated regular disc/cylinder descriptions
0107     /// - if this is not applicable the _vertices view needs to be chosen
0108     std::array<scalar, 2> _radii = {0., 0.};
0109     std::array<scalar, 2> _opening = {-pi, pi};
0110     std::array<scalar, 2> _zparameters = {0., 0.};
0111 
0112     /// Boolean surfaces
0113     std::vector<surface<point3_container>> _boolean_surface = {};
0114     boolean _boolean_operation = boolean::e_none;
0115 
0116     /// Fill and stroke
0117     style::fill _fill = defaults::__s_fill;
0118     style::stroke _stroke = defaults::__s_stroke;
0119     style::transform _transform = defaults::__t_identity;
0120 
0121     /// Type of the surfaces
0122     type _type = type::e_trapez;
0123     sf_type _sf_type = sf_type::e_sensitive;
0124 
0125     /// And their measures
0126     std::vector<scalar> _measures = {};
0127 
0128     /// Decoration
0129     std::map<std::string, svg::object> _decorations;
0130 
0131     /// The surface material
0132     surface_material _material = {};
0133 
0134     /// A (potential) template for this surface
0135     svg::object _template_object;
0136 
0137     using point3_type = typename point3_container::value_type;
0138 
0139     /** Static constructor from a template
0140      * @param t_ the template
0141      * @param o_ the template object
0142      * @param name_ the new name
0143      **/
0144     static surface<point3_container> from_template(
0145         const surface<point3_container>& t_, const svg::object& o_,
0146         const std::string& name_) {
0147         surface<point3_container> s;
0148         s._name = name_;
0149         s._type = t_._type;
0150         s._sf_type = t_._sf_type;
0151         s._aux_info = t_._aux_info;
0152         s._vertices = t_._vertices;
0153         s._measures = t_._measures;
0154         s._radii = t_._radii;
0155         s._opening = t_._opening;
0156         s._fill = t_._fill;
0157         s._stroke = t_._stroke;
0158         s._transform = t_._transform;
0159         s._template_object = o_;
0160         s._decorations = t_._decorations;
0161         return s;
0162     }
0163 };
0164 
0165 }  // namespace proto
0166 
0167 }  // namespace actsvg