File indexing completed on 2026-08-02 08:44:28
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/AnyGridView.hpp"
0015 #include "Acts/Utilities/Delegate.hpp"
0016 #include "Acts/Utilities/Grid.hpp"
0017 #include "Acts/Utilities/GridAccessHelpers.hpp"
0018 #include "Acts/Utilities/ProtoAxis.hpp"
0019
0020 #include <ostream>
0021 #include <stdexcept>
0022 #include <vector>
0023
0024 namespace Acts {
0025
0026
0027
0028
0029
0030
0031
0032 struct IGridMaterialAccessor {
0033 virtual ~IGridMaterialAccessor() = default;
0034 };
0035
0036
0037
0038 struct GridMaterialAccessor : public IGridMaterialAccessor {
0039
0040 using grid_value_type = MaterialSlab;
0041
0042
0043
0044
0045
0046
0047 template <typename grid_type>
0048 inline const MaterialSlab& slab(
0049 grid_type& grid, const typename grid_type::point_t& point) const {
0050 return grid.atPosition(point);
0051 }
0052
0053
0054
0055
0056
0057
0058
0059 template <typename grid_type>
0060 void scale(grid_type& grid, double scale) {
0061
0062 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0063 grid.at(ib).scaleThickness(static_cast<float>(scale));
0064 }
0065 }
0066 };
0067
0068
0069
0070 struct IndexedMaterialAccessor : public IGridMaterialAccessor {
0071
0072 using grid_value_type = std::size_t;
0073
0074
0075
0076 explicit IndexedMaterialAccessor(std::vector<MaterialSlab>&& mmaterial)
0077 : IGridMaterialAccessor(), material(std::move(mmaterial)) {}
0078
0079
0080 std::vector<MaterialSlab> material;
0081
0082
0083
0084
0085
0086
0087 template <typename grid_type>
0088 inline const MaterialSlab& slab(
0089 const grid_type& grid, const typename grid_type::point_t& point) const
0090 requires(std::is_same_v<typename grid_type::value_type, grid_value_type>)
0091 {
0092 std::size_t index = grid.atPosition(point);
0093 return material[index];
0094 }
0095
0096
0097
0098
0099 template <typename grid_type>
0100 void scale(grid_type& , double scale) {
0101 for (auto& m : material) {
0102 m.scaleThickness(static_cast<float>(scale));
0103 }
0104 }
0105 };
0106
0107
0108
0109 struct GloballyIndexedMaterialAccessor : public IGridMaterialAccessor {
0110
0111
0112
0113 explicit GloballyIndexedMaterialAccessor(
0114 std::shared_ptr<std::vector<MaterialSlab>> gMaterial, bool shared = false)
0115 : IGridMaterialAccessor(),
0116 globalMaterial(std::move(gMaterial)),
0117 sharedEntries(shared) {}
0118
0119
0120 using grid_value_type = std::size_t;
0121
0122
0123 std::shared_ptr<std::vector<MaterialSlab>> globalMaterial = nullptr;
0124
0125
0126
0127
0128
0129 bool sharedEntries = false;
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 template <typename grid_type>
0140 inline const MaterialSlab& slab(
0141 const grid_type& grid, const typename grid_type::point_t& point) const {
0142 auto index = grid.atPosition(point);
0143 return (*globalMaterial)[index];
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 template <typename grid_type>
0156 void scale(grid_type& grid, double scale) {
0157 if (sharedEntries) {
0158 throw std::invalid_argument(
0159 "GloballyIndexedMaterialAccessor: shared entry scaling is not "
0160 "supported.");
0161 }
0162
0163 for (std::size_t ib = 0; ib < grid.size(); ++ib) {
0164 auto index = grid.at(ib);
0165 (*globalMaterial)[index].scaleThickness(static_cast<float>(scale));
0166 }
0167 }
0168 };
0169
0170
0171
0172 class IGridSurfaceMaterialBase : public ISurfaceMaterial {};
0173
0174
0175
0176 template <typename grid_value_t>
0177 class IGridSurfaceMaterial : public IGridSurfaceMaterialBase {
0178 public:
0179
0180
0181 virtual const IGrid& grid() const = 0;
0182
0183
0184
0185 virtual const IGridMaterialAccessor& materialAccessor() const = 0;
0186
0187
0188
0189 virtual const GridAccess::IBoundToGridLocal& boundToGridLocal() const = 0;
0190
0191
0192
0193 virtual const GridAccess::IGlobalToGridLocal& globalToGridLocal() const = 0;
0194
0195
0196
0197 virtual AnyGridView<grid_value_t> gridView() = 0;
0198
0199
0200
0201 virtual AnyGridConstView<grid_value_t> gridConstView() const = 0;
0202 };
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214 template <typename grid_t, typename material_accessor_t>
0215 class GridSurfaceMaterialT
0216 : public IGridSurfaceMaterial<
0217 typename material_accessor_t::grid_value_type> {
0218 public:
0219
0220
0221 using BoundToGridLocalDelegate =
0222 OwningDelegate<typename grid_t::point_t(const Vector2&),
0223 GridAccess::IBoundToGridLocal>;
0224
0225
0226
0227 using GlobalToGridLocalDelegate =
0228 OwningDelegate<typename grid_t::point_t(const Vector3&),
0229 GridAccess::IGlobalToGridLocal>;
0230
0231
0232 using grid_type = grid_t;
0233
0234
0235 using material_accessor_type = material_accessor_t;
0236
0237
0238
0239
0240
0241
0242
0243 GridSurfaceMaterialT(grid_type&& grid,
0244 material_accessor_type&& materialAccessor,
0245 BoundToGridLocalDelegate boundToGridLocal,
0246 GlobalToGridLocalDelegate globalToGridLocal)
0247 : m_grid(std::move(grid)),
0248 m_materialAccessor(std::move(materialAccessor)),
0249 m_globalToGridLocal(std::move(globalToGridLocal)),
0250 m_boundToGridLocal(std::move(boundToGridLocal)) {
0251 if (!m_globalToGridLocal.connected()) {
0252 throw std::invalid_argument(
0253 "GridSurfaceMaterialT: GlobalToGridLocalDelegate is not connected.");
0254 }
0255 if (!m_boundToGridLocal.connected()) {
0256 throw std::invalid_argument(
0257 "GridSurfaceMaterialT: BoundToGridLocalDelegate is not connected.");
0258 }
0259 }
0260
0261
0262 const MaterialSlab& materialSlab(const Vector2& lp) const final {
0263 return m_materialAccessor.slab(m_grid, m_boundToGridLocal(lp));
0264 }
0265
0266
0267 const MaterialSlab& materialSlab(const Vector3& gp) const final {
0268 return m_materialAccessor.slab(m_grid, m_globalToGridLocal(gp));
0269 }
0270
0271 using ISurfaceMaterial::materialSlab;
0272
0273
0274
0275
0276
0277 ISurfaceMaterial& scale(double factor) final {
0278 m_materialAccessor.scale(m_grid, factor);
0279 return (*this);
0280 }
0281
0282
0283
0284
0285 std::ostream& toStream(std::ostream& sl) const final {
0286 sl << "GridSurfaceMaterial - material access via accessor.";
0287 return sl;
0288 }
0289
0290
0291
0292 const grid_type& grid() const final { return m_grid; }
0293
0294
0295
0296 AnyGridView<typename material_accessor_t::grid_value_type> gridView() final {
0297 return AnyGridView<typename material_accessor_t::grid_value_type>(m_grid);
0298 }
0299
0300
0301
0302 AnyGridConstView<typename material_accessor_t::grid_value_type>
0303 gridConstView() const final {
0304 return AnyGridConstView<typename material_accessor_t::grid_value_type>(
0305 m_grid);
0306 }
0307
0308
0309
0310 const material_accessor_type& materialAccessor() const final {
0311 return m_materialAccessor;
0312 }
0313
0314
0315
0316 const GridAccess::IBoundToGridLocal& boundToGridLocal() const final {
0317 return *(m_boundToGridLocal.instance());
0318 }
0319
0320
0321
0322 const BoundToGridLocalDelegate& boundToGridLocalDelegate() const {
0323 return m_boundToGridLocal;
0324 }
0325
0326
0327
0328 const GridAccess::IGlobalToGridLocal& globalToGridLocal() const final {
0329 return *(m_globalToGridLocal.instance());
0330 }
0331
0332
0333
0334 const GlobalToGridLocalDelegate& globalToGridLocalDelegate() const {
0335 return m_globalToGridLocal;
0336 }
0337
0338 private:
0339
0340 grid_type m_grid;
0341
0342
0343 material_accessor_type m_materialAccessor;
0344
0345
0346 GlobalToGridLocalDelegate m_globalToGridLocal;
0347
0348
0349 BoundToGridLocalDelegate m_boundToGridLocal;
0350 };
0351
0352
0353
0354
0355 template <typename grid_type>
0356 using IndexedSurfaceMaterial =
0357 GridSurfaceMaterialT<grid_type, IndexedMaterialAccessor>;
0358
0359
0360
0361 template <typename grid_type>
0362 using GloballyIndexedSurfaceMaterial =
0363 GridSurfaceMaterialT<grid_type, GloballyIndexedMaterialAccessor>;
0364
0365
0366
0367 template <typename grid_type>
0368 using GridSurfaceMaterial =
0369 GridSurfaceMaterialT<grid_type, GridMaterialAccessor>;
0370
0371
0372
0373 }