SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLCompactGrid.h
Go to the documentation of this file.
1 /**
2  * \file SLCompactGrid.h
3  * \authors Manuel Frischknecht, Marcus Hudritsch
4  * \date July 2015
5  * \authors Manuel Frischknecht, Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7 */
8 
9 #ifndef SL_COMPACTGRID
10 #define SL_COMPACTGRID
11 
12 #include <array>
13 #include <atomic>
14 #include <numeric>
15 #include <vector>
16 
17 #include <SLAccelStruct.h>
18 #include <SLGLVertexArrayExt.h>
19 #include <SLVec3.h>
20 
21 //-----------------------------------------------------------------------------
22 typedef std::function<void(const SLuint, const SLuint)> triVoxCallback;
23 //-----------------------------------------------------------------------------
24 //! Class for compact uniform grid acceleration structure
25 /*! This class implements the data structure proposed by Lagae & Dutre in their
26 paper "Compact, Fast and Robust Grids for Ray Tracing". It reduces the memory
27 footprint to 20% of a regular uniform grid implemented in SLUniformGrid.
28 */
30 {
31 public:
32  using Triangle = std::array<SLVec3f, 3>;
33 
36 
37  void build(SLVec3f minV, SLVec3f maxV);
38  void updateStats(SLNodeStats& stats);
39  void draw(SLSceneView* sv);
40  SLbool intersect(SLRay* ray, SLNode* node);
41 
42  void deleteAll();
44  {
45  if (_vao.vaoID())
47  }
48 
49  SLuint indexAtPos(const SLVec3i& p) const
50  {
51  return (SLuint)p.x + (SLuint)p.y * _size.x +
52  (SLuint)p.z * _size.x * _size.y;
53  }
54  SLVec3f voxelCenter(const SLVec3i& pos) const;
55  SLVec3i containingVoxel(const SLVec3f& p) const;
56  void getMinMaxVoxel(const Triangle& triangle,
57  SLVec3i& minCell,
58  SLVec3i& maxCell);
60 
61 private:
62  SLVec3ui _size; //!< num. of voxel in grid dir.
63  SLuint _numTriangles; //!< NO. of triangles in the mesh
64  SLVec3f _voxelSize; //!< size of a voxel
65  SLVec3f _voxelSizeHalf; //!< half size of a voxel
66  SLVuint _voxelOffsets; //!< Offset array (C in the paper)
67  SLVushort _triangleIndexes16; //!< 16 bit triangle index array (L in the paper)
68  SLVuint _triangleIndexes32; //!< 32 bit triangle index array (L in the paper)
69  SLGLVertexArrayExt _vao; //!< Vertex array object for rendering
70 };
71 //-----------------------------------------------------------------------------
72 #endif // SL_COMPACTGRID
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
vector< SLushort > SLVushort
Definition: SL.h:195
vector< SLuint > SLVuint
Definition: SL.h:197
std::function< void(const SLuint, const SLuint)> triVoxCallback
Definition: SLCompactGrid.h:22
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.
Extension class with functions for quick line & point drawing.
SLAccelStruct is an abstract base class for acceleration structures.
Definition: SLAccelStruct.h:22
Class for compact uniform grid acceleration structure.
Definition: SLCompactGrid.h:30
SLVec3f _voxelSizeHalf
half size of a voxel
Definition: SLCompactGrid.h:65
SLVec3f voxelCenter(const SLVec3i &pos) const
Returns the voxel center point for a given voxel by index.
SLCompactGrid(SLMesh *m)
SLVec3f _voxelSize
size of a voxel
Definition: SLCompactGrid.h:64
SLuint _numTriangles
NO. of triangles in the mesh.
Definition: SLCompactGrid.h:63
void build(SLVec3f minV, SLVec3f maxV)
SLuint indexAtPos(const SLVec3i &p) const
Definition: SLCompactGrid.h:49
void updateStats(SLNodeStats &stats)
Updates the statistics in the parent node.
SLVuint _voxelOffsets
Offset array (C in the paper)
Definition: SLCompactGrid.h:66
void disposeBuffers()
Definition: SLCompactGrid.h:43
void deleteAll()
Deletes the entire uniform grid data.
SLVec3ui _size
num. of voxel in grid dir.
Definition: SLCompactGrid.h:62
SLVushort _triangleIndexes16
16 bit triangle index array (L in the paper)
Definition: SLCompactGrid.h:67
SLVuint _triangleIndexes32
32 bit triangle index array (L in the paper)
Definition: SLCompactGrid.h:68
SLbool intersect(SLRay *ray, SLNode *node)
void draw(SLSceneView *sv)
SLCompactGrid::draw draws the non-empty voxels of the uniform grid.
SLGLVertexArrayExt _vao
Vertex array object for rendering.
Definition: SLCompactGrid.h:69
void getMinMaxVoxel(const Triangle &triangle, SLVec3i &minCell, SLVec3i &maxCell)
Returns the min. and max. voxel of a triangle.
SLVec3i containingVoxel(const SLVec3f &p) const
Returns the indices of the voxel around a given point.
void ifTriangleInVoxelDo(triVoxCallback cb)
Loops over triangles gets their voxels and calls the callback function.
std::array< SLVec3f, 3 > Triangle
Definition: SLCompactGrid.h:32
SLGLVertexArray adds Helper Functions for quick Line & Point Drawing.
void clearAttribs()
Clears the attribute definition.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
Ray class with ray and intersection properties.
Definition: SLRay.h:40
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43
Struct for scene graph statistics.
Definition: SLNode.h:37