[英]Depth First Search - Scene Graph - Whats my current depth?
-- Hi All, I am trying to implement a "Depth First Search" for a Scene Graph. - 大家好,我正在尝试为场景图实现“深度优先搜索”。 This is what I have so far - but I am stuck figuring how to keep track of how deep the current element is inside the graph.
这就是我到目前为止所做的 - 但我很难想象如何跟踪当前元素在图形中的深度。 Lets say I could count the order.size() as depth for the first branch - but how do I pop of elements when the code jumps up again and into the next branch?
假设我可以将order.size()计为第一个分支的深度 - 但是当代码再次跳转到下一个分支时,如何弹出元素? Any hint would be greatly appreciated.
任何暗示都将非常感激。 Thanks a lot in advance.
非常感谢提前。
//======================================================================
//depth first search
//======================================================================
// clean start - init visited flags in joints
for (int i = 0 ; i < m_joints.size(); i++){m_joints[i]->visited = false;}
// joint indices
vector<int> stack;
vector<int> order;
for(int i = 0; i < m_joints.size(); i++)
{
if(!m_joints[i]->visited)
{
stack.push_back(i);
while(!stack.empty())
{
int top = stack.back();
stack.pop_back();
if(m_joints[top]->visited)
{
continue;
}
m_joints[top]->visited = true;
order.push_back(top);
// need to know how deep I am inside of the scene graph here
// update transformation matrix here
// draw joint here
for(int j = 0 ; j < m_joints[top]->children.size();j++)//all neighbours of top
{
if(!m_joints[top]->children[j]->visited)
{
stack.push_back(m_joints[top]->children[j]->listPosition);
}
}
}
}
}
If I understood well your problem, you can just add an integer variable "depth" to each element and update it every time element's depth is changing. 如果我理解你的问题,你可以在每个元素中添加一个整数变量“depth”,并在每次元素的深度变化时更新它。 In addition, you can always ask your element at which depth it is currently
此外,您始终可以询问您的元素当前的深度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.