TreeNode *newExpNode(ExpKind kind) { TreeNode *t; t = allocNewNode(); if (t) { t->nodekind = ExpK; t->kind.exp = kind; } return t; }
TreeNode *newDecNode(DecKind kind) { TreeNode *t; t = allocNewNode(); if (t) { t->nodekind = DecK; t->kind.dec = kind; } return t; }
TreeNode *newStmtNode(StmtKind kind) { TreeNode *t; t = allocNewNode(); if (t) { t->nodekind = StmtK; t->kind.stmt = kind; } return t; }
bool CSpaceTree::constructTree(CTriContainer *pTriContainer_) { if(pTriContainer_->getCountTries()<1) { return false; } m_pTriContainer = pTriContainer_; m_pNodeRoot = allocNewNode( 0 ); reserveNodeTableEstimate( m_vecNodeTable, m_pTriContainer ); CreateRoot( m_vecNodeTable, m_pNodeRoot, pTriContainer_->m_vecTris ); BuildupTree_recurse( m_vecNodeTable, m_pNodeRoot, pTriContainer_->m_vecTris, LIMITTRISPERNODE, 0 ); return true; }
void insertAtTail(struct Node** t, struct Node** h, int val) { /* DIAGRAM OF LINKED LIST /[Tmp]\ *[N][T][N1]...[Nn][H] */ struct Node* newNode = allocNewNode(val); struct Node* tmp = *t; if (*t == NULL) { *t = newNode; *h = newNode; } else { //(*t)->next = tmp; *t = newNode; newNode->next = tmp; tmp->prev = newNode; } }
void insertAtHead(struct Node** h, struct Node** t, int val) { /* DIAGRAM OF LINKED LIST /[Tmp]\ [N][T][N1]...[Nn][H][N]* */ struct Node* newNode = allocNewNode(val); struct Node* tmp = *h; if (*h == NULL) { *h = newNode; *t = newNode; } else { //(*h)->prev = tmp; // Have to get tricky with multiple indirect *h = newNode; newNode->prev = tmp; tmp->next = newNode; } }
void CSpaceTree::BuildupTree_recurse( vector<SPACETREENODE*> &vecNodeTable, SPACETREENODE *tnodeParent, const vector<CTri>& vecTris, unsigned int uiLimitTries, int iDepthNode ) { if(DEPTH_BUILDSPCTREE_MAX<=iDepthNode) { return; } vector<SPACETREENODE*>::iterator iterLast; if(tnodeParent->_listSTris.size() <= uiLimitTries) { return; } int iDepthNodeChld = iDepthNode+1; for(int iChild = 0;iChild<NUM_CHILDREN;++iChild) { set<unsigned int> listSTriChld_; set<unsigned int>::iterator iter_; BV::_BV_AABB_Sphere bvsphereChld_; unsigned int iSeqTri = 0; bool bintersectedTri = false; MakeupBVBoxSpaceTree( tnodeParent->_BVBoxSphere, bvsphereChld_, iChild ); for(iter_=tnodeParent->_listSTris.begin();iter_!=tnodeParent->_listSTris.end();++iter_) { iSeqTri = static_cast<unsigned int>(*iter_); CTri &tri = (CTri&)(vecTris[iSeqTri]); if(IntersectTriBox( bvsphereChld_, tri ) == INSIDE) { listSTriChld_.insert( iSeqTri ); bintersectedTri = true; } } if( true==bintersectedTri ) { // insert New Node SPACETREENODE *pNewNodeChld = allocNewNode(iDepthNodeChld); bool bNodeChldIsLeaf = (listSTriChld_.size()<=uiLimitTries); pNewNodeChld->_bLeaf = bNodeChldIsLeaf; pNewNodeChld->setBV( bvsphereChld_ ); pNewNodeChld->setlistTri( listSTriChld_ ); listSTriChld_.clear(); vecNodeTable.push_back(pNewNodeChld); tnodeParent->_iNodeChildIdx[iChild] = vecNodeTable.size()-1; if(false==bNodeChldIsLeaf) { BuildupTree_recurse( vecNodeTable, pNewNodeChld, vecTris, uiLimitTries, iDepthNodeChld ); } } } }