| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    VSLAMFactor.h | 
					
						
							|  |  |  |  * @brief   A Nonlinear Factor, specialized for visual SLAM | 
					
						
							|  |  |  |  * @author  Alireza Fathi | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "NonlinearFactor.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-13 00:16:32 +08:00
										 |  |  | #include "GaussianFactor.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | #include "Cal3_S2.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-12 05:09:43 +08:00
										 |  |  | #include "Testable.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | class VSLAMConfig; | 
					
						
							| 
									
										
										
										
											2009-10-14 04:55:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Non-linear factor for a constraint derived from a 2D measurement, | 
					
						
							|  |  |  |  * i.e. the main building block for visual SLAM. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-11-12 05:09:43 +08:00
										 |  |  | class VSLAMFactor : public NonlinearFactor<VSLAMConfig>, Testable<VSLAMFactor> | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-17 07:49:04 +08:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2009-11-09 12:46:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int cameraFrameNumber_, landmarkNumber_; | 
					
						
							| 
									
										
										
										
											2009-11-17 07:49:04 +08:00
										 |  |  | 	std::string cameraFrameName_, landmarkName_; | 
					
						
							| 
									
										
										
										
											2009-11-17 08:51:27 +08:00
										 |  |  | 	boost::shared_ptr<Cal3_S2> K_; // Calibration stored in each factor. FD: need to think about this.
 | 
					
						
							| 
									
										
										
										
											2009-11-17 07:49:04 +08:00
										 |  |  | 	typedef NonlinearFactor<VSLAMConfig> ConvenientFactor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	typedef boost::shared_ptr<VSLAMFactor> shared_ptr; // shorthand for a smart pointer to a factor
 | 
					
						
							| 
									
										
										
										
											2009-11-17 08:51:27 +08:00
										 |  |  | 	typedef boost::shared_ptr<Cal3_S2> shared_ptrK; | 
					
						
							| 
									
										
										
										
											2009-11-17 07:49:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Default constructor | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	VSLAMFactor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Constructor | 
					
						
							|  |  |  | 	 * @param z is the 2 dimensional location of point in image (the measurement) | 
					
						
							|  |  |  | 	 * @param sigma is the standard deviation | 
					
						
							|  |  |  | 	 * @param cameraFrameNumber is basically the frame number | 
					
						
							|  |  |  | 	 * @param landmarkNumber is the index of the landmark | 
					
						
							|  |  |  | 	 * @param K the constant calibration | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-17 08:51:27 +08:00
										 |  |  | 	VSLAMFactor(const Point2& z, double sigma, int cameraFrameNumber, int landmarkNumber, const shared_ptrK & K); | 
					
						
							| 
									
										
										
										
											2009-11-17 07:49:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * print | 
					
						
							|  |  |  | 	 * @param s optional string naming the factor | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	void print(const std::string& s="VSLAMFactor") const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * equals | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	bool equals(const VSLAMFactor&, double tol=1e-9) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * predict the measurement | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	Vector predict(const VSLAMConfig&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * calculate the error of the factor | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	Vector error_vector(const VSLAMConfig&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * linerarization | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	GaussianFactor::shared_ptr linearize(const VSLAMConfig&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int getCameraFrameNumber() const { return cameraFrameNumber_; } | 
					
						
							|  |  |  | 	int getLandmarkNumber()    const { return landmarkNumber_;    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	/** Serialization function */ | 
					
						
							|  |  |  | 	friend class boost::serialization::access; | 
					
						
							|  |  |  | 	template<class Archive> | 
					
						
							|  |  |  | 	void serialize(Archive & ar, const unsigned int version) { | 
					
						
							|  |  |  | 		ar & BOOST_SERIALIZATION_NVP(cameraFrameNumber_); | 
					
						
							|  |  |  | 		ar & BOOST_SERIALIZATION_NVP(landmarkNumber_); | 
					
						
							|  |  |  | 		ar & BOOST_SERIALIZATION_NVP(cameraFrameName_); | 
					
						
							|  |  |  | 		ar & BOOST_SERIALIZATION_NVP(landmarkName_); | 
					
						
							|  |  |  | 		ar & BOOST_SERIALIZATION_NVP(K_); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 02:25:04 +08:00
										 |  |  | } |