Skip to content

Commit dc9f56c

Browse files
committed
simplify tree "rebalancing"
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.
1 parent 405114b commit dc9f56c

File tree

2 files changed

+4
-68
lines changed

2 files changed

+4
-68
lines changed

src/TransformerGraph.cpp

+4-63
Original file line numberDiff line numberDiff line change
@@ -485,43 +485,6 @@ static void invertOSGTransform(osg::Vec3d& trans, osg::Quat& quat,
485485
std::swap(source_frame, target_frame);
486486
}
487487

488-
static void makeRoot(osg::Node& _transformer,
489-
osg::ref_ptr<osg::PositionAttitudeTransform> desiredRoot,
490-
std::set<osg::Node*> ancestors)
491-
{
492-
PositionAttitudeTransform* transformer = getTransform(&_transformer);
493-
494-
osg::Vec3d trans = osg::Vec3d(0, 0, 0);
495-
osg::Quat rot = osg::Quat(0, 0, 0, 1);
496-
497-
ref_ptr<PositionAttitudeTransform> currentNode(desiredRoot);
498-
ref_ptr<PositionAttitudeTransform> lastNode(transformer);
499-
while(currentNode != transformer && !ancestors.count(currentNode))
500-
{
501-
osg::Vec3d nextTrans = currentNode->getPosition();
502-
osg::Quat nextRot = currentNode->getAttitude();
503-
currentNode->setPosition(trans);
504-
currentNode->setAttitude(rot);
505-
rot = nextRot.inverse();
506-
trans = -(rot * nextTrans);
507-
508-
ref_ptr<PositionAttitudeTransform> parent(getTransform(currentNode->getParent(0)));
509-
parent->removeChild(currentNode);
510-
lastNode->addChild(currentNode);
511-
lastNode = currentNode;
512-
currentNode = parent;
513-
}
514-
}
515-
516-
void TransformerGraph::makeRoot(osg::Node& _transformer, std::string const& frame)
517-
{
518-
ref_ptr<PositionAttitudeTransform> desiredRoot(FindFrame::find(_transformer, frame));
519-
if (!desiredRoot)
520-
return;
521-
522-
return ::makeRoot(_transformer, desiredRoot, std::set<osg::Node*>());
523-
}
524-
525488
bool TransformerGraph::setTransformation(osg::Node &transformer,const std::string &_source_frame,const std::string &_target_frame,
526489
const osg::Quat &_quat, const osg::Vec3d &_trans)
527490
{
@@ -549,36 +512,14 @@ bool TransformerGraph::setTransformation(osg::Node &transformer,const std::strin
549512
}
550513
else if (target->getParent(0) != source)
551514
{
552-
if (target == &transformer || (source->getParent(0) == &transformer && target->getParent(0) != &transformer))
515+
if (target == &transformer)
553516
{
554517
invertOSGTransform(trans, quat, source, target, source_frame, target_frame);
555518
}
556519

557-
if (target->getParent(0) != &transformer)
558-
{
559-
std::set<osg::Node*> ancestors;
560-
osg::ref_ptr<osg::Node> sourceAncestor = source;
561-
while (sourceAncestor != &transformer)
562-
{
563-
ancestors.insert(sourceAncestor);
564-
if (sourceAncestor->getParent(0) == target)
565-
{
566-
target->removeChild(sourceAncestor);
567-
getTransform(&transformer)->addChild(sourceAncestor);
568-
ancestors.clear();
569-
break;
570-
}
571-
else
572-
sourceAncestor = sourceAncestor->getParent(0);
573-
}
574-
575-
::makeRoot(transformer, getTransform(target), ancestors);
576-
577-
}
578-
579-
osg::ref_ptr<osg::Node> node = target; //insures that node is not deleted
580-
removeFrame(transformer,target_frame);
581-
source->addChild(node);
520+
osg::ref_ptr<osg::Node> node = target; //insures that node is not deleted
521+
target->getParent(0)->removeChild(target);
522+
source->addChild(target);
582523
}
583524

584525
target->setAttitude(quat);

src/TransformerGraph.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ namespace vizkit3d
133133
static bool setTransformation(osg::Node &transformer,const std::string &source_frame,const std::string &target_frame,
134134
const osg::Quat &quat, const osg::Vec3d &trans);
135135

136-
/** Ensures that the transform node for the given frame is a direct
137-
* child of the transformer node
138-
*/
139-
static void makeRoot(osg::Node& transformer, std::string const& desiredRoot);
140-
141136
/**
142137
* Gets the transformation between two coordinate frames. Thereby unlike setTransformation the frames do not have to be subsequently.
143138
*

0 commit comments

Comments
 (0)