| 
									
										
										
										
											2011-11-09 09:40:20 +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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file    testRot3.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for Rot3Q class | 
					
						
							|  |  |  |  * @author  Richard Roberts | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/Testable.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/numericalDerivative.h>
 | 
					
						
							|  |  |  | #include <gtsam/base/lieProxies.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Point3.h>
 | 
					
						
							| 
									
										
										
										
											2012-01-02 10:24:29 +08:00
										 |  |  | #include <gtsam/geometry/Rot3.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-21 07:25:43 +08:00
										 |  |  | #include <gtsam/nonlinear/NonlinearFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2012-03-23 01:46:43 +08:00
										 |  |  | #include <gtsam/nonlinear/GaussNewtonOptimizer.h>
 | 
					
						
							| 
									
										
										
										
											2013-08-19 23:32:16 +08:00
										 |  |  | #include <gtsam/inference/Symbol.h>
 | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  | #include <gtsam/slam/BetweenFactor.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-07 12:02:20 +08:00
										 |  |  | typedef BetweenFactor<Rot3> Between; | 
					
						
							| 
									
										
										
										
											2012-01-30 12:34:46 +08:00
										 |  |  | typedef NonlinearFactorGraph Graph; | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 16:40:32 +08:00
										 |  |  | using symbol_shorthand::R; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2012-01-02 10:24:29 +08:00
										 |  |  | TEST(Rot3, optimize) { | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Optimize a circle
 | 
					
						
							| 
									
										
										
										
											2012-02-03 00:16:46 +08:00
										 |  |  |   Values truth; | 
					
						
							|  |  |  |   Values initial; | 
					
						
							| 
									
										
										
										
											2012-01-03 04:24:23 +08:00
										 |  |  |   Graph fg; | 
					
						
							| 
									
										
										
										
											2023-02-06 16:40:32 +08:00
										 |  |  |   fg.addPrior(R(0), Rot3(), noiseModel::Isotropic::Sigma(3, 0.01)); | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  |   for(int j=0; j<6; ++j) { | 
					
						
							| 
									
										
										
										
											2023-02-06 16:40:32 +08:00
										 |  |  |     truth.insert(R(j), Rot3::Rz(M_PI/3.0 * double(j))); | 
					
						
							|  |  |  |     initial.insert(R(j), Rot3::Rz(M_PI/3.0 * double(j) + 0.1 * double(j%2))); | 
					
						
							|  |  |  |     fg.emplace_shared<Between>(R(j), R((j+1)%6), Rot3::Rz(M_PI/3.0), noiseModel::Isotropic::Sigma(3, 0.01)); | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 05:07:56 +08:00
										 |  |  |   Values final = GaussNewtonOptimizer(fg, initial).optimize(); | 
					
						
							| 
									
										
										
										
											2011-11-09 09:40:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   EXPECT(assert_equal(truth, final, 1e-5)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  |   TestResult tr; | 
					
						
							|  |  |  |   return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |