| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 05:13:07 +08:00
										 |  |  |  * -------------------------------1------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:34:03 +08:00
										 |  |  |  * @file testExpression.cpp | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  |  * @date September 18, 2014 | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							| 
									
										
										
										
											2014-09-29 18:06:04 +08:00
										 |  |  |  * @author Paul Furgale | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  |  * @brief unit tests for Block Automatic Differentiation | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:29:57 +08:00
										 |  |  | #include <gtsam/geometry/PinholeCamera.h>
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:12:17 +08:00
										 |  |  | #include <gtsam/geometry/Pose3.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Cal3_S2.h>
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:34:03 +08:00
										 |  |  | #include <gtsam_unstable/nonlinear/Expression.h>
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:12:17 +08:00
										 |  |  | #include <gtsam/base/Testable.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-21 22:30:30 +08:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-22 00:22:28 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-09-21 23:59:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<class CAL> | 
					
						
							| 
									
										
										
										
											2014-09-22 00:36:19 +08:00
										 |  |  | Point2 uncalibrate(const CAL& K, const Point2& p, boost::optional<Matrix&> Dcal, | 
					
						
							| 
									
										
										
										
											2014-09-27 21:48:07 +08:00
										 |  |  |     boost::optional<Matrix&> Dp) { | 
					
						
							| 
									
										
										
										
											2014-09-22 00:36:19 +08:00
										 |  |  |   return K.uncalibrate(p, Dcal, Dp); | 
					
						
							| 
									
										
										
										
											2014-09-21 23:59:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:24 +08:00
										 |  |  | TEST(Expression, test) { | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-27 21:58:34 +08:00
										 |  |  |   // Test Constant expression
 | 
					
						
							|  |  |  |   Expression<int> c(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  |   // Create leaves
 | 
					
						
							| 
									
										
										
										
											2014-09-27 17:39:46 +08:00
										 |  |  |   Expression<Pose3> x(1); | 
					
						
							|  |  |  |   Expression<Point3> p(2); | 
					
						
							|  |  |  |   Expression<Cal3_S2> K(3); | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Create expression tree
 | 
					
						
							| 
									
										
										
										
											2014-10-01 05:13:07 +08:00
										 |  |  |   Expression<Point3> p_cam(x, &Pose3::transform_to, p); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:24 +08:00
										 |  |  |   Expression<Point2> projection(PinholeCamera<Cal3_S2>::project_to_camera, p_cam); | 
					
						
							| 
									
										
										
										
											2014-09-29 13:22:25 +08:00
										 |  |  |   Expression<Point2> uv_hat(uncalibrate<Cal3_S2>, K, projection); | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-27 22:08:59 +08:00
										 |  |  |   // Check keys
 | 
					
						
							|  |  |  |   std::set<Key> expectedKeys; | 
					
						
							|  |  |  |   expectedKeys.insert(1); | 
					
						
							|  |  |  |   expectedKeys.insert(2); | 
					
						
							|  |  |  |   expectedKeys.insert(3); | 
					
						
							|  |  |  |   EXPECT(expectedKeys == uv_hat.keys()); | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-28 00:22:37 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 05:26:59 +08:00
										 |  |  | TEST(Expression, compose1) { | 
					
						
							| 
									
										
										
										
											2014-09-29 18:14:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Create expression
 | 
					
						
							| 
									
										
										
										
											2014-09-28 23:50:36 +08:00
										 |  |  |   Expression<Rot3> R1(1), R2(2); | 
					
						
							| 
									
										
										
										
											2014-09-29 13:22:25 +08:00
										 |  |  |   Expression<Rot3> R3 = R1 * R2; | 
					
						
							| 
									
										
										
										
											2014-09-29 18:14:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:29:57 +08:00
										 |  |  |   // Check keys
 | 
					
						
							|  |  |  |   std::set<Key> expectedKeys; | 
					
						
							|  |  |  |   expectedKeys.insert(1); | 
					
						
							|  |  |  |   expectedKeys.insert(2); | 
					
						
							|  |  |  |   EXPECT(expectedKeys == R3.keys()); | 
					
						
							| 
									
										
										
										
											2014-09-29 18:14:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Test compose with arguments referring to the same rotation
 | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:24 +08:00
										 |  |  | TEST(Expression, compose2) { | 
					
						
							| 
									
										
										
										
											2014-09-29 18:14:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Create expression
 | 
					
						
							|  |  |  |   Expression<Rot3> R1(1), R2(1); | 
					
						
							|  |  |  |   Expression<Rot3> R3 = R1 * R2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-30 18:29:57 +08:00
										 |  |  |   // Check keys
 | 
					
						
							|  |  |  |   std::set<Key> expectedKeys; | 
					
						
							|  |  |  |   expectedKeys.insert(1); | 
					
						
							|  |  |  |   EXPECT(expectedKeys == R3.keys()); | 
					
						
							| 
									
										
										
										
											2014-09-28 23:50:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 05:26:59 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Test compose with one arguments referring to a constant same rotation
 | 
					
						
							|  |  |  | TEST(Expression, compose3) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Create expression
 | 
					
						
							|  |  |  |   Expression<Rot3> R1(Rot3::identity()), R2(3); | 
					
						
							|  |  |  |   Expression<Rot3> R3 = R1 * R2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Check keys
 | 
					
						
							|  |  |  |   std::set<Key> expectedKeys; | 
					
						
							|  |  |  |   expectedKeys.insert(3); | 
					
						
							|  |  |  |   EXPECT(expectedKeys == R3.keys()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 06:10:39 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  |   TestResult tr; | 
					
						
							|  |  |  |   return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 |