| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file RelativeElevationFactor.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @date Aug 17, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam_unstable/slam/RelativeElevationFactor.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | RelativeElevationFactor::RelativeElevationFactor(Key poseKey, Key pointKey, double measured, | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     const SharedNoiseModel& model) | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | : Base(model, poseKey, pointKey), measured_(measured) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Vector RelativeElevationFactor::evaluateError(const Pose3& pose, const Point3& point, | 
					
						
							| 
									
										
										
										
											2023-01-10 06:52:56 +08:00
										 |  |  |     OptionalMatrixType H1, OptionalMatrixType H2) const { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   double hx = pose.z() - point.z(); | 
					
						
							|  |  |  |   if (H1) { | 
					
						
							| 
									
										
										
										
											2016-04-12 03:11:29 +08:00
										 |  |  |     *H1 = Matrix::Zero(1,6); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     // Use bottom row of rotation matrix for derivative of translation
 | 
					
						
							|  |  |  |     (*H1)(0, 3) = pose.rotation().r1().z(); | 
					
						
							|  |  |  |     (*H1)(0, 4) = pose.rotation().r2().z(); | 
					
						
							|  |  |  |     (*H1)(0, 5) = pose.rotation().r3().z(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (H2) { | 
					
						
							| 
									
										
										
										
											2016-04-12 03:11:29 +08:00
										 |  |  |     *H2 = Matrix::Zero(1,3); | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     (*H2)(0, 2) = -1.0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-11-23 08:35:27 +08:00
										 |  |  |   return (Vector(1) << hx - measured_).finished(); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | bool RelativeElevationFactor::equals(const NonlinearFactor& expected, double tol) const { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const This *e = dynamic_cast<const This*> (&expected); | 
					
						
							| 
									
										
										
										
											2020-04-07 05:31:05 +08:00
										 |  |  |   return e != nullptr && Base::equals(*e, tol) && std::abs(this->measured_ - e->measured_) < tol; | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void RelativeElevationFactor::print(const std::string& s, const KeyFormatter& keyFormatter) const { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   std::cout << s << "RelativeElevationFactor, relative elevation = " << measured_ << std::endl; | 
					
						
							|  |  |  |   Base::print("", keyFormatter); | 
					
						
							| 
									
										
										
										
											2012-08-20 22:25:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |