38 #define NO_NODE FW_S32_MIN 
   41 #define COLOR_NODE 0x14FFFFFF 
   42 #define COLOR_SIBLING 0x14000000 
   43 #define COLOR_LEFT 0x330000FF 
   44 #define COLOR_RIGHT 0x3300FF00 
   45 #define COLOR_RAY 0xFFFFFFFF 
   46 #define COLOR_TRI_INVIS 0xFF000000 
   47 #define COLOR_TRI_VIS 0xFFFFFFFF 
   49 #define COLOR_LEFT_SAH 0x330000FF 
   50 #define COLOR_RIGHT_SAH 0x3300FF00 
   51 #define COLOR_LEFT_SVBH 0x33FF00FF 
   52 #define COLOR_RIGHT_SVBH 0x33FFFF00 
   53 #define COLOR_LEFT_OSAH 0x3300FFFF 
   54 #define COLOR_RIGHT_OSAH 0x33FF0000 
   65     splitNode(m_node, m_left.addr, m_right.addr, m_left.box, m_right.box, m_nodeSplit);
 
   74     m_nodeStack.
add(m_node);
 
  126     for(
int i = 0; i < emptyBoxes.
getSize(); i++)
 
  127         addBoxQuads(emptyBoxes[i], boxes);
 
  134     for(
int r = 0; r < 2; r++)
 
  135         for(
int g = 0; g < 2; g++)
 
  136             for(
int b = 0; b < 2; b++)
 
  138                     colorPalette.
add(
Vec4f((
float)r, (
float)g, (
float)b, 0.33
f));
 
  139     for(
int i = 0; i < emptyBoxes.
getSize(); i++)
 
  140         for(
int j = 0; j < 6*4; j++) 
 
  142             colors.
add(colorPalette[i % colorPalette.
getSize()]);
 
  143             lineColors.
add(colorPalette[i % colorPalette.
getSize()]);
 
  152     if(visibility != 
NULL)
 
  252         splitNode(m_node, m_left.addr, m_right.addr, m_left.box, m_right.box, m_nodeSplit);
 
  289         splitNode(m_node, m_left.addr, m_right.addr, m_left.box, m_right.box, m_nodeSplit);
 
  306     m_nodeStack.
add(m_node);
 
  323         splitNode(m_node, m_left.addr, m_right.addr, m_left.box, m_right.box, m_nodeSplit);
 
  340     m_nodeStack.
add(m_node);
 
  377     glPushAttrib(GL_ENABLE_BIT);
 
  378     glEnable(GL_DEPTH_TEST);
 
  379     glDepthFunc(GL_LESS);
 
  380     glEnable(GL_CULL_FACE);
 
  401     glDisable(GL_DEPTH_TEST);
 
  402     glDisable(GL_CULL_FACE);
 
  405     drawNodes(gl, 
false);
 
  420 void VisualizationKDTree::getFromIndex(
S32 idx)
 
  422     if(idx < 0 || idx > m_nodeStack.
getSize()-1)
 
  425     if(m_nodeStack[idx].addr >= 0)
 
  427         splitNode(m_nodeStack[idx], m_left.addr, m_right.addr, m_left.box, m_right.box, m_nodeSplit);
 
  437         NodeData parent = m_nodeStack[idx-1];
 
  438         NodeData left, right;
 
  440         splitNode(parent, left.addr, right.addr, left.box, right.box, m_nodeSplit);
 
  442         if(left.addr == m_nodeStack[idx].addr) 
 
  455         m_node.addr = m_nodeStack[idx].addr;
 
  456         m_node.box = m_left.box + m_right.box;
 
  467 void VisualizationKDTree::growParentBox()
 
  469     float incrTop = (m_node.box.max() - m_node.box.min()).
length() / 50.0f;
 
  471     m_node.box.grow(m_node.box.min()-incrTop); 
 
  472     m_node.box.grow(m_node.box.max()+incrTop); 
 
  476         m_sibling.box.grow(m_sibling.box.min()-incrTop); 
 
  477         m_sibling.box.grow(m_sibling.box.max()+incrTop); 
 
  483 void VisualizationKDTree::drawNodes(
GLContext* gl, 
bool onlyChildren)
 
  510             glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
  515             glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
  523 void VisualizationKDTree::drawBox(
GLContext* gl, 
const NodeData &node, 
U32 abgr)
 
  528         gl->
drawBox(node.box.min(), node.box.max(), abgr);
 
  529         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
  531         gl->
