| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * LocalOrientedPlane3Factor.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Author: David Wisth | 
					
						
							|  |  |  |  *  Created on: February 12, 2021 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "LocalOrientedPlane3Factor.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //***************************************************************************
 | 
					
						
							|  |  |  | void LocalOrientedPlane3Factor::print(const string& s, | 
					
						
							|  |  |  |     const KeyFormatter& keyFormatter) const { | 
					
						
							|  |  |  |   cout << s << (s == "" ? "" : "\n"); | 
					
						
							| 
									
										
										
										
											2022-12-24 23:06:26 +08:00
										 |  |  |   cout << "LocalOrientedPlane3Factor Factor (" << keyFormatter(key<1>()) << ", " | 
					
						
							|  |  |  |        << keyFormatter(key<2>()) << ", " << keyFormatter(key<3>()) << ")\n"; | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  |   measured_p_.print("Measured Plane"); | 
					
						
							|  |  |  |   this->noiseModel_->print("  noise model: "); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //***************************************************************************
 | 
					
						
							| 
									
										
										
										
											2021-02-16 19:48:26 +08:00
										 |  |  | Vector LocalOrientedPlane3Factor::evaluateError(const Pose3& wTwi, | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |     const Pose3& wTwa, const OrientedPlane3& a_plane, | 
					
						
							| 
									
										
										
										
											2023-01-10 06:52:56 +08:00
										 |  |  |     OptionalMatrixType H1, OptionalMatrixType H2, | 
					
						
							|  |  |  |     OptionalMatrixType H3) const { | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |   Matrix66 aTai_H_wTwa, aTai_H_wTwi; | 
					
						
							|  |  |  |   Matrix36 predicted_H_aTai; | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  |   Matrix33 predicted_H_plane, error_H_predicted; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |   // Find the relative transform from anchor to sensor frame.
 | 
					
						
							|  |  |  |   const Pose3 aTai = wTwa.transformPoseTo(wTwi, | 
					
						
							|  |  |  |       H2 ? &aTai_H_wTwa : nullptr, | 
					
						
							|  |  |  |       H1 ? &aTai_H_wTwi : nullptr); | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |   // Transform the plane measurement into sensor frame.
 | 
					
						
							|  |  |  |   const OrientedPlane3 i_plane = a_plane.transform(aTai, | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  |       H2 ? &predicted_H_plane : nullptr, | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |       (H1 || H3) ? &predicted_H_aTai  : nullptr); | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |   // Calculate the error between measured and estimated planes in sensor frame.
 | 
					
						
							|  |  |  |   const Vector3 err = measured_p_.errorVector(i_plane, | 
					
						
							| 
									
										
										
										
											2023-01-13 06:02:31 +08:00
										 |  |  |     {}, (H1 || H2 || H3) ? &error_H_predicted : nullptr); | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Apply the chain rule to calculate the derivatives.
 | 
					
						
							|  |  |  |   if (H1) { | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |     *H1 = error_H_predicted * predicted_H_aTai * aTai_H_wTwi; | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (H2) { | 
					
						
							| 
									
										
										
										
											2021-02-15 23:08:57 +08:00
										 |  |  |     *H2 = error_H_predicted * predicted_H_aTai * aTai_H_wTwa; | 
					
						
							| 
									
										
										
										
											2021-02-15 21:15:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (H3) { | 
					
						
							|  |  |  |     *H3 = error_H_predicted * predicted_H_plane; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace gtsam
 |