MobileRT  1.0
A multi platform C++ CPU progressive Ray Tracer.
MobileRT::RegularGrid< T > Class Template Referencefinal

#include <RegularGrid.hpp>

Collaboration diagram for MobileRT::RegularGrid< T >:
Collaboration graph

Public Member Functions

 RegularGrid ()=default
 
 RegularGrid (::std::vector< T > &&primitives, ::std::uint32_t gridSize)
 
 RegularGrid (const RegularGrid &regularGrid)=delete
 
 RegularGrid (RegularGrid &&regularGrid) noexcept=default
 
 ~RegularGrid ()
 
RegularGridoperator= (const RegularGrid &regularGrid)=delete
 
RegularGridoperator= (RegularGrid &&regularGrid) noexcept=default
 
Intersection trace (Intersection intersection)
 
Intersection shadowTrace (Intersection intersection)
 
const ::std::vector< T > & getPrimitives () const
 

Private Member Functions

void addPrimitives ()
 
void addPrimitivesThreadWork (::std::uint32_t threadId, ::std::uint32_t numberOfThreads)
 
Intersection intersect (Intersection intersection)
 
::std::uint32_t bitCounter (::std::uint32_t value) const
 
::std::int32_t getCellIndex (::std::int32_t cellX, ::std::int32_t cellY, ::std::int32_t cellZ) const
 

Private Attributes

::std::vector<::std::vector< T * > > grid_
 
::std::vector< T > primitives_
 
::std::int32_t gridSize_ {}
 
::std::uint32_t gridShift_ {}
 
AABB worldBoundaries_ {}
 
::glm::vec3 cellSizeInverted_ {}
 
::glm::vec3 cellSize_ {}
 
::std::vector<::std::mutex > mutexes_ {}
 

Detailed Description

template<typename T>
class MobileRT::RegularGrid< T >

A class which represents the Regular Grid acceleration structure.
This is a structure where all the primitives are stored in a matrix where each cell represents a 3D space of the scene. So the scene geometry is divided in many boxes (each cell of the 3D matrix) and when a ray is casted into the scene, it tries to intersect the nearest cell and then the primitives inside it until it finds the nearest intersection point.

Template Parameters
TThe type of the primitives.

Constructor & Destructor Documentation

◆ RegularGrid() [1/4]

template<typename T>
MobileRT::RegularGrid< T >::RegularGrid ( )
explicitdefault

◆ RegularGrid() [2/4]

template<typename T>
MobileRT::RegularGrid< T >::RegularGrid ( ::std::vector< T > &&  primitives,
::std::uint32_t  gridSize 
)
explicit

The constructor.

Template Parameters
TThe type of the primitives.
Parameters
primitivesThe primitives in the scene.
gridSizeThe size of the cells in all the axes.

◆ RegularGrid() [3/4]

template<typename T>
MobileRT::RegularGrid< T >::RegularGrid ( const RegularGrid< T > &  regularGrid)
delete

◆ RegularGrid() [4/4]

template<typename T>
MobileRT::RegularGrid< T >::RegularGrid ( RegularGrid< T > &&  regularGrid)
defaultnoexcept

◆ ~RegularGrid()

template<typename T >
MobileRT::RegularGrid< T >::~RegularGrid ( )

The destructor.

Template Parameters
TThe type of the primitives.

Member Function Documentation

◆ addPrimitives()

template<typename T >
void MobileRT::RegularGrid< T >::addPrimitives ( )
private

Helper method which adds the primitives into the grid.

Template Parameters
TThe type of the primitives.

◆ addPrimitivesThreadWork()

template<typename T >
void MobileRT::RegularGrid< T >::addPrimitivesThreadWork ( ::std::uint32_t  threadId,
::std::uint32_t  numberOfThreads 
)
private

Store primitives in the grid cells.

◆ bitCounter()

template<typename T >
std::uint32_t MobileRT::RegularGrid< T >::bitCounter ( ::std::uint32_t  value) const
private

