Mercurial Hosting > traffic-intelligence
comparison c/Motion.cpp @ 187:aa1061fb9695
using minmaxsimilarity
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 01 Dec 2011 18:13:10 -0500 |
parents | 6c48283a78ca |
children | 1435965d8181 |
comparison
equal
deleted
inserted
replaced
186:6c48283a78ca | 187:aa1061fb9695 |
---|---|
63 } | 63 } |
64 return result; | 64 return result; |
65 } | 65 } |
66 | 66 |
67 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) { | 67 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, float connectionDistance, float segmentationDistance) { |
68 Point2f diff = positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant); | 68 float minDistance = norm(positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant)); |
69 float minDistance = norm(diff); | |
70 float maxDistance = minDistance; | 69 float maxDistance = minDistance; |
71 bool connected = minDistance <= connectionDistance; | 70 bool connected = minDistance <= connectionDistance; |
72 int t=firstInstant+1; | 71 int t=firstInstant+1; |
73 while (t <= lastInstant && connected) { | 72 while (t <= lastInstant && connected) { |
74 diff = positions->getPointAtInstant(t)-ft.positions->getPointAtInstant(t); | 73 float distance = norm(positions->getPointAtInstant(t)-ft.positions->getPointAtInstant(t)); |
75 float distance = norm(diff); | |
76 if (distance < minDistance) | 74 if (distance < minDistance) |
77 minDistance = distance; | 75 minDistance = distance; |
78 else if (distance > maxDistance) | 76 else if (distance > maxDistance) |
79 maxDistance = distance; | 77 maxDistance = distance; |
80 connected = connected && (maxDistance-minDistance < segmentationDistance); | 78 connected = connected && (maxDistance-minDistance < segmentationDistance); |
144 UndirectedGraph::vertex_descriptor newVertex = add_vertex(graph); | 142 UndirectedGraph::vertex_descriptor newVertex = add_vertex(graph); |
145 graph[newVertex].feature = ft; | 143 graph[newVertex].feature = ft; |
146 for (boost::graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; | 144 for (boost::graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first; |
147 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor | 145 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor |
148 FeatureTrajectoryPtr ft2 = graph[*vi].feature; | 146 FeatureTrajectoryPtr ft2 = graph[*vi].feature; |
149 unsigned int lastInstant = min(ft->getLastInstant(), ft2->getLastInstant()); | 147 int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant())); |
150 unsigned int firstInstant = max(ft->getLastInstant(), ft2->getLastInstant()); | 148 int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant())); |
151 if (lastInstant-firstInstant > minFeatureTime) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime | 149 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime |
152 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { | 150 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) { |
153 UndirectedGraph::edge_descriptor e; | 151 UndirectedGraph::edge_descriptor e; |
154 bool unused; | 152 bool unused; |
155 tie(e, unused) = add_edge(newVertex, *vi, graph); | 153 tie(e, unused) = add_edge(newVertex, *vi, graph); |
156 // no need to add measures to graph[e] | 154 // no need to add measures to graph[e] |