Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 #ifndef __MAPMAKER_H
00015 #define __MAPMAKER_H
00016 #include <cvd/image.h>
00017 #include <cvd/byte.h>
00018 #include <cvd/thread.h>
00019 
00020 #include "Map.h"
00021 #include "KeyFrame.h"
00022 #include "ATANCamera.h"
00023 #include "SmallBlurryImage.h"
00024 #include <queue>
00025 #include <sstream>
00026 #include <boost/shared_ptr.hpp>
00027 #include <ptam/OctomapInterface.h>
00028 
00029 
00030 
00031 
00032 
00033 struct MapMakerData
00034 {
00035   std::set<KeyFrame::Ptr> sMeasurementKFs;   
00036   std::set<KeyFrame::Ptr> sNeverRetryKFs;    
00037   inline int GoodMeasCount()            
00038   {  return sMeasurementKFs.size(); }
00039 };
00040 
00041 
00042 class MapMaker : protected CVD::Thread
00043 {
00044 public:
00045   MapMaker(Map &m, const ATANCamera &cam, ros::NodeHandle& nh);
00046   ~MapMaker();
00047 
00048   
00049   bool InitFromStereo(KeyFrame::Ptr kFirst, KeyFrame::Ptr kSecond,
00050                       std::vector<std::pair<CVD::ImageRef, CVD::ImageRef> > &vMatches,
00051                       SE3<> &se3CameraPos);
00052 
00053   bool InitFromStereo_OLD(KeyFrame::Ptr kFirst, KeyFrame::Ptr kSecond,  
00054                           std::vector<std::pair<CVD::ImageRef, CVD::ImageRef> > &vMatches,
00055                           SE3<> &se3CameraPos);
00056 
00057 
00058   void AddKeyFrame(KeyFrame::Ptr k);   
00059   void RequestReset();   
00060   bool ResetDone();      
00061   int  QueueSize() { return mvpKeyFrameQueue.size() ;} 
00062   bool NeedNewKeyFrame(KeyFrame::Ptr kCurrent);            
00063   bool IsDistanceToNearestKeyFrameExcessive(KeyFrame::Ptr kCurrent);  
00064 
00065   std::string getMessageForUser(){return mMessageForUser.str();};
00066   void resetMessageForUser(){mMessageForUser.str(""); };
00067 
00068   
00069   void ApplyGlobalScaleToMap(double dScale);
00070   void ApplyGlobalTransformationToMap(SE3<> se3NewFromOld);
00071   KeyFrame::Ptr ClosestKeyFrame(KeyFrame::Ptr k);
00072   std::vector<KeyFrame::Ptr> NClosestKeyFrames(KeyFrame::Ptr k, unsigned int N);
00073   
00074 
00075 protected:
00076 
00077   Map &mMap;               
00078   ATANCamera mCamera;      
00079   virtual void run();      
00080 
00081   
00082   OctoMapInterface octomap_interface;
00083   
00084 
00085   
00086   SE3<> CalcPlaneAligner();
00087 
00088   
00089   void AddKeyFrameFromTopOfQueue();  
00090   void ThinCandidates(KeyFrame::Ptr k, int nLevel);
00091   bool AddSomeMapPoints(int nLevel);
00092   bool AddPointEpipolar(KeyFrame::Ptr kSrc, KeyFrame::Ptr kTarget, int nLevel, int nCandidate);
00093   
00094   Vector<3> ReprojectPoint(SE3<> se3AfromB, const Vector<2> &v2A, const Vector<2> &v2B);
00095 
00096   
00097   void BundleAdjust(std::set<KeyFrame::Ptr>, std::set<KeyFrame::Ptr>, std::set<boost::shared_ptr<MapPoint> >, bool);
00098   void BundleAdjustAll();
00099   void BundleAdjustRecent();
00100 
00101   
00102   int ReFindInSingleKeyFrame(KeyFrame::Ptr k);
00103   void ReFindFromFailureQueue();
00104   void ReFindNewlyMade();
00105   void ReFindAll();
00106   bool ReFind_Common(KeyFrame::Ptr k, boost::shared_ptr<MapPoint> p);
00107   void SubPixelRefineMatches(KeyFrame::Ptr k, int nLevel);
00108 
00109   
00110   void Reset();
00111   void HandleBadPoints();
00112   double DistToNearestKeyFrame(KeyFrame::Ptr kCurrent);
00113   double KeyFrameLinearDist(KeyFrame::Ptr k1, KeyFrame::Ptr k2);
00114   bool RefreshSceneDepth(KeyFrame::Ptr pKF);
00115 
00116 
00117   
00118   void GUICommandHandler(std::string sCommand, std::string sParams);
00119   static void GUICommandCallBack(void* ptr, std::string sCommand, std::string sParams);
00120   struct Command {std::string sCommand; std::string sParams; };
00121   std::vector<Command> mvQueuedCommands;
00122 
00123 
00124   
00125   std::vector<KeyFrame::Ptr> mvpKeyFrameQueue;  
00126   std::vector<std::pair<KeyFrame::Ptr, boost::shared_ptr<MapPoint> > > mvFailureQueue; 
00127   std::queue<boost::shared_ptr<MapPoint> > mqNewQueue;   
00128 
00129   double mdWiggleScale;  
00130   
00131   
00132   double mdWiggleScaleDepthNormalized;  
00133   
00134 
00135   bool mbBundleConverged_Full;    
00136   bool mbBundleConverged_Recent;  
00137 
00138   
00139   bool mbResetRequested;   
00140   bool mbResetDone;        
00141   bool mbBundleAbortRequested;      
00142   bool mbBundleRunning;             
00143   bool mbBundleRunningIsRecent;     
00144 
00145 
00146   std::ostringstream mMessageForUser;
00147 };
00148 
00149 #endif
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167