50 class FrameConnection;
52 typedef size_t NodeId;
53 typedef size_t WordId;
54 typedef float WordValue;
55 typedef std::map<WordId,float> BowVector;
56 typedef std::map<WordId,std::vector<unsigned int> > FeatureVector;
57 typedef Point3d Point3Type;
58 typedef Point3ub ColorType;
59 typedef size_t PointID;
60 typedef size_t FrameID;
61 typedef std::shared_ptr<GObject> GObjectPtr;
62 typedef std::shared_ptr<MapFrame> FramePtr;
63 typedef std::shared_ptr<MapPoint> PointPtr;
64 typedef std::shared_ptr<FrameConnection> FrameConnectionPtr;
65 typedef std::shared_ptr<Map> MapPtr;
66 typedef std::shared_ptr<SLAM> SLAMPtr;
67 typedef std::vector<FramePtr> FrameArray;
68 typedef std::vector<PointPtr> PointArray;
69 typedef std::map<GSLAM::FrameID, FrameConnectionPtr > FrameConnectionMap;
70 typedef std::vector<std::pair<FrameID,size_t> > MapPointObsVec;
73 typedef GSLAM::SLAMPtr (*funcCreateSLAMInstance)();
74 typedef std::mutex MutexRW;
75 typedef std::unique_lock<std::mutex> ReadMutex;
76 typedef ReadMutex WriteMutex;
78 enum ImageChannelFlags{
87 IMAGE_RGBD =IMAGE_BGRA|IMAGE_DEPTH,
99 IMAGE_THUMBNAIL =1<<12
106 virtual std::string type()
const{
return "GObject";}
107 virtual void call(
const std::string& command,
void* arg=NULL){}
108 virtual void draw(){}
109 virtual bool toByteArray(std::vector<uchar>& array){
return false;}
110 virtual bool fromByteArray(std::vector<uchar>& array){
return false;}
118 virtual void handle(
const GObjectPtr& obj){}
119 void handle(
GObject* obj){handle(GObjectPtr(obj));}
125 : pt(0, 0), size(0), angle(-1), response(0), octave(0), class_id(-1) {}
127 KeyPoint(
Point2f _pt,
float _size,
float _angle = -1,
float _response = 0,
128 int _octave = 0,
int _class_id = -1)
134 class_id(_class_id) {}
136 KeyPoint(
float x,
float y,
float _size,
float _angle = -1,
137 float _response = 0,
int _octave = 0,
int _class_id = -1)
143 class_id(_class_id) {}
145 #ifdef __OPENCV_FEATURES_2D_HPP__ 146 explicit KeyPoint(
const cv::KeyPoint& kp)
147 : pt(kp.pt.x, kp.pt.y),
150 response(kp.response),
152 class_id(kp.class_id) {}
154 operator cv::KeyPoint()
const {
155 return cv::KeyPoint(pt.x, pt.y, size, angle, response, octave, class_id);
164 size_t hash()
const {
165 size_t _Val = 2166136261U, scale = 16777619U;
168 _Val = (scale * _Val) ^ u.u;
170 _Val = (scale * _Val) ^ u.u;
172 _Val = (scale * _Val) ^ u.u;
174 _Val = (scale * _Val) ^ u.u;
176 _Val = (scale * _Val) ^ u.u;
177 _Val = (scale * _Val) ^ ((size_t)octave);
178 _Val = (scale * _Val) ^ ((
size_t)class_id);
203 MapPoint(
const PointID&
id,
const Point3Type& position=Point3Type(0,0,0));
205 virtual std::string type()
const{
return "InvalidPoint";}
206 const PointID& id()
const{
return _id;}
208 Point3Type getPose()
const;
209 void setPose(
const Point3Type& pt);
211 virtual Point3Type getNormal()
const{
return Point3Type(0,0,0);}
212 virtual bool setNormal(
const Point3Type& nVec){
return false;}
214 virtual ColorType getColor()
const{
return ColorType(255,255,255);}
215 virtual bool setColor(
const ColorType& color)
const{
return false;}
217 virtual bool setDescriptor(
const GImage& des){
return false;}
220 virtual bool isPoseRelative()
const{
return false;}
221 virtual FrameID refKeyframeID()
const{
return 0;}
222 virtual FramePtr refKeyframe()
const{
return FramePtr();}
224 virtual int observationNum()
const{
return -1;}
225 virtual bool getObservations(std::map<FrameID,size_t>& obs)
const{
return false;}
226 virtual MapPointObsVec getObservations()
const{
228 std::map<FrameID,size_t> m;
230 r.insert(r.end(),m.begin(),m.end());
233 virtual bool addObservation(GSLAM::FrameID frId,
size_t featId){
return false;}
234 virtual bool eraseObservation(GSLAM::FrameID frId){
return false;}
235 virtual bool clearObservation(){
return false;}
238 mutable MutexRW _mutexPt;
249 virtual std::string type()
const{
return "FrameConnection";}
250 virtual int matchesNum(){
return 0;}
252 virtual bool getMatches(std::vector<std::pair<int,int> >& matches){
return false;}
253 std::vector<std::pair<int,int> > getMatches(){std::vector<std::pair<int,int> > r;getMatches(r);
return r;}
254 virtual bool getChild2Parent(
GSLAM::SIM3& sim3){
return false;}
255 virtual bool getChild2Parent(
GSLAM::SE3& se3){
return false;}
256 virtual bool getInformation(
double* info){
return false;}
258 virtual bool setMatches(std::vector<std::pair<int,int> >& matches){
return false;}
259 virtual bool setChild2Parent(
GSLAM::SIM3& sim3){
return false;}
260 virtual bool setChild2Parent(
GSLAM::SE3& se3){
return false;}
261 virtual bool setInformation(
double* info){
return false;}
267 MapFrame(
const FrameID&
id=0,
const double& timestamp=0);
269 virtual std::string type()
const{
return "InvalidFrame";}
272 const PointID& id()
const{
return _id;}
273 const double& timestamp()
const{
return _timestamp;}
276 void setPose(
const SE3& pose);
277 void setPose(
const SIM3& pose);
279 bool getPose(
SIM3& pose)
const;
280 SIM3 getPoseScale()
const;
283 virtual int cameraNum()
const{
return 0;}
284 virtual SE3 getCameraPose(
int idx=0)
const{
return SE3();}
285 virtual int imageChannels(
int idx=0)
const{
return IMAGE_BGRA;}
287 virtual GImage getImage(
int idx=0,
int channalMask=IMAGE_UNDEFINED){
return GImage();}
288 virtual bool setImage(
const GImage& img,
int idx=0,
int channalMask=IMAGE_UNDEFINED){
return false;}
289 virtual bool setCamera(
const Camera& camera,
int idx=0){
return false;}
292 virtual int getIMUNum()
const{
return 0;}
293 virtual SE3 getIMUPose(
int idx=0)
const{
return SE3();}
294 virtual bool getAcceleration(
Point3d& acc,
int idx=0)
const{
return false;}
295 virtual bool getAngularVelocity(
Point3d& angularV,
int idx=0)
const{
return false;}
296 virtual bool getMagnetic(
Point3d& mag,
int idx=0)
const{
return false;}
297 virtual bool getAccelerationNoise(
Point3d& accN,
int idx=0)
const{
return false;}
298 virtual bool getAngularVNoise(
Point3d& angularVN,
int idx=0)
const{
return false;}
299 virtual bool getPitchYawRoll(
Point3d& pyr,
int idx=0)
const{
return false;}
300 virtual bool getPYRSigma(
Point3d& pyrSigma,
int idx=0)
const{
return false;}
302 virtual int getGPSNum()
const{
return 0;}
303 virtual SE3 getGPSPose(
int idx=0)
const{
return SE3();}
304 virtual bool getGPSLLA(
Point3d& LonLatAlt,
int idx=0)
const{
return false;}
305 virtual bool getGPSLLASigma(
Point3d& llaSigma,
int idx=0)
const{
return false;}
306 virtual bool getGPSECEF(
Point3d& xyz,
int idx=0)
const{
return false;}
307 virtual bool getHeight2Ground(
Point2d& height,
int idx=0)
const{
return false;}
310 virtual int keyPointNum()
const{
return 0;}
311 virtual bool setKeyPoints(
const std::vector<GSLAM::KeyPoint>& keypoints,
313 virtual bool getKeyPoint(
int idx,
Point2f& pt)
const{
return false;}
314 virtual bool getKeyPoint(
int idx,
KeyPoint &pt)
const{
return false;}
315 virtual bool getKeyPoints(std::vector<Point2f>& keypoints)
const{
return false;}
316 virtual bool getKeyPoints(std::vector<KeyPoint>& keypoints)
const{
return false;}
317 virtual std::vector<KeyPoint> getKeyPoints()
const{std::vector<KeyPoint> r;getKeyPoints(r);
return r;}
318 virtual bool getKeyPointColor(
int idx,ColorType& color){
return false;}
319 virtual bool getKeyPointIDepthInfo(
int idx,
Point2d& idepth){
return false;}
320 virtual PointID getKeyPointObserve(
int idx){
return 0;}
321 virtual GImage getDescriptor(
int idx=-1)
const{
return GImage();}
322 virtual bool getBoWVector(BowVector& bowvec)
const{
return false;}
323 virtual BowVector getBoWVector()
const{BowVector r;getBoWVector(r);
return r;}
324 virtual bool getFeatureVector(FeatureVector& featvec)
const{
return false;}
325 virtual FeatureVector getFeatureVector()
const{FeatureVector r;getFeatureVector(r);
return r;}
326 virtual std::vector<size_t> getFeaturesInArea(
const float& x,
const float& y,
327 const float& r,
bool precisely=
true)
const{
return std::vector<size_t>();}
330 virtual int observationNum()
const{
return 0;}
331 virtual bool getObservations(std::map<GSLAM::PointID,size_t>& obs)
const{
return false;}
332 virtual std::map<GSLAM::PointID,size_t> getObservations()
const{std::map<GSLAM::PointID,size_t> r;getObservations(r);
return r;}
333 virtual bool addObservation(
const GSLAM::PointPtr& pt,
size_t featId,
bool add2Point=
false){
return false;}
334 virtual bool eraseObservation(
const GSLAM::PointPtr& pt,
bool erasePoint=
false){
return false;}
335 virtual bool clearObservations(){
return false;}
337 virtual std::shared_ptr<FrameConnection> getParent(GSLAM::FrameID parentId)
const{
return std::shared_ptr<FrameConnection>();}
338 virtual std::shared_ptr<FrameConnection> getChild(GSLAM::FrameID childId)
const{
return std::shared_ptr<FrameConnection>();}
339 virtual bool getParents(FrameConnectionMap& parents)
const{
return false;}
340 virtual bool getChildren(FrameConnectionMap& children)
const{
return false;}
341 FrameConnectionMap getParents()
const{FrameConnectionMap r;getParents(r);
return r;}
342 FrameConnectionMap getChildren()
const{FrameConnectionMap r;getChildren(r);
return r;}
343 virtual bool addParent(GSLAM::FrameID parentId,
const std::shared_ptr<FrameConnection>& parent){
return false;}
344 virtual bool addChildren(GSLAM::FrameID childId,
const std::shared_ptr<FrameConnection>& child){
return false;}
345 virtual bool eraseParent(GSLAM::FrameID parentId){
return false;}
346 virtual bool eraseChild(GSLAM::FrameID childId){
return false;}
347 virtual bool clearParents(){
return false;}
348 virtual bool clearChildren(){
return false;}
351 virtual double getMedianDepth(){
return getPoseScale().get_scale();}
353 static std::string channelTypeString(
const int channels);
354 std::string channelString(
int idx=0)
const{
return channelTypeString(imageChannels(idx));}
361 mutable MutexRW _mutexPose;
370 :frameId(frameId_),score(score_){}
376 return l.score<r.score;
379 typedef std::vector<LoopCandidate> LoopCandidates;
385 virtual std::string type()
const{
return "LoopDetector";}
386 virtual bool insertMapFrame(
const FramePtr& frame){
return false;}
387 virtual bool eraseMapFrame(
const FrameID& frame){
return false;}
388 virtual bool obtainCandidates(
const FramePtr& frame,LoopCandidates& candidates){
return false;}
389 virtual LoopCandidates obtainCandidates(
const FramePtr& frame){
391 obtainCandidates(frame,c);
395 typedef std::shared_ptr<LoopDetector> LoopDetectorPtr;
402 virtual std::string type()
const{
return "InvalidMap";}
406 virtual bool insertMapFrame(
const FramePtr& frame){
return false;}
407 virtual bool eraseMapPoint(
const PointID& pointId){
return false;}
408 virtual bool eraseMapFrame(
const FrameID& frameId){
return false;}
409 virtual void clear(){}
411 virtual std::size_t frameNum()
const{
return 0;}
412 virtual std::size_t pointNum()
const{
return 0;}
414 virtual FramePtr getFrame(
const FrameID&
id)
const{
return FramePtr();}
415 virtual PointPtr getPoint(
const PointID&
id)
const{
return PointPtr();}
416 virtual bool getFrames(FrameArray& frames)
const{
return false;}
417 virtual bool getPoints(PointArray& points)
const{
return false;}
418 virtual FrameArray getFrames()
const{FrameArray r;getFrames(r);
return r;}
419 virtual PointArray getPoints()
const{PointArray r;getPoints(r);
return r;}
421 virtual bool setLoopDetector(
const LoopDetectorPtr& loopdetector){
return false;}
422 virtual LoopDetectorPtr getLoopDetector()
const{
return LoopDetectorPtr();}
423 virtual bool obtainCandidates(
const FramePtr& frame,LoopCandidates& candidates){
return false;}
424 virtual LoopCandidates obtainCandidates(
const FramePtr& frame){
426 obtainCandidates(frame,c);
431 virtual bool save(std::string path)
const{
return false;}
432 virtual bool load(std::string path){
return false;}
436 FrameID getFid(){
return _frId++;}
443 typedef std::shared_ptr<Map> MapPtr;
446 inline MapPoint::MapPoint(
const PointID&
id,
const Point3Type& position)
447 :_id(
id),_pt(position)
451 inline Point3Type MapPoint::getPose()
const 453 ReadMutex lock(_mutexPt);
457 inline void MapPoint::setPose(
const Point3Type& pt)
459 WriteMutex lock(_mutexPt);
463 inline MapFrame::MapFrame(
const FrameID&
id,
const double& timestamp)
464 :_id(
id),_timestamp(timestamp)
468 inline SE3 MapFrame::getPose()
const 470 ReadMutex lock(_mutexPose);
471 return _c2w.get_se3();
474 inline SIM3 MapFrame::getPoseScale()
const 476 ReadMutex lock(_mutexPose);
480 inline bool MapFrame::getPose(
SIM3& pose)
const 486 inline void MapFrame::setPose(
const SE3& pose)
488 WriteMutex lock(_mutexPose);
493 inline void MapFrame::setPose(
const SIM3& pose)
495 WriteMutex lock(_mutexPose);
499 inline std::string MapFrame::channelTypeString(
const int channels)
501 static std::string _type[32]={
"RGBA",
"BGRA",
"GRAY",
"DEPTH",
"IDEPTH",
"GRE",
"NIR",
"RED",
"REG",
"LIDAR",
"SONAR",
"SAR",
"THUMBNAIL"};
504 return "IMAGE_UNDEFINED";
508 for(uint i=0; i<
sizeof(channels)*8;i++)
510 int j = channels & (0x00000001<<i);
513 type+=(type.empty()?
"":
"|")+_type[i];
521 inline Map::Map():_ptId(1),_frId(1)
int class_id
object class (if the keypoints need to be clustered by an object they belong to)
Definition: Map.h:193
Point2f pt
coordinates of the keypoints
Definition: Map.h:182
PointID getPid()
0 is reserved for INVALID
Definition: Map.h:435
The GImage class is a tiny implementation of image for removing dependency of opencv.
Definition: GImage.h:160
int octave
octave (pyramid layer) from which the keypoint has been extracted
Definition: Map.h:191
The MapPoint class.
Definition: Map.h:200
virtual bool insertMapPoint(const PointPtr &point)
MapFrame & MapPoint interface.
Definition: Map.h:405
float size
diameter of the meaningful keypoint neighborhood
Definition: Map.h:183
Represent a three-dimensional similarity transformation,7 degrees of freedom a rotation: R (Here is r...
Definition: SIM3.h:57
float angle
computed orientation of the keypoint (-1 if not applicable); < it's in [0,360) degrees and measured r...
Definition: Map.h:185
Represent a three-dimensional Euclidean transformation (a rotation and a translation).
Definition: SE3.h:69
virtual bool save(std::string path) const
Save or load the map from/to the file.
Definition: Map.h:431
float response
the response by which the most strong keypoints have been selected. Can be used for the further sorti...
Definition: Map.h:188