1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
// This file is part of VecGeom and is distributed under the
// conditions in the file LICENSE.txt in the top directory.
// For the full list of authors see CONTRIBUTORS.txt and `git log`.
/// \file navigation/VoxelLevelLocator.h
/// \author Sandro Wenzel (CERN)
#ifndef NAVIGATION_VOXELLEVELLOCATOR_H_
#define NAVIGATION_VOXELLEVELLOCATOR_H_
#include "VecGeom/navigation/VLevelLocator.h"
#include "VecGeom/volumes/LogicalVolume.h"
#include "VecGeom/volumes/PlacedVolume.h"
#include "VecGeom/management/FlatVoxelManager.h"
#include "VecGeom/volumes/kernel/BoxImplementation.h"
#include "VecGeom/navigation/SimpleLevelLocator.h"
#include "VecGeom/management/ABBoxManager.h"
namespace vecgeom {
inline namespace VECGEOM_IMPL_NAMESPACE {
//! A LevelLocator using voxel hash-maps containing candidate volume ids to quickly
//! decide in which volume a point is.
template <bool IsAssemblyAware = false>
class TVoxelLevelLocator : public VLevelLocator {
private:
FlatVoxelManager &fAccelerationStructure;
TVoxelLevelLocator() : fAccelerationStructure(FlatVoxelManager::Instance()) {}
// the actual implementation kernel
// the template "ifs" should be optimized away
// arguments are pointers to allow for nullptr
template <bool ExclV, bool ModifyState>
__attribute__((always_inline)) bool LevelLocateKernel(LogicalVolume const *lvol, VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint, NavigationState *state,
VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint) const
{
const auto accstructure = fAccelerationStructure.GetStructure(lvol);
// fetch the right voxels
const auto locatevoxels = accstructure->fVoxelToLocateCandidates;
// fetch the list of candidates to check (as id)
Vector3D<float> floatlocalpoint(localpoint.x(), localpoint.y(), localpoint.z());
int numbercandidates{0};
const auto candidateidsptr = locatevoxels->getProperties(floatlocalpoint, numbercandidates);
if (numbercandidates > 0) {
// here we have something to do
int numberboxes{0};
const auto boxes = ABBoxManager::Instance().GetABBoxes(lvol, numberboxes);
for (int i = 0; i < numbercandidates; ++i) {
const int daughterid = candidateidsptr[i];
// discard blocked volume
VPlacedVolume const *candidate = lvol->GetDaughters()[daughterid];
if (ExclV) {
if (candidate == exclvol) continue;
}
// quick aligned bounding box check (could be done in SIMD fashion if multiple candidates)
const auto &lower = boxes[2 * daughterid];
const auto &upper = boxes[2 * daughterid + 1];
bool boxcontains{false};
ABBoxImplementation::ABBoxContainsKernel(lower, upper, localpoint, boxcontains);
if (!boxcontains) {
continue;
}
// final candidate check
if (CheckCandidateVol<IsAssemblyAware, ModifyState>(candidate, localpoint, state, pvol, daughterlocalpoint)) {
return true;
}
}
}
return false;
}
// the actual implementation kernel
// the template "ifs" should be optimized away
// arguments are pointers to allow for nullptr
template <bool ExclV, bool ModifyState>
__attribute__((always_inline)) bool LevelLocateKernelWithDirection(LogicalVolume const *lvol,
VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint,
Vector3D<Precision> const &localdir,
NavigationState *state, VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint) const
{
const auto accstructure = fAccelerationStructure.GetStructure(lvol);
// fetch the right voxels
const auto locatevoxels = accstructure->fVoxelToLocateCandidates;
// fetch the list of candidates to check (as id)
Vector3D<float> floatlocalpoint(localpoint.x(), localpoint.y(), localpoint.z());
int numbercandidates{0};
const auto candidateidsptr = locatevoxels->getProperties(floatlocalpoint, numbercandidates);
if (numbercandidates > 0) {
// here we have something to do
int numberboxes{0};
const auto boxes = ABBoxManager::Instance().GetABBoxes(lvol, numberboxes);
for (int i = 0; i < numbercandidates; ++i) {
const int daughterid = candidateidsptr[i];
// discard blocked volume
VPlacedVolume const *candidate = lvol->GetDaughters()[daughterid];
if (ExclV) {
if (candidate == exclvol) continue;
}
// quick aligned bounding box check (could be done in SIMD fashion if multiple candidates)
const auto &lower = boxes[2 * daughterid];
const auto &upper = boxes[2 * daughterid + 1];
bool boxcontains{false};
ABBoxImplementation::ABBoxContainsKernel(lower, upper, localpoint, boxcontains);
if (!boxcontains) {
continue;
}
// final candidate check
if (CheckCandidateVolWithDirection<IsAssemblyAware, ModifyState>(candidate, localpoint, localdir, state, pvol,
daughterlocalpoint)) {
return true;
}
}
}
return false;
}
public:
static std::string GetClassName() { return "VoxelLevelLocator"; }
std::string GetName() const override { return GetClassName(); }
bool LevelLocate(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint, VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint) const override
{
return LevelLocateKernel<false, false>(lvol, nullptr, localpoint, nullptr, pvol, daughterlocalpoint);
}
bool LevelLocate(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint, NavigationState &state,
Vector3D<Precision> &daughterlocalpoint) const override
{
VPlacedVolume const *pvol;
return LevelLocateKernel<false, true>(lvol, nullptr, localpoint, &state, pvol, daughterlocalpoint);
}
bool LevelLocateExclVol(LogicalVolume const *lvol, VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint, VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint) const override
{
return LevelLocateKernel<true, false>(lvol, exclvol, localpoint, nullptr, pvol, daughterlocalpoint);
}
bool LevelLocateExclVol(LogicalVolume const *lvol, VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint, Vector3D<Precision> const &localdir,
VPlacedVolume const *&pvol, Vector3D<Precision> &daughterlocalpoint) const override
{
return LevelLocateKernelWithDirection<true, false>(lvol, exclvol, localpoint, localdir, nullptr, pvol,
daughterlocalpoint);
}
static VLevelLocator const *GetInstance()
{
static TVoxelLevelLocator instance;
return &instance;
}
}; // end class declaration
template <>
inline std::string TVoxelLevelLocator<true>::GetClassName()
{
return "AssemblyAwareVoxelLevelLocator";
}
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom
#endif /* NAVIGATION_VOXELLEVELLOCATOR_H_ */
|