Skip to content

Commit

Permalink
simplify tree "rebalancing"
Browse files Browse the repository at this point in the history
We now unconditionally ensure that the graph is a tree (as it should),
by always removing the parent from the target node, and reconnecting
said node to the new transformation.

The very complex implementation currently there did not seem to be needed.
  • Loading branch information
doudou committed Jun 25, 2019
1 parent 405114b commit a4646ee
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions src/TransformerGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,36 +549,14 @@ bool TransformerGraph::setTransformation(osg::Node &transformer,const std::strin
}
else if (target->getParent(0) != source)
{
if (target == &transformer || (source->getParent(0) == &transformer && target->getParent(0) != &transformer))
if (target == &transformer)
{
invertOSGTransform(trans, quat, source, target, source_frame, target_frame);
}

if (target->getParent(0) != &transformer)
{
std::set<osg::Node*> ancestors;
osg::ref_ptr<osg::Node> sourceAncestor = source;
while (sourceAncestor != &transformer)
{
ancestors.insert(sourceAncestor);
if (sourceAncestor->getParent(0) == target)
{
target->removeChild(sourceAncestor);
getTransform(&transformer)->addChild(sourceAncestor);
ancestors.clear();
break;
}
else
sourceAncestor = sourceAncestor->getParent(0);
}

::makeRoot(transformer, getTransform(target), ancestors);

}

osg::ref_ptr<osg::Node> node = target; //insures that node is not deleted
removeFrame(transformer,target_frame);
source->addChild(node);
osg::ref_ptr<osg::Node> node = target; //insures that node is not deleted
target->getParent(0)->removeChild(target);
source->addChild(target);
}

target->setAttitude(quat);
Expand Down

0 comments on commit a4646ee

Please sign in to comment.