33 template<
short_t d,
class Z = index_t>
75 box =
new kdBox( point::Zero(), upp);
101 "Problem: leaf with children." );
108 "Problem: split node with box." );
133 const point & lowCorner()
const
139 const point & uppCorner()
const
145 bool isLeaf()
const {
return axis == -1; }
147 bool isRoot()
const {
return parent == NULL; }
149 bool isTerminal()
const
156 bool isDegenerate()
const
157 {
return (
box->first.array() >=
box->second.array()).any(); }
169 box->first .array() *= 2;
170 box->second.array() *= 2;
182 box->first .array() /= 2;
183 box->second.array() /= 2;
195 "Can only split leaf nodes.");
224 "Can only merge terminal nodes.");
242 void split(
int splitAxis, Z splitPos)
244 GISMO_ASSERT(
box->second[splitAxis] != splitPos,
"Degenerate split " <<
box->second[splitAxis] <<
" != "<<splitPos);
245 GISMO_ASSERT(
box->first [splitAxis] != splitPos,
"Degenerate split " <<
box->first[splitAxis] <<
" != "<<splitPos);
265 const unsigned h = 1 << (index_level -
level) ;
266 const unsigned mask = ~(h - 1);
267 for (
unsigned i = 0; i < d; ++i )
270 (
box->first [i] + (
box->second[i] -
box->first[i])/2) & mask ;
271 if ( c !=
box->first [i] )
287 const unsigned h = 1 << (index_level -
level) ;
289 for (
short_t i = 0; i < d; ++i)
291 const Z c1 = insBox. first[i] - insBox. first[i] % h;
292 const Z cc = insBox.second[i] % h;
293 const Z c2 = insBox.second[i] + (cc ? h-cc : 0 );
295 if ( c1 >
box->first[i] )
301 else if ( c2 < box->second[i] )
318 for (
unsigned i = 0; i < d; ++i )
321 if ( insBox.first[i] >
box->first[i] )
324 pos = insBox.first[i];
328 else if ( insBox.second[i] <
box->second[i] )
331 pos = insBox.second[i];
340 friend std::ostream & operator<<(std::ostream & os,
const gsKdNode & n)
344 os <<
"Leaf node ("<< n.
box->first.transpose() <<
"), ("
345 << n.
box->second.transpose() <<
"). level="<<n.
level<<
" \n";
349 os <<
"Split node, axis= "<< n.
axis <<
", pos="<< n.
pos <<
"\n";
~gsKdNode()
Recursively deletes the whole subtree under this node.
Definition: gsKdNode.h:117
void split(int splitAxis, Z splitPos)
Splits the node (i.e., two children are added)
Definition: gsKdNode.h:242
#define short_t
Definition: gsConfig.h:35
gsKdNode(kdBox const &bb)
Constructor (leaf node)
Definition: gsKdNode.h:87
gsKdNode * adaptiveAlignedSplit(kdBox const &insBox, int index_level)
Definition: gsKdNode.h:285
gsKdNode * left
Pointer to the left child of this split node (if it is one)
Definition: gsKdNode.h:60
Struct representing a kd-tree node.
Definition: gsKdNode.h:34
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void nextMidSplit()
Splits the node in the middle (ie. two children are added)
Definition: gsKdNode.h:253
gsKdNode()
Constructor (empty node)
Definition: gsKdNode.h:66
gsKdNode * adaptiveSplit(kdBox const &insBox)
Definition: gsKdNode.h:315
Z pos
Split coordinate (meaningfull only for split nodes)
Definition: gsKdNode.h:45
gsKdNode(point const &upp)
Constructor (root node)
Definition: gsKdNode.h:71
void merge()
Merges terminal node (i.e., two children are joined)
Definition: gsKdNode.h:221
int level
Definition: gsKdNode.h:49
void anyMidSplit(int index_level)
Definition: gsKdNode.h:263
gsKdNode(const gsKdNode &o, gsKdNode *parentNode=NULL)
Definition: gsKdNode.h:95
Struct of for an Axis-aligned bounding box.
Definition: gsAABB.h:30
kdBox * box
Definition: gsKdNode.h:54
void split()
Splits the node (i.e., two children are added)
Definition: gsKdNode.h:192
gsKdNode * parent
Pointer to the parent node.
Definition: gsKdNode.h:57
int axis
Definition: gsKdNode.h:42
Declarations of the class gsAABB, i.e., the axis-aligned bounding box.
gsKdNode(point const &low, point const &upp)
Constructor (root node)
Definition: gsKdNode.h:79
gsKdNode * right
Pointer to the right child of this split node (if it is one)
Definition: gsKdNode.h:63