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