# HG changeset patch # User Nicolas Saunier # Date 1323673526 18000 # Node ID 38974d27dd2dd638ded878d91516d742780f5e35 # Parent 0e60a306d324f42aede5f71cecd6b4222434577b connected_components is working with listS for vertex list diff -r 0e60a306d324 -r 38974d27dd2d c/Motion.cpp --- a/c/Motion.cpp Thu Dec 08 18:32:35 2011 -0500 +++ b/c/Motion.cpp Mon Dec 12 02:05:26 2011 -0500 @@ -74,7 +74,7 @@ return result; } -bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) { +bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, const float& connectionDistance, const float& segmentationDistance) { float minDistance = norm(positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant)); float maxDistance = minDistance; bool connected = (minDistance <= connectionDistance); @@ -168,22 +168,23 @@ } vector > FeatureGraph::connectedComponents(const int& lastInstant) { - int nVertices = num_vertices(graph); - vector components(nVertices); - // map::vertices_size_type> vertex2component; - // associative_property_map< map::vertices_size_type> > components(vertex2component); + computeVertexIndex(); + property_map::type components = get(&VertexInformation::index, graph); - int num = connected_components(graph, &components[0]); + int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph))); cout << "Total number of components: " << num << endl; vector lastInstants(num, 0); vector > tmpobjects(num), objects; - for (int i = 0; i < nVertices; ++i) { - cout << "Vertex " << i <<" is in component " << components[i] << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; - if (lastInstants[components[i]] < graph[i].feature->getLastInstant()) - lastInstants[components[i]] = graph[i].feature->getLastInstant(); - tmpobjects[components[i]].push_back(i); + graph_traits::vertex_iterator vi, vend; + for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) { + //for (int i = 0; i < nVertices; ++i) { + unsigned int id = components[*vi]; + cout << "Vertex " << *vi << " is in component " << id << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; + if (lastInstants[id] < graph[*vi].feature->getLastInstant()) + lastInstants[id] = graph[*vi].feature->getLastInstant(); + tmpobjects[id].push_back(*vi); } for (int i = 0; i < num; ++i) { @@ -221,3 +222,10 @@ ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges"; return ss.str(); } + +void FeatureGraph::computeVertexIndex(void) { + graph_traits::vertex_iterator vi, vend; + graph_traits::vertices_size_type cnt = 0; + for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) + graph[*vi].index = cnt++; +} diff -r 0e60a306d324 -r 38974d27dd2d include/Motion.hpp --- a/include/Motion.hpp Thu Dec 08 18:32:35 2011 -0500 +++ b/include/Motion.hpp Mon Dec 12 02:05:26 2011 -0500 @@ -45,7 +45,7 @@ bool isMotionSmooth(const int& accelerationBound, const int& deviationBound) const; /// computes the distance according to the Beymer et al. algorithm - bool minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance); + bool minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, const float& connectionDistance, const float& segmentationDistance); void addPoint(const int& frameNum, const cv::Point2f& p, const cv::Mat& homography); @@ -101,14 +101,14 @@ struct VertexInformation { FeatureTrajectoryPtr feature; + int index; }; - typedef boost::adjacency_list UndirectedGraph; + typedef boost::adjacency_list UndirectedGraph; public: typedef UndirectedGraph::vertex_descriptor vertex_descriptor; - //FeatureGraph(float _minDistance, float _maxDistance) : minDistance (_minDistance), maxDistance(_maxDistance) {} FeatureGraph(float _connectionDistance, float _segmentationDistance, unsigned int _minFeatureTime, float _minNFeaturesPerGroup) : connectionDistance (_connectionDistance), segmentationDistance(_segmentationDistance), minFeatureTime(_minFeatureTime), minNFeaturesPerGroup(_minNFeaturesPerGroup) {} void addFeature(const FeatureTrajectoryPtr& ft); @@ -135,6 +135,8 @@ // float maxDistance; UndirectedGraph graph; + + void computeVertexIndex(void); //std::vector currentVertices, lostVertices; };