return all keys (slow)

release/4.3a0
Frank Dellaert 2012-09-16 04:36:35 +00:00
parent e26ab012de
commit 896d006ddf
2 changed files with 25 additions and 9 deletions

View File

@ -77,14 +77,26 @@ namespace gtsam {
return true;
}
/* ************************************************************************* */
template<class FACTOR>
size_t FactorGraph<FACTOR>::nrFactors() const {
size_t size_ = 0;
for (const_iterator factor = factors_.begin(); factor != factors_.end(); factor++)
if (*factor != NULL) size_++;
return size_;
}
/* ************************************************************************* */
template<class FACTOR>
size_t FactorGraph<FACTOR>::nrFactors() const {
size_t size_ = 0;
BOOST_FOREACH(const sharedFactor& factor, factors_)
if (factor) size_++;
return size_;
}
/* ************************************************************************* */
template<class FACTOR>
std::set<typename FACTOR::KeyType> FactorGraph<FACTOR>::keys() const {
std::set<KeyType> allKeys;
BOOST_FOREACH(const sharedFactor& factor, factors_)
if (factor) {
BOOST_FOREACH(Index j, factor->keys())
allKeys.insert(j);
}
return allKeys;
}
/* ************************************************************************* */
template<class FACTOR>

View File

@ -27,6 +27,7 @@
#include <boost/serialization/nvp.hpp>
#include <boost/function.hpp>
#include <set>
namespace gtsam {
@ -44,7 +45,7 @@ template<class CONDITIONAL, class CLIQUE> class BayesTree;
public:
typedef FACTOR FactorType; ///< factor type
typedef typename FACTOR::KeyType KeyType; ///< type of Keys we use to index factors with
typedef typename FACTOR::KeyType KeyType; ///< type of Keys we use to index variables with
typedef boost::shared_ptr<FACTOR> sharedFactor; ///< Shared pointer to a factor
typedef boost::shared_ptr<typename FACTOR::ConditionalType> sharedConditional; ///< Shared pointer to a conditional
@ -208,6 +209,9 @@ template<class CONDITIONAL, class CLIQUE> class BayesTree;
/** return the number valid factors */
size_t nrFactors() const;
/** Potentially very slow function to return all keys involved */
std::set<KeyType> keys() const;
private:
/** Serialization function */