| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file    timeCameraExpression.cpp | 
					
						
							|  |  |  |  * @brief   time CalibratedCamera derivatives | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  * @date    October 3, 2014 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-28 23:37:54 +08:00
										 |  |  | #include <gtsam/slam/expressions.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/ExpressionFactor.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | #include <gtsam/slam/ProjectionFactor.h>
 | 
					
						
							|  |  |  | #include <gtsam/slam/GeneralSFMFactor.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Pose3.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Cal3_S2.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  | #include "timeLinearize.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-15 17:01:27 +08:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-02 00:45:23 +08:00
										 |  |  | #define time timeSingleThreaded
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  | boost::shared_ptr<Cal3_S2> fixedK(new Cal3_S2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Point2 myProject(const Pose3& pose, const Point3& point, | 
					
						
							| 
									
										
										
										
											2014-12-28 23:37:54 +08:00
										 |  |  |     OptionalJacobian<2,6> H1, OptionalJacobian<2,3> H2) { | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   PinholeCamera<Cal3_S2> camera(pose, *fixedK); | 
					
						
							| 
									
										
										
										
											2014-10-07 07:01:46 +08:00
										 |  |  |   return camera.project(point, H1, H2, boost::none); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | int main() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Create leaves
 | 
					
						
							|  |  |  |   Pose3_ x(1); | 
					
						
							|  |  |  |   Point3_ p(2); | 
					
						
							|  |  |  |   Cal3_S2_ K(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Some parameters needed
 | 
					
						
							|  |  |  |   Point2 z(-17, 30); | 
					
						
							|  |  |  |   SharedNoiseModel model = noiseModel::Unit::Create(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Create values
 | 
					
						
							|  |  |  |   Values values; | 
					
						
							|  |  |  |   values.insert(1, Pose3()); | 
					
						
							|  |  |  |   values.insert(2, Point3(0, 0, 1)); | 
					
						
							|  |  |  |   values.insert(3, Cal3_S2()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // UNCALIBRATED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Dedicated factor
 | 
					
						
							|  |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   // 4.2 musecs/call
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr f1 = | 
					
						
							|  |  |  |       boost::make_shared<GeneralSFMFactor2<Cal3_S2> >(z, model, 1, 2, 3); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("GeneralSFMFactor2<Cal3_S2>  : ", f1, values); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-09 19:00:56 +08:00
										 |  |  |   // ExpressionFactor
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   // 20.3 musecs/call
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr f2 = | 
					
						
							|  |  |  |       boost::make_shared<ExpressionFactor<Point2> >(model, z, | 
					
						
							| 
									
										
										
										
											2019-05-17 02:33:58 +08:00
										 |  |  |           uncalibrate(K, project(transformTo(x, p)))); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("Bin(Leaf,Un(Bin(Leaf,Leaf))): ", f2, values); | 
					
						
							| 
									
										
										
										
											2014-10-07 19:04:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-09 19:00:56 +08:00
										 |  |  |   // ExpressionFactor ternary
 | 
					
						
							| 
									
										
										
										
											2014-10-07 19:04:04 +08:00
										 |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							|  |  |  |   // 20.3 musecs/call
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr f3 = | 
					
						
							|  |  |  |       boost::make_shared<ExpressionFactor<Point2> >(model, z, | 
					
						
							|  |  |  |           project3(x, p, K)); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("Ternary(Leaf,Leaf,Leaf)     : ", f3, values); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // CALIBRATED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Dedicated factor
 | 
					
						
							|  |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   // 3.4 musecs/call
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr g1 = boost::make_shared< | 
					
						
							|  |  |  |       GenericProjectionFactor<Pose3, Point3> >(z, model, 1, 2, fixedK); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("GenericProjectionFactor<P,P>: ", g1, values); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-09 19:00:56 +08:00
										 |  |  |   // ExpressionFactor
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   // 16.0 musecs/call
 | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr g2 = | 
					
						
							|  |  |  |       boost::make_shared<ExpressionFactor<Point2> >(model, z, | 
					
						
							| 
									
										
										
										
											2019-05-17 02:33:58 +08:00
										 |  |  |           uncalibrate(Cal3_S2_(*fixedK), project(transformTo(x, p)))); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("Bin(Cnst,Un(Bin(Leaf,Leaf))): ", g2, values); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-09 19:00:56 +08:00
										 |  |  |   // ExpressionFactor, optimized
 | 
					
						
							| 
									
										
										
										
											2014-10-03 20:35:39 +08:00
										 |  |  |   // Oct 3, 2014, Macbook Air
 | 
					
						
							|  |  |  |   // 9.0 musecs/call
 | 
					
						
							|  |  |  |   typedef PinholeCamera<Cal3_S2> Camera; | 
					
						
							|  |  |  |   typedef Expression<Camera> Camera_; | 
					
						
							| 
									
										
										
										
											2014-10-10 23:17:20 +08:00
										 |  |  |   NonlinearFactor::shared_ptr g3 = | 
					
						
							|  |  |  |       boost::make_shared<ExpressionFactor<Point2> >(model, z, | 
					
						
							|  |  |  |           Point2_(myProject, x, p)); | 
					
						
							| 
									
										
										
										
											2014-10-08 23:27:46 +08:00
										 |  |  |   time("Binary(Leaf,Leaf)           : ", g3, values); | 
					
						
							| 
									
										
										
										
											2014-10-03 20:19:23 +08:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } |