Mercurial Hosting > traffic-intelligence
comparison c/Motion.cpp @ 192:38974d27dd2d
connected_components is working with listS for vertex list
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 12 Dec 2011 02:05:26 -0500 |
parents | 0e60a306d324 |
children | 09c7881073f3 |
comparison
equal
deleted
inserted
replaced
191:0e60a306d324 | 192:38974d27dd2d |
---|---|
72 result &= (ratio < accelerationBound) & (cosine > deviationBound); | 72 result &= (ratio < accelerationBound) & (cosine > deviationBound); |
73 } | 73 } |
74 return result; | 74 return result; |
75 } | 75 } |
76 | 76 |
77 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) { | 77 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, const float& connectionDistance, const float& segmentationDistance) { |
78 float minDistance = norm(positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant)); | 78 float minDistance = norm(positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant)); |
79 float maxDistance = minDistance; | 79 float maxDistance = minDistance; |
80 bool connected = (minDistance <= connectionDistance); | 80 bool connected = (minDistance <= connectionDistance); |
81 int t=firstInstant+1; | 81 int t=firstInstant+1; |
82 while (t <= lastInstant && connected) { | 82 while (t <= lastInstant && connected) { |
166 } | 166 } |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 vector<vector<FeatureGraph::vertex_descriptor> > FeatureGraph::connectedComponents(const int& lastInstant) { | 170 vector<vector<FeatureGraph::vertex_descriptor> > FeatureGraph::connectedComponents(const int& lastInstant) { |
171 int nVertices = num_vertices(graph); | 171 computeVertexIndex(); |
172 vector<vertex_descriptor> components(nVertices); | 172 property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph); |
173 // map<UndirectedGraph::vertex_descriptor, graph_traits<UndirectedGraph>::vertices_size_type> vertex2component; | 173 |
174 // associative_property_map< map<UndirectedGraph::vertex_descriptor, graph_traits<UndirectedGraph>::vertices_size_type> > components(vertex2component); | 174 int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph))); |
175 | |
176 int num = connected_components(graph, &components[0]); | |
177 cout << "Total number of components: " << num << endl; | 175 cout << "Total number of components: " << num << endl; |
178 | 176 |
179 vector<unsigned int> lastInstants(num, 0); | 177 vector<unsigned int> lastInstants(num, 0); |
180 vector<vector<vertex_descriptor> > tmpobjects(num), objects; | 178 vector<vector<vertex_descriptor> > tmpobjects(num), objects; |
181 | 179 |
182 for (int i = 0; i < nVertices; ++i) { | 180 graph_traits<UndirectedGraph>::vertex_iterator vi, vend; |
183 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; | 181 for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) { |
184 if (lastInstants[components[i]] < graph[i].feature->getLastInstant()) | 182 //for (int i = 0; i < nVertices; ++i) { |
185 lastInstants[components[i]] = graph[i].feature->getLastInstant(); | 183 unsigned int id = components[*vi]; |
186 tmpobjects[components[i]].push_back(i); | 184 cout << "Vertex " << *vi << " is in component " << id << endl;// "(last " << graph[i].feature->getLastInstant() << " " << lastInstants[components[i]] << " " << (lastInstants[components[i]] < graph[i].feature->getLastInstant()) << ")" << endl; |
185 if (lastInstants[id] < graph[*vi].feature->getLastInstant()) | |
186 lastInstants[id] = graph[*vi].feature->getLastInstant(); | |
187 tmpobjects[id].push_back(*vi); | |
187 } | 188 } |
188 | 189 |
189 for (int i = 0; i < num; ++i) { | 190 for (int i = 0; i < num; ++i) { |
190 cout << i << " " << lastInstants[i] << endl; | 191 cout << i << " " << lastInstants[i] << endl; |
191 if (static_cast<int>(lastInstants[i]) < lastInstant) | 192 if (static_cast<int>(lastInstants[i]) < lastInstant) |
219 string FeatureGraph::informationString(void) { | 220 string FeatureGraph::informationString(void) { |
220 stringstream ss; | 221 stringstream ss; |
221 ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges"; | 222 ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges"; |
222 return ss.str(); | 223 return ss.str(); |
223 } | 224 } |
225 | |
226 void FeatureGraph::computeVertexIndex(void) { | |
227 graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend; | |
228 graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0; | |
229 for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) | |
230 graph[*vi].index = cnt++; | |
231 } |