drawBox(node.box.min(), node.box.max(), abgr | 0xFF000000);
 
  532         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
  538 void VisualizationKDTree::drawRays(
GLContext* gl, 
U32 abgr)
 
  550 void VisualizationKDTree::drawPrimitives(
GLContext* gl)
 
  554         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
  557         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
  563 void VisualizationKDTree::drawPathInfo(
GLContext* gl)
 
  572     char leftBox[100], rightBox[100];
 
  573     memset(leftBox, 
'\0', 100);
 
  574     memset(rightBox, 
'\0', 100);
 
  576     strcat_s(leftBox, 
", ");
 
  579     strcat_s(rightBox, 
", ");
 
  586         pos.y -= (
F32)fontSize;
 
  588         m_left.box.area(), leftBox, m_right.box.area(), rightBox), pos, 
Vec2f(0.0
f, 1.0
f), 0xFFFFFFFF);
 
  593             m_left.box.area(), leftBox, m_right.box.area(), rightBox), pos, 
Vec2f(0.0
f, 1.0
f), 0xFFFFFFFF);
 
  595     pos.y -= (
F32)fontSize;
 
  598     pos.y -= (
F32)fontSize;
 
  600     const float rightMargin = 100.0f;
 
  601     String header(
"Split path: ");
 
  611             pos.y -= (
F32)fontSize;
 
  623         pos.y -= (
F32)fontSize;
 
  634             pos.y -= (
F32)fontSize;
 
  648 void VisualizationKDTree::setColorMapping()
 
  676 void VisualizationKDTree::prepareTreeData(NodeData node)
 
  690     while(stackIndex > 0)
 
  703                     S32 idx = ~node.addr;
 
  715                     for(
int i = 0; i < indices.
getSize(); i++)
 
  722                         for(
int j = 0; j < 3; j++)
 
  736                 S32 child0Addr, child1Addr;
 
  739                 splitNode(node, child0Addr, child1Addr, child0, child1, m_nodeSplit);
 
  741                     rightChild = child1Addr;
 
  750                     addBoxQuads(child0, boxes);
 
  751                     addBoxQuads(child1, boxes);
 
  754                 node.addr = child0Addr;
 
  755                 stack[stackIndex++].addr = child1Addr;
 
  759         node = stack[stackIndex];
 
  791     buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
 
  792     buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
 
  793     buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
 
  794     buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
 
  796     buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
 
  797     buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
 
  798     buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
 
  799     buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
 
  801     buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
 
  802     buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
 
  803     buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
 
  804     buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
 
  806     buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
 
  807     buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
 
  808     buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
 
  809     buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
 
  811     buffer.
add(
Vec4f(min.x, min.y, min.z, 1.0f));
 
  812     buffer.
add(
Vec4f(max.x, min.y, min.z, 1.0f));
 
  813     buffer.
add(
Vec4f(max.x, max.y, min.z, 1.0f));
 
  814     buffer.
add(
Vec4f(min.x, max.y, min.z, 1.0f));
 
  816     buffer.
add(
Vec4f(max.x, max.y, max.z, 1.0f));
 
  817     buffer.
add(
Vec4f(max.x, min.y, max.z, 1.0f));
 
  818     buffer.
add(
Vec4f(min.x, min.y, max.z, 1.0f));
 
  819     buffer.
add(
Vec4f(min.x, max.y, max.z, 1.0f));
 
  824 void VisualizationKDTree::splitNode(
const NodeData& currNode, 
S32& leftAdd, 
S32& rightAdd, 
AABB& leftBox, 
AABB& rightBox, 
SplitInfo& split)
 
  834     leftCut[
dim] = splitPos;
 
  836     Vec3f rightCut = currNode.box.
min();
 
  837     rightCut[
dim] = splitPos;
 
  839     leftBox = 
AABB(currNode.box.min(), leftCut);
 
  840     rightBox = 
AABB(rightCut, currNode.box.
max());
 
  843     split.pos = splitPos;
 
~VisualizationKDTree(void)
Destructor. 
 
Class for the visualization. 
 
FW_CUDA_FUNC T length(const VectorBase< T, L, S > &v)
 
S32 getSize() const 
Gets size of the buffer (number of rays). 
 
void set(const void *ptr)
 
VisualizationKDTree(CudaKDTree *kdtree, Scene *scene, const Array< AABB > &emptyBoxes, const RayBuffer *rays=NULL, Buffer *visibility=NULL)
Constructor. 
 
Buffer & getTriVtxIndexBuffer(void)
Returns buffer of triangle's vertex indieces. 
 
Buffer & getTriIndexBuffer(void)
Returns triangle index buffer. 
 
void draw(GLContext *gl, CameraControls &camera)
The method used to draw the current state of visualization to the OpenGL context. ...
 
S32 m_currentDepth
Current node's depth information. 
 
Buffer m_emptyLineColors
Buffer holding line colors of empty boxes as quad primitives. 
 
