void visitChildren(CDGNode * node, int outcome) { CDGNode *children; if (outcome) { children = getTrueNodeSet(node); } else { children = getFalseNodeSet(node); } while (children) { if (isLeaf(children)) { setScore(children, 0); } children = getNextNode(children); } return; }
void UpperNode::self_collide() { if (isLeaf()) { s_trees[getID()]->self_collide(); return; } getLeftChild()->self_collide(); if (getRightChild()) { getRightChild()->self_collide(); getLeftChild()->collide(getRightChild()); } }
void KStaticGeometryNode::drawAabb(KTransform3D &trans, const KColor &color, size_t min, size_t max) const { if (depth <= max) { if (depth >= min) { aabb.draw(trans, Karma::colorShift(color, 0.1f * depth)); } if (!isLeaf()) { if (left) left->drawAabb(trans, color, min, max); if (right) right->drawAabb(trans, color, min, max); } } }
Voronoi::ParabolaNode * Voronoi::ParabolaNode::emplaceParabola(const Point & site) { if (!isValid()) { setSite(site); return this; } ParabolaNode * parabola = findParabola(site); assert(parabola->site().y() >= site.y()); // disable event including parabola->sites in the middle of a triple. parabola->setEvent(nullptr); // Handle special case when: one_parabola_in_root && parabolaSite.y() == site.y() const Point parabolaSite = parabola->site(); if (isLeaf(this) && parabolaSite.y() == site.y()) { if (site.x() < parabolaSite.x()) { parabola->_createChildren(site, parabolaSite); return parabola->leftChild(); } else { parabola->_createChildren(parabolaSite, site); return parabola->rightChild(); } } else if (site.x() < parabolaSite.x()) { // Create new parabola branch parabola->_createChildren(Point(), parabolaSite); parabola->leftChild()->_createChildren(parabolaSite, site); // Set edge to right sibling from the original parabola parabola->_rightChild->setEdge(parabola->edge()); // the rightmost parabola parabola->setEdge(nullptr); return parabola->leftChild()->rightChild(); } else { // Create new parabola branch parabola->_createChildren(parabolaSite, Point()); parabola->rightChild()->_createChildren(site, parabolaSite); // Set edge to right sibling from the original parabola parabola->rightChild()->_rightChild->setEdge(parabola->edge()); // the rightmost parabola parabola->setEdge(nullptr); return parabola->rightChild()->leftChild(); } }
bool ccHObject::addChild(ccHObject* child, int dependencyFlags/*=DP_PARENT_OF_OTHER*/, int insertIndex/*=-1*/) { if (!child) { assert(false); return false; } if (isLeaf()) { ccLog::ErrorDebug("[ccHObject::addChild] Leaf objects shouldn't have any child!"); return false; } //insert child try { if (insertIndex < 0 || static_cast<size_t>(insertIndex) >= m_children.size()) m_children.push_back(child); else m_children.insert(m_children.begin()+insertIndex,child); } catch(std::bad_alloc) { //not enough memory! return false; } //we want to be notified whenever this child is deleted! child->addDependency(this,DP_NOTIFY_OTHER_ON_DELETE); //DGM: potentially redundant with calls to 'addDependency' but we can't miss that ;) if (dependencyFlags != 0) { addDependency(child,dependencyFlags); } //the strongest link: between a parent and a child ;) if ((dependencyFlags & DP_PARENT_OF_OTHER) == DP_PARENT_OF_OTHER) { child->setParent(this); if (child->isShareable()) dynamic_cast<CCShareable*>(child)->link(); if (!child->getDisplay()) child->setDisplay(getDisplay()); } return true; }
template<class T> deque<T> Tree<T>::travelDfs(){ deque<T> retv; retv.push_back(*node); cout << toId() << ","; if(isLeaf()){ }else{ for(int i=0;i<m_childs->size();i++){ Tree& ti = (*m_childs)[i]; deque<T> temp = ti.travelDfs(); retv.insert(retv.end(),temp.begin(),temp.end()); } } return retv; }
void COSBindingNode::printNode(unsigned int offset) { unsigned i; for(i = 0; i < offset; i++) std::cerr << "*"; std::cerr << name << " "; if( isLeaf() ) std::cerr << (isDead() ? "(Dead)" : "(Alive)"); std::cerr << std::endl; for(i = 0; i < branches(); i++) { (*this)[i].printNode(offset + 1); } }
uint64_t quadtree::pruned_size(const std::unique_ptr<node> & subroot, uint32_t tolerance) const { if(isLeaf(subroot)) return 1; if(isPrunable(subroot, tolerance)) return 1; uint64_t leaves = 0; leaves += pruned_size(subroot->northwest, tolerance); leaves += pruned_size(subroot->northeast, tolerance); leaves += pruned_size(subroot->southwest, tolerance); leaves += pruned_size(subroot->southeast, tolerance); return leaves; }
void jfBVHNode_x86::recalculateBoundingVolume(bool recurse) { if (isLeaf()) { return; } // Use the bounding volume combining constructor. m_Volume->recalculateBoundingVolume(*m_Children[0]->getVolume(), *m_Children[1]->getVolume()); // Recurse up the tree if (m_Parent) { m_Parent->recalculateBoundingVolume(true); } }
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); } }
static int next_key(struct iterator_mtree *imt, u64 blknum) { struct block *b; u64 key = imt->key; int i; int rc; if (!blknum) return DONE; b = get_blk(imt->mt->dev, blknum); if (isLeaf(b)) { struct leaf *leaf = b->buf; struct record *rec = (struct record *)leaf->data; for (i = 0; i < leaf->num_recs; i++, rec++) { if (key < rec->key) { imt->key = rec->key; imt->val.size = rec->size; memcpy(imt->data, &leaf->data[rec->offset], rec->size); put_blk(b); return 0; } } put_blk(b); return NEXT; } else { struct branch *branch = b->buf; struct twig *twig = branch->twig; for (i = 0; i < branch->num_twigs - 1; i++, twig++) { if (key < twig[1].key) break; } for (; i < branch->num_twigs; i++, twig++) { rc = next_key(imt, twig->blknum); if (rc == 0) { put_blk(b); return 0; } } put_blk(b); return NEXT; } }
//-------------------------------------------------------------------- // get the node with origin and size void PtrOctNode::getNode( PtrOctree* tree, int size, int nodeX, int nodeY, int nodeZ, int nodeSize, int& foundX, // target/found position int& foundY, int& foundZ, int& foundSize, // target/found size BOOL& foundLeaf, // true if found is leaf PtrOctNode*& foundNode) { // figure which child this block goes into int halfSize = size >> 1; int cell = (nodeX%size < halfSize) ? 0 : 4; cell += (nodeY%size < halfSize) ? 0 : 2; cell += (nodeZ%size < halfSize) ? 0 : 1; PtrOctNode* child = m_children[cell]; foundX = nodeX - nodeX % halfSize; foundY = nodeY - nodeY % halfSize; foundZ = nodeZ - nodeZ % halfSize; foundSize = halfSize; foundNode = child; // if this is a leaf cell if (isLeaf(cell)) { // can't recurse farther. this may be larger than requested node. foundLeaf = true; return; } // if this is requested node if (foundSize == nodeSize) { foundLeaf = false; return; } // recurse to child child->getNode(tree, halfSize, nodeX, nodeY, nodeZ, nodeSize, foundX, foundY, foundZ, foundSize, foundLeaf, foundNode); }
void Tree::printTree() { if (isLeaf()) { cout << data << endl; } else { cout << "--"; cout << data; cout << "="; cout << leftBranch; if (left->isLeaf()) { cout << " "; } else { cout << endl; //cout << "--"; } left->printTree(); if (centerBranch!="") { cout << "--"; cout << data; cout << "="; cout << centerBranch; if (center->isLeaf()) { cout << " "; } else { cout << endl; //cout << "--"; } center->printTree(); if (rightBranch!="") { cout << "--"; cout << data; cout << "="; cout << rightBranch; if (right->isLeaf()) { cout << " "; } else { cout << endl; //cout << "--"; } right->printTree(); } } } }
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; } }
//each of x and y has less then t keys and keys of y migrate to x, splitten by mediane //it is, of course, used both on left and right merging void mergeToLeft(TreeNodePtr parent, int lPos){ assert(parent != NULL); if(isLeaf(parent)) return; assert(lPos >= 0 && lPos < parent->keyCount && parent->keyCount <= MAX_KEY_COUNT); TreeNodePtr x = parent->nodes[lPos], y = parent->nodes[lPos + 1]; assert(x->keyCount < t && y->keyCount < t); x->items[x->keyCount++] = parent->items[lPos]; pourElements(x, y, 0); excludeKey(parent, lPos, false); parent->subtreeKeyCount[lPos] += parent->subtreeKeyCount[lPos + 1] + 1; excludeNode(parent, lPos + 1, true); //and free it, yep }
void OctreeNode::setBlocks(Vector<3, VoxelSize> bottomLeftPosition, Vector<3, VoxelSize> topRightPosition, Block block){ if (isLeaf()){ Vector<3, VoxelSize> insertionSize(topRightPosition - bottomLeftPosition); VoxelSize nodeSize = getSize(); if (insertionSize[Dimensions::X] == nodeSize && insertionSize[Dimensions::Y] == nodeSize){ // No need to check position since a node will not be passed a volume which does not fit inside it. m_block = block; } else{ subdivide(); redistributeInsertion(bottomLeftPosition, topRightPosition, block, 0); } } else{ redistributeInsertion(bottomLeftPosition, topRightPosition, block, 0); } };
void Octree::reduceToParent() { assert(isLeaf()); assert(!isRoot()); parent->reference += reference; parent->red += red; parent->green += green; parent->blue += blue; parent->alpha += alpha; for (int i = 0; i < 16; i++) { if (parent->children[i] == this) { parent->children[i] = nullptr; break; } } }
OctreeElement* OctreeElement::addChildAtIndex(int childIndex) { OctreeElement* childAt = getChildAtIndex(childIndex); if (!childAt) { // before adding a child, see if we're currently a leaf if (isLeaf()) { _voxelNodeLeafCount--; } unsigned char* newChildCode = childOctalCode(getOctalCode(), childIndex); childAt = createNewElement(newChildCode); setChildAtIndex(childIndex, childAt); _isDirty = true; markWithChangedTime(); } return childAt; }
void quadtree::prune(std::unique_ptr<node> & subroot, uint32_t tolerance) { if(isLeaf(subroot)) return; if(isPrunable(subroot, tolerance)){ subroot->northwest = NULL; subroot->northeast = NULL; subroot->southwest = NULL; subroot->southeast = NULL; return; } prune(subroot->northwest, tolerance); prune(subroot->northeast, tolerance); prune(subroot->southwest, tolerance); prune(subroot->southeast, tolerance); }
OctreeElement::~OctreeElement() { // We can't call notifyDeleteHooks from here: // notifyDeleteHooks(); // see comment in EntityTreeElement::createNewElement. assert(_deleteHooksNotified); _voxelNodeCount--; if (isLeaf()) { _voxelNodeLeafCount--; } if (_octcodePointer) { _octcodeMemoryUsage -= bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(getOctalCode())); delete[] _octalCode.pointer; } // delete all of this node's children, this also takes care of all population tracking data deleteAllChildren(); }
void VoxelTreeNode::insert(Voxel* voxel) { assert(m_gridAABB.contains(voxel->cell())); if (isAtomic()) { assert(m_voxel == nullptr); m_voxel = voxel; m_voxel->setVoxelTreeNode(this); setActive(true); } else { if (isLeaf()) { toGroup(); } cellSubnode(voxel->cell())->insert(voxel); } }
//-------------------------------------------------------------- // return count of child and interior nodes void mgOctNode::countNodes( mgOctree* tree, int &interiorNodeCount, int &leafNodeCount) { interiorNodeCount++; // for each child for (int i = 0; i < 8; i++) { // if not a leaf, count children if (!isLeaf(i)) { m_children[i]->countNodes(tree, interiorNodeCount, leafNodeCount); } else leafNodeCount++; } }
void linex_node_handler::traverseToLeaf(byte *node_paths[]) { byte level; level = 1; if (isPut) *node_paths = buf; while (!isLeaf()) { int16_t idx = locate(); if (idx < 0) { idx = ~idx; if (idx) idx--; key_at = prev_key_at; } setBuf(getChildPtr(key_at)); if (isPut) node_paths[level++] = buf; } }
template<class T> int Tree<T>::depth() const{ int retv = -1; if(isLeaf()){ retv = 1; }else{ //deque<T>::iterator itr1,itr2; //itr1 = m_childs->begin(); //itr2 = m_childs->end(); deque<Tree>::iterator ditr; ditr = max_element(m_childs->begin(),m_childs->end(),depthLessthan); //ditr = // max_element(m_childs->begin(),m_childs->end()); //retv = (*m_childs)[0].depth() + 1; retv = (*ditr).depth() + 1; } return retv; }
TID N::getAnyChildTid(const N *n, bool &needRestart) { const N *nextNode = n; while (true) { const N *node = nextNode; auto v = node->readLockOrRestart(needRestart); if (needRestart) return 0; nextNode = getAnyChild(node); node->readUnlockOrRestart(v, needRestart); if (needRestart) return 0; assert(nextNode != nullptr); if (isLeaf(nextNode)) { return getLeaf(nextNode); } } }
Tree deleteTree(Tree t, TreeEntry e, int *diminuiu) { // Node with entry e is supposed to exist. Before deleteTree, call searchTree. Tree aux, min; // step 1 - remove node with entry e if(e == t->entry) { if(isLeaf(t)) { // if node with entry e is a leaf, just (physically) remove it aux = t; t = NULL; free(aux); *diminuiu = 1; } else if(has1child(t)) { switch(t->bf) { // if node with entry e has only 1 child, check balance factor case LH: // overwrite node entry with left child entry and remove left child aux = t->left; t->entry = aux->entry; t->left = NULL; free(aux); break; case RH: // set node entry to right child entry and remove right child aux = t->right; t->entry = aux->entry; t->right = NULL; free(aux); break; } *diminuiu = 1; } else { // if node with entry e has both subtrees aux = minEntry(t->right); t->entry = aux->entry; // overwrite t's entry with the smallest entry in the right subtree t->right = deleteTree(t->right,aux->entry,diminuiu); } } else if(e < t->entry) t = deleteLeft(t, e, diminuiu); else t = deleteRight(t, e, diminuiu); // step 2 - rebalance the tree (if necessary) return t; }
/** * recursive handler for DOT graph generator. */ static void ln_genDotPTreeGraphRec(struct ln_ptree *tree, es_str_t **str) { int i; ln_fieldList_t *node; dotAddPtr(str, tree); es_addBufConstcstr(str, " [label=\""); if(tree->lenPrefix > 0) { es_addChar(str, '\''); es_addBuf(str, (char*) prefixBase(tree), tree->lenPrefix); es_addChar(str, '\''); } es_addBufConstcstr(str, "\""); if(isLeaf(tree)) { es_addBufConstcstr(str, " style=\"bold\""); } es_addBufConstcstr(str, "]\n"); /* display char subtrees */ for(i = 0 ; i < 256 ; ++i) { if(tree->subtree[i] != NULL) { dotAddPtr(str, tree); es_addBufConstcstr(str, " -> "); dotAddPtr(str, tree->subtree[i]); es_addBufConstcstr(str, " [label=\""); es_addChar(str, (char) i); es_addBufConstcstr(str, "\"]\n"); ln_genDotPTreeGraphRec(tree->subtree[i], str); } } /* display field subtrees */ for(node = tree->froot ; node != NULL ; node = node->next ) { dotAddPtr(str, tree); es_addBufConstcstr(str, " -> "); dotAddPtr(str, node->subtree); es_addBufConstcstr(str, " [label=\""); es_addStr(str, node->name); es_addBufConstcstr(str, "\" style=\"dotted\"]\n"); ln_genDotPTreeGraphRec(node->subtree, str); } }
/* process a new binary symbol */ void CTNode::update(bit_t b, bool skip) { // update the KT estimate and counts double log_kt_mul = logKTMul(b); m_log_prob_est += log_kt_mul; m_count[b]++; if (isLeaf()) { m_log_prob_weighted = logProbEstimated(); } else { if (skip) { double log_prob_on = child(1) ? child(1)->logProbWeighted() : 0.0; double log_prob_off = child(0) ? child(0)->logProbWeighted() : 0.0; m_log_prob_weighted = log_prob_on + log_prob_off; } else { updateWeighted(); } } }
void RenderTerrainNode::walkQuadTree( RenderCamera* camera, Array<RenderElement*>& visible ) { bool vis = checkVisible(camera); if (vis) { if (!isLeaf()) { for (int i = 0; i < 4; ++i) { m_children[i]->walkQuadTree(camera,visible); } } else { visible.Append(this); } } }
TreeElement::~TreeElement() { if (pair != 0) { pair->setPair(0); pair = 0; } if (!isLeaf()) removeAllChildren(); if (parent != 0) { if (!parent->isImportant()) delete parent; else parent->removeChild(this); } }