SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIMap Class Reference

#include <WAIMap.h>

Public Types

enum  TransformType {
  ROT_X = 0 , ROT_Y , ROT_Z , TRANS_X , TRANS_Y , TRANS_Z ,
  SCALE
}
 

Public Member Functions

 WAIMap (WAIKeyFrameDB *kfDB)
 
 ~WAIMap ()
 
void AddKeyFrame (WAIKeyFrame *pKF)
 
void AddMapPoint (WAIMapPoint *pMP)
 
void EraseMapPoint (WAIMapPoint *pMP)
 
void EraseKeyFrame (WAIKeyFrame *pKF)
 
void SetReferenceMapPoints (const std::vector< WAIMapPoint * > &vpMPs)
 
void InformNewBigChange ()
 
int GetLastBigChangeIdx ()
 
std::vector< WAIKeyFrame * > GetAllKeyFrames ()
 
std::vector< WAIMapPoint * > GetAllMapPoints ()
 
WAIKeyFrameDBGetKeyFrameDB ()
 
long unsigned int MapPointsInMap ()
 
long unsigned int KeyFramesInMap ()
 
long unsigned int GetMaxKFid ()
 
float GetSize ()
 
void clear ()
 
void transform (cv::Mat transform)
 
void rotate (float degVal, int type)
 
void translate (float value, int type)
 
void scale (float value)
 
void applyTransformation (double value, TransformType type)
 
cv::Mat buildTransMat (float &val, int type)
 
cv::Mat buildRotMat (float &valDeg, int type)
 
size_t getSizeOf ()
 
bool isKeyFrameInMap (WAIKeyFrame *pKF)
 
void incNumLoopClosings ()
 
void setNumLoopClosings (int n)
 
int getNumLoopClosings ()
 

Public Attributes

vector< WAIKeyFrame * > mvpKeyFrameOrigins
 
std::mutex mMutexMapUpdate
 
std::mutex mMutexPointCreation
 

Protected Attributes

std::set< WAIMapPoint * > mspMapPoints
 
std::set< WAIKeyFrame * > mspKeyFrames
 
std::vector< WAIKeyFrame * > _deletedKeyFrames
 
WAIKeyFrameDBmKfDB {nullptr}
 
std::vector< WAIMapPoint * > mvpReferenceMapPoints
 
long unsigned int mnMaxKFid
 
int mnBigChangeIdx
 
std::mutex mMutexMap
 
std::mutex _mutexLoopClosings
 
int _numberOfLoopClosings = 0
 
int _numOfKeyframes
 

Detailed Description

Definition at line 51 of file WAIMap.h.

Member Enumeration Documentation

◆ TransformType

Enumerator
ROT_X 
ROT_Y 
ROT_Z 
TRANS_X 
TRANS_Y 
TRANS_Z 
SCALE 

Definition at line 54 of file WAIMap.h.

55  {
56  ROT_X = 0,
57  ROT_Y,
58  ROT_Z,
59  TRANS_X,
60  TRANS_Y,
61  TRANS_Z,
62  SCALE
63  };
@ SCALE
Definition: WAIMap.h:62
@ TRANS_Z
Definition: WAIMap.h:61
@ ROT_Y
Definition: WAIMap.h:57
@ ROT_Z
Definition: WAIMap.h:58
@ TRANS_X
Definition: WAIMap.h:59
@ ROT_X
Definition: WAIMap.h:56
@ TRANS_Y
Definition: WAIMap.h:60

Constructor & Destructor Documentation

◆ WAIMap()

WAIMap::WAIMap ( WAIKeyFrameDB kfDB)

Definition at line 36 of file WAIMap.cpp.

37  : mnMaxKFid(0), mnBigChangeIdx(0)
38 {
39  mKfDB = kfDB;
40 }
int mnBigChangeIdx
Definition: WAIMap.h:123
WAIKeyFrameDB * mKfDB
Definition: WAIMap.h:116
long unsigned int mnMaxKFid
Definition: WAIMap.h:120

◆ ~WAIMap()

WAIMap::~WAIMap ( )

