28 #include "../common/WAssert.h"
29 #include "../common/WLogger.h"
34 m_size( size ), m_pointArray( pointArray )
36 WAssert( size > 2,
"The current kD-tree implementation works only with at least 3 vertices." );
40 wlog::debug(
"KdTree" ) <<
" Start building KdTree";
42 for(
int i = 0; i < size; ++i )
45 int root = ( size - 1 ) / 2;
48 int rootLeft = ( root - 1 ) / 2;
51 int rootRight = ( size + root ) / 2;
90 int div = ( left + right ) / 2;
93 buildTree( left, div - 1, ( axis + 1 ) % 3 );
94 buildTree( div + 1, right, ( axis + 1 ) % 3 );
98 WThreadedRunner(), m_tree( tree ), m_pointArray( pointArray ), m_left( left ), m_right( right ), m_axis( axis )
113 int div = ( left + right ) / 2;
116 buildTree( left, div - 1, ( axis + 1 ) % 3 );
117 buildTree( div + 1, right, ( axis + 1 ) % 3 );
virtual void run()
Run thread.
int m_axis
stores axis, since the threadMain method has no arguments
void buildTree(int left, int right, int axis)
recursive function to compute a part of the kd 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.
WKdTreeThread(float *pointArray, std::vector< unsigned int > *tree, int left, int right, int axis)
constructor
int m_left
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
std::vector< unsigned int > * m_tree
stores a pointer to the tree
implements the compare function for std::nth_element on a point array
void wait(bool requestFinish=false)
Wait for the thread to be finished.
int m_right
stores left boundary, since the threadMain method has no arguments
WKdTree(int size, float *pointArray)
constructor
std::vector< unsigned int > m_tree
stores the tree
WStreamedLogger debug(const std::string &source)
Logging a debug message.
class to provide threaded computation of parts of the kd tree
float * m_pointArray
stores a pointer to the vertex array