Support Forum       G3D Web Page     
Public Member Functions | Protected Attributes | List of all members
G3D::RayGridIterator Class Reference


Computes conservative line raster/voxelization across a grid for use in walking a grid spatial data structure or or voxel scene searching for intersections. More...

Public Member Functions

 RayGridIterator (Ray ray, const Vector3int32 &numCells, const Vector3 &cellSize=Vector3(1, 1, 1), const Point3 &minBoundsLocation=Point3(0, 0, 0), const Point3int32 &minBoundsCellIndex=Point3int32(0, 0, 0))
 Initialize the iterator to the first grid cell hit by the ray and precompute traversal variables. More...
 
const Vector3cellSize () const
 Size of each cell along each axis.
More...
 
bool containsRayOrigin () const
 True if this cell contains the ray origin.
More...
 
int enterAxis () const
 The axis along which the ray entered the cell; X = 0, Y = 1, Z = 2.
More...
 
float enterDistance () const
 Distance along the ray of the first intersection with the current cell (i.e., that given by m_index).
More...
 
Vector3int32 enterNormal () const
 Outward-facing normal to the current grid cell along the partition just entered. More...
 
Point3 enterPoint () const
 Location where the ray entered the current grid cell. More...
 
float exitDistance () const
 Distance from the ray origin to the exit point in this cell. More...
 
Point3 exitPoint () const
 Location where the ray exits the current grid cell. More...
 
const Vector3int32index () const
 Current grid cell m_index.
More...
 
bool insideGrid () const
 True if index() refers to a valid cell inside the grid.
More...
 
Vector3int32 numCells () const
 Extent of the grid in each dimension, in grid cell units.
More...
 
RayGridIteratoroperator++ ()
 Increment the iterator, moving to the next grid cell. More...
 
const Rayray () const
 The original ray.
More...
 
const Vector3int32step () const
 Sign of the direction that the ray moves along each axis; +/-1 or 0.
More...
 
const Vector3tDelta () const
 Size of one cell in units of t along each axis.
More...
 

Protected Attributes

Vector3int32 m_boundaryIndex
 The value that the index will take on along each boundary when it just leaves the grid. More...
 
Vector3 m_cellSize
 Size of each cell along each axis. More...
 
bool m_containsRayOrigin
 True if this cell contains the ray origin. More...
 
int m_enterAxis
 The axis along which the ray entered the cell; X = 0, Y = 1, Z = 2. More...
 
float m_enterDistance
 Distance along the ray of the first intersection with the current cell (i.e., that given by m_index). More...
 
Vector3 m_exitDistance
 Distance along the ray to the intersection with the next grid cell. More...
 
Vector3int32 m_index
 Current grid cell m_index. More...
 
bool m_insideGrid
 True if index() refers to a valid cell inside the grid. More...
 
Vector3int32 m_numCells
 Extent of the grid in each dimension, in grid cell units. More...
 
Ray m_ray
 The original ray. More...
 
Vector3int32 m_step
 Sign of the direction that the ray moves along each axis; +/-1 or 0. More...
 
Vector3 m_tDelta
 Size of one cell in units of t along each axis. More...
 

Detailed Description


Computes conservative line raster/voxelization across a grid for use in walking a grid spatial data structure or or voxel scene searching for intersections.

At each iteration, the iterator steps exactly one cell in exactly one dimension.

Example of this iterator applied to ray-primitive intersection in a grid:

bool firstRayIntersection(const Ray& ray, Value*& value, float& distance) const {
for (RayGridIterator it(ray, cellSize); inBounds(it.index); ++it) {
// Search for an intersection within this grid cell
const Cell& c = cell(it.index);
float maxdistance = min(distance, t.tExit);
if (c.firstRayIntersection(ray, value, maxdistance)) {
distance = maxdistance;
return true;
}
}
}
See also
CollisionDetection, PointHashGrid, Ray, Intersect

Constructor & Destructor Documentation

◆ RayGridIterator()

G3D::RayGridIterator::RayGridIterator ( Ray  ray,
const Vector3int32 numCells,
const Vector3 cellSize = Vector3(1, 1, 1),
const Point3 minBoundsLocation = Point3(0, 0, 0),
const Point3int32 minBoundsCellIndex = Point3int32(0, 0, 0) 
)

Initialize the iterator to the first grid cell hit by the ray and precompute traversal variables.

The grid is assumed to have a corner at (0,0,0) and extend along the canonical axes. For intersections grids transformed by a rigid body transformation, first transform the ray into the grid's object space with CFrame::rayToObjectSpace.

If the ray never passes through the grid, insideGrid() will be false immediately after intialization.

If using for 2D iteration, set numCells.z = 1 and ray.origin().z = 0.5

Parameters
cellSizeThe extent of one cell
minBoundsLocationThe location of the lowest corner of grid cell minBoundsCellIndex along each axis.
This translates the grid relative to the ray's coordinate frame.
minBoundsCellIndexThe index of the first grid cell. This allows operation with grids defined on negative indices. This translates all grid indices.

