diff c/Motion.cpp @ 231:249d65ff6c35

merged modifications for windows
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 02 Jul 2012 23:49:39 -0400
parents bc4ea09b1743 d4d3b1e8a9f1
children 04355e51d895
line wrap: on
line diff
--- a/c/Motion.cpp	Fri Jun 29 16:15:13 2012 -0400
+++ b/c/Motion.cpp	Mon Jul 02 23:49:39 2012 -0400
@@ -158,13 +158,13 @@
        vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor
     FeatureTrajectoryPtr ft2 = graph[*vi].feature;
     if (newVertex != *vi) {
-      int lastInstant = static_cast<int>(min(ft->getLastInstant(), ft2->getLastInstant()));
-      int firstInstant = static_cast<int>(max(ft->getFirstInstant(), ft2->getFirstInstant()));
+      int lastInstant = static_cast<int>(MIN(ft->getLastInstant(), ft2->getLastInstant()));
+      int firstInstant = static_cast<int>(MAX(ft->getFirstInstant(), ft2->getFirstInstant()));
       if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime
 	if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) {
 	  UndirectedGraph::edge_descriptor e;
 	  bool unused;
-	  std::tr1::tie(e, unused) = add_edge(newVertex, *vi, graph);
+	  tr1::tie(e, unused) = add_edge(newVertex, *vi, graph);
 	  // no need to add measures to graph[e] (edge properties)
 	}
       }
@@ -172,50 +172,60 @@
   }
 }
 
-void FeatureGraph::connectedComponents(const int& lastInstant) {
+void FeatureGraph::connectedComponents(const unsigned int& lastInstant) {
   computeVertexIndex();
   property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph);
 
   int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph)));
+#ifdef DEBUG
   cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl;
+#endif
 
-  std::vector<unsigned int> lastInstants(num, 0); // last instant of component with id
-  std::vector<std::vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors)
+  vector<unsigned int> lastInstants(num, 0); // last instant of component with id
+  vector<vector<vertex_descriptor> > tmpobjects(num), objects; // vector of components (component = vector of vertex descriptors)
 
   graph_traits<UndirectedGraph>::vertex_iterator vi, vend;
-  for(std::tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
-    //for (int i = 0; i < nVertices; ++i) {
+  for(tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
     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();
+    lastInstants[id] = max(lastInstants[id], graph[*vi].feature->getLastInstant());
     tmpobjects[id].push_back(*vi);
   }
 
   objectHypotheses.clear();
   for (int i = 0; i < num; ++i) {
+#ifdef DEBUG
     cout << i << " " << lastInstants[i] << endl;
+#endif
     if (static_cast<int>(lastInstants[i]) < lastInstant)
       objectHypotheses.push_back(tmpobjects[i]);
   }
 }
 
-std::vector<std::vector<unsigned int> > FeatureGraph::getFeatureGroups(void) {
-  std::vector<std::vector<unsigned int> > featureGroups;
+vector<vector<unsigned int> > FeatureGraph::getFeatureGroups(void) {
+  vector<vector<unsigned int> > featureGroups;
 
   for (unsigned int i=0; i<objectHypotheses.size(); ++i) {
     // check that there is on average at least minNFeaturesPerGroup features at each frame in the group
-    float totalFeatureTime=0;
-    for (unsigned int j=0; j<objectHypotheses[i].size(); ++j)
-      totalFeatureTime += static_cast<float>(graph[objectHypotheses[i][j]].feature->length());
-    cout << i << endl;
-    if (totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) > minNFeaturesPerGroup) {
-      cout << "save group " << objectHypotheses[i].size() << " " << totalFeatureTime/static_cast<float>(objectHypotheses[i].size()) << endl;
-      featureGroups.push_back(std::vector<unsigned int>());
+    unsigned int totalFeatureTime= graph[objectHypotheses[i][0]].feature->length();
+    unsigned int firstInstant = graph[objectHypotheses[i][0]].feature->getFirstInstant();
+    unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant();
+      for (unsigned int j=1; j<objectHypotheses[i].size(); ++j) {
+	totalFeatureTime += graph[objectHypotheses[i][j]].feature->length();
+	firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant());
+	lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant());	
+      }
+    if (static_cast<float>(totalFeatureTime)/static_cast<float>(lastInstant-firstInstant+1) > minNFeaturesPerGroup) {
+#if DEBUG
+      cout << "save group " << i << " of " << objectHypotheses[i].size() << " features " << endl;
+#endif
+      featureGroups.push_back(vector<unsigned int>());
       for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) {
-	featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId());cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl;
-	clear_vertex(objectHypotheses[i][j], graph);cout << "cleared "<< objectHypotheses[i][j] << endl;
-	remove_vertex(objectHypotheses[i][j], graph);cout << "removed "<< objectHypotheses[i][j] << endl;
+	featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId());
+#if DEBUG
+	cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl;
+#endif
+	clear_vertex(objectHypotheses[i][j], graph);
+	remove_vertex(objectHypotheses[i][j], graph);
       }
     }
   }
@@ -236,6 +246,6 @@
 void FeatureGraph::computeVertexIndex(void) {
   graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend;
   graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0;
-  for(std::tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi)
+  for(tr1::tie(vi,vend) = vertices(graph); vi != vend; ++vi)
     graph[*vi].index = cnt++;
 }