Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 179:4f10e97cb677 | 180:3a4eef37384f |
|---|---|
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 /******************** FeatureGraph ********************/ | 121 /******************** FeatureGraph ********************/ |
| 122 | 122 |
| 123 void FeatureGraph::addFeature(const FeatureTrajectoryPtr& ft) { | |
| 124 UndirectedGraph::vertex_descriptor newVertex = add_vertex(graph); | |
| 125 graph[newVertex].feature = ft; | |
| 126 for (boost::graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; | |
| 127 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor | |
| 128 FeatureTrajectoryPtr ft2 = graph[*vi].feature; | |
| 129 unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant()); | |
| 130 unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant()); | |
| 131 if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime | |
| 132 // compute the distance and add edge if ok | |
| 133 UndirectedGraph::edge_descriptor e; | |
| 134 bool unused; | |
| 135 tie(e, unused) = add_edge(newVertex, *vi, graph); | |
| 136 // no need to add measures to graph[e] | |
| 137 } | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 string FeatureGraph::informationString(void) { | |
| 142 stringstream ss; | |
| 143 ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges"; | |
| 144 return ss.str(); | |
| 145 } |
