Skip to content
Snippets Groups Projects
Commit 2fd0c26a authored by Van Dung NGUYEN's avatar Van Dung NGUYEN
Browse files

fix bug when removing ndoes

parent cd5e6bde
No related branches found
No related tags found
1 merge request!309Master
......@@ -1188,6 +1188,18 @@ bool Tree::treeMerging()
node->parent = parent->parent;
node->childOrder = parent->childOrder;
grandParent->childs[parent->childOrder] = node;
//
// decrease all associated nodes by 1
std::vector<TreeNode*> allAssociatedNodesToChild;
getRefToAssociatedNodes(node,allAssociatedNodesToChild);
for (int j=0; j< allAssociatedNodesToChild.size(); j++)
{
std::vector<int> loc;
getMaxLocationByDepth(loc);
allAssociatedNodesToChild[j]->depth--;
allAssociatedNodesToChild[j]->location=loc[allAssociatedNodesToChild[j]->depth]+1;
};
};
for (std::set<TreeNode*>::iterator itp = allParents.begin(); itp != allParents.end(); itp++)
......@@ -1367,7 +1379,10 @@ bool Tree::removeZeroBranches(double tol)
getRefToAssociatedNodes(child,allAssociatedNodesToChild);
for (int j=0; j< allAssociatedNodesToChild.size(); j++)
{
std::vector<int> loc;
getMaxLocationByDepth(loc);
allAssociatedNodesToChild[j]->depth--;
allAssociatedNodesToChild[j]->location=loc[allAssociatedNodesToChild[j]->depth]+1;
};
Msg::Info("------------------");
......@@ -1729,6 +1744,25 @@ void Tree::getAllNodesByDepth(std::map<int,std::vector<TreeNode*> >& allNodes)
};
};
void Tree::getMaxLocationByDepth(std::vector<int>& loc) const
{
std::map<int,nodeContainer > allNodes;
getAllNodesByDepth(allNodes);
loc.resize(allNodes.size(),0);
for (std::map<int,nodeContainer >::const_iterator it = allNodes.begin(); it != allNodes.end(); it++)
{
const nodeContainer& depthNode = it->second;
for (int j=0; j< depthNode.size(); j++)
{
const TreeNode* node = depthNode[j];
if (node->location >loc[it->first])
{
loc[it->first]= node->location;
}
}
}
};
void Tree::getAllNodesByDepth(std::map<int,nodeContainer >& allNodes) const
{
allNodes.clear();
......
......@@ -86,6 +86,7 @@ class Tree
void getAllLeaves(nodeContainer& allLeaves) const;
void getAllNodes(nodeContainer& allNodes) const;
void getAllNodesByDepth(std::map<int,nodeContainer>& allNodes) const;
void getMaxLocationByDepth(std::vector<int>& loc) const;
void getAllNodesByDepth(std::map<int,std::vector<TreeNode*> >& allNodes);
void getAssociatedLeavesForNode(const TreeNode* node, nodeContainer& allLeaves) const;
void getAssociatedLeavesForNode(TreeNode* node, std::vector<TreeNode*>& allLeaves);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment