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

correct tree removing

parent aa13d163
No related branches found
No related tags found
1 merge request!309Master
......@@ -64,6 +64,7 @@ void TreeNode::saveToFile(FILE* f) const
fprintf(f," %f",direction[i]);
}
fprintf(f," %s\n",af->getName().c_str());
fflush(f);
};
void TreeNode::getNormal(std::vector<SVector3>& allVec, bool stiff, std::vector<std::vector<SVector3> >* allDnormalDunknown) const
......@@ -917,7 +918,13 @@ void Tree::loadDataFromFile(std::string filename)
node->depth = depth;
node->location = location;
node->childOrder = childOrder;
node->parent = nodeMap[std::pair<int,int>(depth-1,parentIdLoc)];
std::pair<int,int> twoNum(depth-1,parentIdLoc);
if (nodeMap.find(twoNum) == nodeMap.end())
{
Msg::Error("node %d %d is not found !!!",depth-1,parentIdLoc);
Msg::Exit(0);
}
node->parent = nodeMap[twoNum];
node->parent->childs[childOrder] = node;
node->matIndex = matIndex;
if (numChild > 0)
......@@ -1195,10 +1202,8 @@ bool Tree::treeMerging()
for (std::map<int, std::vector<std::pair<TreeNode*, int> > >::iterator it = mapIndexes.begin(); it != mapIndexes.end(); it++)
{
int mIndex = it->first;
if (mIndex >=0)
{
std::vector<std::pair<TreeNode*, int> >& sameMat = it->second;
if (sameMat.size()> 1)
if ((mIndex >=0) && (sameMat.size()> 1))
{
std::vector<TreeNode*> nodes;
std::set<int> position;
......@@ -1263,8 +1268,6 @@ bool Tree::treeMerging()
//
break;
}
}
}
};
}
......@@ -1359,6 +1362,14 @@ bool Tree::removeZeroBranches(double tol)
child->parent = node->parent;
child->childOrder = node->childOrder;
grandParent->childs[node->childOrder] = child;
// decrease all associated nodes by 1
std::vector<TreeNode*> allAssociatedNodesToChild;
getRefToAssociatedNodes(child,allAssociatedNodesToChild);
for (int j=0; j< allAssociatedNodesToChild.size(); j++)
{
allAssociatedNodesToChild[j]->depth--;
};
Msg::Info("------------------");
Msg::Info("node is replaced by child");
}
......@@ -1463,7 +1474,7 @@ void Tree::printTree() const
{
printf("Tree print \n");
if (_root == NULL) return;
std::vector< TreeNode*> listPrev, listCur;
std::vector< TreeNode*> listPrev(0), listCur(0);
listPrev.push_back(_root);
int depth = 0;
while (true)
......@@ -1994,6 +2005,35 @@ void Tree::getAllNodes(nodeContainer& allNodes) const
};
};
void Tree::getRefToAssociatedNodes(TreeNode* node, std::vector<TreeNode*>& allNodes)
{
allNodes.clear();
std::vector<TreeNode*> listPrev, listCur;
listPrev.push_back(node);
//
while (true)
{
listCur.clear();
for (int i =0; i< listPrev.size(); i++)
{
TreeNode* np = listPrev[i];
for (int j=0; j< np->childs.size(); j++)
{
listCur.push_back(np->childs[j]);
}
}
listPrev = listCur;
if (listCur.size() == 0)
{
break;
}
else
{
allNodes.insert(allNodes.end(),listCur.begin(),listCur.end());
}
};
}
void Tree::getRefToAllNodes(std::vector<TreeNode*>& allNodes)
{
allNodes.clear();
......
......@@ -93,6 +93,7 @@ class Tree
double getNonNegativeWeight(const TreeNode* node) const;
void getRefToAllLeaves(std::vector<TreeNode*>& allLeaves);
void getRefToAllNodes(std::vector<TreeNode*>& allNodes);
void getRefToAssociatedNodes(TreeNode* node, std::vector<TreeNode*>& allNodes);
#endif //SWIG
protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment