Loading...
Searching...
No Matches
Factor.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
// \callgraph
#pragma once
#include <boost/serialization/nvp.hpp>
#include <boost/shared_ptr.hpp>
#include <gtsam/base/types.h>
#include <gtsam/base/FastVector.h>
#include <gtsam/inference/Key.h>
namespace gtsam {
typedef FastVector<FactorIndex> FactorIndices;
typedef FastSet<FactorIndex> FactorIndexSet;
class HybridValues; // forward declaration of a Value type for error.
class GTSAM_EXPORT Factor
{
private:
// These typedefs are private because they must be overridden in derived classes.
typedef Factor This;
typedef boost::shared_ptr<Factor> shared_ptr;
public:
typedef KeyVector::iterator iterator;
typedef KeyVector::const_iterator const_iterator;
protected:
KeyVector keys_;
Factor() {}
template<typename CONTAINER>
explicit Factor(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
template<typename ITERATOR>
Factor(ITERATOR first, ITERATOR last) : keys_(first, last) {}
template<typename CONTAINER>
static Factor FromKeys(const CONTAINER& keys) {
return Factor(keys.begin(), keys.end()); }
template<typename ITERATOR>
static Factor FromIterators(ITERATOR first, ITERATOR last) {
return Factor(first, last); }
public:
// public since it is required for boost serialization and static methods.
// virtual since it is public.
// http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
virtual ~Factor() = default;
bool empty() const { return keys_.empty(); }
Key front() const { return keys_.front(); }
Key back() const { return keys_.back(); }
const_iterator find(Key key) const { return std::find(begin(), end(), key); }
const KeyVector& keys() const { return keys_; }
const_iterator begin() const { return keys_.begin(); }
const_iterator end() const { return keys_.end(); }
virtual double error(const HybridValues& c) const;
size_t size() const { return keys_.size(); }
virtual void print(
const std::string& s = "Factor",
const KeyFormatter& formatter = DefaultKeyFormatter) const;
virtual void printKeys(
const std::string& s = "Factor",
const KeyFormatter& formatter = DefaultKeyFormatter) const;
bool equals(const This& other, double tol = 1e-9) const;
KeyVector& keys() { return keys_; }
iterator begin() { return keys_.begin(); }
iterator end() { return keys_.end(); }
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_NVP(keys_);
}
};
} // \namespace gtsam
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
types.h
Typedefs for easier changing of types.
Key.h
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
gtsam::FactorIndices
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition Factor.h:34
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::FastSet
FastSet is a thin wrapper around std::set that uses the boost fast_pool_allocator instead of the defa...
Definition FastSet.h:50
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::HybridValues
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:140
gtsam::Factor::keys_
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:85
gtsam::Factor::find
const_iterator find(Key key) const
find
Definition Factor.h:137
gtsam::Factor::begin
const_iterator begin() const
Iterator at beginning of involved variable keys.
Definition Factor.h:143
gtsam::Factor::Factor
Factor()
Default constructor for I/O.
Definition Factor.h:91
gtsam::Factor::end
iterator end()
Iterator at end of involved variable keys.
Definition Factor.h:188
gtsam::Factor::empty
bool empty() const
Whether the factor is empty (involves zero variables).
Definition Factor.h:128
gtsam::Factor::keys
KeyVector & keys()
Definition Factor.h:182
gtsam::Factor::FromIterators
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition Factor.h:112
gtsam::Factor::FromKeys
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition Factor.h:106
gtsam::Factor::begin
iterator begin()
Iterator at beginning of involved variable keys.
Definition Factor.h:185
gtsam::Factor::~Factor
virtual ~Factor()=default
Default destructor.
gtsam::Factor::Factor
Factor(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition Factor.h:101
gtsam::Factor::const_iterator
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition Factor.h:80
gtsam::Factor::end
const_iterator end() const
Iterator at end of involved variable keys.
Definition Factor.h:146
gtsam::Factor::Factor
Factor(const CONTAINER &keys)
Construct factor from container of keys.
Definition Factor.h:96
gtsam::Factor::iterator
KeyVector::iterator iterator
Iterator over keys.
Definition Factor.h:77
gtsam::Factor::back
Key back() const
Last key.
Definition Factor.h:134
gtsam::Factor::front
Key front() const
First key.
Definition Factor.h:131
gtsam::Factor::size
size_t size() const
Definition Factor.h:157