Mat4f setVGXform(const Mat4f &m)
 
void setDefaultFont(void)
 
void moveToSibling()
Sets the node to be visualized to be the sibling of the currently visualized node. 
 
U32 m_nodeColor
Color of the current node. 
 
FW_CUDA_FUNC const Vec3f & max(void) const 
 
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
 
FW_CUDA_FUNC T max(void) const 
 
bool m_showEmpty
Flag whether to show empty nodes. 
 
Cuda friendly KDTree representation. 
 
void moveToRight()
Sets the node to be visualized to be the right child of the currently visualized node. 
 
S32 m_osahSplits[3]
Counters of the number of OSAH splits in the subtree under the set node in the x, y and z dimensions...
 
Buffer m_rays
Buffer holding some rays as line segments. 
 
Buffer & getVtxPosBuffer(void)
Returns vertex position buffer. 
 
Vec2i drawLabel(const String &str, const Vec4f &pos, const Vec2f &align, U32 fgABGR, U32 bgABGR)
 
FW_CUDA_FUNC bool hit(void) const 
 
U32 m_leftColor
Color of the left child of the current node. 
 
Buffer m_emptyBoxes
Buffer holding empty boxes as quad primitives. 
 
void drawBuffer(Buffer &buffer, GLenum mode, int offset, U32 abgr)
 
Vec2i getStringSize(const String &str)
 
Mat4f getWorldToClip(void) const 
 
const Ray & getRayForSlot(S32 slot) const 
Gets a ray assigned to a given slot. 
 
const U8 * getPtr(S64 ofs=0)
 
S32 getNumBytes(void) const
 
void drawColorBuffer(Buffer &buffer, Buffer &color, GLenum mode, int offset)
 
bool m_splitColors
Flag whether to map left/right children colors based on the split type. 
 
Mat4f xformFitToView(const Vec2f &pos, const Vec2f &size) const 
 
bool m_showAllOSAH
Flag whether to show all OSAH split nodes. 
 
void moveUp()
Sets the node to be visualized to be the predecesor of the currently visualized node on the set path...
 
const T & getLast(void) const
 
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 GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v
 
Buffer m_visTris
Buffer holding invisible selected triangles. 
 
Ray buffer class. Stores rays. 
 
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
 
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
 
void setFont(const String &name, int size, U32 style)
 
int getNumTriangles(void) const 
 
Definitions for the BVH visualization framework. 
 
U32 m_rayColor
Color of the ray line indices. 
 
Array< String > m_splitPath
Text representation of the VisualizationBVH::m_nodeStack path. 
 
FW::String getAxisName(void)
 
virtual bool handleEvent(const Window::Event &ev)
Handles visualization events - key commands influencing the output. 
 
Mat4f xformMatchPixels(void) const 
 
FW_CUDA_FUNC const Vec3f & min(void) const 
 
String sprintf(const char *fmt,...)
 
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 dim
 
bool isVisible() const 
Return whether the visualization renders its output. 
 
Class holding information about a split of a BVH node. 
 
bool m_showRays
Flag whether to show the ray segments. 
 
Buffer m_emptyColors
Buffer holding colors of empty boxes as quad primitives. 
 
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 GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei stride
 
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 f
 
U32 m_rightPrims
Number of primitives in the right child of the current node. 
 
const RayResult & getResultForSlot(S32 slot) const 
Gets a ray result assigned to a given slot. 
 
Buffer & getNodeBuffer(void)
Returns node buffer. 
 
bool m_showChildren
Flag whether to show children of the current node. 
 
void drawBox(const Vec3f &min, const Vec3f &max, U32 abgr)
 
Buffer m_boxes
Buffer holding selected boxes as quad primitives. 
 
void moveToLeft()
Sets the node to be visualized to be the left child of the currently visualized node. 
 
T set(S idx, const T &item)
 
U32 m_rightColor
Color of the right child of the current node. 
 
void moveDown()
Sets the node to be visualized to be the succesor of the currently visualized node on the set path...
 
const Vec2i & getViewSize(void) const 
 
void moveToParent()
Sets the node to be visualized to be the parent of the currently visualized node. ...
 
bool m_showCurrTris
Flag whether to show triangles of the current 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 GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type
 
const T * getPtr(S32idx=0) const
 
U32 m_siblingColor
Color of the sibling of the current node. 
 
void resizeDiscard(S64 size)
 
const AABB & getBBox(void) const 
Returns bounding box of the CudaKDTree's source scene. 
 
U32 m_leftPrims
Number of primitives in the left child of the current node. 
 
Array< S32 > m_visibility
Visibility of individual triangles. 
 
FW_CUDA_FUNC T min(void) const 
 
Buffer m_invisTris
Buffer holding visible selected triangles.