Member Function Documentation

◆ cellSize()

const Vector3& G3D::RayGridIterator::cellSize ( ) const
inline

Size of each cell along each axis.

◆ containsRayOrigin()

bool G3D::RayGridIterator::containsRayOrigin ( ) const
inline

True if this cell contains the ray origin.

◆ enterAxis()

int G3D::RayGridIterator::enterAxis ( ) const
inline

The axis along which the ray entered the cell; X = 0, Y = 1, Z = 2.

This is always set to X for the cell that contains the ray origin.

◆ enterDistance()

float G3D::RayGridIterator::enterDistance ( ) const
inline

Distance along the ray of the first intersection with the current cell (i.e., that given by m_index).

Zero for the cell that contains the ray origin.

◆ enterNormal()

Vector3int32 G3D::RayGridIterator::enterNormal ( ) const
inline

Outward-facing normal to the current grid cell along the partition just entered.

Initially zero.

◆ enterPoint()

Point3 G3D::RayGridIterator::enterPoint ( ) const
inline

Location where the ray entered the current grid cell.

◆ exitDistance()

float G3D::RayGridIterator::exitDistance ( ) const
inline

Distance from the ray origin to the exit point in this cell.

◆ exitPoint()

Point3 G3D::RayGridIterator::exitPoint ( ) const
inline

Location where the ray exits the current grid cell.

◆ index()

const Vector3int32& G3D::RayGridIterator::index ( ) const
inline

Current grid cell m_index.

◆ insideGrid()

bool G3D::RayGridIterator::insideGrid ( ) const
inline

True if index() refers to a valid cell inside the grid.

This is usually employed as the loop termination condition.

◆ numCells()

Vector3int32 G3D::RayGridIterator::numCells ( ) const
inline

Extent of the grid in each dimension, in grid cell units.

◆ operator++()

RayGridIterator& G3D::RayGridIterator::operator++ ( )
inline

Increment the iterator, moving to the next grid cell.

◆ ray()

const Ray& G3D::RayGridIterator::ray ( ) const
inline

The original ray.

◆ step()

const Vector3int32& G3D::RayGridIterator::step ( ) const
inline

Sign of the direction that the ray moves along each axis; +/-1 or 0.

◆ tDelta()

const Vector3& G3D::RayGridIterator::tDelta ( ) const
inline

Size of one cell in units of t along each axis.

Member Data Documentation

◆ m_boundaryIndex

Vector3int32 G3D::RayGridIterator::m_boundaryIndex
protected

The value that the index will take on along each boundary when it just leaves the grid.

Referenced by operator++().

◆ m_cellSize

Vector3 G3D::RayGridIterator::m_cellSize
protected

Size of each cell along each axis.

Referenced by cellSize().

◆ m_containsRayOrigin

bool G3D::RayGridIterator::m_containsRayOrigin
protected

True if this cell contains the ray origin.

Referenced by containsRayOrigin(), and operator++().

◆ m_enterAxis

int G3D::RayGridIterator::m_enterAxis
protected

The axis along which the ray entered the cell; X = 0, Y = 1, Z = 2.

This is always set to X for the cell that contains the ray origin.

Referenced by enterAxis(), enterNormal(), and operator++().

◆ m_enterDistance

float G3D::RayGridIterator::m_enterDistance
protected

Distance along the ray of the first intersection with the current cell (i.e., that given by m_index).

Zero for the cell that contains the ray origin.

Referenced by enterDistance(), enterPoint(), and operator++().

◆ m_exitDistance

Vector3 G3D::RayGridIterator::m_exitDistance
protected

Distance along the ray to the intersection with the next grid cell.

enterDistance and m_exitDistance can be used to bracket ray ray-primitive intersection tests within a cell.

Referenced by exitDistance(), exitPoint(), and operator++().

◆ m_index

Vector3int32 G3D::RayGridIterator::m_index
protected

Current grid cell m_index.

Referenced by index(), and operator++().

◆ m_insideGrid

bool G3D::RayGridIterator::m_insideGrid
protected

True if index() refers to a valid cell inside the grid.

This is usually employed as the loop termination condition.

Referenced by insideGrid(), and operator++().

◆ m_numCells

Vector3int32 G3D::RayGridIterator::m_numCells
protected

Extent of the grid in each dimension, in grid cell units.

Referenced by numCells().

◆ m_ray

Ray G3D::RayGridIterator::m_ray
protected

The original ray.

Referenced by enterPoint(), exitPoint(), and ray().

◆ m_step

Vector3int32 G3D::RayGridIterator::m_step
protected

Sign of the direction that the ray moves along each axis; +/-1 or 0.

Referenced by enterNormal(), operator++(), and step().

◆ m_tDelta

Vector3 G3D::RayGridIterator::m_tDelta
protected

Size of one cell in units of t along each axis.

Referenced by operator++(), and tDelta().


documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15