diff --git a/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.cpp b/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.cpp index fbf7ac3e4..7a3cfe888 100644 --- a/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.cpp +++ b/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.cpp @@ -42,7 +42,8 @@ bool ConcurrentIncrementalFilter::equals(const ConcurrentFilter& rhs, double tol } /* ************************************************************************* */ -ConcurrentIncrementalFilter::Result ConcurrentIncrementalFilter::update(const NonlinearFactorGraph& newFactors, const Values& newTheta, const boost::optional >& keysToMove) { +ConcurrentIncrementalFilter::Result ConcurrentIncrementalFilter::update(const NonlinearFactorGraph& newFactors, const Values& newTheta, + const boost::optional >& keysToMove, const boost::optional< std::vector >& removeFactorIndices) { gttic(update); @@ -54,8 +55,11 @@ ConcurrentIncrementalFilter::Result ConcurrentIncrementalFilter::update(const No // Create the return result meta-data Result result; - // We do not need to remove any factors at this time + // Remove any user-provided factors from iSAM2 gtsam::FastVector removedFactors; + if(removeFactorIndices){ + removedFactors.insert(removedFactors.end(), removeFactorIndices->begin(), removeFactorIndices->end()); + } // Generate ordering constraints that force the 'keys to move' to the end boost::optional > orderingConstraints = boost::none; @@ -147,7 +151,8 @@ ConcurrentIncrementalFilter::Result ConcurrentIncrementalFilter::update(const No result.iterations = 1; result.linearVariables = isam2_.getFixedVariables().size(); result.nonlinearVariables = isam2_.getLinearizationPoint().size() - result.linearVariables; - result.error = isam2_.getFactorsUnsafe().error(isam2_.calculateEstimate()); + result.newFactorsIndices = isam2Result.newFactorsIndices; +// result.error = isam2_.getFactorsUnsafe().error(isam2_.calculateEstimate()); if(debug) std::cout << "ConcurrentIncrementalFilter::update End" << std::endl; diff --git a/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.h b/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.h index bef94ef32..6e5216642 100644 --- a/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.h +++ b/gtsam_unstable/nonlinear/ConcurrentIncrementalFilter.h @@ -38,6 +38,7 @@ public: size_t iterations; ///< The number of optimizer iterations performed size_t nonlinearVariables; ///< The number of variables that can be relinearized size_t linearVariables; ///< The number of variables that must keep a constant linearization point + std::vector newFactorsIndices; ///< The indices of the newly-added factors, in 1-to-1 correspondence with the factors passed in double error; ///< The final factor graph error /// Constructor @@ -110,9 +111,11 @@ public: * You must include here all new variables occurring in newFactors that were not already * in the filter. * @param keysToMove An optional set of keys to move from the filter to the smoother + * @param removeFactorIndices An optional set of indices corresponding to the factors you want to remove from the graph */ Result update(const NonlinearFactorGraph& newFactors = NonlinearFactorGraph(), const Values& newTheta = Values(), - const boost::optional >& keysToMove = boost::none); + const boost::optional >& keysToMove = boost::none, + const boost::optional< std::vector >& removeFactorIndices = boost::none); /** * Perform any required operations before the synchronization process starts.