Definition at line 42 of file WAIMap.cpp.

43 {
44  clear();
45  if (mKfDB)
46  delete mKfDB;
47 }
void clear()
Definition: WAIMap.cpp:158

Member Function Documentation

◆ AddKeyFrame()

void WAIMap::AddKeyFrame ( WAIKeyFrame pKF)

Definition at line 49 of file WAIMap.cpp.

50 {
51  unique_lock<mutex> lock(mMutexMap);
52  mspKeyFrames.insert(pKF);
53  if (pKF->mnId > mnMaxKFid)
54  mnMaxKFid = pKF->mnId;
55  //mKfDB->add(pKF);
56 }
long unsigned int mnId
Definition: WAIKeyFrame.h:175
std::mutex mMutexMap
Definition: WAIMap.h:125
std::set< WAIKeyFrame * > mspKeyFrames
Definition: WAIMap.h:114

◆ AddMapPoint()

void WAIMap::AddMapPoint ( WAIMapPoint pMP)

Definition at line 58 of file WAIMap.cpp.

59 {
60  unique_lock<mutex> lock(mMutexMap);
61  mspMapPoints.insert(pMP);
62 }
std::set< WAIMapPoint * > mspMapPoints
Definition: WAIMap.h:113

◆ applyTransformation()

void WAIMap::applyTransformation ( double  value,
TransformType  type 
)

Definition at line 320 of file WAIMap.cpp.

321 {
322  //apply rotation, translation and scale to Keyframe and MapPoint poses
323  cout << "apply transform with value: " << value << endl;
324  switch (type)
325  {
326  case ROT_X:
327  //build different transformation matrices for x,y and z rotation
328  rotate((float)value, 0);
329  break;
330  case ROT_Y:
331  rotate((float)value, 1);
332  break;
333  case ROT_Z:
334  rotate((float)value, 2);
335  break;
336  case TRANS_X:
337  translate((float)value, 0);
338  break;
339  case TRANS_Y:
340  translate((float)value, 1);
341  break;
342  case TRANS_Z:
343  translate((float)value, 2);
344  break;
345  case SCALE:
346  scale((float)value);
347  break;
348  }
349 
350  //compute resulting values for map points
351  for (auto& mp : mspMapPoints)
352  {
353  //mean viewing direction and depth
354  mp->UpdateNormalAndDepth();
355  mp->ComputeDistinctiveDescriptors();
356  }
357 
358 #if 0
359  //update scene objects
360  //exchange all Keyframes (also change name)
361  if (_mapNode)
362  {
363  _mapNode->updateAll(*this);
364  }
365  else
366  {
367  // TODO(jan): handle errors
368  //SL_WARN_MSG("WAIMap: applyTransformation: WAIMapNode is NULL! Cannot update visualization!\n");
369  }
370 #endif
371 }
void rotate(float degVal, int type)
Definition: WAIMap.cpp:242
void scale(float value)
Definition: WAIMap.cpp:295
void translate(float value, int type)
Definition: WAIMap.cpp:271

◆ buildRotMat()

Mat WAIMap::buildRotMat ( float &  valDeg,
int  type 
)

Definition at line 398 of file WAIMap.cpp.

