diff --git a/cpp/ISAM2-inl.h b/cpp/ISAM2-inl.h index c2c8a8020..5ad3d3127 100644 --- a/cpp/ISAM2-inl.h +++ b/cpp/ISAM2-inl.h @@ -74,8 +74,7 @@ namespace gtsam { /* ************************************************************************* */ template - FactorGraph > - ISAM2::getAffectedFactors(const list& keys) const { + list ISAM2::getAffectedFactors(const list& keys) const { FactorGraph > allAffected; list indices; BOOST_FOREACH(const Symbol& key, keys) { @@ -84,10 +83,7 @@ namespace gtsam { } indices.sort(); indices.unique(); - BOOST_FOREACH(int i, indices) { - allAffected.push_back(nonlinearFactors_[i]); - } - return allAffected; + return indices; } /* ************************************************************************* */ @@ -98,21 +94,20 @@ namespace gtsam { list affectedKeysList; // todo: shouldn't have to convert back to list... affectedKeysList.insert(affectedKeysList.begin(), affectedKeys.begin(), affectedKeys.end()); - FactorGraph > candidates = getAffectedFactors(affectedKeysList); + list candidates = getAffectedFactors(affectedKeysList); NonlinearFactorGraph nonlinearAffectedFactors; - typename FactorGraph >::const_iterator it; - for(it = candidates.begin(); it != candidates.end(); it++) { + BOOST_FOREACH(int idx, candidates) { bool inside = true; - BOOST_FOREACH(const Symbol& key, (*it)->keys()) { + BOOST_FOREACH(const Symbol& key, nonlinearFactors_[idx]->keys()) { if (affectedKeys.find(key) == affectedKeys.end()) { inside = false; break; } } if (inside) - nonlinearAffectedFactors.push_back(*it); + nonlinearAffectedFactors.push_back(nonlinearFactors_[idx]); } return nonlinearAffectedFactors.linearize(theta_); @@ -161,8 +156,14 @@ namespace gtsam { // basically calculate all the keys contained in the factors that contain any of the keys... // the goal is to relinearize all variables directly affected by new factors - FactorGraph > allAffected = getAffectedFactors(marked_); - marked_ = allAffected.keys(); + list allAffected = getAffectedFactors(marked_); + set accumulate; + BOOST_FOREACH(int idx, allAffected) { + list tmp = nonlinearFactors_[idx]->keys(); + accumulate.insert(tmp.begin(), tmp.end()); + } + marked_.clear(); + marked_.insert(marked_.begin(), accumulate.begin(), accumulate.end()); // merge keys of new factors with mask const list newKeys = newFactors.keys(); diff --git a/cpp/ISAM2.h b/cpp/ISAM2.h index 702ccf885..ba0a94c93 100644 --- a/cpp/ISAM2.h +++ b/cpp/ISAM2.h @@ -85,7 +85,7 @@ namespace gtsam { private: - FactorGraph > getAffectedFactors(const std::list& keys) const; + std::list getAffectedFactors(const std::list& keys) const; FactorGraph relinearizeAffectedFactors(const std::set& affectedKeys) const; FactorGraph getCachedBoundaryFactors(Cliques& orphans);