RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
Signature.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#pragma once
29
30#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
31
32#include <pcl/point_types.h>
33#include <opencv2/core/core.hpp>
34#if CV_MAJOR_VERSION < 5
35#include <opencv2/features2d/features2d.hpp>
36#else
37#include <opencv2/features.hpp>
38#endif
39#include <opencv2/imgproc/imgproc.hpp>
40#include <map>
41#include <list>
42#include <vector>
43#include <set>
44
45#include <rtabmap/core/Transform.h>
46#include <rtabmap/core/SensorData.h>
47#include <rtabmap/core/Link.h>
48
49namespace rtabmap
50{
51
83class RTABMAP_CORE_EXPORT Signature
84{
85
86public:
94
112 Signature(int id,
113 int mapId = -1,
114 int weight = 0,
115 double stamp = 0.0,
116 const std::string & label = std::string(),
117 const Transform & pose = Transform(),
118 const Transform & groundTruthPose = Transform(),
119 const SensorData & sensorData = SensorData());
120
132 Signature(const SensorData & data);
133
137 virtual ~Signature();
138
151 float compareTo(const Signature & signature) const;
152
162 bool isBadSignature() const;
163
168 int id() const {return _id;}
169
174 int mapId() const {return _mapId;}
175
189 void setWeight(int weight) {_modified=_modified || _weight!=weight;_weight = weight;}
190
195 int getWeight() const {return _weight;}
196
208 void setLabel(const std::string & label) {_modified=_modified || _label.compare(label)!=0;_label = label;}
209
214 const std::string & getLabel() const {return _label;}
215
220 double getStamp() const {return _stamp;}
221
233 void addLinks(const std::list<Link> & links);
234
247 void addLinks(const std::map<int, Link> & links);
248
263 void addLink(const Link & link);
264
272 bool hasLink(int idTo, Link::Type type = Link::kUndef) const;
273
285 void changeLinkIds(int idFrom, int idTo);
286
295 void removeLinks(bool keepSelfReferringLinks = false);
296
304 void removeLink(int idTo);
305
314
326 void addLandmark(const Link & landmark);
327
332 const std::map<int, Link> & getLandmarks() const {return _landmarks;}
333
338
343 void removeLandmark(int landmarkId);
344
349 void setSaved(bool saved) {_saved = saved;}
350
359 void setModified(bool modified) {_modified = modified; _linksModified = modified;}
360
365 const std::multimap<int, Link> & getLinks() const {return _links;}
366
371 bool isSaved() const {return _saved;}
372
380 bool isModified() const {return _modified || _linksModified;}
381
386 bool isLinksModified() const {return _linksModified;}
387
388 // Visual words management
389
397
409 void changeWordsRef(int oldWordId, int activeWordId);
410
426 void setWords(const std::multimap<int, int> & words, const std::vector<cv::KeyPoint> & keypoints, const std::vector<cv::Point3f> & words3, const cv::Mat & descriptors);
427
436 bool isEnabled() const {return _enabled;}
437
442 void setEnabled(bool enabled) {_enabled = enabled;}
443
452 const std::multimap<int, int> & getWords() const {return _words;}
453
458 const std::vector<cv::KeyPoint> & getWordsKpts() const {return _wordsKpts;}
459
469 int getInvalidWordsCount() const {return _invalidWordsCount;}
470
479 const std::map<int, int> & getWordsChanged() const {return _wordsChanged;}
480
485 const cv::Mat & getWordsDescriptors() const {return _wordsDescriptors;}
486
495 void setWordsDescriptors(const cv::Mat & descriptors);
496
497 // Pose and metric information
498
519 void setPose(const Transform & pose) {_pose = pose;}
520
529 void setGroundTruthPose(const Transform & pose) {_groundTruthPose = pose;}
530
544 void setVelocity(float vx, float vy, float vz, float vroll, float vpitch, float vyaw) {
545 _velocity = std::vector<float>(6,0);
546 _velocity[0]=vx;
547 _velocity[1]=vy;
548 _velocity[2]=vz;
549 _velocity[3]=vroll;
550 _velocity[4]=vpitch;
551 _velocity[5]=vyaw;
552 }
553
562 const std::vector<cv::Point3f> & getWords3() const {return _words3;}
563
569 const Transform & getPose() const {return _pose;}
570
579 cv::Mat getPoseCovariance() const;
580
585 const Transform & getGroundTruthPose() const {return _groundTruthPose;}
586
591 const std::vector<float> & getVelocity() const {return _velocity;}
592
597 SensorData & sensorData() {return _sensorData;}
598
603 const SensorData & sensorData() const {return _sensorData;}
604
614 unsigned long getMemoryUsed(bool withSensorData=true) const;
615
616private:
617 int _id;
618 int _mapId;
619 double _stamp;
620 std::multimap<int, Link> _links;
621 std::map<int, Link> _landmarks;
622 int _weight;
623 std::string _label;
624 bool _saved;
625 bool _modified;
626 bool _linksModified;
627
635 std::multimap<int, int> _words;
636 std::vector<cv::KeyPoint> _wordsKpts;
637 std::vector<cv::Point3f> _words3;
638 cv::Mat _wordsDescriptors;
639 std::map<int, int> _wordsChanged;
640 bool _enabled;
641 int _invalidWordsCount;
642
643 Transform _pose;
644 Transform _groundTruthPose;
645 std::vector<float> _velocity;
646
647 SensorData _sensorData;
648};
649
650} // namespace rtabmap
Container class for all sensor data captured at a specific time.
Definition SensorData.h:97
Represents a node in RTAB-Map's pose graph.
Definition Signature.h:84
unsigned long getMemoryUsed(bool withSensorData=true) const
Computes the memory usage of this signature.
const std::map< int, int > & getWordsChanged() const
Returns the word ID change mapping.
Definition Signature.h:479
void setSaved(bool saved)
Sets whether this signature has been saved to the database.
Definition Signature.h:349
bool isSaved() const
Checks if this signature has been saved to the database.
Definition Signature.h:371
const SensorData & sensorData() const
Returns const access to the sensor data.
Definition Signature.h:603
void changeWordsRef(int oldWordId, int activeWordId)
Changes visual word references from one word ID to another.
void changeLinkIds(int idFrom, int idTo)
Changes all link target IDs from one value to another.
const std::multimap< int, Link > & getLinks() const
Returns all links from this signature.
Definition Signature.h:365
void setVelocity(float vx, float vy, float vz, float vroll, float vpitch, float vyaw)
Sets the velocity of this signature.
Definition Signature.h:544
const cv::Mat & getWordsDescriptors() const
Returns the feature descriptors for visual words.
Definition Signature.h:485
const std::map< int, Link > & getLandmarks() const
Returns all landmark observations.
Definition Signature.h:332
void setModified(bool modified)
Sets the modification flag for this signature.
Definition Signature.h:359
SensorData & sensorData()
Returns mutable access to the sensor data.
Definition Signature.h:597
void setWeight(int weight)
Sets the weight/importance of this signature.
Definition Signature.h:189
int id() const
Returns the signature ID.
Definition Signature.h:168
void removeVirtualLinks()
Removes all virtual links from this signature.
bool isEnabled() const
Checks if this signature is enabled.
Definition Signature.h:436
void addLink(const Link &link)
Adds a single link to this signature.
const std::vector< cv::KeyPoint > & getWordsKpts() const
Returns the keypoints associated with visual words.
Definition Signature.h:458
const Transform & getPose() const
Returns the pose of this signature.
Definition Signature.h:569
void setEnabled(bool enabled)
Sets whether this signature is enabled.
Definition Signature.h:442
const Transform & getGroundTruthPose() const
Returns the ground truth pose.
Definition Signature.h:585
virtual ~Signature()
Virtual destructor.
const std::multimap< int, int > & getWords() const
Returns the visual words map.
Definition Signature.h:452
bool isBadSignature() const
Checks if this signature is considered "bad".
void setWords(const std::multimap< int, int > &words, const std::vector< cv::KeyPoint > &keypoints, const std::vector< cv::Point3f > &words3, const cv::Mat &descriptors)
Sets all visual words for this signature.
void removeLandmark(int landmarkId)
Removes a specific landmark observation.
int getWeight() const
Returns the weight/importance of this signature.
Definition Signature.h:195
void addLandmark(const Link &landmark)
Adds a landmark observation to this signature.
const std::string & getLabel() const
Returns the label/name of this signature.
Definition Signature.h:214
void setWordsDescriptors(const cv::Mat &descriptors)
Sets the feature descriptors for visual words.
void removeLinks(bool keepSelfReferringLinks=false)
Removes all links from this signature.
Signature()
Default constructor.
bool isLinksModified() const
Checks if the links have been modified.
Definition Signature.h:386
Signature(int id, int mapId=-1, int weight=0, double stamp=0.0, const std::string &label=std::string(), const Transform &pose=Transform(), const Transform &groundTruthPose=Transform(), const SensorData &sensorData=SensorData())
Constructor with explicit parameters.
void removeLandmarks()
Removes all landmark observations.
void setLabel(const std::string &label)
Sets a label/name for this signature.
Definition Signature.h:208
void addLinks(const std::list< Link > &links)
Adds multiple links from a list.
void setGroundTruthPose(const Transform &pose)
Sets the ground truth pose for evaluation.
Definition Signature.h:529
double getStamp() const
Returns the timestamp of this signature.
Definition Signature.h:220
void removeAllWords()
Removes all visual words from this signature.
bool isModified() const
Checks if this signature has been modified.
Definition Signature.h:380
const std::vector< cv::Point3f > & getWords3() const
Returns the 3D points of visual words.
Definition Signature.h:562
void removeLink(int idTo)
Removes a specific link to a target signature.
float compareTo(const Signature &signature) const
Compares this signature to another signature.
int getInvalidWordsCount() const
Returns the count of invalid visual words.
Definition Signature.h:469
int mapId() const
Returns the map ID.
Definition Signature.h:174
void setPose(const Transform &pose)
Sets the pose of this signature.
Definition Signature.h:519
bool hasLink(int idTo, Link::Type type=Link::kUndef) const
Checks if this signature has a link to a target signature.
const std::vector< float > & getVelocity() const
Returns the velocity of this signature.
Definition Signature.h:591
Signature(const SensorData &data)
Constructor from sensor data.
void addLinks(const std::map< int, Link > &links)
Adds multiple links from a map.
cv::Mat getPoseCovariance() const
Gets the pose covariance matrix.
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53