| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file PoseRotationPrior.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @brief Implements a prior on the rotation component of a pose | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @date Jun 14, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | #include <gtsam_unstable/slam/PoseTranslationPrior.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class POSE> | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | class PoseRotationPrior : public NoiseModelFactor1<POSE> { | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   typedef PoseRotationPrior<POSE> This; | 
					
						
							|  |  |  |   typedef NoiseModelFactor1<POSE> Base; | 
					
						
							|  |  |  |   typedef POSE Pose; | 
					
						
							|  |  |  |   typedef typename POSE::Translation Translation; | 
					
						
							|  |  |  |   typedef typename POSE::Rotation Rotation; | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   GTSAM_CONCEPT_POSE_TYPE(Pose) | 
					
						
							|  |  |  |   GTSAM_CONCEPT_GROUP_TYPE(Pose) | 
					
						
							|  |  |  |   GTSAM_CONCEPT_LIE_TYPE(Rotation) | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Rotation measured_; | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** standard constructor */ | 
					
						
							|  |  |  |   PoseRotationPrior(Key key, const Rotation& rot_z, const SharedNoiseModel& model) | 
					
						
							|  |  |  |   : Base(model, key), measured_(rot_z) {} | 
					
						
							| 
									
										
										
										
											2012-08-03 03:57:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Constructor that pulls the translation from an incoming POSE */ | 
					
						
							|  |  |  |   PoseRotationPrior(Key key, const POSE& pose_z, const SharedNoiseModel& model) | 
					
						
							|  |  |  |   : Base(model, key), measured_(pose_z.rotation()) {} | 
					
						
							| 
									
										
										
										
											2012-08-03 03:57:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   virtual ~PoseRotationPrior() {} | 
					
						
							| 
									
										
										
										
											2012-08-03 03:57:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // access
 | 
					
						
							|  |  |  |   const Rotation& measured() const { return measured_; } | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // testable
 | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** equals specialized to this factor */ | 
					
						
							|  |  |  |   virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const { | 
					
						
							|  |  |  |     const This *e = dynamic_cast<const This*> (&expected); | 
					
						
							|  |  |  |     return e != NULL && Base::equals(*e, tol) && measured_.equals(e->measured_, tol); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** print contents */ | 
					
						
							|  |  |  |   void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { | 
					
						
							|  |  |  |     Base::print(s + "PoseRotationPrior", keyFormatter); | 
					
						
							|  |  |  |     measured_.print("Measured Rotation"); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** h(x)-z */ | 
					
						
							|  |  |  |   Vector evaluateError(const Pose& pose, boost::optional<Matrix&> H = boost::none) const { | 
					
						
							|  |  |  |     const Rotation& newR = pose.rotation(); | 
					
						
							|  |  |  |     const size_t rDim = newR.dim(), xDim = pose.dim(); | 
					
						
							|  |  |  |     if (H) { | 
					
						
							|  |  |  |       *H = gtsam::zeros(rDim, xDim); | 
					
						
							|  |  |  |       if (pose_traits::isRotFirst<Pose>()) | 
					
						
							|  |  |  |         (*H).leftCols(rDim).setIdentity(rDim, rDim); | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         (*H).rightCols(rDim).setIdentity(rDim, rDim); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     return Rotation::Logmap(newR) - Rotation::Logmap(measured_); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 00:51:52 +08:00
										 |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Serialization function */ | 
					
						
							|  |  |  |   friend class boost::serialization::access; | 
					
						
							|  |  |  |   template<class ARCHIVE> | 
					
						
							|  |  |  |   void serialize(ARCHIVE & ar, const unsigned int version) { | 
					
						
							|  |  |  |     ar & boost::serialization::make_nvp("NoiseModelFactor1", | 
					
						
							|  |  |  |         boost::serialization::base_object<Base>(*this)); | 
					
						
							|  |  |  |     ar & BOOST_SERIALIZATION_NVP(measured_); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-15 04:00:51 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |