changeset 196:aeab0b88c9b6

began testing of FeatureGraph
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 20 Dec 2011 00:31:37 -0500
parents 1247e26a8b5e
children 2788b2827670
files c/Makefile c/Motion.cpp c/test_feature.cpp c/test_graph.cpp include/Motion.hpp include/testutils.hpp
diffstat 6 files changed, 65 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/c/Makefile	Fri Dec 16 11:34:07 2011 -0500
+++ b/c/Makefile	Tue Dec 20 00:31:37 2011 -0500
@@ -51,11 +51,11 @@
 
 #GUI_OBJS = 
 CV_OBJS = cvutils.o
-COMMON_OBJS = utils.o
+COMMON_OBJS = utils.o Motion.o Parameters.o utils.o
 OBJS = $(COMMON_OBJS) $(CV_OBJS)
-TESTS_OBJS = test_feature.o
+TESTS_OBJS = test_feature.o test_graph.o
 ifeq ($(UNAME), Linux)
-	TESTS_OBJS += $(LINUX_BOOST_PREFIX)/lib/libboost_unit_test_framework-mt.a
+	TESTS_OBJS += $(LINUX_BOOST_PREFIX)/lib/libboost_unit_test_framework.a
 endif
 
 
@@ -75,7 +75,7 @@
 	$(CXX) $(CFLAGS) $(LIBS) -o $(EXE_DIR)/$@ $^ $(LDFLAGS)
 	$(EXE_DIR)/$@
 
-feature-based-tracking: feature-based-tracking.o cvutils.o Motion.o Parameters.o utils.o
+feature-based-tracking: feature-based-tracking.o $(OBJS)
 	$(CXX) $(CFLAGS) $(LIBS) $^ -o $(EXE_DIR)/$@ $(LDFLAGS)
 
 track-features.o: track-features.cpp
--- a/c/Motion.cpp	Fri Dec 16 11:34:07 2011 -0500
+++ b/c/Motion.cpp	Tue Dec 20 00:31:37 2011 -0500
@@ -217,12 +217,16 @@
   return featureGroups;
 }
 
-string FeatureGraph::informationString(void) {
+string FeatureGraph::informationString(void) const {
   stringstream ss;
   ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges";
   return ss.str();
 }
 
+int FeatureGraph::getNVertices(void) const { return num_vertices(graph);}
+
+int FeatureGraph::getNEdges(void) const  { return num_edges(graph);}
+
 void FeatureGraph::computeVertexIndex(void) {
   graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend;
   graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0;
--- a/c/test_feature.cpp	Fri Dec 16 11:34:07 2011 -0500
+++ b/c/test_feature.cpp	Tue Dec 20 00:31:37 2011 -0500
@@ -5,7 +5,7 @@
 
 using namespace std;
 
-BOOST_AUTO_TEST_SUITE(test_process)
+BOOST_AUTO_TEST_SUITE(test_feature)
 
 BOOST_AUTO_TEST_CASE(feature_stationary) {
   int i=5;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/test_graph.cpp	Tue Dec 20 00:31:37 2011 -0500
@@ -0,0 +1,30 @@
+#include "Motion.hpp"
+#include "testutils.hpp"
+
+#include "opencv2/core/core.hpp"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+
+using namespace std;
+using namespace cv;
+
+BOOST_AUTO_TEST_SUITE(test_graph)
+
+BOOST_AUTO_TEST_CASE(graph_add_delete) {
+  FeatureGraph featureGraph(5, 1, 5, 1.);
+  FeatureTrajectoryPtr ft1 = createFeatureTrajectory(10, 20, Point2f(1,1), Point2f(0.5, 0.));
+  FeatureTrajectoryPtr ft2 = createFeatureTrajectory(10, 20, Point2f(1.1,1), Point2f(0.5, 0.));
+
+  featureGraph.addFeature(ft1);
+  BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 1);
+  BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0);
+
+  // featureGraph.addFeature(ft2);
+  // BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2);
+  // BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1);
+
+  
+}
+
+BOOST_AUTO_TEST_SUITE_END()
--- a/include/Motion.hpp	Fri Dec 16 11:34:07 2011 -0500
+++ b/include/Motion.hpp	Tue Dec 20 00:31:37 2011 -0500
@@ -124,7 +124,10 @@
    */
   std::vector<std::vector<unsigned int> > getFeatureGroups(void);
 
-  std::string informationString(void);
+  std::string informationString(void) const;
+
+  int getNVertices(void) const;
+  int getNEdges(void) const;
 
 protected:
   float connectionDistance;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/testutils.hpp	Tue Dec 20 00:31:37 2011 -0500
@@ -0,0 +1,21 @@
+#ifndef TEST_UTILS_HPP
+#define TEST_UTILS_HPP
+
+#include "Motion.hpp"
+
+#include "opencv2/core/core.hpp"
+
+#include <boost/shared_ptr.hpp>
+
+inline boost::shared_ptr<FeatureTrajectory> createFeatureTrajectory(const int& firstInstant, const int& lastInstant, const cv::Point2f& firstPosition, const cv::Point2f& velocity) {
+  cv::Mat emptyHomography;
+  boost::shared_ptr<FeatureTrajectory> t = boost::shared_ptr<FeatureTrajectory>(new FeatureTrajectory(firstInstant, firstPosition, emptyHomography));
+  cv::Point2f p = firstPosition;
+  for (int i=firstInstant+1; i<=lastInstant; ++i) {
+    p = p+velocity;
+    t->addPoint(i, p, emptyHomography);
+  }
+  return t;
+}
+
+#endif