| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file   VSLAMConfig.h | 
					
						
							|  |  |  |  * @brief  Config for VSLAM | 
					
						
							|  |  |  |  * @author Alireza Fathi | 
					
						
							|  |  |  |  * @author Carlos Nieto | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | #include "VectorConfig.h"
 | 
					
						
							|  |  |  | #include "Pose3.h"
 | 
					
						
							|  |  |  | #include "Cal3_S2.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  | #include "Testable.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam{ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Config that knows about points and poses | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  | class VSLAMConfig : Testable<VSLAMConfig> { | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   typedef std::map<int, Pose3> PoseMap; | 
					
						
							|  |  |  |   typedef std::map<int, Point3> PointMap; | 
					
						
							|  |  |  |   PointMap landmarkPoints_; | 
					
						
							|  |  |  |   PoseMap cameraPoses_; | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   typedef std::map<std::string, Vector>::const_iterator const_iterator; | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * default constructor | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   VSLAMConfig() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*
 | 
					
						
							|  |  |  |    * copy constructor | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   VSLAMConfig(const VSLAMConfig& original): | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   	cameraPoses_(original.cameraPoses_), landmarkPoints_(original.landmarkPoints_){} | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Exponential map: takes 6D vectors in VectorConfig | 
					
						
							|  |  |  | 	 * and applies them to the poses in the VSLAMConfig. | 
					
						
							|  |  |  | 	 * Needed for use in nonlinear optimization | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   VSLAMConfig exmap(const VectorConfig & delta) const; | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   PoseMap::const_iterator cameraIteratorBegin() const  { return cameraPoses_.begin();} | 
					
						
							|  |  |  |   PoseMap::const_iterator cameraIteratorEnd() const   { return cameraPoses_.end();} | 
					
						
							|  |  |  |   PointMap::const_iterator landmarkIteratorBegin() const { return landmarkPoints_.begin();} | 
					
						
							|  |  |  |   PointMap::const_iterator landmarkIteratorEnd() const  { return landmarkPoints_.end();} | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * print | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void print(const std::string& s = "") const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Retrieve robot pose | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   bool cameraPoseExists(int i) const | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |     PoseMap::const_iterator it = cameraPoses_.find(i); | 
					
						
							|  |  |  |     if (it==cameraPoses_.end()) | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  |       return false; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   Pose3 cameraPose(int i) const { | 
					
						
							|  |  |  |     PoseMap::const_iterator it = cameraPoses_.find(i); | 
					
						
							|  |  |  |     if (it==cameraPoses_.end()) | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  |       throw(std::invalid_argument("robotPose: invalid key")); | 
					
						
							|  |  |  |     return it->second; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Check whether a landmark point exists | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   bool landmarkPointExists(int i) const | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |     PointMap::const_iterator it = landmarkPoints_.find(i); | 
					
						
							|  |  |  |     if (it==landmarkPoints_.end()) | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  |       return false; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Retrieve landmark point | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   Point3 landmarkPoint(int i) const { | 
					
						
							|  |  |  |     PointMap::const_iterator it = landmarkPoints_.find(i); | 
					
						
							|  |  |  |     if (it==landmarkPoints_.end()) | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  |       throw(std::invalid_argument("markerPose: invalid key")); | 
					
						
							|  |  |  |     return it->second; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * check whether two configs are equal | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   bool equals(const VSLAMConfig& c, double tol=1e-6) const; | 
					
						
							|  |  |  |   void addCameraPose(const int i, Pose3 cp); | 
					
						
							|  |  |  |   void addLandmarkPoint(const int i, Point3 lp); | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void removeCameraPose(const int i); | 
					
						
							|  |  |  |   void removeLandmarkPose(const int i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |   void clear() {landmarkPoints_.clear(); cameraPoses_.clear();} | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   inline size_t size(){ | 
					
						
							| 
									
										
										
										
											2009-11-11 13:14:03 +08:00
										 |  |  |     return landmarkPoints_.size() + cameraPoses_.size(); | 
					
						
							| 
									
										
										
										
											2009-11-11 04:19:00 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 | 
					
						
							|  |  |  | 
 |