16#include <boost/shared_ptr.hpp>
18#include "PartitionWorkSpace.h"
20namespace gtsam {
namespace partition {
25 enum GenericNode2DType { NODE_POSE_2D, NODE_LANDMARK_2D };
28 struct GenericNode2D {
30 GenericNode2DType type;
31 GenericNode2D (
const std::size_t& index_in,
const GenericNode2DType& type_in) : index(index_in), type(type_in) {}
35 struct GenericFactor2D {
40 GenericFactor2D(
const size_t index1,
const GenericNode2DType type1,
const size_t index2,
const GenericNode2DType type2,
const int index_ = -1,
const int weight_ = 1)
41 : key1(index1, type1), key2(index2, type2), index(index_), weight(weight_) {}
42 GenericFactor2D(
const size_t index1,
const char type1,
const size_t index2,
const char type2,
const int index_ = -1,
const int weight_ = 1)
43 : key1(index1, type1 ==
'x' ? NODE_POSE_2D : NODE_LANDMARK_2D),
44 key2(index2, type2 ==
'x' ? NODE_POSE_2D : NODE_LANDMARK_2D), index(index_), weight(weight_) {}
48 typedef boost::shared_ptr<GenericFactor2D> sharedGenericFactor2D;
49 typedef std::vector<sharedGenericFactor2D> GenericGraph2D;
52 std::list<std::vector<size_t> > findIslands(
const GenericGraph2D& graph,
const std::vector<size_t>& keys,
WorkSpace& workspace,
53 const int minNrConstraintsPerCamera,
const int minNrConstraintsPerLandmark);
56 inline void reduceGenericGraph(
const GenericGraph2D& graph,
const std::vector<size_t>& cameraKeys,
const std::vector<size_t>& landmarkKeys,
57 const std::vector<int>& dictionary, GenericGraph2D& reducedGraph) {
58 throw std::runtime_error(
"reduceGenericGraph 2d not implemented");
62 inline void checkSingularity(
const GenericGraph2D& graph,
const std::vector<size_t>& frontals,
63 WorkSpace& workspace,
const int minNrConstraintsPerCamera,
const int minNrConstraintsPerLandmark) {
return; }
66 void print(
const GenericGraph2D& graph,
const std::string name =
"GenericGraph2D");
71 enum GenericNode3DType { NODE_POSE_3D, NODE_LANDMARK_3D };
77 struct GenericNode3D {
79 GenericNode3DType type;
80 GenericNode3D (
const std::size_t& index_in,
const GenericNode3DType& type_in) : index(index_in), type(type_in) {}
84 struct GenericFactor3D {
89 GenericFactor3D() :key1(-1, NODE_POSE_3D), key2(-1, NODE_LANDMARK_3D), index(-1), weight(1) {}
90 GenericFactor3D(
const size_t index1,
const size_t index2,
const int index_ = -1,
91 const GenericNode3DType type1 = NODE_POSE_3D,
const GenericNode3DType type2 = NODE_LANDMARK_3D,
const int weight_ = 1)
92 : key1(index1, type1), key2(index2, type2), index(index_), weight(weight_) {}
96 typedef boost::shared_ptr<GenericFactor3D> sharedGenericFactor3D;
97 typedef std::vector<sharedGenericFactor3D> GenericGraph3D;
100 std::list<std::vector<size_t> > findIslands(
const GenericGraph3D& graph,
const std::vector<size_t>& keys,
WorkSpace& workspace,
101 const size_t minNrConstraintsPerCamera,
const size_t minNrConstraintsPerLandmark);
104 void reduceGenericGraph(
const GenericGraph3D& graph,
const std::vector<size_t>& cameraKeys,
const std::vector<size_t>& landmarkKeys,
105 const std::vector<int>& dictionary, GenericGraph3D& reducedGraph);
108 void checkSingularity(
const GenericGraph3D& graph,
const std::vector<size_t>& frontals,
109 WorkSpace& workspace,
const size_t minNrConstraintsPerCamera,
const size_t minNrConstraintsPerLandmark);
113 void print(
const GenericGraph3D& graph,
const std::string name =
"GenericGraph3D");
119 struct GenericUnaryFactor {
122 GenericUnaryFactor(
const size_t key_,
const GenericNode2DType type_,
const int index_ = -1)
123 : key(key_, type_), index(index_) {}
124 GenericUnaryFactor(
const size_t key_,
const char type_,
const int index_ = -1)
125 : key(key_, type_ ==
'x' ? NODE_POSE_2D : NODE_LANDMARK_2D), index(index_) {}
129 typedef boost::shared_ptr<GenericUnaryFactor> sharedGenericUnaryFactor;
130 typedef std::vector<sharedGenericUnaryFactor> GenericUnaryGraph;
135 inline bool hasCommonCamera(
const std::set<size_t>& cameras1,
const std::set<size_t>& cameras2) {
136 if (cameras1.empty() || cameras2.empty())
137 throw std::invalid_argument(
"hasCommonCamera: the input camera set is empty!");
138 std::set<size_t>::const_iterator it1 = cameras1.begin();
139 std::set<size_t>::const_iterator it2 = cameras2.begin();
140 while (it1 != cameras1.end() && it2 != cameras2.end()) {
143 else if (*it1 < *it2)
Global functions in a separate testing namespace.
Definition chartTesting.h:28
the index of the node and the type of the node
Definition GenericGraph.h:28
the index of the node and the type of the node
Definition GenericGraph.h:77
Definition PartitionWorkSpace.h:19