32 #include <opencv2/highgui/highgui.hpp> 57 const std::string & label,
107 for(std::list<Link>::const_iterator iter = links.begin(); iter!=links.end(); ++iter)
114 for(std::map<int, Link>::const_iterator iter = links.begin(); iter!=links.end(); ++iter)
125 _links.insert(std::make_pair(link.
to(), link));
137 for(std::multimap<int, Link>::const_iterator iter=
_links.begin(); iter!=
_links.end(); ++iter)
139 if(type == iter->second.type())
147 for(std::multimap<int, Link>::const_iterator iter=
_links.find(idTo); iter!=
_links.end() && iter->first == idTo; ++iter)
149 if(type == iter->second.type())
160 std::multimap<int, Link>::iterator iter =
_links.find(idFrom);
161 while(iter !=
_links.end() && iter->first == idFrom)
163 Link link = iter->second;
166 _links.insert(std::make_pair(idTo, link));
168 UDEBUG(
"(%d) neighbor ids changed from %d to %d",
_id, idFrom, idTo);
174 size_t sizeBefore =
_links.size();
175 if(keepSelfReferringLinks)
177 for(std::multimap<int, Link>::iterator iter =
_links.begin(); iter !=
_links.end();)
179 if(iter->second.from() == iter->second.to())
193 if(
_links.size() != sizeBefore)
199 int count = (int)
_links.erase(idTo);
202 UDEBUG(
"Removed link %d from %d", idTo, this->
id());
209 for(std::multimap<int, Link>::iterator iter=
_links.begin(); iter!=
_links.end();)
224 float similarity = 0.0f;
225 const std::multimap<int, int> & words = s.
getWords();
229 std::list<std::pair<int, std::pair<int, int> > > pairs;
234 similarity = float(pairs.size()) /
float(totalWords);
254 _wordsChanged.insert(std::make_pair(oldWordId, activeWordId));
255 for(std::list<int>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
257 _words.insert(std::pair<int, int>(activeWordId, (*iter)));
263 const std::vector<cv::KeyPoint> & keypoints,
264 const std::vector<cv::Point3f> & points,
265 const cv::Mat & descriptors)
267 UASSERT_MSG(descriptors.empty() || descriptors.rows == (int)words.size(),
uFormat(
"words=%d, descriptors=%d", (
int)words.size(), descriptors.rows).c_str());
268 UASSERT_MSG(points.empty() || points.size() == words.size(),
uFormat(
"words=%d, points=%d", (
int)words.size(), (int)points.size()).c_str());
269 UASSERT_MSG(keypoints.empty() || keypoints.size() == words.size(),
uFormat(
"words=%d, descriptors=%d", (
int)words.size(), (int)keypoints.size()).c_str());
270 UASSERT(words.empty() || !keypoints.empty() || !points.empty() || !descriptors.empty());
273 for(std::multimap<int, int>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
280 UASSERT_MSG(iter->second >=0 && iter->second < (
int)words.size(),
uFormat(
"iter->second=%d words.size()=%d", iter->second, (
int)words.size()).c_str());
306 if(descriptors.empty())
326 cv::Mat covariance = cv::Mat::eye(6,6,CV_64FC1);
329 for(std::multimap<int, Link>::const_iterator iter =
_links.begin(); iter!=
_links.end(); ++iter)
331 if(iter->second.kNeighbor)
334 if(iter->second.to() < iter->second.from())
336 covariance = iter->second.infMatrix().inv();
348 total +=
_words.size() * (
sizeof(int)*2+
sizeof(std::multimap<int, cv::KeyPoint>::iterator)) +
sizeof(std::multimap<int, cv::KeyPoint>);
349 total +=
_wordsKpts.size() *
sizeof(cv::KeyPoint) +
sizeof(std::vector<cv::KeyPoint>);
350 total +=
_words3.size() *
sizeof(cv::Point3f) +
sizeof(std::vector<cv::Point3f>);
352 total +=
_wordsChanged.size() * (
sizeof(int)*2+
sizeof(std::map<int, int>::iterator)) +
sizeof(std::map<int, int>);
359 total +=
_velocity.size() *
sizeof(float);
360 total +=
_links.size() * (
sizeof(int) +
sizeof(
Transform) + 12 *
sizeof(float) +
sizeof(cv::Mat) + 36 *
sizeof(double)+
sizeof(std::multimap<int, Link>::iterator)) +
sizeof(std::multimap<int, Link>);
361 total +=
_landmarks.size() * (
sizeof(int) +
sizeof(
Transform) + 12 *
sizeof(float) +
sizeof(cv::Mat) + 36 *
sizeof(double)+
sizeof(std::map<int, Link>::iterator)) +
sizeof(std::map<int, Link>);
void changeWordsRef(int oldWordId, int activeWordId)
int getInvalidWordsCount() const
cv::Mat _wordsDescriptors
void removeVirtualLinks()
std::map< int, Link > _landmarks
unsigned long getMemoryUsed() const
std::vector< float > _velocity
double rotVariance(bool minimum=true) const
#define UASSERT(condition)
std::vector< cv::Point3f > _words3
Transform _groundTruthPose
std::vector< cv::KeyPoint > _wordsKpts
void removeLinks(bool keepSelfReferringLinks=false)
const std::multimap< int, int > & getWords() const
#define UASSERT_MSG(condition, msg_str)
std::multimap< int, int > _words
static int findPairs(const std::map< int, T > &wordsA, const std::map< int, T > &wordsB, std::list< std::pair< int, std::pair< T, T > > > &pairs, bool ignoreNegativeIds=true)
void setWordsDescriptors(const cv::Mat &descriptors)
std::multimap< int, Link > _links
float compareTo(const Signature &signature) const
double transVariance(bool minimum=true) const
void addLinks(const std::list< Link > &links)
std::vector< V > uValues(const std::multimap< K, V > &mm)
SensorData & sensorData()
void setWords(const std::multimap< int, int > &words, const std::vector< cv::KeyPoint > &keypoints, const std::vector< cv::Point3f > &words3, const cv::Mat &descriptors)
bool hasLink(int idTo, Link::Type type=Link::kUndef) const
void addLink(const Link &link)
unsigned long getMemoryUsed(bool withSensorData=true) const
void removeLink(int idTo)
bool isBadSignature() const
void changeLinkIds(int idFrom, int idTo)
std::string UTILITE_EXP uFormat(const char *fmt,...)
cv::Mat getPoseCovariance() const
std::map< int, int > _wordsChanged