Skip to content

Commit

Permalink
refactor: Remove BVH navigation remnants (to be reimplemented) (acts-…
Browse files Browse the repository at this point in the history
…project#3029)

This is to be reimplemented in the navigation delegate scheme, and blocks refactoring.
  • Loading branch information
paulgessinger authored Mar 13, 2024
1 parent a606f8a commit ccc1975
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 565 deletions.
46 changes: 0 additions & 46 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,6 @@ class TrackingVolume : public Volume {
return MutableTrackingVolumePtr(new TrackingVolume(
transform, std::move(volumeBounds), containedVolumes, volumeName));
}

/// Factory constructor for Tracking Volume with a bounding volume hierarchy
///
/// @param transform is the global 3D transform to position the volume in
/// space
/// @param volbounds is the description of the volume boundaries
/// @param boxStore Vector owning the contained bounding boxes
/// @param descendants Vector owning the child volumes
/// @param top The top of the hierarchy (top node)
/// @param volumeMaterial is the materials of the tracking volume
/// @param volumeName is a string identifier
///
/// @return shared pointer to a new TrackingVolume
static MutableTrackingVolumePtr create(
const Transform3& transform, VolumeBoundsPtr volbounds,
std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
std::vector<std::unique_ptr<const Volume>> descendants,
const Volume::BoundingBox* top,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
const std::string& volumeName = "undefined") {
return MutableTrackingVolumePtr(new TrackingVolume(
transform, std::move(volbounds), std::move(boxStore),
std::move(descendants), top, std::move(volumeMaterial), volumeName));
}

/// Factory constructor for Tracking Volumes with content
/// - can not be a container volume
///
Expand Down Expand Up @@ -435,11 +410,6 @@ class TrackingVolume : public Volume {
/// - positiveFaceXY
GlueVolumesDescriptor& glueVolumesDescriptor();

/// Return whether this TrackingVolume has a BoundingVolumeHierarchy
/// associated
/// @return If it has a BVH or not.
bool hasBoundingVolumeHierarchy() const;

/// Register the color code
///
/// @param icolor is a color number
Expand Down Expand Up @@ -470,13 +440,6 @@ class TrackingVolume : public Volume {
containedVolumeArray = nullptr,
const std::string& volumeName = "undefined");

TrackingVolume(const Transform3& transform, VolumeBoundsPtr volbounds,
std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
std::vector<std::unique_ptr<const Volume>> descendants,
const Volume::BoundingBox* top,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
const std::string& volumeName = "undefined");

/// Constructor for a full equipped Tracking Volume
///
/// @param transform is the global 3D transform to position the volume in
Expand Down Expand Up @@ -555,11 +518,6 @@ class TrackingVolume : public Volume {

/// color code for displaying
unsigned int m_colorCode{20};

/// Bounding Volume Hierarchy (BVH)
std::vector<std::unique_ptr<const Volume::BoundingBox>> m_boundingBoxes;
std::vector<std::unique_ptr<const Volume>> m_descendantVolumes;
const Volume::BoundingBox* m_bvhTop{nullptr};
};

inline const std::string& TrackingVolume::volumeName() const {
Expand Down Expand Up @@ -609,10 +567,6 @@ inline void TrackingVolume::setMotherVolume(const TrackingVolume* mvol) {
m_motherVolume = mvol;
}

inline bool TrackingVolume::hasBoundingVolumeHierarchy() const {
return m_bvhTop != nullptr;
}

#ifndef DOXYGEN
#include "Acts/Geometry/detail/TrackingVolume.ipp"
#endif
Expand Down
76 changes: 0 additions & 76 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,82 +719,6 @@ class Navigator {
ACTS_VERBOSE(volInfo(state)
<< "No layers present, resolve volume first.");

// check if current volume has BVH, or layers
if (state.navigation.currentVolume->hasBoundingVolumeHierarchy()) {
// has hierarchy, use that, skip layer resolution
NavigationOptions<Surface> navOpts;
navOpts.resolveSensitive = m_cfg.resolveSensitive;
navOpts.resolveMaterial = m_cfg.resolveMaterial;
navOpts.resolvePassive = m_cfg.resolvePassive;
navOpts.endObject = state.navigation.targetSurface;
navOpts.nearLimit = stepper.overstepLimit(state.stepping);
double opening_angle = 0;

// Preliminary version of the frustum opening angle estimation.
// Currently not used (only rays), but will be.

/*
Vector3 pos = stepper.position(state.stepping);
double mom = stepper.momentum(state.stepping) / UnitConstants::GeV;
double q = stepper.charge(state.stepping);
Vector3 dir = stepper.direction(state.stepping);
Vector3 B = stepper.getField(state.stepping, pos);
if (B.squaredNorm() > 1e-9) {
// ~ non-zero field
double ir = (dir.cross(B).norm()) * q / mom;
double s;
if (state.options.direction == Direction::Forward) {
s = state.stepping.stepSize.max();
} else {
s = state.stepping.stepSize.min();
}
opening_angle = std::atan((1 - std::cos(s * ir)) / std::sin(s * ir));
}
ACTS_VERBOSE(volInfo(state) << "Estimating opening angle for frustum
nav:"); ACTS_VERBOSE(volInfo(state) << "pos: " << pos.transpose());
ACTS_VERBOSE(volInfo(state) << "dir: " << dir.transpose());
ACTS_VERBOSE(volInfo(state) << "B: " << B.transpose() << " |B|: " <<
B.norm()); ACTS_VERBOSE(volInfo(state) << "step mom: " <<
stepper.momentum(state.stepping)); ACTS_VERBOSE(volInfo(state) << "=>
opening angle: " << opening_angle);
*/

auto protoNavSurfaces =
state.navigation.currentVolume->compatibleSurfacesFromHierarchy(
state.geoContext, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping),
opening_angle, navOpts);
if (!protoNavSurfaces.empty()) {
// did we find any surfaces?

// Check: are we on the first surface?
// TODO magic number `1_um`
if ((state.navigation.currentSurface == nullptr &&
state.navigation.navSurfaces.empty()) ||
protoNavSurfaces.front().pathLength() > 1_um) {
// we are not, go on
// state.navigation.navSurfaces = std::move(protoNavSurfaces);
state.navigation.navSurfaces.clear();
state.navigation.navSurfaces.insert(
state.navigation.navSurfaces.begin(), protoNavSurfaces.begin(),
protoNavSurfaces.end());

state.navigation.navSurfaceIndex = 0;
state.navigation.navLayers = {};
state.navigation.navLayerIndex = state.navigation.navLayers.size();
// The stepper updates the step size ( single / multi component)
stepper.updateStepSize(state.stepping,
state.navigation.navSurface(),
state.options.direction, true);
ACTS_VERBOSE(volInfo(state)
<< "Navigation stepSize updated to "
<< stepper.outputStepSize(state.stepping));
return true;
}
}
}

if (resolveLayers(state, stepper)) {
// The layer resolving worked
return true;
Expand Down
120 changes: 0 additions & 120 deletions Core/src/Geometry/TrackingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,6 @@ Acts::TrackingVolume::TrackingVolume(
connectDenseBoundarySurfaces(denseVolumeVector);
}

// constructor for arguments
Acts::TrackingVolume::TrackingVolume(
const Transform3& transform, VolumeBoundsPtr volbounds,
std::vector<std::unique_ptr<Volume::BoundingBox>> boxStore,
std::vector<std::unique_ptr<const Volume>> descendants,
const Volume::BoundingBox* top,
std::shared_ptr<const IVolumeMaterial> volumeMaterial,
const std::string& volumeName)
: Volume(transform, std::move(volbounds)),
m_volumeMaterial(std::move(volumeMaterial)),
m_name(volumeName),
m_descendantVolumes(std::move(descendants)),
m_bvhTop(top) {
createBoundarySurfaces();
// we take a copy of the unique box pointers, but we want to
// store them as consts.
for (auto& uptr : boxStore) {
m_boundingBoxes.push_back(
std::unique_ptr<Volume::BoundingBox>(uptr.release()));
}
}

Acts::TrackingVolume::~TrackingVolume() {
delete m_glueVolumeDescriptor;
}
Expand Down Expand Up @@ -429,23 +407,6 @@ void Acts::TrackingVolume::closeGeometry(
mutableLayerPtr->closeGeometry(materialDecorator, layerID, hook,
logger);
}
} else if (m_bvhTop != nullptr) {
GeometryIdentifier::Value isurface = 0;
for (const auto& descVol : m_descendantVolumes) {
// Attempt to cast to AbstractVolume: only one we'll handle
const AbstractVolume* avol =
dynamic_cast<const AbstractVolume*>(descVol.get());
if (avol != nullptr) {
const auto& bndSrf = avol->boundarySurfaces();
for (const auto& bnd : bndSrf) {
const auto& srf = bnd->surfaceRepresentation();
RegularSurface* mutableSurfcePtr =
const_cast<RegularSurface*>(&srf);
auto geoID = GeometryIdentifier(volumeID).setSensitive(++isurface);
mutableSurfcePtr->assignGeometryId(geoID);
}
}
}
}
} else {
// B) this is a container volume, go through sub volume
Expand Down Expand Up @@ -632,84 +593,3 @@ Acts::TrackingVolume::compatibleLayers(
// and return
return lIntersections;
}

namespace {
template <typename T>
std::vector<const Acts::Volume*> intersectSearchHierarchy(
const T obj, const Acts::Volume::BoundingBox* lnode) {
std::vector<const Acts::Volume*> hits;
hits.reserve(20); // arbitrary
do {
if (lnode->intersect(obj)) {
if (lnode->hasEntity()) {
// found primitive
// check obb to limit false positives
const Acts::Volume* vol = lnode->entity();
const auto& obb = vol->orientedBoundingBox();
if (obb.intersect(obj.transformed(vol->itransform()))) {
hits.push_back(vol);
}
// we skip in any case, whether we actually hit the OBB or not
lnode = lnode->getSkip();
} else {
// go over children
lnode = lnode->getLeftChild();
}
} else {
lnode = lnode->getSkip();
}
} while (lnode != nullptr);

return hits;
}
} // namespace

std::vector<Acts::SurfaceIntersection>
Acts::TrackingVolume::compatibleSurfacesFromHierarchy(
const GeometryContext& gctx, const Vector3& position,
const Vector3& direction, double angle,
const NavigationOptions<Surface>& options) const {
std::vector<SurfaceIntersection> sIntersections;
sIntersections.reserve(20); // arbitrary

// The limits for this navigation step
double nearLimit = options.nearLimit;
double farLimit = options.farLimit;

if (m_bvhTop == nullptr) {
return sIntersections;
}

std::vector<const Volume*> hits;
if (angle == 0) {
// use ray
Ray3D obj(position, direction);
hits = intersectSearchHierarchy(std::move(obj), m_bvhTop);
} else {
Acts::Frustum<ActsScalar, 3, 4> obj(position, direction, angle);
hits = intersectSearchHierarchy(std::move(obj), m_bvhTop);
}

// have cells, decompose to surfaces
for (const Volume* vol : hits) {
const AbstractVolume* avol = dynamic_cast<const AbstractVolume*>(vol);
const std::vector<std::shared_ptr<const BoundarySurfaceT<AbstractVolume>>>&
boundarySurfaces = avol->boundarySurfaces();
for (const auto& bs : boundarySurfaces) {
const Surface& srf = bs->surfaceRepresentation();
auto sfmi =
srf.intersect(gctx, position, direction, BoundaryCheck(false));
for (const auto& sfi : sfmi.split()) {
if (sfi && detail::checkIntersection(sfi, nearLimit, farLimit)) {
sIntersections.push_back(sfi);
}
}
}
}

// Sort according to the path length
std::sort(sIntersections.begin(), sIntersections.end(),
SurfaceIntersection::pathLengthOrder);

return sIntersections;
}

This file was deleted.

Loading

0 comments on commit ccc1975

Please sign in to comment.