File indexing completed on 2025-09-13 08:28:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Material/ISurfaceMaterial.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Utilities/Delegate.hpp"
0015 #include "Acts/Utilities/GridAccessHelpers.hpp"
0016
0017 #include <ostream>
0018 #include <stdexcept>
0019 #include <vector>
0020
0021 namespace Acts {
0022
0023
0024
0025 struct GridMaterialAccessor {
0026
0027
0028
0029
0030
0031
0032 template <typename grid_type>
0033 inline const MaterialSlab& slab(
0034 grid_type& grid, const typename grid_type::point_t& point) const {
0035 return grid.atPosition(point);
0036 }
0037
0038
0039
0040
0041
0042
0043
0044 template <typename grid_type>
0045 void scale(grid_type& grid, double scale) {
0046
0047 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0048 grid.at(ib).scaleThickness(scale);
0049 }
0050 }
0051 };
0052
0053
0054
0055 struct IndexedMaterialAccessor {
0056
0057 std::vector<MaterialSlab> material;
0058
0059
0060
0061
0062
0063
0064 template <typename grid_type>
0065 inline const MaterialSlab& slab(
0066 const grid_type& grid, const typename grid_type::point_t& point) const {
0067 auto index = grid.atPosition(point);
0068 return material[index];
0069 }
0070
0071
0072
0073
0074 template <typename grid_type>
0075 void scale(grid_type& , double scale) {
0076 for (auto& m : material) {
0077 m.scaleThickness(scale);
0078 }
0079 }
0080 };
0081
0082
0083
0084 struct GloballyIndexedMaterialAccessor {
0085
0086 std::shared_ptr<std::vector<MaterialSlab>> globalMaterial = nullptr;
0087
0088
0089
0090
0091
0092 bool sharedEntries = false;
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 template <typename grid_type>
0103 inline const MaterialSlab& slab(
0104 const grid_type& grid, const typename grid_type::point_t& point) const {
0105 auto index = grid.atPosition(point);
0106 return (*globalMaterial)[index];
0107 }
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 template <typename grid_type>
0119 void scale(grid_type& grid, double scale) {
0120 if (sharedEntries) {
0121 throw std::invalid_argument(
0122 "GloballyIndexedMaterialAccessor: shared entry scaling is not "
0123 "supported.");
0124 }
0125
0126 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0127 auto index = grid.at(ib);
0128 (*globalMaterial)[index].scaleThickness(scale);
0129 }
0130 }
0131 };
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 template <typename grid_t, typename material_accessor_t = GridMaterialAccessor>
0144 class GridSurfaceMaterialT : public ISurfaceMaterial {
0145 public:
0146
0147 using BoundToGridLocalDelegate =
0148 OwningDelegate<typename grid_t::point_t(const Vector2&),
0149 GridAccess::IBoundToGridLocal>;
0150
0151
0152 using GlobalToGridLocalDelegate =
0153 OwningDelegate<typename grid_t::point_t(const Vector3&),
0154 GridAccess::IGlobalToGridLocal>;
0155
0156
0157 using grid_type = grid_t;
0158
0159
0160 using material_accessor_type = material_accessor_t;
0161
0162
0163
0164
0165
0166
0167
0168 GridSurfaceMaterialT(grid_type&& grid,
0169 material_accessor_type&& materialAccessor,
0170 BoundToGridLocalDelegate boundToGridLocal,
0171 GlobalToGridLocalDelegate globalToGridLocal)
0172 : m_grid(std::move(grid)),
0173 m_materialAccessor(std::move(materialAccessor)),
0174 m_globalToGridLocal(std::move(globalToGridLocal)),
0175 m_boundToGridLocal(std::move(boundToGridLocal)) {
0176 if (!m_globalToGridLocal.connected()) {
0177 throw std::invalid_argument(
0178 "GridSurfaceMaterialT: GlobalToGridLocalDelegate is not connected.");
0179 }
0180 if (!m_boundToGridLocal.connected()) {
0181 throw std::invalid_argument(
0182 "GridSurfaceMaterialT: BoundToGridLocalDelegate is not connected.");
0183 }
0184 }
0185
0186
0187 const MaterialSlab& materialSlab(const Vector2& lp) const final {
0188 return m_materialAccessor.slab(m_grid, m_boundToGridLocal(lp));
0189 }
0190
0191
0192 const MaterialSlab& materialSlab(const Vector3& gp) const final {
0193 return m_materialAccessor.slab(m_grid, m_globalToGridLocal(gp));
0194 }
0195
0196
0197
0198
0199 ISurfaceMaterial& scale(double factor) final {
0200 m_materialAccessor.scale(m_grid, factor);
0201 return (*this);
0202 }
0203
0204
0205 std::ostream& toStream(std::ostream& sl) const final {
0206 sl << "GridSurfaceMaterial - material access via accessor.";
0207 return sl;
0208 }
0209
0210
0211 const grid_type& grid() const { return m_grid; }
0212
0213
0214 const material_accessor_type& materialAccessor() const {
0215 return m_materialAccessor;
0216 }
0217
0218
0219 const BoundToGridLocalDelegate& boundToGridLocal() const {
0220 return m_boundToGridLocal;
0221 }
0222
0223
0224 const GlobalToGridLocalDelegate& globalToGridLocal() const {
0225 return m_globalToGridLocal;
0226 }
0227
0228 private:
0229
0230 grid_type m_grid;
0231
0232
0233 material_accessor_type m_materialAccessor;
0234
0235
0236 GlobalToGridLocalDelegate m_globalToGridLocal;
0237
0238
0239 BoundToGridLocalDelegate m_boundToGridLocal;
0240 };
0241
0242
0243 template <typename grid_type>
0244 using IndexedSurfaceMaterial =
0245 GridSurfaceMaterialT<grid_type, IndexedMaterialAccessor>;
0246
0247
0248 template <typename grid_type>
0249 using GloballyIndexedSurfaceMaterial =
0250 GridSurfaceMaterialT<grid_type, GloballyIndexedMaterialAccessor>;
0251
0252
0253 template <typename grid_type>
0254 using GridSurfaceMaterial = GridSurfaceMaterialT<grid_type>;
0255
0256 }