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