diff c/Motion.cpp @ 180:3a4eef37384f

method to add features and vertices to graph
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 01 Nov 2011 00:12:33 -0400
parents 4f10e97cb677
children 6c48283a78ca
line wrap: on
line diff
--- a/c/Motion.cpp	Mon Oct 31 19:17:42 2011 -0400
+++ b/c/Motion.cpp	Tue Nov 01 00:12:33 2011 -0400
@@ -120,3 +120,26 @@
 
 /******************** FeatureGraph ********************/
 
+void FeatureGraph::addFeature(const FeatureTrajectoryPtr& ft) {
+  UndirectedGraph::vertex_descriptor newVertex = add_vertex(graph);
+  graph[newVertex].feature = ft;
+  for (boost::graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; 
+       vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor
+    FeatureTrajectoryPtr ft2 = graph[*vi].feature;
+    unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant());
+    unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant());
+    if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime
+      // compute the distance and add edge if ok
+      UndirectedGraph::edge_descriptor e;
+      bool unused;
+      tie(e, unused) = add_edge(newVertex, *vi, graph);
+      // no need to add measures to graph[e]
+    }
+  }
+}
+
+string FeatureGraph::informationString(void) {
+  stringstream ss;
+  ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges";
+  return ss.str();
+}