31 #include <boost/assign/list_inserter.hpp> 32 #include <boost/bind.hpp> 33 #include <boost/make_shared.hpp> 34 #include <boost/serialization/nvp.hpp> 35 #include <boost/serialization/vector.hpp> 38 #include <type_traits> 46 template <
class CLIQUE>
93 template <
class FACTOR>
97 typedef boost::shared_ptr<FACTOR>
105 typedef boost::shared_ptr<This>
109 template <
typename DERIVEDFACTOR>
110 using IsDerived =
typename std::enable_if<
114 template <
typename T>
119 template <
typename T>
137 template <
typename ITERATOR>
139 push_back(firstFactor, lastFactor);
143 template <
class CONTAINER>
165 template <
class DERIVEDFACTOR>
167 factors_.push_back(boost::shared_ptr<FACTOR>(factor));
171 template <
class DERIVEDFACTOR,
class... Args>
173 factors_.push_back(boost::allocate_shared<DERIVEDFACTOR>(
175 std::forward<Args>(
args)...));
182 template <
class DERIVEDFACTOR>
184 factors_.push_back(boost::allocate_shared<DERIVEDFACTOR>(
189 template <
class DERIVEDFACTOR>
195 template <
class DERIVEDFACTOR>
196 typename std::enable_if<
198 boost::assign::list_inserter<RefCallPushBack<This>>>::type
212 template <
typename ITERATOR>
214 ITERATOR lastFactor) {
215 factors_.insert(
end(), firstFactor, lastFactor);
219 template <
typename ITERATOR>
221 ITERATOR lastFactor) {
222 for (ITERATOR
f = firstFactor;
f != lastFactor; ++
f) push_back(*
f);
233 template <
typename CONTAINER>
235 push_back(container.begin(), container.end());
239 template <
typename CONTAINER>
241 push_back(container.begin(), container.end());
248 template <
class FACTOR_OR_CONTAINER>
249 void add(
const FACTOR_OR_CONTAINER& factorOrContainer) {
250 push_back(factorOrContainer);
257 template <
class FACTOR_OR_CONTAINER>
258 boost::assign::list_inserter<CRefCallPushBack<This>>
operator+=(
259 const FACTOR_OR_CONTAINER& factorOrContainer) {
273 template <
class CLIQUE>
274 typename std::enable_if<
284 template <
typename CONTAINER,
typename = HasDerivedElementType<CONTAINER>>
285 FactorIndices add_factors(
const CONTAINER&
factors,
286 bool useEmptySlots =
false);
293 virtual void print(
const std::string&
s =
"FactorGraph",
297 bool equals(
const This& fg,
double tol = 1
e-9)
const;
306 size_t size()
const {
return factors_.size(); }
310 bool empty()
const {
return factors_.empty(); }
333 const_iterator
begin()
const {
return factors_.begin(); }
336 const_iterator
end()
const {
return factors_.end(); }
349 iterator
begin() {
return factors_.begin(); }
352 iterator
end() {
return factors_.end(); }
362 void remove(
size_t i) { factors_.at(
i).reset(); }
368 iterator
erase(iterator item) {
return factors_.erase(item); }
372 return factors_.erase(first, last);
380 size_t nrFactors()
const;
393 inline bool exists(
size_t idx)
const {
return idx <
size() && at(idx); }
397 friend class boost::serialization::access;
398 template <
class ARCHIVE>
400 ar& BOOST_SERIALIZATION_NVP(factors_);
void print(const Matrix &A, const string &s, ostream &stream)
constexpr int last(int, int result)
void add(const FACTOR_OR_CONTAINER &factorOrContainer)
void replace(size_t index, sharedFactor factor)
Concept check for values that can be used in unit tests.
boost::assign::list_inserter< CRefCallPushBack< This > > operator+=(const FACTOR_OR_CONTAINER &factorOrContainer)
void operator()(const A &a)
boost::shared_ptr< This > shared_ptr
Shared pointer for this class.
HasDerivedElementType< ITERATOR > push_back(ITERATOR firstFactor, ITERATOR lastFactor)
FactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
HasDerivedValueType< ITERATOR > push_back(ITERATOR firstFactor, ITERATOR lastFactor)
Push back many factors with an iterator (factors are copied)
FastVector< FactorIndex > FactorIndices
Define collection types:
HasDerivedValueType< CONTAINER > push_back(const CONTAINER &container)
Push back non-pointer objects in a container (factors are copied).
IsDerived< DERIVEDFACTOR > push_back(const DERIVEDFACTOR &factor)
const sharedFactor operator[](size_t i) const
void addFactorsToGraph(FactorGraph< FactorType > *graph) const
sharedFactor back() const
GaussianFactorGraph factors(list_of(factor1)(factor2)(factor3))
typename std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value >::type IsDerived
Check if a DERIVEDFACTOR is in fact derived from FactorType.
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
FastVector< sharedFactor >::iterator iterator
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
IsDerived< DERIVEDFACTOR > add(boost::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
const_iterator begin() const
FACTOR FactorType
factor type
static const KeyFormatter DefaultKeyFormatter
const KeyFormatter & formatter
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
constexpr int first(int i)
Implementation details for constexpr functions.
STL compatible allocator to use with types requiring a non standrad alignment.
sharedFactor & at(size_t i)
FactorGraph(const CONTAINER &factors)
boost::shared_ptr< FACTOR > sharedFactor
Shared pointer to a factor.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const_iterator end() const
void operator()(const A &a)
sharedFactor & operator[](size_t i)
Matrix< Scalar, Dynamic, Dynamic > C
A thin wrapper around std::vector that uses a custom allocator.
const sharedFactor at(size_t i) const
typename std::enable_if< std::is_base_of< FactorType, typename T::value_type >::value >::type HasDerivedValueType
Check if T has a value_type derived from FactorType.
FastVector< sharedFactor >::const_iterator const_iterator
iterator erase(iterator first, iterator last)
HasDerivedElementType< CONTAINER > push_back(const CONTAINER &container)
std::enable_if< std::is_base_of< This, typename CLIQUE::FactorGraphType >::value >::type push_back(const BayesTree< CLIQUE > &bayesTree)
FactorGraph< FACTOR > This
Typedef for this class.
sharedFactor front() const
void serialize(ARCHIVE &ar, const unsigned int)
std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value, boost::assign::list_inserter< RefCallPushBack< This > > >::type operator+=(boost::shared_ptr< DERIVEDFACTOR > factor)
+= works well with boost::assign list inserter.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
void reserve(size_t size)
typename std::enable_if< std::is_base_of< FactorType, typename T::value_type::element_type >::value >::type HasDerivedElementType
Check if T has a value_type derived from FactorType.
bool exists(size_t idx) const
iterator erase(iterator item)