diff --git a/cpp/FactorGraph-inl.h b/cpp/FactorGraph-inl.h index 57af9427e..bfedfa33c 100644 --- a/cpp/FactorGraph-inl.h +++ b/cpp/FactorGraph-inl.h @@ -274,19 +274,16 @@ void FactorGraph::associateFactor(int index, sharedFactor factor) { template template map FactorGraph::findMinimumSpanningTree() const { - typedef typename boost::graph_traits >::vertex_descriptor BoostVertex; - typedef typename boost::graph_traits >::vertex_iterator BoostVertexIterator; - SDGraph g = gtsam::toBoostGraph, sharedFactor, Key>(*this); // find minimum spanning tree - vector p_map(boost::num_vertices(g)); + vector::Vertex> p_map(boost::num_vertices(g)); prim_minimum_spanning_tree(g, &p_map[0]); // convert edge to string pairs map tree; - BoostVertexIterator itVertex = boost::vertices(g).first; - typename vector::iterator vi; + typename SDGraph::vertex_iterator itVertex = boost::vertices(g).first; + typename vector::Vertex>::iterator vi; for (vi = p_map.begin(); vi!=p_map.end(); itVertex++, vi++) { string key = boost::get(boost::vertex_name, g, *itVertex); string parent = boost::get(boost::vertex_name, g, *vi); diff --git a/cpp/Ordering.cpp b/cpp/Ordering.cpp index 9a4c786c2..1b24b6566 100644 --- a/cpp/Ordering.cpp +++ b/cpp/Ordering.cpp @@ -38,7 +38,7 @@ Ordering::Ordering(const PredecessorMap& p_map) { SGraph g; SVertex root; map key2vertex; - //boost::tie(g, root, key2vertex) = predecessorMap2Graph(p_map); + boost::tie(g, root, key2vertex) = predecessorMap2Graph, SVertex, string>(p_map); // breadth first visit on the graph ordering_key_visitor vis(*this); diff --git a/cpp/graph-inl.h b/cpp/graph-inl.h index 5d067bb0c..ede7b16a9 100644 --- a/cpp/graph-inl.h +++ b/cpp/graph-inl.h @@ -61,12 +61,11 @@ SDGraph toBoostGraph(const G& graph) { } /* ************************************************************************* */ -template -boost::tuple, typename SDGraph::Vertex, std::map::Vertex> > +template +boost::tuple > predecessorMap2Graph(const PredecessorMap& p_map) { - typedef typename SDGraph::Vertex V; - SDGraph g; + G g; map key2vertex; V v1, v2, root; Key child, parent; @@ -94,7 +93,7 @@ predecessorMap2Graph(const PredecessorMap& p_map) { if (!foundRoot) throw invalid_argument("predecessorMap2Graph: invalid predecessor map!"); - return boost::tuple, V, std::map >(g, root, key2vertex); + return boost::tuple >(g, root, key2vertex); } /* ************************************************************************* */ @@ -133,8 +132,8 @@ boost::shared_ptr composePoses(const G& graph, const PredecessorMap key2vertex; -// boost::tie(g, root, key2vertex) = -// predecessorMap2Graph(tree); + boost::tie(g, root, key2vertex) = + predecessorMap2Graph(tree); // attach the relative poses to the edges PoseEdge edge1, edge2; diff --git a/cpp/graph.h b/cpp/graph.h index 77bdc324d..946a8372d 100644 --- a/cpp/graph.h +++ b/cpp/graph.h @@ -24,13 +24,15 @@ namespace gtsam { class SDGraph: public boost::adjacency_list, boost::property< boost::edge_weight_t, double> > { + public: + typedef typename boost::graph_traits >::vertex_descriptor Vertex; }; template class SGraph : public boost::adjacency_list > { + boost::property > { public: - typedef typename boost::graph_traits >::vertex_descriptor Vertex; + typedef typename boost::graph_traits >::vertex_descriptor Vertex; }; //typedef boost::graph_traits::vertex_descriptor SVertex; @@ -54,9 +56,8 @@ namespace gtsam { * G = Graph type * V = Vertex type */ - template - boost::tuple, typename SDGraph::Vertex, std::map::Vertex> > - predecessorMap2Graph(const PredecessorMap& p_map); + template + boost::tuple > predecessorMap2Graph(const PredecessorMap& p_map); /** * Compose the poses by following the chain specified by the spanning tree diff --git a/cpp/testGraph.cpp b/cpp/testGraph.cpp index 5a4e06ebb..c3a82fe9b 100644 --- a/cpp/testGraph.cpp +++ b/cpp/testGraph.cpp @@ -20,6 +20,24 @@ using namespace std; using namespace boost; using namespace gtsam; +/* ************************************************************************* */ +TEST( Graph, predecessorMap2Graph ) +{ + typedef SGraph::Vertex SVertex; + SGraph graph; + SVertex root; + map key2vertex; + + PredecessorMap p_map; + p_map.insert(make_pair("x1", "x2")); + p_map.insert(make_pair("x2", "x2")); + p_map.insert(make_pair("x3", "x2")); + tie(graph, root, key2vertex) = predecessorMap2Graph, SVertex, string>(p_map); + + LONGS_EQUAL(3, boost::num_vertices(graph)); + CHECK(root == key2vertex["x2"]); +} + /* ************************************************************************* */ TEST( Graph, composePoses ) { diff --git a/cpp/testOrdering.cpp b/cpp/testOrdering.cpp index 8872d8cee..068c82783 100644 --- a/cpp/testOrdering.cpp +++ b/cpp/testOrdering.cpp @@ -11,12 +11,12 @@ using namespace std; using namespace gtsam; using namespace boost::assign; -/* ************************************************************************* * +/* ************************************************************************* */ // x1 -> x2 // -> x3 -> x4 // -> x5 TEST ( Ordering, constructorFromTree ) { - map p_map; + PredecessorMap p_map; p_map.insert(make_pair("x1", "x1")); p_map.insert(make_pair("x2", "x1")); p_map.insert(make_pair("x3", "x1"));