| 1 | /* ---------------------------------------------------------------------------- |
| 2 | |
| 3 | * GTSAM Copyright 2010, Georgia Tech Research Corporation, |
| 4 | * Atlanta, Georgia 30332-0415 |
| 5 | * All Rights Reserved |
| 6 | * Authors: Frank Dellaert, et al. (see THANKS for the full author list) |
| 7 | |
| 8 | * See LICENSE for the license information |
| 9 | |
| 10 | * -------------------------------------------------------------------------- */ |
| 11 | |
| 12 | /** |
| 13 | * @file timePinholeCamera.cpp |
| 14 | * @brief time PinholeCamera derivatives |
| 15 | * @author Frank Dellaert |
| 16 | */ |
| 17 | |
| 18 | #include <time.h> |
| 19 | #include <iostream> |
| 20 | |
| 21 | #include <gtsam/geometry/PinholeCamera.h> |
| 22 | #include <gtsam/geometry/Cal3Bundler.h> |
| 23 | |
| 24 | using namespace std; |
| 25 | using namespace gtsam; |
| 26 | |
| 27 | int main() |
| 28 | { |
| 29 | int n = 1e6; |
| 30 | |
| 31 | const Pose3 pose1(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5)); |
| 32 | |
| 33 | static Cal3Bundler K(500, 1e-3, 2.0*1e-3); |
| 34 | const PinholeCamera<Cal3Bundler> camera(pose1,K); |
| 35 | const Point3 point1(-0.08,-0.08, 0.0); |
| 36 | |
| 37 | /** |
| 38 | * NOTE: because we only have combined derivative functions now, |
| 39 | * parts of this test are no longer useful. |
| 40 | */ |
| 41 | |
| 42 | // Oct 12 2013, iMac 3.06GHz Core i3 |
| 43 | // Original: 0.14737 musecs/call |
| 44 | // After collapse: 0.11469 musecs/call |
| 45 | // Cal3DS2: 0.14201 musecs/call |
| 46 | // After Cal3DS2 fix: 0.12231 musecs/call |
| 47 | // Cal3Bundler: 0.12000 musecs/call |
| 48 | // Cal3Bundler fix: 0.14637 musecs/call |
| 49 | // June 24 2014, Macbook Pro 2.3GHz Core i7 |
| 50 | // GTSAM 3.1: 0.04295 musecs/call |
| 51 | // After project fix: 0.04193 musecs/call |
| 52 | |
| 53 | { |
| 54 | long timeLog = clock(); |
| 55 | for(int i = 0; i < n; i++) |
| 56 | camera.project(pw: point1); |
| 57 | long timeLog2 = clock(); |
| 58 | double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; |
| 59 | cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl; |
| 60 | } |
| 61 | |
| 62 | // Oct 12 2014, Macbook Air |
| 63 | { |
| 64 | long timeLog = clock(); |
| 65 | Point2 measurement(0,0); |
| 66 | for(int i = 0; i < n; i++) |
| 67 | camera.project(pw: point1)-measurement; |
| 68 | long timeLog2 = clock(); |
| 69 | double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; |
| 70 | cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl; |
| 71 | } |
| 72 | |
| 73 | // Oct 12 2013, iMac 3.06GHz Core i3 |
| 74 | // Original: 3.8720 musecs/call |
| 75 | // After collapse: 2.6269 musecs/call |
| 76 | // Cal3DS2: 4.3330 musecs/call |
| 77 | // After Cal3DS2 fix: 3.2857 musecs/call |
| 78 | // Cal3Bundler: 2.6556 musecs/call |
| 79 | // Cal3Bundler fix: 2.1613 musecs/call |
| 80 | // June 24 2014, Macbook Pro 2.3GHz Core i7 |
| 81 | // GTSAM 3.1: 0.2322 musecs/call |
| 82 | // After project fix: 0.2094 musecs/call |
| 83 | { |
| 84 | Matrix Dpose, Dpoint; |
| 85 | long timeLog = clock(); |
| 86 | for(int i = 0; i < n; i++) |
| 87 | camera.project(pw: point1, Dpose, Dpoint, Dcal: {}); |
| 88 | long timeLog2 = clock(); |
| 89 | double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; |
| 90 | cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl; |
| 91 | } |
| 92 | |
| 93 | // Oct 12 2013, iMac 3.06GHz Core i3 |
| 94 | // Original: 4.0119 musecs/call |
| 95 | // After collapse: 2.5698 musecs/call |
| 96 | // Cal3DS2: 4.8325 musecs/call |
| 97 | // After Cal3DS2 fix: 3.4483 musecs/call |
| 98 | // Cal3Bundler: 2.5112 musecs/call |
| 99 | // Cal3Bundler fix: 2.0946 musecs/call |
| 100 | // June 24 2014, Macbook Pro 2.3GHz Core i7 |
| 101 | // GTSAM 3.1: 0.2294 musecs/call |
| 102 | // After project fix: 0.2093 nanosecs/call |
| 103 | { |
| 104 | Matrix Dpose, Dpoint, Dcal; |
| 105 | long timeLog = clock(); |
| 106 | for(int i = 0; i < n; i++) |
| 107 | camera.project(pw: point1, Dpose, Dpoint, Dcal); |
| 108 | long timeLog2 = clock(); |
| 109 | double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; |
| 110 | cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl; |
| 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |