1515 * @author Frank Dellaert
1616 */
1717
18- #include < gtsam/slam/dataset.h>
1918#include < gtsam/geometry/CalibratedCamera.h>
19+ #include < gtsam/slam/dataset.h>
2020
2121#include < boost/assign/std/vector.hpp>
2222
@@ -26,22 +26,16 @@ using namespace gtsam;
2626
2727/* ************************************************************************* */
2828
29- void createExampleBALFile (const string& filename, const vector<Point3>& P,
30- const Pose3& pose1, const Pose3& pose2, const Cal3Bundler& K =
31- Cal3Bundler ()) {
32-
29+ void createExampleBALFile (const string& filename, const vector<Point3>& points,
30+ const Pose3& pose1, const Pose3& pose2,
31+ const Cal3Bundler& K = Cal3Bundler()) {
3332 // Class that will gather all data
3433 SfmData data;
35-
36- // Create two cameras
37- Rot3 aRb = Rot3::Yaw (M_PI_2);
38- Point3 aTb (0.1 , 0 , 0 );
39- Pose3 identity, aPb (aRb, aTb);
34+ // Create two cameras and add them to data
4035 data.cameras .push_back (SfmCamera (pose1, K));
4136 data.cameras .push_back (SfmCamera (pose2, K));
4237
43- for (const Point3& p: P) {
44-
38+ for (const Point3& p : points) {
4539 // Create the track
4640 SfmTrack track;
4741 track.p = p;
@@ -51,7 +45,7 @@ void createExampleBALFile(const string& filename, const vector<Point3>& P,
5145
5246 // Project points in both cameras
5347 for (size_t i = 0 ; i < 2 ; i++)
54- track.measurements .push_back (make_pair (i, data.cameras [i].project (p)));
48+ track.measurements .push_back (make_pair (i, data.cameras [i].project (p)));
5549
5650 // Add track to data
5751 data.tracks .push_back (track);
@@ -63,49 +57,66 @@ void createExampleBALFile(const string& filename, const vector<Point3>& P,
6357/* ************************************************************************* */
6458
6559void create5PointExample1 () {
66-
6760 // Create two cameras poses
6861 Rot3 aRb = Rot3::Yaw (M_PI_2);
6962 Point3 aTb (0.1 , 0 , 0 );
7063 Pose3 pose1, pose2 (aRb, aTb);
7164
7265 // Create test data, we need at least 5 points
73- vector<Point3> P;
74- P += Point3 (0 , 0 , 1 ), Point3 (-0.1 , 0 , 1 ), Point3 (0.1 , 0 , 1 ), //
75- Point3 (0 , 0.5 , 0.5 ), Point3 (0 , -0.5 , 0.5 );
66+ vector<Point3> points = {
67+ {0 , 0 , 1 }, {-0.1 , 0 , 1 }, {0.1 , 0 , 1 }, {0 , 0.5 , 0.5 }, {0 , -0.5 , 0.5 }};
7668
7769 // Assumes example is run in ${GTSAM_TOP}/build/examples
78- const string filename = " ../../examples/data /5pointExample1.txt" ;
79- createExampleBALFile (filename, P , pose1, pose2);
70+ const string filename = " ../../examples/Data /5pointExample1.txt" ;
71+ createExampleBALFile (filename, points , pose1, pose2);
8072}
8173
8274/* ************************************************************************* */
8375
8476void create5PointExample2 () {
85-
8677 // Create two cameras poses
8778 Rot3 aRb = Rot3::Yaw (M_PI_2);
8879 Point3 aTb (10 , 0 , 0 );
8980 Pose3 pose1, pose2 (aRb, aTb);
9081
9182 // Create test data, we need at least 5 points
92- vector<Point3> P;
93- P += Point3 ( 0 , 0 , 100 ), Point3 (- 10 , 0 , 100 ), Point3 ( 10 , 0 , 100 ), //
94- Point3 ( 0 , 50 , 50 ), Point3 ( 0 , - 50 , 50 ), Point3 (- 20 , 0 , 80 ), Point3 ( 20 , -50 , 80 ) ;
83+ vector<Point3> points = {{ 0 , 0 , 100 }, {- 10 , 0 , 100 }, { 10 , 0 , 100 }, //
84+ { 0 , 50 , 50 }, { 0 , - 50 , 50 }, {- 20 , 0 , 80 }, //
85+ { 20 , -50 , 80 }} ;
9586
9687 // Assumes example is run in ${GTSAM_TOP}/build/examples
97- const string filename = " ../../examples/data /5pointExample2.txt" ;
88+ const string filename = " ../../examples/Data /5pointExample2.txt" ;
9889 Cal3Bundler K (500 , 0 , 0 );
99- createExampleBALFile (filename, P , pose1, pose2,K);
90+ createExampleBALFile (filename, points , pose1, pose2, K);
10091}
10192
10293/* ************************************************************************* */
10394
95+ void create18PointExample1 () {
96+ // Create two cameras poses
97+ Rot3 aRb = Rot3::Yaw (M_PI_2);
98+ Point3 aTb (0.1 , 0 , 0 );
99+ Pose3 pose1, pose2 (aRb, aTb);
100+
101+ // Create test data, we need 15 points
102+ vector<Point3> points = {
103+ {0 , 0 , 1 }, {-0.1 , 0 , 1 }, {0.1 , 0 , 1 }, //
104+ {0 , 0.5 , 0.5 }, {0 , -0.5 , 0.5 }, {-1 , -0.5 , 2 }, //
105+ {-1 , 0.5 , 2 }, {0.25 , -0.5 , 1.5 }, {0.25 , 0.5 , 1.5 }, //
106+ {-0.1 , -0.5 , 0.5 }, {0.1 , -0.5 , 1 }, {0.1 , 0.5 , 1 }, //
107+ {-0.1 , 0 , 0.5 }, {-0.1 , 0.5 , 0.5 }, {0 , 0 , 0.5 }, //
108+ {0.1 , -0.5 , 0.5 }, {0.1 , 0 , 0.5 }, {0.1 , 0.5 , 0.5 }};
109+
110+ // Assumes example is run in ${GTSAM_TOP}/build/examples
111+ const string filename = " ../../examples/Data/18pointExample1.txt" ;
112+ createExampleBALFile (filename, points, pose1, pose2);
113+ }
114+
104115int main (int argc, char * argv[]) {
105116 create5PointExample1 ();
106117 create5PointExample2 ();
118+ create18PointExample1 ();
107119 return 0 ;
108120}
109121
110122/* ************************************************************************* */
111-
0 commit comments