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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*
* SimpleLevelLocator.h
*
* Created on: Aug 27, 2015
* Author: swenzel
*/
#ifndef NAVIGATION_SIMPLELEVELLOCATOR_H_
#define NAVIGATION_SIMPLELEVELLOCATOR_H_
#include "VecGeom/navigation/VLevelLocator.h"
#include "VecGeom/volumes/LogicalVolume.h"
#include "VecGeom/navigation/NavigationState.h"
#include "VecGeom/volumes/PlacedAssembly.h"
namespace vecgeom {
inline namespace VECGEOM_IMPL_NAMESPACE {
// shared kernel for many locators
// treats the actual final check (depending on which interface to serve)
template <bool IsAssemblyAware, bool ModifyState>
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
static bool CheckCandidateVol(VPlacedVolume const *nextvolume,
Vector3D<Precision> const &localpoint,
NavigationState *state, VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint)
{
if (IsAssemblyAware && ModifyState) {
if (nextvolume->GetUnplacedVolume()->IsAssembly()) {
// in this case we call a special version of Contains
// offered by the assembly
assert(ModifyState == true);
if (((PlacedAssembly *)nextvolume)->Contains(localpoint, daughterlocalpoint, *state)) {
return true;
}
} else {
if (nextvolume->Contains(localpoint, daughterlocalpoint)) {
state->Push(nextvolume);
return true;
}
}
} else {
if (nextvolume->Contains(localpoint, daughterlocalpoint)) {
if (ModifyState) {
state->Push(nextvolume);
} else {
pvol = nextvolume;
}
return true;
}
}
return false;
}
// shared kernel for many locators
// treats the actual final check (depending on which interface to serve)
template <bool IsAssemblyAware, bool ModifyState>
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
static bool CheckCandidateVolWithDirection(
VPlacedVolume const *nextvolume, Vector3D<Precision> const &localpoint, Vector3D<Precision> const &localdirection,
NavigationState *state, VPlacedVolume const *&pvol, Vector3D<Precision> &daughterlocalpoint)
{
if (IsAssemblyAware && ModifyState) {
/* if (nextvolume->GetUnplacedVolume()->IsAssembly()) { */
/* // in this case we call a special version of Contains */
/* // offered by the assembly */
/* assert(ModifyState == true); */
/* if (((PlacedAssembly *)nextvolume)->Inside(localpoint, daughterlocalpoint, *state)) { */
/* return true; */
/* } */
/* } else { */
/* if (nextvolume->Inside(localpoint, daughterlocalpoint)) { */
/* state->Push(nextvolume); */
/* return true; */
/* } */
/* } */
assert(false && "not implemented yet");
} else {
//
const auto transf = nextvolume->GetTransformation();
const auto testdaughterlocal = transf->Transform(localpoint);
const auto inside = nextvolume->GetUnplacedVolume()->Inside(testdaughterlocal);
auto CheckEntering = [&transf, &testdaughterlocal, &localdirection, &nextvolume]() {
const auto unpl = nextvolume->GetUnplacedVolume();
Vector3D<Precision> normal;
unpl->Normal(testdaughterlocal, normal);
const auto directiondaughterlocal = transf->TransformDirection(localdirection);
const auto dot = normal.Dot(directiondaughterlocal);
if (dot >= 0) {
return false;
}
return true;
};
if (inside == kInside || ((inside == kSurface) && CheckEntering())) {
if (ModifyState) {
state->Push(nextvolume);
daughterlocalpoint = testdaughterlocal;
} else {
pvol = nextvolume;
daughterlocalpoint = testdaughterlocal;
}
return true;
}
}
return false;
}
// a simple version of a LevelLocator offering a generic brute force algorithm
template <bool IsAssemblyAware = false>
class TSimpleLevelLocator : public VLevelLocator {
public:
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
TSimpleLevelLocator() {}
private:
// the actual implementation kernel
// the template "ifs" should be optimized away
// arguments are pointers to allow for nullptr
template <bool ExclV, bool ModifyState>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
bool LevelLocateKernel(LogicalVolume const *lvol, VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint, NavigationState *state,
VPlacedVolume const *&pvol,
Vector3D<Precision> &daughterlocalpoint) const
{
auto daughters = lvol->GetDaughtersp();
for (size_t i = 0; i < daughters->size(); ++i) {
VPlacedVolume const *nextvolume = (*daughters)[i];
if (ExclV) {
if (exclvol == nextvolume) continue;
}
if (CheckCandidateVol<IsAssemblyAware, ModifyState>(nextvolume, 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>
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
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
{
auto daughters = lvol->GetDaughtersp();
for (size_t i = 0; i < daughters->size(); ++i) {
VPlacedVolume const *nextvolume = (*daughters)[i];
if (ExclV) {
if (exclvol == nextvolume) continue;
}
if (CheckCandidateVolWithDirection<IsAssemblyAware, ModifyState>(nextvolume, localpoint, localdir, state, pvol,
daughterlocalpoint)) {
return true;
}
}
return false;
}
public:
VECCORE_ATT_HOST_DEVICE
virtual 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);
}
VECCORE_ATT_HOST_DEVICE
virtual bool LevelLocate(LogicalVolume const *lvol, Vector3D<Precision> const &localpoint, NavigationState &state,
Vector3D<Precision> &daughterlocalpoint) const override
{
VPlacedVolume const *pvol = nullptr;
return LevelLocateKernel<false, true>(lvol, nullptr, localpoint, &state, pvol, daughterlocalpoint);
}
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
virtual 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);
}
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
virtual bool LevelLocateExclVol(LogicalVolume const *lvol, VPlacedVolume const *exclvol,
Vector3D<Precision> const &localpoint, Vector3D<Precision> const &localdirection,
VPlacedVolume const *&pvol, Vector3D<Precision> &daughterlocalpoint) const override
{
return LevelLocateKernelWithDirection<true, false>(lvol, exclvol, localpoint, localdirection, nullptr, pvol,
daughterlocalpoint);
}
static std::string GetClassName() { return "SimpleLevelLocator"; }
virtual std::string GetName() const override { return GetClassName(); }
#ifndef VECCORE_CUDA
VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE
static VLevelLocator const *GetInstance()
{
static TSimpleLevelLocator instance;
return &instance;
}
#endif
}; // end class declaration
using SimpleLevelLocator = TSimpleLevelLocator<>;
template <>
inline std::string TSimpleLevelLocator<true>::GetClassName()
{
return "SimpleAssemblyLevelLocator";
}
using SimpleAssemblyLevelLocator = TSimpleLevelLocator<true>;
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom
#endif /* NAVIGATION_SIMPLELEVELLOCATOR_H_ */
|