28 #include "../common/WAssert.h"
29 #include "../common/WLogger.h"
34 m_size( size ), m_pointArray( pointArray )
40 wlog::debug(
"KdTree" ) <<
" Start building KdTree";
42 for(
int i = 0; i <
m_size; ++i )
45 int root = (
m_size - 1 ) / 2;
56 int rootLeft = ( root - 1 ) / 2;
62 int rootRight = (
m_size + root ) / 2;
107 int div = ( left + right ) / 2;
110 buildTree( left, div - 1, ( axis + 1 ) % 3 );
111 buildTree( div + 1, right, ( axis + 1 ) % 3 );
115 WThreadedRunner(), m_tree( tree ), m_pointArray( pointArray ), m_left( left ), m_right( right ), m_axis( axis )
130 int div = ( left + right ) / 2;
133 buildTree( left, div - 1, ( axis + 1 ) % 3 );
134 buildTree( div + 1, right, ( axis + 1 ) % 3 );
class to provide threaded computation of parts of the kd tree
std::vector< unsigned int > * m_tree
stores a pointer to the tree
WKdTreeThread(float *pointArray, std::vector< unsigned int > *tree, int left, int right, int axis)
constructor
int m_axis
stores axis, since the threadMain method has no arguments
int m_left
stores left boundary, since the threadMain method has no arguments
float * m_pointArray
stores a pointer to the vertex array
void buildTree(int left, int right, int axis)
recursive function to compute a part of the kd tree
int m_right
stores left boundary, since the threadMain method has no arguments
virtual void threadMain()
entry for the run command
float * m_pointArray
stores a pointer to the vertex array
WKdTree(int size, float *pointArray)
constructor
int m_size
size of the tree
unsigned int m_root
index of the root point
std::vector< unsigned int > m_tree
stores the tree
void buildTree(int left, int right, int axis)
recursive function to compute a part of the kd tree
Base class for all classes needing to be executed in a separate thread.
virtual void run()
Run thread.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
implements the compare function for std::nth_element on a point array