Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
imagePointManager.hpp
00001 /* $Id$ */
00002 
00003 #ifndef SLAM_IMAGE_POINT_MANAGER_HPP
00004 #define SLAM_IMAGE_POINT_MANAGER_HPP
00005 
00006 #include <string>
00007 #include <ostream>
00008 #include <list>
00009 #include <algorithm>
00010 
00011 #include "boost/tuple/tuple.hpp"
00012 
00013 #include "kernel/dataLog.hpp"
00014 
00015 #include "jmath/jblas.hpp"
00016 
00017 #include "image/Image.hpp"
00018 #ifndef THALES_TAROT_DISABLE
00019 #include "datareader/ImageReader.hpp"
00020 #include "datareader/StereoReader.hpp"
00021 #include "datareader/MonoReader.hpp"
00022 #endif
00023 
00024 #include "geom/t3dEuler.hpp"
00025 
00026 #include "camera/cameraBarreto.hpp"
00027 #include "camera/mask.hpp"
00028 
00029 #include "hpm/export.hpp"
00030 #include "hpm/engine.hpp"
00031 
00032 #include "slampt/managerTools.hpp"
00033 #include "slam/bearingOnlySlam.hpp"
00034 #include <kernel/IdFactory.hpp>
00035 
00036 namespace jafar {
00037   namespace slampt {
00038 
00039 // #ifndef SWIG
00040 
00046     class MonoImageFrameDataBase : public FrameDataBase {
00047 
00048     public:
00049 
00050       unsigned int loopClosingIndexDistanceMin;
00051 
00052       double loopClosingDistanceMax;
00053 
00054 #ifndef SWIG
00055       DBFrameList::iterator tentativeLoopClosing(unsigned int currentFrameIndex,
00056              geom::T3DEuler const& pose);
00057 #endif
00058     }; // class MonoImageFrameDataBase
00059 
00060 // #endif // SWIG
00061 
00067     class ImagePointManager : 
00068       public jafar::kernel::DataLoggable
00069     {
00070       bool ownFrameDataBase;
00071       int processEvents;
00072     protected :
00073 
00074       static kernel::IdFactory<>* s_idFactory;
00075       kernel::IdFactory<>* m_idFactory;
00076       slam::BaseSlam& slam;
00077 
00079       bool loopClosingOn;
00080       jafar::hpm::Engine& hpmEngineLoopClosing;
00081       MonoImageFrameDataBase* frameDataBase;
00082       bool loopClosingDetection;
00083       unsigned int loopClosingFrameIndex;
00084       unsigned int loopClosingNbUsedFeatures;
00085       jafar::hpm::vecHarrisPoints loopClosingPoints;
00086 
00087       typedef std::vector<QualityIndexPoint> QualityIndexPoints;
00088 
00090       std::vector<QualityIndexPoints> pointsInZone;
00091       std::vector<unsigned int> nbFeaturesInZone;
00092 
00094       typedef std::list<std::size_t> FeaturesList;
00095       FeaturesList knownFeatures;
00096       FeaturesList newFeatures;
00097 
00098       
00100       unsigned int imageWidth;
00101       unsigned int imageHeight;
00102       std::size_t nbZonesU;
00103       std::size_t nbZonesV;
00104       unsigned int nbDesiredFeaturesPerZone;
00105 
00106       unsigned int processingTime;
00107       class Stats
00108       {
00109       public:
00110   unsigned int processingTime;
00111   int loopClosingDetection;
00112   int loopClosingNbUsedFeatures;
00113   int nframes;
00114   Stats(): processingTime(0), loopClosingDetection(0), loopClosingNbUsedFeatures(0), nframes(0) {}
00115       } stats;
00116       
00117       virtual boost::tuple<bool, unsigned int> isPointInZone(double u_, double v_);
00118 
00119       static unsigned int computeZoneIndex(double x_, unsigned int nbInt_, double xMax_);
00120 
00121       unsigned int getNewFeatureId() {return m_idFactory->getId(); }
00122 
00123       virtual bool isFeatureCandidate(std::size_t index_) = 0;
00124 
00125       void addNewFeature(std::size_t index_, hpm::HarrisPoint& point_);
00126 
00127       void addKnownFeature(std::size_t index_, jafar::hpm::HarrisPoint const& point_);
00128 
00129       struct IdPredicate {
00130         IdPredicate( unsigned int _id ) : id(_id) {}
00131         unsigned int id;
00132         bool operator()(const hpm::HarrisPoint& pt)
00133         {
00134           return pt.id == id;
00135         }
00136       };
00137 
00138 #ifndef THALES_TAROT_DISABLE
00139       template<class VecPoints>
00140       void loopClosing(VecPoints& framePoints_, unsigned int robotId_)
00141       {
00142   loopClosingDetection = false;
00143   loopClosingNbUsedFeatures = 0;
00144 
00145   JFR_DEBUG("ImagePointManager::loopClosing:");
00146 
00147 /*        JFR_DEBUG("Already observed" );
00148         JFR_FOREACH( const hpm::HarrisPoint& hp, framePoints_ )
00149         {
00150           if(hp.id != 0)
00151           {
00152             JFR_DEBUG(hp.id);
00153           }
00154         }
00155         JFR_DEBUG("Already observed end" );*/
00156         
00157   // FIXME does this function work correctly with a MultiMapManager
00158   geom::T3DEuler robotPose;
00159   slam.getRobotPose(robotPose, robotId_);
00160 
00161         JFR_DEBUG("Current pose: " << robotPose);
00162   FrameDataBase::DBFrameList::iterator tentativeLoopClosingFrame = 
00163     frameDataBase->tentativeLoopClosing(currentFrameIndex, robotPose);
00164   
00165   if (tentativeLoopClosingFrame != frameDataBase->frameList.end()) {
00166     loopClosingDetection = true;
00167     loopClosingFrameIndex = tentativeLoopClosingFrame->index;
00168     JFR_DEBUG("Tentative loop closing: frame " << tentativeLoopClosingFrame->index);
00169     JFR_DEBUG("pose: " << tentativeLoopClosingFrame->pose.getX());
00170     JFR_DEBUG("nb tentative landmarks: " << tentativeLoopClosingFrame->landmarks.size());
00171 
00172     jafar::hpm::vecHarrisPoints framePointsTmp; // FIXME optimization
00173     hpm::mapMatches loopClosingMatches;
00174 
00175     // (re)compute harris points of frame tentativeLoopClosingFrame->index
00176     // compute matches between currentFrameIndex and tentativeLoopClosingFrame->index
00177 
00178     image::Image* im1 = loadImage(tentativeLoopClosingFrame->index);
00179     image::Image* im2 = loadImage(currentFrameIndex);
00180     hpmEngineLoopClosing.computeMatch(*im1, *im2,
00181               loopClosingPoints, framePointsTmp, loopClosingMatches);
00182     delete im1;
00183     delete im2;
00184 
00185     JFR_DEBUG("matched points: " << loopClosingMatches.size() << JFR_PP_VAR(tentativeLoopClosingFrame->landmarks.size()));
00186 
00187     // iterate on the past frame landmarks
00188     for (DBFrame::LandmarksList::const_iterator it =  tentativeLoopClosingFrame->landmarks.begin() ; 
00189          it != tentativeLoopClosingFrame->landmarks.end() ; ++it) {
00190       // is the point corresponding to that landmark is matched ?
00191       hpm::mapMatches::iterator match = loopClosingMatches.find(it->hpmIndex);
00192       if (match != loopClosingMatches.end()
00193               and (
00194                 std::find_if(framePoints_.begin(),
00195                               framePoints_.end(),
00196                               IdPredicate( it->id ) ) == framePoints_.end() ) ) {
00197         loopClosingNbUsedFeatures++;
00198         JFR_DEBUG("loop closing frame feature matched: " << it->id);
00199         if (framePoints_[match->second].id == hpm::HarrisPoint::NO_ID) {
00200     // the point is not yet a landmark
00201     framePoints_[match->second].id = it->id;
00202         }
00203         else {
00204     // the point is already a landmark
00205     if (framePoints_[match->second].id != it->id) {
00206       JFR_DEBUG("loop closing feature already in the map with another id, removing feature " 
00207            << framePoints_[match->second].id);
00208       unsigned int oldId = framePoints_[match->second].id;
00209       unsigned int newId = it->id;
00210 
00211       slam.removeFeature(oldId);
00212       framePoints_[match->second].id = newId;
00213 
00214       // back propagation of this change in the previous DBFrames
00215       JFR_DEBUG("back propagation of id: " << oldId << " -> " << newId);
00216       // FIXME
00217       //      frameDataBase.changeLandmarkId(oldId, newId, 
00218       //             tentativeLoopClosingFrame->index, 
00219       //             frameDataBase.frameList.back().index);
00220       frameDataBase->changeLandmarkId(oldId, newId, 
00221              0,
00222              frameDataBase->frameList.back().index);
00223     }
00224     else {
00225       JFR_DEBUG("confirm loop closing match: " << it->id);
00226     }
00227         }
00228       }
00229       else { 
00230         JFR_DEBUG("loop closing frame feature NOT matched: " << it->id);
00231       }
00232     }
00233     
00234     JFR_DEBUG("loop closing nb lanmarks: " << loopClosingNbUsedFeatures);
00235 
00236     jafar::hpm::backPropagateId(loopClosingMatches, loopClosingPoints, framePoints_);
00237 
00238   }
00239       }
00240 #endif
00241 
00242       template<class VecPoints>
00243       void featureSelection(VecPoints& points_)
00244       {
00245   // init the process
00246   newFeatures.clear();
00247   knownFeatures.clear();
00248 
00249   for (std::size_t i = 0 ; i < nbFeaturesInZone.size() ; i++) {
00250     nbFeaturesInZone[i]=0;
00251     pointsInZone[i].clear();
00252   }
00253 
00254   // fill in the zones
00255   int notCandidateNb = 0;
00256   for (std::size_t i = 0 ; i < points_.size() ; ++i) 
00257     {
00258       // features that are beeing tracked
00259       if (points_[i].id != hpm::HarrisPoint::NO_ID)
00260         addKnownFeature(i, points_[i]);
00261 
00262       bool isInZone;
00263       unsigned int zoneIndex;
00264       boost::tie(isInZone, zoneIndex) = isPointInZone(points_[i].u, points_[i].v);
00265       JFR_POSTCOND(zoneIndex >= 0 && zoneIndex < nbFeaturesInZone.size(),
00266        "ImagePointManager::featureSelection invalid zone index: " << zoneIndex);
00267       if (isInZone) {
00268         if (points_[i].id != hpm::HarrisPoint::NO_ID)
00269     nbFeaturesInZone[zoneIndex]++;
00270         else {
00271     if (isFeatureCandidate(i))
00272       pointsInZone[zoneIndex].push_back(QualityIndexPoint(i,points_[i].lambdaLow));
00273     else
00274       notCandidateNb++;
00275 //      JFR_DEBUG("ImagePointManager::featureSelection: feature " << i << " id " << points_[i].id << " not candidate");
00276         }
00277       }
00278     }
00279   JFR_DEBUG(notCandidateNb << " features were not candidate");
00280   
00281   // add new features from zones
00282   for (std::size_t i = 0 ; i < nbFeaturesInZone.size() ; i++) {
00283     std::sort(pointsInZone[i].begin(), pointsInZone[i].end());
00284     while (nbFeaturesInZone[i] < nbDesiredFeaturesPerZone) {
00285       if (!pointsInZone[i].empty()) {
00286         std::size_t newIndex = pointsInZone[i].back().hpmIndex;
00287         addNewFeature(newIndex, points_[newIndex]);
00288         pointsInZone[i].pop_back();
00289         nbFeaturesInZone[i]++;
00290         //         JFR_DEBUG("add feature: " << features.back()->id);
00291       }
00292       else {
00293         JFR_DEBUG("featureSelection: not enough points in zone " << i);
00294         break;
00295       }
00296     }
00297   }
00298 
00299       }
00300 
00301       template<class VecPoints>
00302       void updateFrameDataBase(VecPoints& points_, unsigned int robotId_)
00303       {
00304   frameDataBase->frameList.push_back(DBFrame());
00305   DBFrame& dbFrame = frameDataBase->frameList.back();
00306   dbFrame.index=currentFrameIndex;
00307   slam.getRobotPose(dbFrame.pose, robotId_);
00308 //  dbFrame.pose.set(slam.getRobotPose(), slam.getRobotPoseCov());
00309   for (FeaturesList::const_iterator it = knownFeatures.begin() ; it != knownFeatures.end() ; ++it) {
00310     dbFrame.landmarks.push_back(DBFrameLandmark(*it, points_[*it].id));
00311   }
00312   for (FeaturesList::const_iterator it = newFeatures.begin() ; it != newFeatures.end() ; ++it) {
00313     dbFrame.landmarks.push_back(DBFrameLandmark(*it, points_[*it].id));
00314   }
00315       }
00316 
00317 #ifndef THALES_TAROT_DISABLE
00318       virtual jafar::image::Image* loadImage(unsigned int frameNumber) const = 0;
00319 #endif
00320 
00321       virtual bool fillObservation(std::size_t index_, slam::Observation& obs, unsigned int sensorId_, unsigned int robotId_) const = 0;
00322       
00323       //FIXME should it be sensorId instead of robotId?
00325       void slamProcessObservations(unsigned int robotId_, unsigned int sensorId_) const;
00326 
00328       unsigned int currentFrameIndex;
00329 
00330     public :
00331 
00332       ImagePointManager(slam::BaseSlam& slam_, jafar::hpm::Engine& hpmEngineLoopClosing_, kernel::IdFactory<>* _idFactory);
00333 
00334       virtual ~ImagePointManager();
00335 
00336       void setFrameDataBase( MonoImageFrameDataBase* _frameDataBase );
00337       
00338       virtual slam::Observation::ObservationType getObservationType() const = 0;
00339 
00340       virtual void setupZones(unsigned int imageWidth_, unsigned int imageHeight_,
00341           double reduction_,
00342           std::size_t nbZonesU_,
00343           std::size_t nbZonesV_,
00344           unsigned int nbDesiredFeaturesPerZone_);
00345 
00346       void setupLoopClosing(double loopClosingDistanceMax_, 
00347           unsigned int loopClosingIndexDistanceMin_, bool enable = true);
00348 
00349       bool isLoopClosingDetected() const {return loopClosingDetection;}
00350 
00351       unsigned int getLoopClosingFrameIndex() const {return loopClosingFrameIndex;}
00352 
00353       jafar::hpm::vecHarrisPoints const& getLoopClosingPoints() const {return loopClosingPoints;}
00354 
00355       //       FeaturesList const& getKnownFeatures() const {return knownFeatures;}
00356       //       FeaturesList const& getNewFeatures() const {return newFeatures;}
00357 
00358       virtual void writeLogHeader(jafar::kernel::DataLogger& dataLogger) const;
00359       virtual void writeLogData(jafar::kernel::DataLogger& dataLogger) const;
00360       virtual void writeLogStats(jafar::kernel::DataLogger& log) const;
00361 
00362       friend std::ostream& operator <<(std::ostream& s, const ImagePointManager& slam_);
00363       friend std::string getZones(ImagePointManager const& m);
00364       void setProcessEvents(int events_)
00365       {
00366         processEvents = events_;
00367       }
00368 
00369     }; // class ImagePointManager
00370     std::ostream& operator <<(std::ostream& s, const ImagePointManager& manager_);
00371 
00372 
00373 #ifndef THALES_TAROT_DISABLE
00374 
00379     class MonoImagePointManager : 
00380       public ImagePointManager,
00381       public slam::BoSlamEventAdapter {
00382 
00383     protected:
00384 
00386       jafar::hpm::TrackingEngine& hpmTrackingEngine;
00387 
00388       jafar::hpm::vecHarrisPoints vecPointsPrev;
00389       jafar::hpm::vecHarrisPoints vecPointsCur;
00390 
00391       bool isFeatureCandidate(std::size_t index_) { return true; }
00392 
00393       jafar::image::Image* loadImage(unsigned int frameNumber) const {
00394   return imageReader.loadImage(frameNumber);
00395       }
00396 
00397       jafar::datareader::ImageReader imageReader;
00398 
00399       bool fillObservation(std::size_t index_, slam::Observation& obs, unsigned int sensorId_, unsigned int robotId_) const;
00400 
00401       void removeLandmark(unsigned int id) {
00402   for (jafar::hpm::vecHarrisPoints::iterator it = vecPointsCur.begin();
00403        it != vecPointsCur.end() ; ++it)
00404     {
00405       if (it->id == id) {
00406         JFR_DEBUG("MonoImagePointManager: remove feature " << it->id);
00407         it->id = jafar::hpm::HarrisPoint::NO_ID;
00408       }
00409     }
00410 
00411   for (jafar::hpm::vecHarrisPoints::iterator it = loopClosingPoints.begin();
00412        it != loopClosingPoints.end() ; ++it)
00413     {
00414       if (it->id == id) {
00415         JFR_DEBUG("MonoImagePointManager: remove feature " << it->id);
00416         it->id = jafar::hpm::HarrisPoint::NO_ID;
00417       }
00418     }
00419       }
00420 
00421       void removeLandmark(slam::BaseFeature const& landmark) {
00422   removeLandmark(landmark.id());
00423 
00424       }
00425       void removeTentativeLandmark(slam::InitFeature const& landmark) {
00426   removeLandmark(landmark.id());
00427       }
00428 
00429     public:
00430 
00431       MonoImagePointManager(slam::BearingOnlySlam& slam_,
00432           jafar::hpm::Engine& hpmEngineLoopClosing_,
00433           jafar::hpm::TrackingEngine& hpmTrackingEngine_, kernel::IdFactory<>* _idFactory = 0) : 
00434   ImagePointManager(slam_, hpmEngineLoopClosing_, _idFactory), 
00435   hpmTrackingEngine(hpmTrackingEngine_)
00436       {
00437   slam_.addBoEventListener(*this);
00438   slam_.addBoEventListener(*frameDataBase);
00439       }
00440 
00441       ~MonoImagePointManager() {}
00442 
00443       slam::Observation::ObservationType getObservationType() const {return slam::Observation::POINT_IMAGE;}
00444 
00445       jafar::datareader::ImageReader& getImageReader() {return imageReader;}
00446 
00447       jafar::hpm::vecHarrisPoints const& getCurrentPoints() const {return vecPointsCur;}
00448       jafar::hpm::vecHarrisPoints const& getPreviousPoints() const {return vecPointsPrev;}
00449 
00450       void initFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00451       void initFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00452 
00453       void processFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00454       void processFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00455 
00456     }; // class MonoImagePointManager
00457 
00463     class IdImagePointManager : 
00464       public ImagePointManager,
00465       public slam::SlamEventAdapter {
00466 
00467     protected:
00468 
00470       jafar::hpm::TrackingEngine& hpmTrackingEngine;
00471 
00472       jafar::hpm::vecHarrisPoints vecPointsPrev;
00473       jafar::hpm::vecHarrisPoints vecPointsCur;
00474 
00475       bool isFeatureCandidate(std::size_t index_) { return true; }
00476 
00477       jafar::image::Image* loadImage(unsigned int frameNumber) const {
00478   return imageReader.loadImage(frameNumber);
00479       }
00480 
00481       jafar::datareader::ImageReader imageReader;
00482 
00483       bool fillObservation(std::size_t index_, slam::Observation& obs, unsigned int sensorId_, unsigned int robotId_) const;
00484 
00485       void removeLandmark(unsigned int id) {
00486   for (jafar::hpm::vecHarrisPoints::iterator it = vecPointsCur.begin();
00487        it != vecPointsCur.end() ; ++it)
00488     {
00489       if (it->id == id) {
00490         JFR_DEBUG("MonoImagePointManager: remove feature " << it->id);
00491         it->id = jafar::hpm::HarrisPoint::NO_ID;
00492       }
00493     }
00494 
00495   for (jafar::hpm::vecHarrisPoints::iterator it = loopClosingPoints.begin();
00496        it != loopClosingPoints.end() ; ++it)
00497     {
00498       if (it->id == id) {
00499         JFR_DEBUG("MonoImagePointManager: remove feature " << it->id);
00500         it->id = jafar::hpm::HarrisPoint::NO_ID;
00501       }
00502     }
00503       }
00504 
00505       void removeLandmark(slam::BaseFeature const& landmark) {
00506   removeLandmark(landmark.id());
00507 
00508       }
00509 
00510     public:
00511 
00512       IdImagePointManager(slam::BaseSlam& slam_,
00513           jafar::hpm::Engine& hpmEngineLoopClosing_,
00514           jafar::hpm::TrackingEngine& hpmTrackingEngine_, kernel::IdFactory<>* _idFactory = 0) : 
00515   ImagePointManager(slam_, hpmEngineLoopClosing_, _idFactory), 
00516   hpmTrackingEngine(hpmTrackingEngine_) 
00517       {
00518   slam_.addEventListener(*this);
00519   slam_.addEventListener(*frameDataBase);
00520       }
00521 
00522       ~IdImagePointManager() {}
00523 
00524       slam::Observation::ObservationType getObservationType() const {return slam::Observation::POINT_IMAGE;}
00525 
00526       jafar::datareader::ImageReader& getImageReader() {return imageReader;}
00527 
00528       jafar::hpm::vecHarrisPoints const& getCurrentPoints() const {return vecPointsCur;}
00529       jafar::hpm::vecHarrisPoints const& getPreviousPoints() const {return vecPointsPrev;}
00530 
00531       void initFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00532       void initFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00533 
00534       void processFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00535       void processFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00536 
00537     }; // class IdImagePointManager
00538 #endif
00539 
00545     class StereoImagePointManager : 
00546       public ImagePointManager,
00547       public slam::SlamEventAdapter {
00548 
00549     protected:
00550       unsigned int lastUsedRobot;
00551 #ifndef THALES_TAROT_DISABLE
00552       jafar::datareader::StereoReader* stereoReader;
00553 #endif
00554       jafar::hpm::StereoTrackingEngine& hpmTrackingEngine;
00555 
00556       jafar::hpm::vecStereoHarrisPoints vecPointsPrev;
00557       jafar::hpm::vecStereoHarrisPoints vecPointsCur;
00558       jafar::hpm::vecStereoHarrisPoints vecPointsStereo;
00559 
00560       static bool checkRectification(hpm::StereoHarrisPoint const& leftPt, 
00561              hpm::StereoHarrisPoint const& rightPt) 
00562       {
00563   double rectCheck = fabs(rightPt.v - leftPt.v);
00564   return rectCheck < 2.0;
00565       }
00566       
00567       static bool checkDisparity(hpm::StereoHarrisPoint const& leftPt,
00568          hpm::StereoHarrisPoint const& rightPt) 
00569       {
00570   double dispCheck = leftPt.u - rightPt.u;
00571   return dispCheck > 2.0;
00572       }
00573 
00574       bool isFeatureCandidate(std::size_t index_);
00575 
00576 #ifndef THALES_TAROT_DISABLE
00577       jafar::image::Image* loadImage(unsigned int frameNumber) const {
00578   return stereoReader->left()->loadImage(frameNumber);
00579       }
00580 #endif
00581 
00582       bool fillObservation(std::size_t index_, slam::Observation& obs, unsigned int sensorId_, unsigned int robotId_) const;
00583 
00584       void removeLandmark(slam::BaseFeature const& landmark) {
00585   for (jafar::hpm::vecStereoHarrisPoints::iterator it = vecPointsCur.begin();
00586        it != vecPointsCur.end() ; ++it)
00587     {
00588       if (it->id == landmark.id()) {
00589         JFR_DEBUG("StereoImagePointManager: remove feature " << it->id);
00590         it->id = jafar::hpm::HarrisPoint::NO_ID;
00591         vecPointsStereo[it->stereoIndex].id = jafar::hpm::HarrisPoint::NO_ID;
00592       }
00593     }
00594 
00595   for (jafar::hpm::vecHarrisPoints::iterator it = loopClosingPoints.begin();
00596        it != loopClosingPoints.end() ; ++it)
00597     {
00598       if (it->id == landmark.id()) {
00599         JFR_DEBUG("MonoImagePointManager: remove feature " << it->id);
00600         it->id = jafar::hpm::HarrisPoint::NO_ID;
00601       }
00602     }
00603       }
00604     public:
00605 
00606       StereoImagePointManager(slam::BaseSlam& slam_,
00607             jafar::hpm::Engine& hpmEngineLoopClosing_, 
00608             jafar::hpm::StereoTrackingEngine& hpmTrackingEngine_ 
00609 #ifndef THALES_TAROT_DISABLE
00610             ,jafar::datareader::StereoReader* stereoReader_
00611 #endif
00612             , kernel::IdFactory<>* _idFactory = 0
00613       ) :
00614   ImagePointManager(slam_, hpmEngineLoopClosing_, _idFactory),
00615 #ifndef THALES_TAROT_DISABLE
00616         stereoReader(stereoReader_),
00617 #endif
00618         hpmTrackingEngine(hpmTrackingEngine_)
00619       {
00620   slam_.addEventListener(*this);
00621   slam_.addEventListener(*frameDataBase);
00622       }
00623 
00624       ~StereoImagePointManager() {}
00625 
00626       slam::Observation::ObservationType getObservationType() const {return slam::Observation::POINT_STEREOIMAGE;}
00627 
00628       jafar::hpm::vecStereoHarrisPoints const& getCurrentPoints() const {return vecPointsCur;}
00629       jafar::hpm::vecStereoHarrisPoints const& getPreviousPoints() const {return vecPointsPrev;}
00630       jafar::hpm::vecStereoHarrisPoints const& getStereoPoints() const {return vecPointsStereo;}
00631 
00632 
00633 #ifndef THALES_TAROT
00634       void initFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00635 #endif
00636       void initFrame(unsigned int frameIndex_, jafar::image::Image* imgLeft, jafar::image::Image* imgRight, unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00637 
00638 #ifndef THALES_TAROT
00639       void processFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00640 #endif
00641       void processFrame(unsigned int frameIndex_, jafar::image::Image* imgLeft, jafar::image::Image* imgRight, unsigned int robotId_ = 0, unsigned int sensorId_ = 0);
00642 
00643     }; // class StereoImagePointManager
00644 
00645 
00651     class IdOmniImagePointManager : 
00652       public ImagePointManager,
00653       public slam::SlamEventAdapter {
00654 
00655     protected:
00656 
00658       jafar::hpm::TrackingEngine& hpmTrackingEngine;
00659 
00660       jafar::hpm::vecHarrisPoints vecPointsPrev;
00661       jafar::hpm::vecHarrisPoints vecPointsCur;
00662 
00663       bool isFeatureCandidate(std::size_t index_) { return true; }
00664 
00665 #ifndef THALES_TAROT_DISABLE
00666       jafar::image::Image* loadImage(unsigned int frameNumber) const {
00667   return imageReader.loadImage(frameNumber);
00668       }
00669 
00670       jafar::datareader::ImageReader imageReader;
00671 #endif
00672 
00673       bool fillObservation(std::size_t index_, slam::Observation& obs, unsigned int sensorId_, unsigned int robotId_) const;
00674 
00675       void removeLandmark(unsigned int id) {
00676   for (jafar::hpm::vecHarrisPoints::iterator it = vecPointsCur.begin();
00677        it != vecPointsCur.end() ; ++it)
00678     {
00679       if (it->id == id) {
00680         JFR_DEBUG("IdOmniImagePointManager: remove feature " << it->id);
00681         it->id = jafar::hpm::HarrisPoint::NO_ID;
00682       }
00683     }
00684 
00685   for (jafar::hpm::vecHarrisPoints::iterator it = loopClosingPoints.begin();
00686        it != loopClosingPoints.end() ; ++it)
00687     {
00688       if (it->id == id) {
00689         JFR_DEBUG("IdOmniImagePointManager: remove feature " << it->id);
00690         it->id = jafar::hpm::HarrisPoint::NO_ID;
00691       }
00692     }
00693       }
00694 
00695       void removeLandmark(slam::BaseFeature const& landmark) {
00696   removeLandmark(landmark.id());
00697 
00698       }
00699 
00700 
00701 
00702 
00703     public:
00704 
00705 // new for omni
00706       // cells definition
00707       jafar::camera::CameraParabolicBarreto camera;
00708       jafar::camera::PanoMask omniMask;
00709       unsigned int imageMargin;
00710       std::size_t nbZonesInRadius;
00711       std::size_t nbZonesInPeriphery;
00712 // /new
00713 
00714 
00715       IdOmniImagePointManager(slam::BaseSlam& slam_,
00716           jafar::hpm::Engine& hpmEngineLoopClosing_,
00717           jafar::hpm::TrackingEngine& hpmTrackingEngine_, kernel::IdFactory<>* _idFactory = 0) :
00718   ImagePointManager(slam_, hpmEngineLoopClosing_, _idFactory), 
00719   hpmTrackingEngine(hpmTrackingEngine_),
00720   camera(),
00721   omniMask()
00722       {
00723   slam_.addEventListener(*this);
00724   slam_.addEventListener(*frameDataBase);
00725       }
00726 
00727       ~IdOmniImagePointManager() {}
00728 
00729       // overload for omni images
00730       virtual void setupZones(jafar::camera::CameraParabolicBarreto& camera_,
00731           unsigned int imageMargin_,
00732           std::size_t nbZonesInRadius_,
00733           std::size_t nbZonesInPeriphery_,
00734           unsigned int nbDesiredFeaturesPerZone_);
00735 
00736       virtual boost::tuple<bool, unsigned int> isPointInZone(double u, double v);
00737 
00738 
00739       slam::Observation::ObservationType getObservationType() const {return slam::Observation::POINT_OMNIIMAGE;}
00740 
00741 #ifndef THALES_TAROT_DISABLE
00742       jafar::datareader::ImageReader& getImageReader() {return imageReader;}
00743 #endif
00744 
00745       jafar::hpm::vecHarrisPoints const& getCurrentPoints() const {return vecPointsCur;}
00746       jafar::hpm::vecHarrisPoints const& getPreviousPoints() const {return vecPointsPrev;}
00747 
00748 #ifndef THALES_TAROT
00749       void initFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00750 #endif
00751       void initFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00752 
00753 #ifndef THALES_TAROT
00754       void processFrame(unsigned int frameIndex_,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00755 #endif
00756       void processFrame(unsigned int frameIndex_, jafar::image::Image* image,unsigned int robotId_ = 0, unsigned int sensortId_ = 0);
00757 
00758     }; // class IdOmniImagePointManager
00759 
00760 
00761 
00762   } // namespace slam
00763 } // namespace jafar
00764 
00765 #endif // SLAM_IMAGE_POINT_MANAGER_HPP
00766 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:28 for Jafar by doxygen 1.7.6.1
LAAS-CNRS