annotate c/Motion.cpp @ 962:64259b9885bf

verbose option to print classification information (more to add)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 06 Nov 2017 21:25:41 -0500
parents 8ac7f61c6e4f
children c3c3a90c08f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
0f790de9437e renamed Feature to Motion files and added code to test blob db
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 135
diff changeset
1 #include "Motion.hpp"
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
2 #include "cvutils.hpp"
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3
188
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
4 #include "src/TrajectoryDBAccessList.h"
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
5
766
6022350f8173 updated to OpenCV 3.1
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 716
diff changeset
6 //#include "opencv2/core/core.hpp"
6022350f8173 updated to OpenCV 3.1
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 716
diff changeset
7 #include "opencv2/imgproc/imgproc.hpp"
132
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
8 #include "opencv2/highgui/highgui.hpp"
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9
188
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
10 #include <boost/graph/connected_components.hpp>
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
11
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
12 #include <iostream>
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
13 #include <vector>
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
14 #include <map>
188
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
15 #include <algorithm>
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
16 #include <utility>
654
045d05cef9d0 updating to c++11 capabilities
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 565
diff changeset
17 #include <memory>
133
63dd4355b6d1 saving of feature positions in sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 132
diff changeset
18
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 using namespace std;
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 using namespace cv;
190
36968a63efe1 Got the connected_components to finally work using a vecS for the vertex list in the adjacency list.
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 189
diff changeset
21 using namespace boost;
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22
163
cde87a07eb58 added graph structures
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 147
diff changeset
23 /******************** FeatureTrajectory ********************/
cde87a07eb58 added graph structures
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 147
diff changeset
24
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
25 FeatureTrajectory::FeatureTrajectory(const unsigned int& frameNum, const cv::Point2f& p, const Mat& homography)
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
26 : firstInstant(frameNum), lastInstant(frameNum) {
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
27 positions = TrajectoryPoint2fPtr(new TrajectoryPoint2f());
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
28 velocities = TrajectoryPoint2fPtr(new TrajectoryPoint2f());
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
29 addPoint(frameNum, p, homography);
132
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
30 }
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
31
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
32 FeatureTrajectory::FeatureTrajectory(TrajectoryPoint2fPtr& _positions, TrajectoryPoint2fPtr& _velocities) {
177
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
33 positions = _positions;
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
34 velocities = _velocities;
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
35 positions->computeInstants(firstInstant, lastInstant);
177
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
36 }
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
37
654
045d05cef9d0 updating to c++11 capabilities
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 565
diff changeset
38 FeatureTrajectory::FeatureTrajectory(const int& id, TrajectoryDBAccess<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) {
177
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
39 bool success = trajectoryDB.read(positions, id, positionsTableName);
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
40 if (!success)
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
41 cout << "problem loading positions" << endl;
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
42 success = trajectoryDB.read(velocities, id, velocitiesTableName);
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
43 if (!success)
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
44 cout << "problem loading velocities" << endl;
179
4f10e97cb677 added getting first and last instant for each feature
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 177
diff changeset
45 // take advantage to request first and last instant from database
4f10e97cb677 added getting first and last instant for each feature
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 177
diff changeset
46 trajectoryDB.timeInterval(firstInstant, lastInstant, id);
177
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
47 }
ae2286b1a3fd added loading FeatureTrajectory from database, printing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 176
diff changeset
48
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
49 bool FeatureTrajectory::isDisplacementSmall(const unsigned int& nDisplacements, const float& minTotalFeatureDisplacement) const {
138
c1b260b48d2a corrected initialization bugs and feature shortening before saving
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 137
diff changeset
50 bool result = false;
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
51 unsigned int nPositions = positions->size();
135
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
52 if (nPositions > nDisplacements) {
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
53 float disp = 0;
137
445e773c9be3 created the parameter structure to parse parameters (bug remaining)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 136
diff changeset
54 for (unsigned int i=0; i<nDisplacements; i++)
135
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
55 disp += displacementDistances[nPositions-2-i];
565
f86f5f25730a changed test for motion from < to <= so that completely stationary features could be extracted
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 486
diff changeset
56 result = disp <= minTotalFeatureDisplacement;
135
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
57 }
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
58 return result;
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
59 }
32d2722d4028 added constraint on minimum displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 133
diff changeset
60
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
61 bool FeatureTrajectory::isMotionSmooth(const int& accelerationBound, const int& deviationBound) const {
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
62 bool result = true;
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
63 unsigned int nPositions = positions->size();
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
64 if (nPositions >= 3) {
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
65 float ratio;
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
66 if (displacementDistances[nPositions-2] > displacementDistances[nPositions-3])
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
67 ratio = displacementDistances[nPositions-2] / displacementDistances[nPositions-3];
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
68 else
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
69 ratio = displacementDistances[nPositions-3] / displacementDistances[nPositions-2];
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
70
481
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
71 float cosine = (*velocities)[nPositions-3].dot((*velocities)[nPositions-2]) / (displacementDistances[nPositions-3] * displacementDistances[nPositions-2]);
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
72
480
f43bc0b0ba74 cleaning code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 391
diff changeset
73 result = (ratio < accelerationBound) & (cosine > deviationBound);
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
74 }
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
75 return result;
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
76 }
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
77
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
78 bool FeatureTrajectory::minMaxSimilarity(const FeatureTrajectory& ft, const int& firstInstant, const int& lastInstant, const float& connectionDistance, const float& segmentationDistance) {
187
aa1061fb9695 using minmaxsimilarity
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 186
diff changeset
79 float minDistance = norm(positions->getPointAtInstant(firstInstant)-ft.positions->getPointAtInstant(firstInstant));
186
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
80 float maxDistance = minDistance;
190
36968a63efe1 Got the connected_components to finally work using a vecS for the vertex list in the adjacency list.
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 189
diff changeset
81 bool connected = (minDistance <= connectionDistance);
186
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
82 int t=firstInstant+1;
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
83 while (t <= lastInstant && connected) {
187
aa1061fb9695 using minmaxsimilarity
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 186
diff changeset
84 float distance = norm(positions->getPointAtInstant(t)-ft.positions->getPointAtInstant(t));
186
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
85 if (distance < minDistance)
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
86 minDistance = distance;
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
87 else if (distance > maxDistance)
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
88 maxDistance = distance;
201
f7ddfc4aeb1e added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 200
diff changeset
89 connected = connected && (maxDistance-minDistance <= segmentationDistance);
186
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
90 t++;
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
91 }
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
92
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
93 return connected;
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
94 }
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
95
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
96 void FeatureTrajectory::addPoint(const unsigned int& frameNum, const Point2f& p, const Mat& homography) {
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
97 Point2f pp = p;
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
98 if (!homography.empty())
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
99 pp = project(p, homography);
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
100 positions->add(frameNum, pp);
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
101 if (frameNum < firstInstant)
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
102 firstInstant = frameNum;
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
103 if (frameNum > lastInstant)
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
104 lastInstant = frameNum;
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
105 computeMotionData(frameNum);
225
d4d3b1e8a9f1 added code to process only needed frames based on saved features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 221
diff changeset
106 assert(positions->size() == displacementDistances.size()+1);
d4d3b1e8a9f1 added code to process only needed frames based on saved features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 221
diff changeset
107 assert(positions->size() == velocities->size()+1);
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
108 }
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
109
138
c1b260b48d2a corrected initialization bugs and feature shortening before saving
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 137
diff changeset
110 void FeatureTrajectory::shorten(void) {
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
111 positions->pop_back();
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
112 velocities->pop_back();
138
c1b260b48d2a corrected initialization bugs and feature shortening before saving
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 137
diff changeset
113 displacementDistances.pop_back();
c1b260b48d2a corrected initialization bugs and feature shortening before saving
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 137
diff changeset
114 }
c1b260b48d2a corrected initialization bugs and feature shortening before saving
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 137
diff changeset
115
481
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
116 void FeatureTrajectory::movingAverage(const unsigned int& nFramesSmoothing) {
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
117 positions->movingAverage(nFramesSmoothing);
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
118 velocities->movingAverage(nFramesSmoothing);
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
119 }
b6ad86ee7033 implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 480
diff changeset
120
142
a3532db00c28 added code to write velocities
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 139
diff changeset
121 void FeatureTrajectory::write(TrajectoryDBAccess<Point2f>& trajectoryDB, const string& positionsTableName, const string& velocitiesTableName) const {
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
122 trajectoryDB.write(*positions, positionsTableName);
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
123 trajectoryDB.write(*velocities, velocitiesTableName);
133
63dd4355b6d1 saving of feature positions in sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 132
diff changeset
124 }
63dd4355b6d1 saving of feature positions in sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 132
diff changeset
125
132
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
126 #ifdef USE_OPENCV
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
127 /// \todo add option for anti-aliased drawing, thickness
933
8ac7f61c6e4f major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 766
diff changeset
128 void FeatureTrajectory::draw(Mat& img, const Mat& homography, const Mat& intrinsicCameraMatrix, const Scalar& color) const {
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
129 Point2f p1, p2;
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
130 if (!homography.empty())
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
131 p1 = project((*positions)[0], homography);
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
132 else
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
133 p1 = (*positions)[0];
933
8ac7f61c6e4f major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 766
diff changeset
134 if (!intrinsicCameraMatrix.empty())
8ac7f61c6e4f major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 766
diff changeset
135 p1 = cameraProject(p1, intrinsicCameraMatrix);
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
136 for (unsigned int i=1; i<positions->size(); i++) {
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
137 if (!homography.empty())
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
138 p2 = project((*positions)[i], homography);
147
0089fb29cd26 added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 142
diff changeset
139 else
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
140 p2 = (*positions)[i];
933
8ac7f61c6e4f major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 766
diff changeset
141 if (!intrinsicCameraMatrix.empty())
8ac7f61c6e4f major rework of homography calibration, no in ideal points if correcting for distortion
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 766
diff changeset
142 p2 = cameraProject(p2, intrinsicCameraMatrix);
132
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
143 line(img, p1, p2, color, 1);
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
144 p1 = p2;
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
145 }
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
146 }
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
147 #endif
45c64e68053c added drawing function for features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 129
diff changeset
148
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
149 // protected
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
150
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
151 void FeatureTrajectory::computeMotionData(const int& frameNum) {
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
152 unsigned int nPositions = positions->size();
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
153 if (nPositions >= 2) {
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
154 Point2f displacement = (*positions)[nPositions-1] - (*positions)[nPositions-2];
139
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
155 //if (nPositions == 2) // duplicate first displacement so that positions and velocities have the same length
47329bd16cc0 cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 138
diff changeset
156 //velocities.add(frameNum-1, displacement);
176
9323427aa0a3 changed positions and velocities to shared pointers and renamed methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 163
diff changeset
157 velocities->add(frameNum, displacement);
129
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
158 float dist = norm(displacement);
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
159 displacementDistances.push_back(dist);
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
160 }
4742b2b6d851 created basic feature saving code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
161 }
163
cde87a07eb58 added graph structures
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 147
diff changeset
162
cde87a07eb58 added graph structures
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 147
diff changeset
163 /******************** FeatureGraph ********************/
179
4f10e97cb677 added getting first and last instant for each feature
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 177
diff changeset
164
180
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
165 void FeatureGraph::addFeature(const FeatureTrajectoryPtr& ft) {
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
166 vertex_descriptor newVertex = add_vertex(graph);
180
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
167 graph[newVertex].feature = ft;
190
36968a63efe1 Got the connected_components to finally work using a vecS for the vertex list in the adjacency list.
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 189
diff changeset
168 for (graph_traits<UndirectedGraph>::vertex_iterator vi = vertices(graph).first;
180
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
169 vi!=vertices(graph).second; ++vi) { // vi pointer to vertex_descriptor
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
170 FeatureTrajectoryPtr ft2 = graph[*vi].feature;
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
171 if (newVertex != *vi) {
225
d4d3b1e8a9f1 added code to process only needed frames based on saved features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 221
diff changeset
172 int lastInstant = static_cast<int>(MIN(ft->getLastInstant(), ft2->getLastInstant()));
d4d3b1e8a9f1 added code to process only needed frames based on saved features
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 221
diff changeset
173 int firstInstant = static_cast<int>(MAX(ft->getFirstInstant(), ft2->getFirstInstant()));
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
174 if (lastInstant-firstInstant > static_cast<int>(minFeatureTime)) { // equivalent to lastInstant-firstInstant+1 >= minFeatureTime
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
175 if (ft->minMaxSimilarity(*ft2, firstInstant, lastInstant, connectionDistance, segmentationDistance)) {
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
176 UndirectedGraph::edge_descriptor e;
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
177 bool unused;
486
46b5cb3f3114 correction to compile on Windows
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 481
diff changeset
178 boost::tuples::tie(e, unused) = add_edge(newVertex, *vi, graph);
200
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
179 // no need to add measures to graph[e] (edge properties)
0a27fa343257 added one test and cleaned the first and last instant mess
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 196
diff changeset
180 }
186
6c48283a78ca work on feature similarity, issue with getting point
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 180
diff changeset
181 }
180
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
182 }
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
183 }
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
184 }
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
185
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
186 void FeatureGraph::connectedComponents(const unsigned int& lastInstant) {
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
187 computeVertexIndex();
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
188 property_map<UndirectedGraph, int VertexInformation::*>::type components = get(&VertexInformation::index, graph);
188
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
189
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
190 int num = connected_components(graph, components, vertex_index_map(get(&VertexInformation::index, graph)));
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
191 #ifdef DEBUG
201
f7ddfc4aeb1e added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 200
diff changeset
192 cout << "last instant threshold " << lastInstant << " Total number of components: " << num << endl;
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
193 #endif
190
36968a63efe1 Got the connected_components to finally work using a vecS for the vertex list in the adjacency list.
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 189
diff changeset
194
201
f7ddfc4aeb1e added tests for graphs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 200
diff changeset
195 vector<unsigned int> lastInstants(num, 0); // last instant of component with id
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
196 vector<vector<vertex_descriptor> > tmpobjects(num); // vector of components (component = vector of vertex descriptors)
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
197
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
198 graph_traits<UndirectedGraph>::vertex_iterator vi, vend;
486
46b5cb3f3114 correction to compile on Windows
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 481
diff changeset
199 for(boost::tuples::tie(vi,vend) = vertices(graph); vi != vend; ++vi) {
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
200 unsigned int id = components[*vi];
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
201 lastInstants[id] = max(lastInstants[id], graph[*vi].feature->getLastInstant());
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
202 tmpobjects[id].push_back(*vi);
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
203 }
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
204
194
09c7881073f3 connected commponents works, but issue with removing the vertices
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 192
diff changeset
205 objectHypotheses.clear();
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
206 for (int i = 0; i < num; ++i) {
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
207 #ifdef DEBUG
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
208 cout << i << " " << lastInstants[i] << endl;
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
209 #endif
277
21f14fadd098 removed warning
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 232
diff changeset
210 if (lastInstants[i] < lastInstant)
194
09c7881073f3 connected commponents works, but issue with removing the vertices
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 192
diff changeset
211 objectHypotheses.push_back(tmpobjects[i]);
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
212 }
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
213 }
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
214
391
03dbecd3a887 modified feature grouping to return vectors of pointers to feature trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 277
diff changeset
215 void FeatureGraph::getFeatureGroups(vector<vector<FeatureTrajectoryPtr> >& featureGroups) {
03dbecd3a887 modified feature grouping to return vectors of pointers to feature trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 277
diff changeset
216 featureGroups.clear();
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
217
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
218 for (unsigned int i=0; i<objectHypotheses.size(); ++i) {
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
219 // check that there is on average at least minNFeaturesPerGroup features at each frame in the group
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
220 unsigned int totalFeatureTime= graph[objectHypotheses[i][0]].feature->length();
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
221 unsigned int firstInstant = graph[objectHypotheses[i][0]].feature->getFirstInstant();
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
222 unsigned int lastInstant = graph[objectHypotheses[i][0]].feature->getLastInstant();
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
223 for (unsigned int j=1; j<objectHypotheses[i].size(); ++j) {
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
224 totalFeatureTime += graph[objectHypotheses[i][j]].feature->length();
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
225 firstInstant = MIN(firstInstant, graph[objectHypotheses[i][j]].feature->getFirstInstant());
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
226 lastInstant = MAX(lastInstant, graph[objectHypotheses[i][j]].feature->getLastInstant());
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
227 }
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
228 bool saveFeatureGroup = (static_cast<float>(totalFeatureTime)/static_cast<float>(lastInstant-firstInstant+1) > minNFeaturesPerGroup);
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
229 #if DEBUG
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
230 cout << "save group " << i << " of " << objectHypotheses[i].size() << " features " << endl;
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
231 #endif
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
232 if (saveFeatureGroup)
391
03dbecd3a887 modified feature grouping to return vectors of pointers to feature trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 277
diff changeset
233 featureGroups.push_back(vector<FeatureTrajectoryPtr>());
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
234 for (unsigned int j=0; j<objectHypotheses[i].size(); ++j) {
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
235 if (saveFeatureGroup)
391
03dbecd3a887 modified feature grouping to return vectors of pointers to feature trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 277
diff changeset
236 featureGroups.back().push_back(graph[objectHypotheses[i][j]].feature);
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
237 #if DEBUG
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
238 cout << featureGroups.size() << " " << objectHypotheses[i][j] << endl;
221
bc93e87a2108 cleaned and corrected connected components and feature groups
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 201
diff changeset
239 #endif
716
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
240 clear_vertex(objectHypotheses[i][j], graph);
85af65b6d531 corrected major bug slowing feature grouping
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 654
diff changeset
241 remove_vertex(objectHypotheses[i][j], graph);
191
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
242 }
0e60a306d324 added basic code to identify features and save them (crash)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 190
diff changeset
243 }
188
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
244 }
1435965d8181 work on connected components
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 187
diff changeset
245
196
aeab0b88c9b6 began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 194
diff changeset
246 string FeatureGraph::informationString(void) const {
180
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
247 stringstream ss;
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
248 ss << num_vertices(graph) << " vertices, " << num_edges(graph) << " edges";
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
249 return ss.str();
3a4eef37384f method to add features and vertices to graph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 179
diff changeset
250 }
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
251
196
aeab0b88c9b6 began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 194
diff changeset
252 int FeatureGraph::getNVertices(void) const { return num_vertices(graph);}
aeab0b88c9b6 began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 194
diff changeset
253
aeab0b88c9b6 began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 194
diff changeset
254 int FeatureGraph::getNEdges(void) const { return num_edges(graph);}
aeab0b88c9b6 began testing of FeatureGraph
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 194
diff changeset
255
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
256 void FeatureGraph::computeVertexIndex(void) {
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
257 graph_traits<FeatureGraph::UndirectedGraph>::vertex_iterator vi, vend;
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
258 graph_traits<FeatureGraph::UndirectedGraph>::vertices_size_type cnt = 0;
486
46b5cb3f3114 correction to compile on Windows
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 481
diff changeset
259 for(boost::tuples::tie(vi,vend) = vertices(graph); vi != vend; ++vi)
192
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
260 graph[*vi].index = cnt++;
38974d27dd2d connected_components is working with listS for vertex list
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 191
diff changeset
261 }