diff c/Motion.cpp @ 194:09c7881073f3

connected commponents works, but issue with removing the vertices
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 12 Dec 2011 18:32:10 -0500
parents 38974d27dd2d
children aeab0b88c9b6
line wrap: on
line diff
--- a/c/Motion.cpp	Mon Dec 12 15:44:54 2011 -0500
+++ b/c/Motion.cpp	Mon Dec 12 18:32:10 2011 -0500
@@ -7,7 +7,6 @@
 #include "opencv2/highgui/highgui.hpp"
 
 #include <boost/graph/connected_components.hpp>
-#include <boost/property_map/property_map.hpp>
 
 #include <iostream>
 #include <vector>
@@ -167,7 +166,7 @@
   }
 }
 
-vector<vector<FeatureGraph::vertex_descriptor> > FeatureGraph::connectedComponents(const int& lastInstant) {
+void FeatureGraph::connectedComponents(const int& lastInstant) {
   computeVertexIndex();
   property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph);
 
@@ -181,37 +180,38 @@
   for(tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
     //for (int i = 0; i < nVertices; ++i) {
     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;
+    //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();
     tmpobjects[id].push_back(*vi);
   }
 
+  objectHypotheses.clear();
   for (int i = 0; i < num; ++i) {
     cout << i << " " << lastInstants[i] << endl;
     if (static_cast<int>(lastInstants[i]) < lastInstant)
-      objects.push_back(tmpobjects[i]);
+      objectHypotheses.push_back(tmpobjects[i]);
   }
-
-  return objects;
 }
 
-vector<vector<unsigned int> > FeatureGraph::getFeatureGroups(const vector<vector<FeatureGraph::vertex_descriptor> >& objectHypotheses) {
+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.size(); ++j)
+    for (unsigned int j=0; j<objectHypotheses[i].size(); ++j)
       totalFeatureTime += static_cast<float>(graph[objectHypotheses[i][j]].feature->length());
-    
-    if (totalFeatureTime/static_cast<float>(objectHypotheses.size()) > minNFeaturesPerGroup) {
-      cout << "save group" << endl;
+    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(vector<unsigned int>());
-      for (unsigned int j=0; j<objectHypotheses.size(); ++j)
-	featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature->getId());
+      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;
+      }
     }
-    // remove vertices: todo using listS
   }
 
   return featureGroups;