void UpperNode::self_collide() { if (isLeaf()) { s_trees[getID()]->self_collide(); return; } getLeftChild()->self_collide(); if (getRightChild()) { getRightChild()->self_collide(); getLeftChild()->collide(getRightChild()); } }
void UpperNode::visulization(int level) { if (isLeaf()) _box.visulization(); else if ((level > 0)) { if (level == 1) _box.visulization(); else if (getLeftChild()) getLeftChild()->visulization(level-1); if (getRightChild()) getRightChild()->visulization(level-1); } }
void UpperNode::Construct(unsigned int *lst, unsigned int lst_num) { if (lst_num == 1){ _child = lst[0]; _box = s_trees[getID()]->box(); return; } _box.empty(); //try to split them for (unsigned int t=0; t<lst_num; t++) { int i=lst[t]; _box += s_trees[i]->box(); } if (lst_num == 2) {// must split it! getLeftChild()->Construct(lst[0]); getRightChild()->Construct(lst[1]); return; } aap pln(_box); unsigned int left_idx=0, right_idx=lst_num-1; for (unsigned int t=0; t<lst_num; t++) { int i=lst[left_idx]; if (pln.inside(s_trees[i]->box().center())) left_idx++; else {// swap it unsigned int tmp = i; lst[left_idx] = lst[right_idx]; lst[right_idx--] = tmp; } } int hal = lst_num/2; if (left_idx == 0 || left_idx == lst_num) { getLeftChild()->Construct(lst, hal); getRightChild()->Construct(lst+hal, lst_num-hal); } else { getLeftChild()->Construct(lst, left_idx); getRightChild()->Construct(lst+left_idx, lst_num-left_idx); } }
void MaxHeap::balanceEntireTreeRec(size_t i) { if (isLeaf(i)) return; balanceEntireTreeRec(getLeftChild(i)); balanceEntireTreeRec(getRightChild(i)); balanceTreeRec(i); }
void UpperNode::refit() { if (isLeaf()) { _box = s_trees[getID()]->box(); } else { getLeftChild()->refit(); if (getRightChild()) getRightChild()->refit(); if (getRightChild()) _box = getLeftChild()->_box + getRightChild()->_box; else _box = getLeftChild()->_box; } }
void DeformBVHNode::Construct(unsigned int *lst, unsigned int lst_num) { _count = lst_num; for (unsigned int t=0; t<lst_num; t++) _box += s_mdl->_tri_boxes[lst[t]]; if (lst_num == 1) { _child = ID(lst[0]); _box = s_mdl->_tri_boxes[lst[0]]; } else { // try to split _child = this-s_current_node; s_current_node += 2; if (lst_num == 2) {// must split getLeftChild()->Construct(ID(lst[0])); getRightChild()->Construct(ID(lst[1])); } else { aap pln(_box); unsigned int left_idx = 0, right_idx = lst_num-1; for (unsigned int t=0; t<lst_num; t++) { int i=lst[left_idx]; if (pln.inside(s_mdl->_tri_centers[i])) left_idx++; else {// swap it unsigned int tmp = i; lst[left_idx] = lst[right_idx]; lst[right_idx--] = tmp; } } int half = lst_num/2; if (left_idx == 0 || left_idx == lst_num) { getLeftChild()->Construct(lst, half); getRightChild()->Construct(lst+half, lst_num-half); } else { getLeftChild()->Construct(lst, left_idx); getRightChild()->Construct(lst+left_idx, lst_num-left_idx); } } } }
void heapify(heap* h,int index,int size) { int lidx = getleftChild(index); int ridx = getRightChild(index); int smallestidx; while(lidx <size && ridx < size) { smallestidx = getMinValueIdx(h,lidx,ridx); if(h->edge[smallestidx]->length > h->edge[index]->length) { return ; } swapEdge(h,smallestidx,index); index = smallestidx; lidx = getleftChild(index); ridx = getRightChild(index); } }
void heap (int arrayList[],int size,int currentLocation) { int temp; int parentIndex,leftChildIndex,rightChildIndex; parentIndex = getParent(currentLocation); leftChildIndex = getLeftChild(currentLocation); rightChildIndex = getRightChild(currentLocation); if(currentLocation<size) { if(arrayList[currentLocation]<arrayList[rightChildIndex]&&rightChildIndex<size) { temp=arrayList[currentLocation]; arrayList[currentLocation]=arrayList[rightChildIndex]; arrayList[rightChildIndex]=temp; } heap(arrayList,size,rightChildIndex); if(arrayList[currentLocation]<arrayList[leftChildIndex]&&leftChildIndex<size) { temp=arrayList[currentLocation]; arrayList[currentLocation]=arrayList[leftChildIndex]; arrayList[leftChildIndex]=temp; } heap(arrayList,size,leftChildIndex); if(currentLocation!=0) { if(arrayList[currentLocation]>arrayList[parentIndex]&&parentIndex<size) { temp=arrayList[currentLocation]; arrayList[currentLocation]=arrayList[parentIndex]; arrayList[parentIndex]=temp; } } } }
void MaxHeap::balanceTreeRec(size_t i) { size_t l = getLeftChild(i); size_t r = getRightChild(i); size_t greatest; if (l < m_nextIndex && (*m_array)[l].key > (*m_array)[i].key) greatest = l; else greatest = i; if (r < m_nextIndex && (*m_array)[r].key > (*m_array)[greatest].key) greatest = r; if (greatest != i) { swapNode(i, greatest); balanceTreeRec(greatest); } }
void UpperNode::collide(UpperNode *other) { s_mdl->_counts[0]._num_box_tests++; if (!_box.overlaps(other->_box)) return; if (isLeaf() && other->isLeaf()) { s_trees[getID()]->collide(s_trees[other->getID()]); return; } if (isLeaf()) { collide(other->getLeftChild()); collide(other->getRightChild()); } else { getLeftChild()->collide(other); getRightChild()->collide(other); } }
void DecisionTree::Node::printTree() const { // cerr << "["; if(isLeaf()) { // cerr << "LEAF: "<< m_probability<<" "; if(m_probability>0 && m_probability<1) cerr << m_probability << " "; } else { // cerr << m_tree->getFeatureName(m_feature_index); } if(!isLeaf()) { // cerr << "-> L: "; getLeftChild()->printTree(); // cerr << " "; } if(!isLeaf()) { // cerr << "-> R: "; getRightChild()->printTree(); // cerr << " "; } // cerr << "]"; }
bool isLeaf(CompleteTree *tree, unsigned int i) { return tree->length < getRightChild(tree, i); }