SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIMapPoint.h
Go to the documentation of this file.
1 /**
2  * \file WAIMapPoint.h
3  * \authors Michael Goettlicher
4  * \date October 2017
5 // Codestyle: https://github.com/cpvrlab/SLProject/wiki/Coding-Style-Guidelines
6  * \authors Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8 */
9 
10 #ifndef WAIMAPPOINT_H
11 #define WAIMAPPOINT_H
12 
13 #include <WAIHelper.h>
14 #include <WAIMap.h>
15 #include <map>
16 #include <mutex>
17 #include <vector>
18 
19 #include <opencv2/core/core.hpp>
20 
21 #include <WAIMath.h>
22 
23 class WAIKeyFrame;
24 class WAIFrame;
25 class WAIMap;
26 //-----------------------------------------------------------------------------
27 //!
28 /*!
29  */
30 
31 #define TRACK_REF_FRAME 0
32 #define FUSE_TARGET_KF 1
33 #define FUSE_CANDIDATE_KF 2
34 #define BA_LOCAL_KF 3
35 #define BA_FIXED_KF 4
36 #define BA_GLOBAL_KF 5
37 #define LOOP_POINT_KF 6
38 
40 {
41 public:
42  //!constructor used during map loading
43  WAIMapPoint(int id, const cv::Mat& Pos, bool fixMp);
44  WAIMapPoint(const cv::Mat& Pos, WAIKeyFrame* pRefKF);
45 
46  //ghm1: getters for scene object position initialization
47  WAI::V3 worldPosVec();
48  WAI::V3 normalVec();
49 
50  void worldPosVec(WAI::V3);
51 
52  void SetWorldPos(const cv::Mat& Pos);
53  cv::Mat GetWorldPos();
54 
55  cv::Mat GetNormal();
56  void SetNormal(const cv::Mat& normal);
57  WAIKeyFrame* GetReferenceKeyFrame();
58 
59  std::map<WAIKeyFrame*, size_t> GetObservations();
60  int Observations();
61 
62  void AddObservation(WAIKeyFrame* pKF, size_t idx);
63  void EraseObservation(WAIKeyFrame* pKF);
64 
65  int GetIndexInKeyFrame(WAIKeyFrame* pKF);
66  bool IsInKeyFrame(WAIKeyFrame* pKF);
67 
68  void SetBadFlag();
69  bool isBad();
70 
71  void Replace(WAIMapPoint* pMP);
72  WAIMapPoint* GetReplaced();
73 
74  void IncreaseVisible(int n = 1);
75  void IncreaseFound(int n = 1);
76  float GetFoundRatio();
77 
78  void ComputeDistinctiveDescriptors();
79  cv::Mat GetDescriptor();
80  void SetDescriptor(const cv::Mat& descriptor);
81 
82  void UpdateNormalAndDepth();
83 
84  float GetMinDistanceInvariance();
85  float GetMaxDistanceInvariance();
86  int PredictScale(const float& currentDist, WAIKeyFrame* pF);
87  int PredictScale(const float& currentDist, WAIFrame* pF);
88 
89  //ghm1: used for map IO
90  WAIKeyFrame* refKf() const { return mpRefKF; }
91  void refKf(WAIKeyFrame* refKf) { mpRefKF = refKf; }
92 
94  {
95  RefKfSource_None = 0,
96  RefKfSource_Constructor = 1,
97  RefKfSource_EraseObservation = 2
98  };
99 
100  RefKfSource refKfSource = RefKfSource_None;
101 
102  size_t getSizeOfCvMat(const cv::Mat& mat);
103  size_t getSizeOf();
104 
105  bool isFixed() const { return _fixed; }
106  bool loadedFromMap() { return _loadedFromMap; }
107 
108  long unsigned int mnId = -1;
109  //ghm1: this keeps track of the highest used id, to never use the same id again
110  static long unsigned int nNextId;
111  long int mnFirstKFid;
112  int nObs = 0;
113 
114  // Variables used by the tracking
115  //ghm1: projection point
116  float mTrackProjX = 0.0f;
117  float mTrackProjY = 0.0f;
118 
119  //ghm1: flags, if the map point is in frustum of the current frame
120  bool mbTrackInView = false;
121  int mnTrackScaleLevel = 0;
122  float mTrackViewCos = 0.0f;
123  //long unsigned int mnTrackReferenceForFrame = 0;
124  long unsigned int mnLastFrameSeen = 0;
125 
126  // Variables used by local mapping
127  //long unsigned int mnBALocalForKF;
128  int mnMarker[7];
129 
130  // Variables used by loop closing
131  //long unsigned int mnLoopPointForKF;
132  long unsigned int mnCorrectedByKF;
133  long unsigned int mnCorrectedReference;
134  cv::Mat mPosGBA;
135  //long unsigned int mnBAGlobalForKF;
136 
137  static std::mutex mGlobalMutex;
138  static std::mutex mMutexMapPointCreation;
139 
140  float GetMaxDistance();
141  float GetMinDistance();
142 
143  void SetMaxDistance(float maxDist);
144  void SetMinDistance(float minDist);
145 
146 protected:
147  //flags if fixed, then
148  bool _fixed = false;
149  //flags if loaded from map
150  bool _loadedFromMap = false;
151 
152  //open cv coordinate representation: z-axis points to principlal point,
153  // x-axis to the right and y-axis down
154  cv::Mat mWorldPos;
155 
156  // Keyframes observing the point and associated index in keyframe
157  std::map<WAIKeyFrame*, size_t> mObservations;
158 
159  // Mean viewing direction
160  cv::Mat mNormalVector;
161 
162  // Best descriptor to fast matching
163  cv::Mat mDescriptor;
164 
165  // Reference KeyFrame
166  WAIKeyFrame* mpRefKF = NULL;
167 
168  // Tracking counters
169  int mnVisible = 0;
170  int mnFound = 0;
171 
172  // Bad flag (we do not currently erase MapPoint from memory)
173  bool mbBad = false;
175 
176  // Scale invariance distances
177  float mfMinDistance = 0.f;
178  float mfMaxDistance = 0.f;
179 
180  std::mutex mMutexPos;
181  std::mutex mMutexFeatures;
182 };
183 
184 #endif // !WAIMAPPOINT_H
#define WAI_API
Definition: WAIHelper.h:36
AR Keyframe node class.
Definition: WAIKeyFrame.h:60
Definition: WAIMap.h:52
cv::Mat mWorldPos
Definition: WAIMapPoint.h:154
std::mutex mMutexFeatures
Definition: WAIMapPoint.h:181
bool isFixed() const
Definition: WAIMapPoint.h:105
std::map< WAIKeyFrame *, size_t > mObservations
Definition: WAIMapPoint.h:157
static long unsigned int nNextId
Definition: WAIMapPoint.h:110
cv::Mat mDescriptor
Definition: WAIMapPoint.h:163
cv::Mat mNormalVector
Definition: WAIMapPoint.h:160
long unsigned int mnCorrectedReference
Definition: WAIMapPoint.h:133
std::mutex mMutexPos
Definition: WAIMapPoint.h:180
bool loadedFromMap()
Definition: WAIMapPoint.h:106
long int mnFirstKFid
Definition: WAIMapPoint.h:111
static std::mutex mGlobalMutex
Definition: WAIMapPoint.h:137
cv::Mat mPosGBA
Definition: WAIMapPoint.h:134
WAIMapPoint * mpReplaced
Definition: WAIMapPoint.h:174
static std::mutex mMutexMapPointCreation
Definition: WAIMapPoint.h:138
void refKf(WAIKeyFrame *refKf)
Definition: WAIMapPoint.h:91
WAIKeyFrame * refKf() const
Definition: WAIMapPoint.h:90
long unsigned int mnCorrectedByKF
Definition: WAIMapPoint.h:132