Class for GPU-accelerated collision detection and spatial queries in Helios. More...
#include <CollisionDetection.h>
Data Structures | |
| struct | AngularBins |
| Angular bin structure for rasterization-based collision detection. More... | |
| struct | Cone |
| Structure representing a cone for collision detection. More... | |
| struct | HitResult |
| Structure representing the result of a ray-primitive intersection. More... | |
| struct | MemoryUsageStats |
| Get memory usage statistics for different BVH layouts. More... | |
| struct | OptimalPathResult |
| Structure representing the result of optimal cone path detection. More... | |
| struct | RayPacket |
| Optimized ray packet for streaming processing Organizes ray data in Structure-of-Arrays format for better memory access. More... | |
| struct | RayQuery |
| Structure representing a ray query for generic ray-tracing operations. More... | |
| struct | RayStream |
| Streaming ray tracer interface Enables efficient batch processing of ray packets. More... | |
| struct | RayTracingStats |
| Structure for batch ray-tracing statistics. More... | |
Public Types | |
| enum class | BVHOptimizationMode { SOA_UNCOMPRESSED } |
| BVH optimization modes for performance improvements. More... | |
Public Member Functions | |
| CollisionDetection (helios::Context *context) | |
| Constructor for CollisionDetection class. | |
| ~CollisionDetection () | |
| Destructor for CollisionDetection class. | |
| std::vector< uint > | findCollisions (uint UUID, bool allow_spatial_culling=true) |
| Find all primitives/objects that collide with a given primitive. | |
| std::vector< uint > | findCollisions (const std::vector< uint > &UUIDs, bool allow_spatial_culling=true) |
| Find all primitives/objects that collide with any of the given primitives. | |
| std::vector< uint > | findCollisions (const std::vector< uint > &primitive_UUIDs, const std::vector< uint > &object_IDs, bool allow_spatial_culling=true) |
| Find collisions between primitives and compound objects. | |
| std::vector< uint > | findCollisions (const std::vector< uint > &query_UUIDs, const std::vector< uint > &query_object_IDs, const std::vector< uint > &target_UUIDs, const std::vector< uint > &target_object_IDs, bool allow_spatial_culling=true) |
| Find collisions restricting both query and target geometry. | |
| HitResult | castRay (const RayQuery &ray_query) |
| Cast a single ray and return detailed intersection information. | |
| HitResult | castRay (const helios::vec3 &origin, const helios::vec3 &direction, float max_distance=-1.0f, const std::vector< uint > &target_UUIDs={}) |
| Cast a single ray with simplified parameters. | |
| std::vector< HitResult > | castRays (const std::vector< RayQuery > &ray_queries, RayTracingStats *stats=nullptr) |
| Cast multiple rays in batch for improved performance. | |
| void | castRaysSoA (const helios::vec3 *origins, const helios::vec3 *directions, size_t count, float max_distance, float *out_distance, helios::vec3 *out_normal, uint *out_primitive_UUID, RayTracingStats *stats=nullptr) |
| Cast a batch of rays supplied as Structure-of-Arrays and write results directly into caller-owned arrays. | |
| void | castRaysSoA_packets (const helios::vec3 *origins, const helios::vec3 *directions, size_t count, size_t packet_size, float max_distance, float *out_distance, helios::vec3 *out_normal, uint *out_primitive_UUID, RayTracingStats *stats=nullptr) |
| Coherent (packet) variant of castRaysSoA that exploits intra-packet ray coherence. | |
| void | setBVHOptimizationMode (BVHOptimizationMode mode) |
| Set BVH optimization mode for performance improvements. | |
| BVHOptimizationMode | getBVHOptimizationMode () const |
| Get current BVH optimization mode. | |
| std::vector< HitResult > | castRaysOptimized (const std::vector< RayQuery > &ray_queries, RayTracingStats *stats=nullptr) |
| Cast rays using optimized Structure-of-Arrays BVH layout. | |
| bool | processRayStream (RayStream &ray_stream, RayTracingStats *stats=nullptr) |
| Cast ray packets using streaming interface for optimal GPU utilization. | |
| MemoryUsageStats | getBVHMemoryUsage () const |
| std::vector< std::vector< std::vector< std::vector< HitResult > > > > | performGridRayIntersection (const helios::vec3 &grid_center, const helios::vec3 &grid_size, const helios::int3 &grid_divisions, const std::vector< RayQuery > &ray_queries) |
| Perform grid-based ray intersection for voxel operations. | |
| std::vector< std::vector< HitResult > > | calculateVoxelPathLengths (const helios::vec3 &scan_origin, const std::vector< helios::vec3 > &ray_directions, const std::vector< helios::vec3 > &voxel_centers, const std::vector< helios::vec3 > &voxel_sizes) |
| Calculate ray path lengths through individual voxels for LiDAR processing. | |
| void | calculateRayPathLengthsDetailed (const helios::vec3 &grid_center, const helios::vec3 &grid_size, const helios::int3 &grid_divisions, const std::vector< helios::vec3 > &ray_origins, const std::vector< helios::vec3 > &ray_directions, std::vector< HitResult > &hit_results) |
| Enhanced ray path length calculations with detailed statistics. | |
| OptimalPathResult | findOptimalConePath (const helios::vec3 &apex, const helios::vec3 ¢ralAxis, float half_angle, float height=0.0f, int initialSamples=256) |
| Find the radial direction through a cone toward the largest gap. | |
| void | calculateGridIntersection (const helios::vec3 &grid_center, const helios::vec3 &grid_size, const helios::int3 &grid_divisions, const std::vector< uint > &UUIDs={}) |
| Calculate which primitives fall within a 3D grid. | |
| std::vector< std::vector< std::vector< std::vector< uint > > > > | getGridCells () |
| Get all grid cells and their contained primitives. | |
| std::vector< uint > | getGridIntersections (int i, int j, int k) |
| Get primitives in a specific grid cell. | |
| std::vector< uint > | slicePrimitive (uint UUID, const std::vector< helios::vec3 > &voxel_face_vertices, helios::WarningAggregator &warnings) |
| Slice a primitive (patch or triangle) into multiple triangles using a planar face. | |
| std::vector< uint > | slicePrimitivesUsingGrid (const std::vector< uint > &UUIDs, const helios::vec3 &grid_center, const helios::vec3 &grid_size, const helios::int3 &grid_divisions) |
| Slice primitives along a regular 3D grid. | |
| void | calculatePrimitiveVoxelIntersection (const std::vector< uint > &UUIDs={}) |
| Calculate voxel-primitive intersections using OpenMP parallelization. | |
| helios::vec3 | linesIntersection (const helios::vec3 &line1_point, const helios::vec3 &line1_direction, const helios::vec3 &line2_point, const helios::vec3 &line2_direction) const |
| Calculate 3D line intersection point. | |
| bool | approxSame (float a, float b, float absTol, float relTol) const |
| Compare floats with dual tolerance (absolute + relative) | |
| bool | approxSame (const helios::vec3 &a, const helios::vec3 &b, float absTol) const |
| Compare vec3's element-wise with absolute tolerance. | |
| helios::vec2 | interpolate_texture_UV_to_slice_point (const helios::vec3 &p1, const helios::vec2 &uv1, const helios::vec3 &p2, const helios::vec2 &uv2, const helios::vec3 &ps) const |
| Interpolate UV texture coordinates to slice point. | |
| void | calculateVoxelRayPathLengths (const helios::vec3 &grid_center, const helios::vec3 &grid_size, const helios::int3 &grid_divisions, const std::vector< helios::vec3 > &ray_origins, const std::vector< helios::vec3 > &ray_directions) |
| Calculate ray path lengths and transmission statistics for a voxel grid. | |
| void | setVoxelTransmissionProbability (int P_denom, int P_trans, const helios::int3 &ijk) |
| Set transmission probability counts for a voxel. | |
| void | getVoxelTransmissionProbability (const helios::int3 &ijk, int &P_denom, int &P_trans) const |
| Get transmission probability counts for a voxel. | |
| void | setVoxelRbar (float r_bar, const helios::int3 &ijk) |
| Set average ray propagation distance for a voxel. | |
| float | getVoxelRbar (const helios::int3 &ijk) const |
| Get average ray propagation distance for a voxel. | |
| void | getVoxelRayHitCounts (const helios::int3 &ijk, int &hit_before, int &hit_after, int &hit_inside) const |
| Get ray classification counts for a voxel (for Beer's law calculations) | |
| std::vector< float > | getVoxelRayPathLengths (const helios::int3 &ijk) const |
| Get individual ray path lengths for a voxel (for Beer's law calculations) | |
| void | clearVoxelData () |
| Clear all voxel ray statistics data. | |
| int | optimizeLayout (const std::vector< uint > &UUIDs, float learning_rate=0.01f, int max_iterations=1000) |
| Optimize layout of primitives/objects to minimize collisions. | |
| std::vector< std::pair< uint, uint > > | findCollisionsWithinDistance (const std::vector< uint > &query_UUIDs, const std::vector< uint > &target_UUIDs, float max_distance) |
| Find collisions within a specified distance threshold. | |
| void | setMaxCollisionDistance (float distance) |
| Set maximum distance for collision detection queries. | |
| float | getMaxCollisionDistance () const |
| Get current maximum collision distance. | |
| std::vector< uint > | filterGeometryByDistance (const helios::vec3 &query_center, float max_radius, const std::vector< uint > &candidate_UUIDs={}) |
| Filter geometry by spatial proximity for efficient collision detection. | |
| bool | findNearestPrimitiveDistance (const helios::vec3 &origin, const helios::vec3 &direction, const std::vector< uint > &candidate_UUIDs, float &distance, helios::vec3 &obstacle_direction) |
| Determine the distance to the nearest primitive in any direction, filtered by direction component. | |
| bool | findNearestSolidObstacleInCone (const helios::vec3 &apex, const helios::vec3 &axis, float half_angle, float height, const std::vector< uint > &candidate_UUIDs, float &distance, helios::vec3 &obstacle_direction, int num_rays=64) |
| Find the nearest solid obstacle within a cone using ray casting. | |
| bool | findNearestSolidObstacleInCone (const helios::vec3 &apex, const helios::vec3 &axis, float half_angle, float height, const std::vector< uint > &candidate_UUIDs, const std::vector< uint > &plant_primitives, float &distance, helios::vec3 &obstacle_direction, int num_rays=64) |
| Find nearest solid obstacle in cone with tree identification for per-tree BVH optimization. | |
| void | buildBVH (const std::vector< uint > &UUIDs={}) |
| Build or rebuild the BVH acceleration structure. | |
| void | updateBVH (const std::vector< uint > &UUIDs, bool force_rebuild=false) |
| Efficiently update BVH with new geometry (avoids full rebuild when possible) | |
| void | setStaticGeometry (const std::vector< uint > &UUIDs) |
| Mark specific geometry as static (will be cached for efficiency) | |
| void | rebuildBVH () |
| Force a complete rebuild of the BVH. | |
| void | disableAutomaticBVHRebuilds () |
| Disable automatic BVH rebuilds (caller must manually manage rebuilds) | |
| void | enableAutomaticBVHRebuilds () |
| Enable automatic BVH rebuilds (default behavior) | |
| void | enableHierarchicalBVH () |
| Enable hierarchical BVH with separate static and dynamic geometry. | |
| void | disableHierarchicalBVH () |
| Disable hierarchical BVH (use single unified BVH) | |
| void | buildStaticBVH () |
| Build static BVH for obstacles and non-growing geometry. | |
| void | enableTreeBasedBVH (float isolation_distance=5.0f) |
| Enable tree-based BVH isolation for spatially separated trees. | |
| void | disableTreeBasedBVH () |
| Disable tree-based BVH isolation. | |
| bool | isTreeBasedBVHEnabled () const |
| Check if tree-based BVH isolation is enabled. | |
| void | initializeObstacleSpatialGrid () |
| Initialize spatial grid for fast static obstacle lookups. | |
| void | registerTree (uint tree_object_id, const std::vector< uint > &tree_primitives) |
| Register a tree object for per-tree BVH isolation. | |
| void | setStaticObstacles (const std::vector< uint > &obstacle_primitives) |
| Set static obstacle geometry for per-tree collision detection. | |
| std::vector< uint > | getRelevantGeometryForTree (const helios::vec3 &query_position, const std::vector< uint > &query_primitives={}, float max_distance=15.0f) |
| Get relevant geometry for tree-based collision detection. | |
| bool | isBVHValid () const |
| Check if BVH is valid and up-to-date. | |
| void | enableGPUAcceleration () |
| Enable GPU acceleration for collision detection. | |
| void | disableGPUAcceleration () |
| Disable GPU acceleration (use CPU-only algorithms) | |
| bool | isGPUAccelerationEnabled () const |
| Check if GPU acceleration is enabled. | |
| void | disableMessages () |
| Disable console output messages. | |
| void | enableMessages () |
| Enable console output messages. | |
| void | setCancelFlag (volatile int *flag) |
| Register an external cancellation flag polled during ray casting. | |
| size_t | getPrimitiveCount () const |
| Get the number of primitives in the BVH. | |
| void | getBVHStatistics (size_t &node_count, size_t &leaf_count, size_t &max_depth) const |
| Get BVH statistics. | |
Static Public Member Functions | |
| static bool | isGPUAvailable () |
| Check whether a CUDA-capable GPU is available for acceleration. | |
| static int | selfTest (int argc, char **argv) |
| Self-test routine to verify plugin functionality. | |
Static Public Attributes | |
| static constexpr size_t | WARP_SIZE = 32 |
| Ray streaming for efficient GPU processing Processes multiple rays simultaneously for better GPU utilization. | |
| static constexpr size_t | RAY_BATCH_SIZE = 1024 |
| Optimal batch size for ray processing. | |
Class for GPU-accelerated collision detection and spatial queries in Helios.
The CollisionDetection class provides efficient algorithms for:
Definition at line 34 of file CollisionDetection.h.
|
strong |
BVH optimization modes for performance improvements.
| Enumerator | |
|---|---|
| SOA_UNCOMPRESSED | Structure-of-Arrays, full precision. |
Definition at line 420 of file CollisionDetection.h.
|
explicit |
Constructor for CollisionDetection class.
| [in] | context | Pointer to the Helios context |
Definition at line 67 of file CollisionDetection.cpp.
| CollisionDetection::~CollisionDetection | ( | ) |
Destructor for CollisionDetection class.
Definition at line 140 of file CollisionDetection.cpp.
| bool CollisionDetection::approxSame | ( | const helios::vec3 & | a, |
| const helios::vec3 & | b, | ||
| float | absTol | ||
| ) | const |
Compare vec3's element-wise with absolute tolerance.
Definition at line 45 of file CollisionDetection_Slicing.cpp.
| bool CollisionDetection::approxSame | ( | float | a, |
| float | b, | ||
| float | absTol, | ||
| float | relTol | ||
| ) | const |
Compare floats with dual tolerance (absolute + relative)
| [in] | a | First value |
| [in] | b | Second value |
| [in] | absTol | Absolute tolerance |
| [in] | relTol | Relative tolerance |
Definition at line 41 of file CollisionDetection_Slicing.cpp.
| void CollisionDetection::buildBVH | ( | const std::vector< uint > & | UUIDs = {} | ) |
Build or rebuild the BVH acceleration structure.
| [in] | UUIDs | Optional vector of specific UUIDs to include (empty = all primitives) |
Definition at line 350 of file CollisionDetection.cpp.
| void CollisionDetection::buildStaticBVH | ( | ) |
Build static BVH for obstacles and non-growing geometry.
Builds the static BVH using geometry set by setStaticGeometry(). Should be called after enabling hierarchical BVH and setting static geometry.
Definition at line 561 of file CollisionDetection.cpp.
| void CollisionDetection::calculateGridIntersection | ( | const helios::vec3 & | grid_center, |
| const helios::vec3 & | grid_size, | ||
| const helios::int3 & | grid_divisions, | ||
| const std::vector< uint > & | UUIDs = {} |
||
| ) |
Calculate which primitives fall within a 3D grid.
| [in] | grid_center | Center point of the 3D grid |
| [in] | grid_size | Size of the grid in x, y, z dimensions |
| [in] | grid_divisions | Number of divisions in x, y, z dimensions |
| [in] | UUIDs | Optional vector of specific UUIDs to test (empty = all primitives) |
Definition at line 2598 of file CollisionDetection.cpp.
| void CollisionDetection::calculatePrimitiveVoxelIntersection | ( | const std::vector< uint > & | UUIDs = {} | ) |
Calculate voxel-primitive intersections using OpenMP parallelization.
| [in] | UUIDs | Optional primitive UUIDs (empty = all primitives) |
Definition at line 1483 of file CollisionDetection_Slicing.cpp.
| void CollisionDetection::calculateRayPathLengthsDetailed | ( | const helios::vec3 & | grid_center, |
| const helios::vec3 & | grid_size, | ||
| const helios::int3 & | grid_divisions, | ||
| const std::vector< helios::vec3 > & | ray_origins, | ||
| const std::vector< helios::vec3 > & | ray_directions, | ||
| std::vector< HitResult > & | hit_results | ||
| ) |
Enhanced ray path length calculations with detailed statistics.
| [in] | grid_center | Center point of the 3D voxel grid |
| [in] | grid_size | Size of the grid in x, y, z dimensions |
| [in] | grid_divisions | Number of divisions in x, y, z dimensions |
| [in] | ray_origins | Vector of ray origin points |
| [in] | ray_directions | Vector of ray direction vectors (should be normalized) |
| [out] | hit_results | Vector of detailed hit results for each ray |
Definition at line 397 of file CollisionDetection_RayTracing.cpp.
| std::vector< std::vector< CollisionDetection::HitResult > > CollisionDetection::calculateVoxelPathLengths | ( | const helios::vec3 & | scan_origin, |
| const std::vector< helios::vec3 > & | ray_directions, | ||
| const std::vector< helios::vec3 > & | voxel_centers, | ||
| const std::vector< helios::vec3 > & | voxel_sizes | ||
| ) |
Calculate ray path lengths through individual voxels for LiDAR processing.
| [in] | scan_origin | Single vec3 LiDAR scanner position |
| [in] | ray_directions | Vector of normalized ray directions (10K-10M rays) |
| [in] | voxel_centers | Vector of voxel center positions (8-1000 voxels) |
| [in] | voxel_sizes | Vector of voxel dimensions (width,height,depth) |
This method extends performGridRayIntersection to handle individual voxels with specific centers and sizes. Uses ray-AABB intersection with path_length = t_max - max(0, t_min) for each intersection. Performance target: 1M rays × 100 voxels in <2 seconds with OpenMP parallelization.
Definition at line 315 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::calculateVoxelRayPathLengths | ( | const helios::vec3 & | grid_center, |
| const helios::vec3 & | grid_size, | ||
| const helios::int3 & | grid_divisions, | ||
| const std::vector< helios::vec3 > & | ray_origins, | ||
| const std::vector< helios::vec3 > & | ray_directions | ||
| ) |
Calculate ray path lengths and transmission statistics for a voxel grid.
| [in] | grid_center | Center point of the 3D voxel grid |
| [in] | grid_size | Size of the grid in x, y, z dimensions |
| [in] | grid_divisions | Number of divisions in x, y, z dimensions |
| [in] | ray_origins | Vector of ray origin points |
| [in] | ray_directions | Vector of ray direction vectors (should be normalized) |
Definition at line 3580 of file CollisionDetection.cpp.
| CollisionDetection::HitResult CollisionDetection::castRay | ( | const helios::vec3 & | origin, |
| const helios::vec3 & | direction, | ||
| float | max_distance = -1.0f, |
||
| const std::vector< uint > & | target_UUIDs = {} |
||
| ) |
Cast a single ray with simplified parameters.
| [in] | origin | Ray origin point |
| [in] | direction | Ray direction vector (should be normalized) |
| [in] | max_distance | Maximum ray distance (negative = infinite) |
| [in] | target_UUIDs | Target primitive UUIDs (empty = all primitives) |
Definition at line 82 of file CollisionDetection_RayTracing.cpp.
| CollisionDetection::HitResult CollisionDetection::castRay | ( | const RayQuery & | ray_query | ) |
Cast a single ray and return detailed intersection information.
| [in] | ray_query | Ray parameters (origin, direction, max distance, target UUIDs) |
Definition at line 78 of file CollisionDetection_RayTracing.cpp.
| std::vector< CollisionDetection::HitResult > CollisionDetection::castRays | ( | const std::vector< RayQuery > & | ray_queries, |
| RayTracingStats * | stats = nullptr |
||
| ) |
Cast multiple rays in batch for improved performance.
| [in] | ray_queries | Vector of ray parameters |
| [out] | stats | Optional ray-tracing statistics |
Definition at line 234 of file CollisionDetection_RayTracing.cpp.
| std::vector< CollisionDetection::HitResult > CollisionDetection::castRaysOptimized | ( | const std::vector< RayQuery > & | ray_queries, |
| RayTracingStats * | stats = nullptr |
||
| ) |
Cast rays using optimized Structure-of-Arrays BVH layout.
| [in] | ray_queries | Vector of ray parameters |
| [out] | stats | Optional ray-tracing statistics |
Definition at line 458 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::castRaysSoA | ( | const helios::vec3 * | origins, |
| const helios::vec3 * | directions, | ||
| size_t | count, | ||
| float | max_distance, | ||
| float * | out_distance, | ||
| helios::vec3 * | out_normal, | ||
| uint * | out_primitive_UUID, | ||
| RayTracingStats * | stats = nullptr |
||
| ) |
Cast a batch of rays supplied as Structure-of-Arrays and write results directly into caller-owned arrays.
This is a low-memory alternative to castRays(const std::vector<RayQuery>&, RayTracingStats*) for very large batches. It takes the ray origins and directions as plain contiguous arrays and writes the per-ray results into caller-provided output arrays, avoiding the intermediate RayQuery input vector and HitResult output vector (which together cost ~96 bytes/ray of transient storage, including an unused per-ray target list). All rays share a single max_distance; per-ray target filtering is not supported on this path (use castRays for that).
A ray that misses every primitive is signalled by writing out_primitive_UUID = 0xFFFFFFFF for that ray; on a miss out_distance and out_normal are left unspecified (callers must check the UUID sentinel before using them). The BVH and primitive cache are ensured current internally, but automatic BVH rebuilds are NOT toggled here — when issuing many batched calls over static geometry, the caller should disable automatic rebuilds and buildBVH once around the whole batch (see disableAutomaticBVHRebuilds).
| [in] | origins | Array of ray origins (length count). |
| [in] | directions | Array of ray directions (length count; need not be pre-normalized). |
| [in] | count | Number of rays. |
| [in] | max_distance | Maximum ray distance shared by all rays (negative = infinite). |
| [out] | out_distance | Array (length count) receiving the hit distance for each ray (valid only where out_primitive_UUID != 0xFFFFFFFF). |
| [out] | out_normal | Array (length count) receiving the surface normal at the hit (valid only where out_primitive_UUID != 0xFFFFFFFF). |
| [out] | out_primitive_UUID | Array (length count) receiving the hit primitive UUID, or 0xFFFFFFFF for a miss. |
| [out] | stats | Optional ray-tracing statistics. |
Definition at line 551 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::castRaysSoA_packets | ( | const helios::vec3 * | origins, |
| const helios::vec3 * | directions, | ||
| size_t | count, | ||
| size_t | packet_size, | ||
| float | max_distance, | ||
| float * | out_distance, | ||
| helios::vec3 * | out_normal, | ||
| uint * | out_primitive_UUID, | ||
| RayTracingStats * | stats = nullptr |
||
| ) |
Coherent (packet) variant of castRaysSoA that exploits intra-packet ray coherence.
Identical inputs, outputs, and closest-hit semantics as castRaysSoA, but the count rays are processed in contiguous packets of packet_size rays (the final packet may be smaller). Rays within a packet are traversed against a single shared BVH stack: each node is fetched and descended once for the whole packet (visited if ANY member ray's own AABB test passes, using that ray's running closest-hit distance), and each leaf primitive is fetched once and tested against every member ray. This amortizes node/primitive memory traffic and traversal control flow across the packet, which is a large win for highly coherent packets such as a LiDAR pulse's sub-rays (shared origin, sub-degree direction cone).
Results are bit-for-bit identical to the per-ray path: a node is never skipped for a ray that would have visited it alone, so each ray finds the same closest hit. Intended for the CPU path; callers may pass any packet_size (1 degenerates to the per-ray traversal). Per-ray target filtering is not supported.
| [in] | origins | Array of ray origins (length count), grouped so rays [g*packet_size, (g+1)*packet_size) form packet g. |
| [in] | directions | Array of ray directions (length count; need not be pre-normalized). |
| [in] | count | Number of rays. |
| [in] | packet_size | Number of contiguous rays per packet (>=1). |
| [in] | max_distance | Maximum ray distance shared by all rays (negative = infinite). |
| [out] | out_distance | Array (length count) receiving per-ray hit distance (valid where out_primitive_UUID != 0xFFFFFFFF). |
| [out] | out_normal | Array (length count) receiving per-ray surface normal (valid where out_primitive_UUID != 0xFFFFFFFF). |
| [out] | out_primitive_UUID | Array (length count) receiving per-ray hit primitive UUID, or 0xFFFFFFFF for a miss. |
| [out] | stats | Optional ray-tracing statistics. |
Definition at line 682 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::clearVoxelData | ( | ) |
Clear all voxel ray statistics data.
Definition at line 3787 of file CollisionDetection.cpp.
| void CollisionDetection::disableAutomaticBVHRebuilds | ( | ) |
Disable automatic BVH rebuilds (caller must manually manage rebuilds)
Definition at line 508 of file CollisionDetection.cpp.
| void CollisionDetection::disableGPUAcceleration | ( | ) |
Disable GPU acceleration (use CPU-only algorithms)
Definition at line 761 of file CollisionDetection.cpp.
| void CollisionDetection::disableHierarchicalBVH | ( | ) |
Disable hierarchical BVH (use single unified BVH)
Definition at line 521 of file CollisionDetection.cpp.
| void CollisionDetection::disableMessages | ( | ) |
Disable console output messages.
Definition at line 796 of file CollisionDetection.cpp.
| void CollisionDetection::disableTreeBasedBVH | ( | ) |
Disable tree-based BVH isolation.
Definition at line 4723 of file CollisionDetection.cpp.
| void CollisionDetection::enableAutomaticBVHRebuilds | ( | ) |
Enable automatic BVH rebuilds (default behavior)
Definition at line 512 of file CollisionDetection.cpp.
| void CollisionDetection::enableGPUAcceleration | ( | ) |
Enable GPU acceleration for collision detection.
Definition at line 741 of file CollisionDetection.cpp.
| void CollisionDetection::enableHierarchicalBVH | ( | ) |
Enable hierarchical BVH with separate static and dynamic geometry.
Definition at line 516 of file CollisionDetection.cpp.
| void CollisionDetection::enableMessages | ( | ) |
Enable console output messages.
Definition at line 800 of file CollisionDetection.cpp.
| void CollisionDetection::enableTreeBasedBVH | ( | float | isolation_distance = 5.0f | ) |
Enable tree-based BVH isolation for spatially separated trees.
| [in] | isolation_distance | Spatial distance threshold for tree isolation |
When enabled, creates separate BVHs for each tree object that are spatially separated by at least isolation_distance. This provides linear scaling for scenarios with multiple non-interacting trees.
Definition at line 4718 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::filterGeometryByDistance | ( | const helios::vec3 & | query_center, |
| float | max_radius, | ||
| const std::vector< uint > & | candidate_UUIDs = {} |
||
| ) |
Filter geometry by spatial proximity for efficient collision detection.
| [in] | query_center | Center point for spatial filtering |
| [in] | max_radius | Maximum radius for including geometry |
| [in] | candidate_UUIDs | Optional list of candidate UUIDs (empty = all geometry) |
Definition at line 3530 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::findCollisions | ( | const std::vector< uint > & | primitive_UUIDs, |
| const std::vector< uint > & | object_IDs, | ||
| bool | allow_spatial_culling = true |
||
| ) |
Find collisions between primitives and compound objects.
| [in] | primitive_UUIDs | Vector of primitive UUIDs to test |
| [in] | object_IDs | Vector of compound object IDs to test against |
| [in] | allow_spatial_culling | If true, use tree-based BVH spatial culling for efficiency (default: true) |
Definition at line 211 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::findCollisions | ( | const std::vector< uint > & | query_UUIDs, |
| const std::vector< uint > & | query_object_IDs, | ||
| const std::vector< uint > & | target_UUIDs, | ||
| const std::vector< uint > & | target_object_IDs, | ||
| bool | allow_spatial_culling = true |
||
| ) |
Find collisions restricting both query and target geometry.
| [in] | query_UUIDs | Vector of primitive UUIDs to test for collisions |
| [in] | query_object_IDs | Vector of object IDs to test for collisions |
| [in] | target_UUIDs | Vector of primitive UUIDs to test against (empty = all primitives) |
| [in] | target_object_IDs | Vector of object IDs to test against (empty = all objects) |
| [in] | allow_spatial_culling | If true, use tree-based BVH spatial culling for efficiency (default: true) |
Definition at line 237 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::findCollisions | ( | const std::vector< uint > & | UUIDs, |
| bool | allow_spatial_culling = true |
||
| ) |
Find all primitives/objects that collide with any of the given primitives.
| [in] | UUIDs | Vector of query primitive UUIDs |
| [in] | allow_spatial_culling | If true, use tree-based BVH spatial culling for efficiency (default: true) |
Definition at line 150 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::findCollisions | ( | uint | UUID, |
| bool | allow_spatial_culling = true |
||
| ) |
Find all primitives/objects that collide with a given primitive.
| [in] | UUID | Unique identifier of the query primitive |
| [in] | allow_spatial_culling | If true, use tree-based BVH spatial culling for efficiency (default: true) |
Definition at line 146 of file CollisionDetection.cpp.
| std::vector< std::pair< uint, uint > > CollisionDetection::findCollisionsWithinDistance | ( | const std::vector< uint > & | query_UUIDs, |
| const std::vector< uint > & | target_UUIDs, | ||
| float | max_distance | ||
| ) |
Find collisions within a specified distance threshold.
| [in] | query_UUIDs | Vector of primitive UUIDs to test for collisions |
| [in] | target_UUIDs | Vector of primitive UUIDs to test against |
| [in] | max_distance | Maximum distance for collision consideration |
Definition at line 3456 of file CollisionDetection.cpp.
| bool CollisionDetection::findNearestPrimitiveDistance | ( | const helios::vec3 & | origin, |
| const helios::vec3 & | direction, | ||
| const std::vector< uint > & | candidate_UUIDs, | ||
| float & | distance, | ||
| helios::vec3 & | obstacle_direction | ||
| ) |
Determine the distance to the nearest primitive in any direction, filtered by direction component.
| [in] | origin | Origin location from which to search |
| [in] | direction | Unit direction vector to filter "forward" surfaces (dot product > 0) |
| [in] | candidate_UUIDs | Vector of primitive UUIDs to consider for intersection |
| [out] | distance | Distance to the nearest primitive (only valid if return is true) |
| [out] | obstacle_direction | Direction from origin to nearest obstacle (only valid if return is true) |
This method finds the nearest solid surface in any direction from the origin point, but only considers surfaces that are "in front" of the growth direction. A surface is considered "in front" if the vector from origin to the closest point on the surface has a positive dot product with the input direction vector.
Definition at line 2823 of file CollisionDetection.cpp.
| bool CollisionDetection::findNearestSolidObstacleInCone | ( | const helios::vec3 & | apex, |
| const helios::vec3 & | axis, | ||
| float | half_angle, | ||
| float | height, | ||
| const std::vector< uint > & | candidate_UUIDs, | ||
| const std::vector< uint > & | plant_primitives, | ||
| float & | distance, | ||
| helios::vec3 & | obstacle_direction, | ||
| int | num_rays = 64 |
||
| ) |
Find nearest solid obstacle in cone with tree identification for per-tree BVH optimization.
Find the nearest solid obstacle within a cone-shaped detection volume with tree identification
This method is optimized for per-tree BVH systems by identifying the querying tree through plant primitive UUIDs, enabling efficient spatial filtering of collision candidates.
| [in] | apex | Location of the cone apex (plant growth point) |
| [in] | axis | Central axis direction of the cone (growth direction, normalized) |
| [in] | half_angle | Half-angle of the cone in radians |
| [in] | height | Height of the cone (detection distance) |
| [in] | candidate_UUIDs | Vector of obstacle primitive UUIDs to check for collisions |
| [in] | plant_primitives | Vector of plant primitive UUIDs to identify the querying tree |
| [out] | distance | Distance to the nearest obstacle surface |
| [out] | obstacle_direction | Direction vector from apex toward the nearest obstacle point |
| [in] | num_rays | Number of rays to cast within the cone for sampling |
Definition at line 3002 of file CollisionDetection.cpp.
| bool CollisionDetection::findNearestSolidObstacleInCone | ( | const helios::vec3 & | apex, |
| const helios::vec3 & | axis, | ||
| float | half_angle, | ||
| float | height, | ||
| const std::vector< uint > & | candidate_UUIDs, | ||
| float & | distance, | ||
| helios::vec3 & | obstacle_direction, | ||
| int | num_rays = 64 |
||
| ) |
Find the nearest solid obstacle within a cone using ray casting.
| [in] | apex | Cone apex position |
| [in] | axis | Central axis of the cone (normalized) |
| [in] | half_angle | Half-angle of cone in radians |
| [in] | height | Maximum detection distance (cone height) |
| [in] | candidate_UUIDs | Vector of primitive UUIDs to consider as solid obstacles |
| [out] | distance | Distance to nearest obstacle (only valid if return is true) |
| [out] | obstacle_direction | Direction from apex to nearest obstacle (only valid if return is true) |
| [in] | num_rays | Number of rays to cast for detection (default: 64) |
This method casts rays within a cone to find the nearest solid obstacle. Unlike the soft collision avoidance, this uses a smaller cone angle and returns the exact distance to the nearest primitive surface using accurate ray-primitive intersection tests.
Definition at line 2917 of file CollisionDetection.cpp.
| CollisionDetection::OptimalPathResult CollisionDetection::findOptimalConePath | ( | const helios::vec3 & | apex, |
| const helios::vec3 & | centralAxis, | ||
| float | half_angle, | ||
| float | height = 0.0f, |
||
| int | initialSamples = 256 |
||
| ) |
Find the radial direction through a cone toward the largest gap.
| [in] | apex | Cone apex position |
| [in] | centralAxis | Central axis of the cone |
| [in] | half_angle | Half-angle of cone in radians |
| [in] | height | Height of cone (0 = infinite) |
| [in] | initialSamples | Number of initial uniform samples (default: 256) |
Definition at line 1859 of file CollisionDetection.cpp.
| CollisionDetection::MemoryUsageStats CollisionDetection::getBVHMemoryUsage | ( | ) | const |
Definition at line 535 of file CollisionDetection_RayTracing.cpp.
| CollisionDetection::BVHOptimizationMode CollisionDetection::getBVHOptimizationMode | ( | ) | const |
Get current BVH optimization mode.
Definition at line 448 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::getBVHStatistics | ( | size_t & | node_count, |
| size_t & | leaf_count, | ||
| size_t & | max_depth | ||
| ) | const |
Get BVH statistics.
| [out] | node_count | Number of nodes in BVH |
| [out] | leaf_count | Number of leaf nodes in BVH |
| [out] | max_depth | Maximum depth of BVH |
Definition at line 812 of file CollisionDetection.cpp.
| std::vector< std::vector< std::vector< std::vector< uint > > > > CollisionDetection::getGridCells | ( | ) |
Get all grid cells and their contained primitives.
Definition at line 2614 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::getGridIntersections | ( | int | i, |
| int | j, | ||
| int | k | ||
| ) |
Get primitives in a specific grid cell.
| [in] | i | Grid cell index in x-dimension |
| [in] | j | Grid cell index in y-dimension |
| [in] | k | Grid cell index in z-dimension |
Definition at line 2618 of file CollisionDetection.cpp.
| float CollisionDetection::getMaxCollisionDistance | ( | ) | const |
Get current maximum collision distance.
Definition at line 3526 of file CollisionDetection.cpp.
| size_t CollisionDetection::getPrimitiveCount | ( | ) | const |
Get the number of primitives in the BVH.
Definition at line 808 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::getRelevantGeometryForTree | ( | const helios::vec3 & | query_position, |
| const std::vector< uint > & | query_primitives = {}, |
||
| float | max_distance = 15.0f |
||
| ) |
Get relevant geometry for tree-based collision detection.
| [in] | query_position | Position of the collision query |
| [in] | query_primitives | Primitives making the query (to identify source tree) |
Returns geometry that includes:
Definition at line 4840 of file CollisionDetection.cpp.
| void CollisionDetection::getVoxelRayHitCounts | ( | const helios::int3 & | ijk, |
| int & | hit_before, | ||
| int & | hit_after, | ||
| int & | hit_inside | ||
| ) | const |
Get ray classification counts for a voxel (for Beer's law calculations)
| [in] | ijk | Voxel indices (i,j,k) |
| [out] | hit_before | Number of rays that hit geometry BEFORE entering the voxel |
| [out] | hit_after | Number of rays that hit geometry AFTER entering the voxel |
| [out] | hit_inside | Number of rays that hit geometry INSIDE the voxel |
Definition at line 3724 of file CollisionDetection.cpp.
| std::vector< float > CollisionDetection::getVoxelRayPathLengths | ( | const helios::int3 & | ijk | ) | const |
Get individual ray path lengths for a voxel (for Beer's law calculations)
| [in] | ijk | Voxel indices (i,j,k) |
Definition at line 3748 of file CollisionDetection.cpp.
| float CollisionDetection::getVoxelRbar | ( | const helios::int3 & | ijk | ) | const |
Get average ray propagation distance for a voxel.
| [in] | ijk | Voxel indices (i,j,k) |
Definition at line 3695 of file CollisionDetection.cpp.
| void CollisionDetection::getVoxelTransmissionProbability | ( | const helios::int3 & | ijk, |
| int & | P_denom, | ||
| int & | P_trans | ||
| ) | const |
Get transmission probability counts for a voxel.
| [in] | ijk | Voxel indices (i,j,k) |
| [out] | P_denom | Number of rays that reached this voxel |
| [out] | P_trans | Number of rays that were transmitted through this voxel |
Definition at line 3645 of file CollisionDetection.cpp.
| void CollisionDetection::initializeObstacleSpatialGrid | ( | ) |
Initialize spatial grid for fast static obstacle lookups.
Definition at line 4733 of file CollisionDetection.cpp.
| helios::vec2 CollisionDetection::interpolate_texture_UV_to_slice_point | ( | const helios::vec3 & | p1, |
| const helios::vec2 & | uv1, | ||
| const helios::vec3 & | p2, | ||
| const helios::vec2 & | uv2, | ||
| const helios::vec3 & | ps | ||
| ) | const |
Interpolate UV texture coordinates to slice point.
| [in] | p1 | First edge vertex position |
| [in] | uv1 | First edge vertex UV |
| [in] | p2 | Second edge vertex position |
| [in] | uv2 | Second edge vertex UV |
| [in] | ps | Slice point position on edge |
Definition at line 49 of file CollisionDetection_Slicing.cpp.
| bool CollisionDetection::isBVHValid | ( | ) | const |
Check if BVH is valid and up-to-date.
Definition at line 710 of file CollisionDetection.cpp.
| bool CollisionDetection::isGPUAccelerationEnabled | ( | ) | const |
Check if GPU acceleration is enabled.
Definition at line 768 of file CollisionDetection.cpp.
|
static |
Check whether a CUDA-capable GPU is available for acceleration.
Returns true only if the plugin was compiled with CUDA support, at least one CUDA device is present at runtime, and the GPU path is not disabled via the HELIOS_NO_GPU environment variable. The result is cached after the first call.
Note: this reports GPU capability. Whether a given calculation actually uses the GPU also depends on batch size and scene complexity (see shouldUseGPU). Use isGPUAccelerationEnabled() to query whether GPU acceleration is currently toggled on.
Definition at line 772 of file CollisionDetection.cpp.
| bool CollisionDetection::isTreeBasedBVHEnabled | ( | ) | const |
Check if tree-based BVH isolation is enabled.
Definition at line 4729 of file CollisionDetection.cpp.
| helios::vec3 CollisionDetection::linesIntersection | ( | const helios::vec3 & | line1_point, |
| const helios::vec3 & | line1_direction, | ||
| const helios::vec3 & | line2_point, | ||
| const helios::vec3 & | line2_direction | ||
| ) | const |
Calculate 3D line intersection point.
| [in] | line1_point | Point on first line |
| [in] | line1_direction | Direction of first line |
| [in] | line2_point | Point on second line |
| [in] | line2_direction | Direction of second line |
Definition at line 22 of file CollisionDetection_Slicing.cpp.
| int CollisionDetection::optimizeLayout | ( | const std::vector< uint > & | UUIDs, |
| float | learning_rate = 0.01f, |
||
| int | max_iterations = 1000 |
||
| ) |
Optimize layout of primitives/objects to minimize collisions.
| [in] | UUIDs | Vector of primitive/object UUIDs to optimize |
| [in] | learning_rate | Step size for optimization algorithm |
| [in] | max_iterations | Maximum number of optimization iterations |
Definition at line 2625 of file CollisionDetection.cpp.
| std::vector< std::vector< std::vector< std::vector< CollisionDetection::HitResult > > > > CollisionDetection::performGridRayIntersection | ( | const helios::vec3 & | grid_center, |
| const helios::vec3 & | grid_size, | ||
| const helios::int3 & | grid_divisions, | ||
| const std::vector< RayQuery > & | ray_queries | ||
| ) |
Perform grid-based ray intersection for voxel operations.
| [in] | grid_center | Center point of the 3D grid |
| [in] | grid_size | Size of the grid in x, y, z dimensions |
| [in] | grid_divisions | Number of divisions in x, y, z dimensions |
| [in] | ray_queries | Vector of rays to intersect with the grid |
Definition at line 276 of file CollisionDetection_RayTracing.cpp.
| bool CollisionDetection::processRayStream | ( | RayStream & | ray_stream, |
| RayTracingStats * | stats = nullptr |
||
| ) |
Cast ray packets using streaming interface for optimal GPU utilization.
| [in] | ray_stream | Ray stream containing batched ray packets |
| [out] | stats | Optional ray-tracing statistics |
Definition at line 493 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::rebuildBVH | ( | ) |
Force a complete rebuild of the BVH.
Definition at line 503 of file CollisionDetection.cpp.
| void CollisionDetection::registerTree | ( | uint | tree_object_id, |
| const std::vector< uint > & | tree_primitives | ||
| ) |
Register a tree object for per-tree BVH isolation.
| [in] | tree_object_id | Object ID of the tree |
| [in] | tree_primitives | Primitive UUIDs belonging to this tree |
Associates primitives with a specific tree for isolated collision detection. Should be called before plant growth begins.
Definition at line 4782 of file CollisionDetection.cpp.
|
static |
Self-test routine to verify plugin functionality.
Definition at line 27 of file selfTest.cpp.
| void CollisionDetection::setBVHOptimizationMode | ( | BVHOptimizationMode | mode | ) |
Set BVH optimization mode for performance improvements.
| [in] | mode | Optimization mode (SOA_UNCOMPRESSED) |
Definition at line 423 of file CollisionDetection_RayTracing.cpp.
| void CollisionDetection::setCancelFlag | ( | volatile int * | flag | ) |
Register an external cancellation flag polled during ray casting.
When the pointed-to int is non-zero, the parallel ray loop in castRaysSoA() skips its remaining work (each thread short-circuits its assigned chunk), so a long synthetic scan can be aborted mid-trace. The flag is owned by the caller (e.g. a ctypes int shared with Python, written under the GIL while this trace runs GIL-free) and must outlive the trace. It is a single-word 0->1 monotonic flag, read via volatile so the loop re-reads it each tick; pass nullptr to clear. The per-ray read is effectively free.
Definition at line 804 of file CollisionDetection.cpp.
| void CollisionDetection::setMaxCollisionDistance | ( | float | distance | ) |
Set maximum distance for collision detection queries.
| [in] | distance | Maximum distance threshold (meters) |
Definition at line 3518 of file CollisionDetection.cpp.
| void CollisionDetection::setStaticGeometry | ( | const std::vector< uint > & | UUIDs | ) |
Mark specific geometry as static (will be cached for efficiency)
| [in] | UUIDs | Vector of primitive UUIDs that represent static obstacles |
Definition at line 648 of file CollisionDetection.cpp.
| void CollisionDetection::setStaticObstacles | ( | const std::vector< uint > & | obstacle_primitives | ) |
Set static obstacle geometry for per-tree collision detection.
| [in] | obstacle_primitives | Primitive UUIDs that represent static obstacles |
These primitives will be included in ALL tree collision detection queries. Should include ground, buildings, and other permanent obstacles.
Definition at line 4825 of file CollisionDetection.cpp.
| void CollisionDetection::setVoxelRbar | ( | float | r_bar, |
| const helios::int3 & | ijk | ||
| ) |
Set average ray propagation distance for a voxel.
| [in] | r_bar | Average ray propagation distance in meters |
| [in] | ijk | Voxel indices (i,j,k) |
Definition at line 3666 of file CollisionDetection.cpp.
| void CollisionDetection::setVoxelTransmissionProbability | ( | int | P_denom, |
| int | P_trans, | ||
| const helios::int3 & | ijk | ||
| ) |
Set transmission probability counts for a voxel.
| [in] | P_denom | Number of rays that reached this voxel (denominator) |
| [in] | P_trans | Number of rays that were transmitted through this voxel (numerator) |
| [in] | ijk | Voxel indices (i,j,k) |
Definition at line 3626 of file CollisionDetection.cpp.
| std::vector< uint > CollisionDetection::slicePrimitive | ( | uint | UUID, |
| const std::vector< helios::vec3 > & | voxel_face_vertices, | ||
| helios::WarningAggregator & | warnings | ||
| ) |
Slice a primitive (patch or triangle) into multiple triangles using a planar face.
| [in] | UUID | Primitive UUID to slice |
| [in] | voxel_face_vertices | Vector of ≥3 points defining the slicing plane |
| [in] | warnings | Warning aggregator for collecting non-fatal warnings |
Definition at line 114 of file CollisionDetection_Slicing.cpp.
| std::vector< uint > CollisionDetection::slicePrimitivesUsingGrid | ( | const std::vector< uint > & | UUIDs, |
| const helios::vec3 & | grid_center, | ||
| const helios::vec3 & | grid_size, | ||
| const helios::int3 & | grid_divisions | ||
| ) |
Slice primitives along a regular 3D grid.
| [in] | UUIDs | Primitives to slice |
| [in] | grid_center | Center of voxel grid |
| [in] | grid_size | Grid dimensions (x, y, z) |
| [in] | grid_divisions | Grid cells (x, y, z) |
Definition at line 1234 of file CollisionDetection_Slicing.cpp.
| void CollisionDetection::updateBVH | ( | const std::vector< uint > & | UUIDs, |
| bool | force_rebuild = false |
||
| ) |
Efficiently update BVH with new geometry (avoids full rebuild when possible)
| [in] | UUIDs | Vector of UUIDs to include in BVH |
| [in] | force_rebuild | Force complete rebuild even if geometry hasn't changed significantly |
Definition at line 594 of file CollisionDetection.cpp.
|
staticconstexpr |
Optimal batch size for ray processing.
Definition at line 135 of file CollisionDetection.h.
|
staticconstexpr |
Ray streaming for efficient GPU processing Processes multiple rays simultaneously for better GPU utilization.
CUDA warp size for optimal batching
Definition at line 134 of file CollisionDetection.h.