File indexing completed on 2025-01-18 10:13:56
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef VECGEOM_MANAGEMENT_EMBREEMANAGER_H_
0009 #define VECGEOM_MANAGEMENT_EMBREEMANAGER_H_
0010
0011 #include "VecGeom/base/Global.h"
0012 #include "VecGeom/volumes/PlacedVolume.h"
0013 #include "VecGeom/base/Vector3D.h"
0014 #include "VecGeom/management/GeoManager.h"
0015 #include <vector>
0016
0017 #include <embree3/rtcore.h>
0018
0019 namespace vecgeom {
0020 inline namespace VECGEOM_IMPL_NAMESPACE {
0021
0022 class VPlacedVolume;
0023
0024
0025 enum class EmbreeBuildMode {
0026 kAABBox,
0027 kBBox
0028 };
0029
0030
0031
0032 class EmbreeManager {
0033
0034 public:
0035 typedef Vector3D<Precision> ABBox_s;
0036 typedef ABBox_s *ABBoxContainer_t;
0037
0038
0039 typedef std::pair<int, double> BoxIdDistancePair_t;
0040 using HitContainer_t = std::vector<BoxIdDistancePair_t>;
0041
0042
0043 struct EmbreeAccelerationStructure {
0044 RTCDevice fDevice;
0045 RTCScene fScene;
0046 Vector3D<float> *fNormals;
0047 int fNumberObjects;
0048 };
0049
0050 private:
0051
0052 std::vector<EmbreeAccelerationStructure const *> fStructureHolder;
0053
0054 public:
0055
0056 void InitStructure(LogicalVolume const *lvol);
0057
0058
0059
0060 void InitVoxelStructureForCompleteGeometry()
0061 {
0062 std::vector<LogicalVolume const *> logicalvolumes;
0063 GeoManager::Instance().GetAllLogicalVolumes(logicalvolumes);
0064 for (auto lvol : logicalvolumes) {
0065 InitStructure(lvol);
0066 }
0067 }
0068
0069 static EmbreeManager &Instance()
0070 {
0071 static EmbreeManager manager;
0072 return manager;
0073 }
0074
0075
0076 void RemoveStructure(LogicalVolume const *lvol);
0077
0078 EmbreeAccelerationStructure const *GetAccStructure(LogicalVolume const *lvol) const
0079 {
0080 return fStructureHolder[lvol->id()];
0081 }
0082
0083
0084
0085 EmbreeAccelerationStructure *BuildStructureFromBoundingBoxes(ABBoxContainer_t alignedboxes,
0086 size_t numberofboxes) const;
0087
0088
0089 EmbreeAccelerationStructure *BuildStructureFromBoundingBoxes(LogicalVolume const *lvol) const;
0090
0091
0092
0093 void SetBuildMode(EmbreeBuildMode mode) { fBuildMode = mode; }
0094
0095 private:
0096
0097 void BuildStructure(LogicalVolume const *lvol);
0098
0099
0100 void AddBoxGeometryToScene(EmbreeAccelerationStructure &, Vector3D<Precision> const &lower,
0101 Vector3D<Precision> const &upper,
0102 Transformation3D const &transf = Transformation3D::kIdentity) const;
0103
0104
0105 void AddArbitraryBBoxToScene(EmbreeAccelerationStructure &, VPlacedVolume const *pvol,
0106 EmbreeBuildMode mode = EmbreeBuildMode::kBBox) const;
0107
0108 EmbreeBuildMode fBuildMode = EmbreeBuildMode::kAABBox;
0109
0110 };
0111 }
0112 }
0113
0114 #endif