399 {
400  Mat rot = Mat::ones(4, 4, CV_32F);
401 
402  switch (type)
403  {
404  case 0:
405  // Calculate rotation about x axis
406  rot = (Mat_<float>(4, 4) << 1, 0, 0, 0, 0, cos(valDeg), -sin(valDeg), 0, 0, sin(valDeg), cos(valDeg), 0, 0, 0, 0, 1);
407  break;
408 
409  case 1:
410  // Calculate rotation about y axis
411  rot = (Mat_<float>(4, 4) << cos(valDeg), 0, sin(valDeg), 0, 0, 1, 0, 0, -sin(valDeg), 0, cos(valDeg), 0, 0, 0, 0, 1);
412  //invert direction for Y
413  rot = rot.inv();
414  break;
415 
416  case 2:
417  // Calculate rotation about z axis
418  rot = (Mat_<float>(4, 4) << cos(valDeg), -sin(valDeg), 0, 0, sin(valDeg), cos(valDeg), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
419  //invert direction for Z
420  rot = rot.inv();
421  break;
422  }
423 
424  return rot;
425 }

◆ buildTransMat()

Mat WAIMap::buildTransMat ( float &  val,
int  type 
)

!turn sign of y coordinate

!turn sign of z coordinate

Definition at line 374 of file WAIMap.cpp.

375 {
376  Mat trans = cv::Mat::zeros(3, 1, CV_32F);
377  switch (type)
378  {
379  case 0:
380  trans.at<float>(0, 0) = val;
381  break;
382 
383  case 1:
384  //!!turn sign of y coordinate
385  trans.at<float>(1, 0) = -val;
386  break;
387 
388  case 2:
389  //!!turn sign of z coordinate
390  trans.at<float>(2, 0) = -val;
391  break;
392  }
393 
394  return trans;
395 }

◆ clear()

void WAIMap::clear ( )

Definition at line 158 of file WAIMap.cpp.

159 {
160  for (auto* pt : mspMapPoints)
161  {
162  if (pt)
163  delete pt;
164  }
165  for (auto* kf : mspKeyFrames)
166  {
167  if (kf)
168  delete kf;
169  }
170  mspMapPoints.clear();
171  mspKeyFrames.clear();
172  mnMaxKFid = 0;
173  mvpReferenceMapPoints.clear();
174  mvpKeyFrameOrigins.clear();
176  mKfDB->clear();
177 
178 #if 0
179  for (WAIKeyFrame* kf : _deletedKeyFrames)
180  {
181  delete kf;
182  }
183 
184  _deletedKeyFrames.clear();
185 #endif
186 
188  WAIFrame::nNextId = 0;
189 }
static long unsigned int nNextId
Definition: WAIFrame.h:158
AR Keyframe node class.
Definition: WAIKeyFrame.h:60
static long unsigned int nNextId
Definition: WAIKeyFrame.h:174
vector< WAIKeyFrame * > mvpKeyFrameOrigins
Definition: WAIMap.h:88
std::vector< WAIKeyFrame * > _deletedKeyFrames
Definition: WAIMap.h:115
std::vector< WAIMapPoint * > mvpReferenceMapPoints
Definition: WAIMap.h:118
void setNumLoopClosings(int n)
Definition: WAIMap.cpp:469

◆ EraseKeyFrame()

void WAIMap::EraseKeyFrame ( WAIKeyFrame pKF)

Definition at line 74 of file WAIMap.cpp.

75 {
76  unique_lock<mutex> lock(mMutexMap);
77  mspKeyFrames.erase(pKF);
78  mKfDB->erase(pKF);
79 
80  //_deletedKeyFrames.push_back(pKF);
81 
82  // TODO: This only erase the pointer.
83  // Delete the MapPoint
84 }
void erase(WAIKeyFrame *pKF)

◆ EraseMapPoint()

void WAIMap::EraseMapPoint ( WAIMapPoint pMP)

Definition at line 64 of file WAIMap.cpp.

65 {
66  unique_lock<mutex> lock(mMutexMap);
67  mspMapPoints.erase(pMP);
68 
69  // TODO: This only erase the pointer.
70  // Delete the MapPoint
71  //delete pMP;
72 }

◆ GetAllKeyFrames()

std::vector< WAIKeyFrame * > WAIMap::GetAllKeyFrames ( )

Definition at line 104 of file WAIMap.cpp.

105 {
106  unique_lock<mutex> lock(mMutexMap);
107  return vector<WAIKeyFrame*>(mspKeyFrames.begin(), mspKeyFrames.end());
108 }

◆ GetAllMapPoints()

vector< WAIMapPoint * > WAIMap::GetAllMapPoints ( )

Definition at line 110 of file WAIMap.cpp.

111 {
112  unique_lock<mutex> lock(mMutexMap);
113  return vector<WAIMapPoint*>(mspMapPoints.begin(), mspMapPoints.end());
114 }

◆ GetKeyFrameDB()

WAIKeyFrameDB* WAIMap::GetKeyFrameDB ( )
inline

Definition at line 78 of file WAIMap.h.

78 { return mKfDB; }

◆ GetLastBigChangeIdx()

int WAIMap::GetLastBigChangeIdx ( )

Definition at line 98 of file WAIMap.cpp.

99 {
100  unique_lock<mutex> lock(mMutexMap);
101  return mnBigChangeIdx;
102 }

◆ GetMaxKFid()

long unsigned int WAIMap::GetMaxKFid ( )

Definition at line 128 of file WAIMap.cpp.

129 {
130  unique_lock<mutex> lock(mMutexMap);
131  return mnMaxKFid;
132 }

◆ getNumLoopClosings()

int WAIMap::getNumLoopClosings ( )

Definition at line 475 of file WAIMap.cpp.

476 {
477  unique_lock<mutex> lock(_mutexLoopClosings);
478  return _numberOfLoopClosings;
479 }
int _numberOfLoopClosings
Definition: WAIMap.h:128
std::mutex _mutexLoopClosings
Definition: WAIMap.h:127

◆ GetSize()

float WAIMap::GetSize ( )

Definition at line 134 of file WAIMap.cpp.

135 {
136  std::vector<WAIMapPoint*> mpv = GetAllMapPoints();
137  WAI::V3 a = mpv[0]->worldPosVec();
138  WAI::V3 b = a;
139 
140  for (WAIMapPoint* mp : mpv)
141  {
142  WAI::V3 v = mp->worldPosVec();
143  a.x = fmax(v.x, a.x);
144  a.y = fmax(v.y, a.y);
145  a.z = fmax(v.z, a.z);
146 
147  b.x = fmin(v.x, b.x);
148  b.y = fmin(v.y, b.y);
149  b.z = fmin(v.z, b.z);
150  }
151 
152  a = WAI::v3(a.x - b.x, a.y - b.y, a.z - b.z);
153 
154  return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
155 }
std::vector< WAIMapPoint * > GetAllMapPoints()
Definition: WAIMap.cpp:110
V3 v3(float x, float y, float z)
Definition: WAIMath.h:38
float x
Definition: WAIMath.h:33
float z
Definition: WAIMath.h:33
float y
Definition: WAIMath.h:33

◆ getSizeOf()

size_t WAIMap::getSizeOf ( )

Definition at line 427 of file WAIMap.cpp.

428 {
429  size_t size = 0;
430 
431  //size of map points
432  std::size_t sizeOfMapPoints = 0;
433  for (auto mp : mspMapPoints)
434  {
435  sizeOfMapPoints += mp->getSizeOf();
436  }
437 
438  //size of key frames
439  std::size_t sizeOfKeyFrames = 0;
440  for (auto kf : mspKeyFrames)
441  {
442  sizeOfKeyFrames += kf->getSizeOf();
443  }
444 
445  //size of map
446  size += sizeof(*this);
447  size += sizeOfMapPoints;
448  size += sizeOfKeyFrames;
449 
450  //cout << "all map points in MB: " << (double)sizeOfMapPoints / 1048576L << endl;
451  //cout << "all keyframes in MB: " << (double)sizeOfKeyFrames / 1048576L << endl;
452  //cout << "total map size in MB: " << (double)size / 1048576L << endl;
453 
454  return size;
455 }

◆ incNumLoopClosings()

void WAIMap::incNumLoopClosings ( )

Definition at line 463 of file WAIMap.cpp.

464 {
465  unique_lock<mutex> lock(_mutexLoopClosings);
467 }

◆ InformNewBigChange()

void WAIMap::InformNewBigChange ( )

Definition at line 92 of file WAIMap.cpp.

93 {
94  unique_lock<mutex> lock(mMutexMap);
96 }

◆ isKeyFrameInMap()

bool WAIMap::isKeyFrameInMap ( WAIKeyFrame pKF)

Definition at line 457 of file WAIMap.cpp.

458 {
459  bool result = (mspKeyFrames.find(pKF) != mspKeyFrames.end());
460  return result;
461 }

◆ KeyFramesInMap()

long unsigned int WAIMap::KeyFramesInMap ( )

Definition at line 116 of file WAIMap.cpp.

117 {
118  unique_lock<mutex> lock(mMutexMap);
119  return (unsigned int)mspKeyFrames.size();
120 }

◆ MapPointsInMap()

long unsigned int WAIMap::MapPointsInMap ( )

Definition at line 122 of file WAIMap.cpp.

123 {
124  unique_lock<mutex> lock(mMutexMap);
125  return (unsigned int)mspMapPoints.size();
126 }

◆ rotate()

void WAIMap::rotate ( float  degVal,
int  type 
)

Definition at line 242 of file WAIMap.cpp.

243 {
244  //transform to degree
245  float value = degVal * Utils::DEG2RAD;
246 
247  Mat rot = buildRotMat(value, type);
248  cout << "rot: " << rot << endl;
249 
250  //rotate keyframes
251  Mat Twc;
252  for (auto& kf : mspKeyFrames)
253  {
254  //get and rotate
255  Twc = kf->GetPose().inv();
256  Twc = rot * Twc;
257  //set back
258  kf->SetPose(Twc.inv());
259  }
260 
261  //rotate keypoints
262  Mat Pw;
263  Mat rot33 = rot.rowRange(0, 3).colRange(0, 3);
264  for (auto& pt : mspMapPoints)
265  {
266  Pw = rot33 * pt->GetWorldPos();
267  pt->SetWorldPos(rot33 * pt->GetWorldPos());
268  }
269 }
cv::Mat buildRotMat(float &valDeg, int type)
Definition: WAIMap.cpp:398
static const float DEG2RAD
Definition: Utils.h:239

◆ scale()

void WAIMap::scale ( float  value)

Definition at line 295 of file WAIMap.cpp.

296 {
297  for (auto& kf : mspKeyFrames)
298  {
299  //get and translate
300  cv::Mat Tcw = kf->GetPose();
301  std::cout << "Tcw before: " << Tcw << std::endl;
302  Tcw.rowRange(0, 3).col(3) *= value;
303  std::cout << "Tcw after: " << Tcw << std::endl;
304 
305  //make scale matrix
306  //cv::Mat scale = cv::Mat::eye(4, 4, Tcw.type());
307  //scale *= value
308 
309  //set back
310  kf->SetPose(Tcw);
311  }
312 
313  //rotate keypoints
314  for (auto& pt : mspMapPoints)
315  {
316  pt->SetWorldPos(value * pt->GetWorldPos());
317  }
318 }

◆ setNumLoopClosings()

void WAIMap::setNumLoopClosings ( int  n)

Definition at line 469 of file WAIMap.cpp.

470 {
471  unique_lock<mutex> lock(_mutexLoopClosings);
473 }

◆ SetReferenceMapPoints()

void WAIMap::SetReferenceMapPoints ( const std::vector< WAIMapPoint * > &  vpMPs)

Definition at line 86 of file WAIMap.cpp.

87 {
88  unique_lock<mutex> lock(mMutexMap);
89  mvpReferenceMapPoints = vpMPs;
90 }

◆ transform()

void WAIMap::transform ( cv::Mat  transform)

Definition at line 192 of file WAIMap.cpp.

193 {
194  cv::Mat t;
195  cv::transpose(transform, t);
196  cv::Mat s2 = t * transform;
197  float sx, sy, sz;
198  sx = sqrt(s2.at<float>(0, 0));
199  sy = sqrt(s2.at<float>(1, 1));
200  sz = sqrt(s2.at<float>(2, 2));
201 
202  t = transform.clone();
203  t.rowRange(0, 3).col(0) *= 1.0f / sx;
204  t.rowRange(0, 3).col(1) *= 1.0f / sy;
205  t.rowRange(0, 3).col(2) *= 1.0f / sz;
206 
207  Mat Twc;
208  Mat Tcw;
209  for (auto& kf : mspKeyFrames)
210  {
211  //get and rotate
212  Tcw = kf->GetPose();
213  Tcw.at<float>(0, 3) *= sx;
214  Tcw.at<float>(1, 3) *= sy;
215  Tcw.at<float>(2, 3) *= sz;
216  Twc = Tcw.inv();
217  Twc = t * Twc;
218  //set back
219  kf->SetPose(Twc.inv());
220  }
221 
222  int i = 0;
223  //transform keypoints
224  for (auto& pt : mspMapPoints)
225  {
226  cv::Mat p = (cv::Mat_<float>(4, 1) << 0, 0, 0, 1.0f);
227  cv::Mat wp = pt->GetWorldPos();
228  wp.copyTo(p.rowRange(0, 3));
229  p = transform * p;
230  p.rowRange(0, 3).copyTo(wp);
231  pt->SetWorldPos(wp);
232  }
233 
234  for (auto& mp : mspMapPoints)
235  {
236  //mean viewing direction and depth
237  mp->UpdateNormalAndDepth();
238  mp->ComputeDistinctiveDescriptors();
239  }
240 }
void transform(cv::Mat transform)
Definition: WAIMap.cpp:192

◆ translate()

void WAIMap::translate ( float  value,
int  type 
)

Definition at line 271 of file WAIMap.cpp.

272 {
273  Mat trans = buildTransMat(value, type);
274 
275  cout << "trans: " << trans << endl;
276 
277  //rotate keyframes
278  Mat Twc;
279  for (auto& kf : mspKeyFrames)
280  {
281  //get and translate
282  cv::Mat Twc = kf->GetPose().inv();
283  Twc.rowRange(0, 3).col(3) += trans;
284  //set back
285  kf->SetPose(Twc.inv());
286  }
287 
288  //rotate keypoints
289  for (auto& pt : mspMapPoints)
290  {
291  pt->SetWorldPos(trans + pt->GetWorldPos());
292  }
293 }
cv::Mat buildTransMat(float &val, int type)
Definition: WAIMap.cpp:374

Member Data Documentation

◆ _deletedKeyFrames

std::vector<WAIKeyFrame*> WAIMap::_deletedKeyFrames
protected

Definition at line 115 of file WAIMap.h.

◆ _mutexLoopClosings

std::mutex WAIMap::_mutexLoopClosings
protected

Definition at line 127 of file WAIMap.h.

◆ _numberOfLoopClosings

int WAIMap::_numberOfLoopClosings = 0
protected

Definition at line 128 of file WAIMap.h.

◆ _numOfKeyframes

int WAIMap::_numOfKeyframes
protected

Definition at line 129 of file WAIMap.h.

◆ mKfDB

WAIKeyFrameDB* WAIMap::mKfDB {nullptr}
protected

Definition at line 116 of file WAIMap.h.

◆ mMutexMap

std::mutex WAIMap::mMutexMap
protected

Definition at line 125 of file WAIMap.h.

◆ mMutexMapUpdate

std::mutex WAIMap::mMutexMapUpdate

Definition at line 90 of file WAIMap.h.

◆ mMutexPointCreation

std::mutex WAIMap::mMutexPointCreation

Definition at line 93 of file WAIMap.h.

◆ mnBigChangeIdx

int WAIMap::mnBigChangeIdx
protected

Definition at line 123 of file WAIMap.h.

◆ mnMaxKFid

long unsigned int WAIMap::mnMaxKFid
protected

Definition at line 120 of file WAIMap.h.

◆ mspKeyFrames

std::set<WAIKeyFrame*> WAIMap::mspKeyFrames
protected

Definition at line 114 of file WAIMap.h.

◆ mspMapPoints

std::set<WAIMapPoint*> WAIMap::mspMapPoints
protected

Definition at line 113 of file WAIMap.h.

◆ mvpKeyFrameOrigins

vector<WAIKeyFrame*> WAIMap::mvpKeyFrameOrigins

Definition at line 88 of file WAIMap.h.

◆ mvpReferenceMapPoints

std::vector<WAIMapPoint*> WAIMap::mvpReferenceMapPoints
protected

Definition at line 118 of file WAIMap.h.


The documentation for this class was generated from the following files: