NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VisualizationKDTree.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, FI MUNI CZ
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors:
28  * Radek Stibora
29  *
30  */
31 
36 #pragma once
37 #include "Visualization.hpp"
38 
39 
40 namespace FW
41 {
42 //------------------------------------------------------------------------
43 
49 {
50 public:
51 
52  struct SplitInfo
53  {
56 
57  SplitInfo(void) : pos(0), dim(-1) {}
58  FW::String getPos(void) { return String(pos); }
59  FW::String getAxisName(void) { if (dim == 0) return String('X'); else if (dim == 1) return String('Y'); else if (dim == 2) return('Z'); }
60  };
61 
69  explicit VisualizationKDTree (CudaKDTree* kdtree, Scene* scene, const Array<AABB> &emptyBoxes, const RayBuffer* rays = NULL, Buffer* visibility = NULL);
73  ~VisualizationKDTree (void);
74 
80  virtual bool handleEvent (const Window::Event& ev); // must be before the listener that queries things
81 
85  void moveToParent ();
89  void moveToSibling ();
93  void moveToLeft ();
97  void moveToRight ();
102  void moveUp ();
107  void moveDown ();
108 
114  void draw (GLContext* gl, CameraControls& camera);
115 
116 private:
120  struct NodeData
121  {
122  S32 addr;
123  //S32 dim;
124  //F32 pos;
125  AABB box;
126 
130  NodeData(void) : addr(0) {}
131  };
132 
137  void getFromIndex (S32 idx);
141  void growParentBox ();
147  void drawNodes (GLContext* gl, bool onlyChildren);
154  void drawBox (GLContext* gl, const NodeData &node, U32 abgr);
160  void drawRays (GLContext* gl, U32 abgr);
165  void drawPrimitives (GLContext* gl);
169  void drawPathInfo (GLContext* gl);
173  void setColorMapping ();
178  void prepareTreeData (NodeData node);
184  void addBoxQuads (const AABB &box, Array<Vec4f> &buffer);
185 
186 
187  void splitNode (const NodeData& currNode, S32& leftAdd, S32& rightAdd, AABB& leftBox, AABB& rightBox, SplitInfo& split);
188 
189 private:
190  // Global and path data
191  CudaKDTree* m_kdtree;
192  Array<NodeData> m_nodeStack;
193  // Currently visible node data
194  NodeData m_node;
195  NodeData m_sibling;
196  NodeData m_left;
197  NodeData m_right;
198  SplitInfo m_nodeSplit;
199 };
200 
201 //------------------------------------------------------------------------
202 }
~VisualizationKDTree(void)
Destructor.
Class for the visualization.
#define NULL
Definition: Defs.hpp:39
VisualizationKDTree(CudaKDTree *kdtree, Scene *scene, const Array< AABB > &emptyBoxes, const RayBuffer *rays=NULL, Buffer *visibility=NULL)
Constructor.
void draw(GLContext *gl, CameraControls &camera)
The method used to draw the current state of visualization to the OpenGL context. ...
Class for the BVH visualization.
void moveToSibling()
Sets the node to be visualized to be the sibling of the currently visualized node.
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer
Definition: DLLImports.inl:315
Cuda friendly KDTree representation.
Definition: CudaKDTree.hpp:20
void moveToRight()
Sets the node to be visualized to be the right child of the currently visualized node.
void moveUp()
Sets the node to be visualized to be the predecesor of the currently visualized node on the set path...
float F32
Definition: Defs.hpp:89
Visualisation framework abstract class above BVH/KDTree visualisations.
Ray buffer class. Stores rays.
Definition: RayBuffer.hpp:38
signed int S32
Definition: Defs.hpp:88
virtual bool handleEvent(const Window::Event &ev)
Handles visualization events - key commands influencing the output.
unsigned int U32
Definition: Defs.hpp:85
Class holding 3d scene.
Definition: Scene.hpp:44
void moveToLeft()
Sets the node to be visualized to be the left child of the currently visualized node.
void moveDown()
Sets the node to be visualized to be the succesor of the currently visualized node on the set path...
void moveToParent()
Sets the node to be visualized to be the parent of the currently visualized node. ...