Helper method which calculates the number bits set in an unsigned integer.

Template Parameters
TThe type of the primitives.
Parameters
valueThe value to count the number of the bits set.
Returns
The number of bits set in the value.

◆ getCellIndex()

template<typename T >
std::int32_t MobileRT::RegularGrid< T >::getCellIndex ( ::std::int32_t  cellX,
::std::int32_t  cellY,
::std::int32_t  cellZ 
) const
private

Helper method which calculates the cell index in the grid.

Parameters
cellXThe index of X.
cellYThe index of Y.
cellZThe index of Z.
Returns
The index of the cell in the grid.

◆ getPrimitives()

template<typename T >
const ::std::vector< T > & MobileRT::RegularGrid< T >::getPrimitives ( ) const

Gets the primitives.

Template Parameters
TThe type of the primitives.
Returns
The primitives.

◆ intersect()

template<typename T >
Intersection MobileRT::RegularGrid< T >::intersect ( Intersection  intersection)
private

Helper method which calculates the intersection point from the origin of the ray.
This method supports two modes:

  • trace the ray until finding the nearest intersection point from the origin of the ray
  • trace the ray until finding any intersection point from the origin of the ray
Template Parameters
TThe type of the primitives.
Parameters
intersectionThe previous intersection point of the ray (used to update its data in case it is found a nearest intersection point.
Returns
The intersection point of the ray in the scene.

◆ operator=() [1/2]

template<typename T>
RegularGrid& MobileRT::RegularGrid< T >::operator= ( const RegularGrid< T > &  regularGrid)
delete

◆ operator=() [2/2]

template<typename T>
RegularGrid& MobileRT::RegularGrid< T >::operator= ( RegularGrid< T > &&  regularGrid)
defaultnoexcept

◆ shadowTrace()

template<typename T >
Intersection MobileRT::RegularGrid< T >::shadowTrace ( Intersection  intersection)

This method casts a ray into the geometry and calculates a random intersection point. The intersection point itself is not important, the important is to determine if the ray intersects some primitive in the scene or not.

Template Parameters
TThe type of the primitives.
Parameters
intersectionThe current intersection of the ray with previous primitives.
Returns
The intersection of the ray with the geometry.

◆ trace()

template<typename T >
Intersection MobileRT::RegularGrid< T >::trace ( Intersection  intersection)

This method casts a ray into the geometry and calculates the nearest intersection point from the origin of the ray.

Template Parameters
TThe type of the primitives.
Parameters
intersectionThe current intersection of the ray with previous primitives.
Returns
The intersection of the ray with the geometry.

Member Data Documentation

◆ cellSize_

template<typename T>
::glm::vec3 MobileRT::RegularGrid< T >::cellSize_ {}
private

The size of a cell (worldBoundaries / gridSize).

◆ cellSizeInverted_

template<typename T>
::glm::vec3 MobileRT::RegularGrid< T >::cellSizeInverted_ {}
private

The inverted cell size (gridSize / worldBoundaries).

◆ grid_

template<typename T>
::std::vector<::std::vector<T*> > MobileRT::RegularGrid< T >::grid_
private

The grid structure.

◆ gridShift_

template<typename T>
::std::uint32_t MobileRT::RegularGrid< T >::gridShift_ {}
private

The number of bits in the grid size value (minus 1).

◆ gridSize_

template<typename T>
::std::int32_t MobileRT::RegularGrid< T >::gridSize_ {}
private

The size of the cells in all the axes.

◆ mutexes_

template<typename T>
::std::vector<::std::mutex> MobileRT::RegularGrid< T >::mutexes_ {}
private

The mutexes to allow multiple threads add primitives to the grid.

◆ primitives_

template<typename T>
::std::vector<T> MobileRT::RegularGrid< T >::primitives_
private

The primitives.

◆ worldBoundaries_

template<typename T>
AABB MobileRT::RegularGrid< T >::worldBoundaries_ {}
private

The World boundaries.


The documentation for this class was generated from the following file: