53 #include <OpenMesh/Tools/VDPM/VHierarchy.hh> 66 n_roots_(0), tree_id_bits_(0)
73 set_num_roots(
unsigned int _n_roots)
78 while (n_roots_ > ((
unsigned int) 0x00000001 << tree_id_bits_))
87 return add_node(VHierarchyNode());
92 add_node(
const VHierarchyNode &_node)
94 nodes_.push_back(_node);
96 return VHierarchyNodeHandle(
int(nodes_.size() - 1));
102 make_children(VHierarchyNodeHandle &_parent_handle)
104 VHierarchyNodeHandle lchild_handle = add_node();
105 VHierarchyNodeHandle rchild_handle = add_node();
107 VHierarchyNode &parent = node(_parent_handle);
108 VHierarchyNode &lchild = node(lchild_handle);
109 VHierarchyNode &rchild = node(rchild_handle);
111 parent.set_children_handle(lchild_handle);
112 lchild.set_parent_handle(_parent_handle);
113 rchild.set_parent_handle(_parent_handle);
115 lchild.set_index(VHierarchyNodeIndex(parent.node_index().tree_id(tree_id_bits_), 2*parent.node_index().node_id(tree_id_bits_), tree_id_bits_));
116 rchild.set_index(VHierarchyNodeIndex(parent.node_index().tree_id(tree_id_bits_), 2*parent.node_index().node_id(tree_id_bits_)+1, tree_id_bits_));
121 node_handle(VHierarchyNodeIndex _node_index)
123 if (_node_index.is_valid(tree_id_bits_) !=
true)
124 return InvalidVHierarchyNodeHandle;
126 VHierarchyNodeHandle node_handle = root_handle(_node_index.tree_id(tree_id_bits_));
127 unsigned int node_id = _node_index.node_id(tree_id_bits_);
128 unsigned int flag = 0x80000000;
130 while (!(node_id & flag)) flag >>= 1;
133 while (flag > 0 && is_leaf_node(node_handle) !=
true)
137 node_handle = rchild_handle(node_handle);
141 node_handle = lchild_handle(node_handle);
151 is_ancestor(VHierarchyNodeIndex _ancestor_index, VHierarchyNodeIndex _descendent_index)
153 if (_ancestor_index.tree_id(tree_id_bits_) != _descendent_index.tree_id(tree_id_bits_))
156 unsigned int ancestor_node_id = _ancestor_index.node_id(tree_id_bits_);
157 unsigned int descendent_node_id = _descendent_index.node_id(tree_id_bits_);
159 if (ancestor_node_id > descendent_node_id)
162 while (descendent_node_id > 0)
164 if (ancestor_node_id == descendent_node_id)
166 descendent_node_id >>= 1;