diff --git a/gtsam/inference/EliminationTreeUnordered-inst.h b/gtsam/inference/EliminationTreeUnordered-inst.h index b9873c058..ec3d600cc 100644 --- a/gtsam/inference/EliminationTreeUnordered-inst.h +++ b/gtsam/inference/EliminationTreeUnordered-inst.h @@ -156,27 +156,8 @@ namespace gtsam { EliminationTreeUnordered& EliminationTreeUnordered::operator=(const EliminationTreeUnordered& other) { - // Start by duplicating the roots. - roots_.clear(); - std::stack > stack; - BOOST_FOREACH(const sharedNode& root, other.roots_) { - roots_.push_back(boost::make_shared(*root)); - stack.push(roots_.back()); - } - - // Traverse the tree, duplicating each node's children and fixing the pointers as we go. We do - // not clone any factors, only copy their pointers (this is a standard in GTSAM). - while(!stack.empty()) { - sharedNode node = stack.top(); - stack.pop(); - BOOST_FOREACH(sharedNode& child, node->children) { - // Important: since we are working with a *reference* to a shared pointer in this - // BOOST_FOREACH loop, the next statement modifies the pointer in the current node's child - // list - it replaces it with a pointer to a copy of the child. - child = boost::make_shared(*child); - stack.push(child); - } - } + // Start by duplicating the tree. + roots_ = treeTraversal::CloneForest(other); // Assign the remaining factors - these are pointers to factors in the original factor graph and // we do not clone them. diff --git a/gtsam/inference/JunctionTreeUnordered-inst.h b/gtsam/inference/JunctionTreeUnordered-inst.h index f575b6611..400b05ea4 100644 --- a/gtsam/inference/JunctionTreeUnordered-inst.h +++ b/gtsam/inference/JunctionTreeUnordered-inst.h @@ -156,18 +156,18 @@ namespace gtsam { remainingFactors_ = eliminationTree.remainingFactors(); } - /* ************************************************************************* */ - template - JunctionTreeUnordered::JunctionTreeUnordered(const This& other) - { - - } - /* ************************************************************************* */ template JunctionTreeUnordered& JunctionTreeUnordered::operator=(const This& other) { + // Start by duplicating the tree. + roots_ = treeTraversal::CloneForest(other); + // Assign the remaining factors - these are pointers to factors in the original factor graph and + // we do not clone them. + remainingFactors_ = other.remainingFactors_; + + return *this; } /* ************************************************************************* */