| 845 | } |
| 846 | |
| 847 | void KeyFrame::PreSave(set<KeyFrame*>& spKF,set<MapPoint*>& spMP, set<GeometricCamera*>& spCam) |
| 848 | { |
| 849 | // Save the id of each MapPoint in this KF, there can be null pointer in the vector |
| 850 | mvBackupMapPointsId.clear(); |
| 851 | mvBackupMapPointsId.reserve(N); |
| 852 | for(int i = 0; i < N; ++i) |
| 853 | { |
| 854 | |
| 855 | if(mvpMapPoints[i] && spMP.find(mvpMapPoints[i]) != spMP.end()) // Checks if the element is not null |
| 856 | mvBackupMapPointsId.push_back(mvpMapPoints[i]->mnId); |
| 857 | else // If the element is null his value is -1 because all the id are positives |
| 858 | mvBackupMapPointsId.push_back(-1); |
| 859 | } |
| 860 | // Save the id of each connected KF with it weight |
| 861 | mBackupConnectedKeyFrameIdWeights.clear(); |
| 862 | for(std::map<KeyFrame*,int>::const_iterator it = mConnectedKeyFrameWeights.begin(), end = mConnectedKeyFrameWeights.end(); it != end; ++it) |
| 863 | { |
| 864 | if(spKF.find(it->first) != spKF.end()) |
| 865 | mBackupConnectedKeyFrameIdWeights[it->first->mnId] = it->second; |
| 866 | } |
| 867 | |
| 868 | // Save the parent id |
| 869 | mBackupParentId = -1; |
| 870 | if(mpParent && spKF.find(mpParent) != spKF.end()) |
| 871 | mBackupParentId = mpParent->mnId; |
| 872 | |
| 873 | // Save the id of the childrens KF |
| 874 | mvBackupChildrensId.clear(); |
| 875 | mvBackupChildrensId.reserve(mspChildrens.size()); |
| 876 | for(KeyFrame* pKFi : mspChildrens) |
| 877 | { |
| 878 | if(spKF.find(pKFi) != spKF.end()) |
| 879 | mvBackupChildrensId.push_back(pKFi->mnId); |
| 880 | } |
| 881 | |
| 882 | // Save the id of the loop edge KF |
| 883 | mvBackupLoopEdgesId.clear(); |
| 884 | mvBackupLoopEdgesId.reserve(mspLoopEdges.size()); |
| 885 | for(KeyFrame* pKFi : mspLoopEdges) |
| 886 | { |
| 887 | if(spKF.find(pKFi) != spKF.end()) |
| 888 | mvBackupLoopEdgesId.push_back(pKFi->mnId); |
| 889 | } |
| 890 | |
| 891 | // Save the id of the merge edge KF |
| 892 | mvBackupMergeEdgesId.clear(); |
| 893 | mvBackupMergeEdgesId.reserve(mspMergeEdges.size()); |
| 894 | for(KeyFrame* pKFi : mspMergeEdges) |
| 895 | { |
| 896 | if(spKF.find(pKFi) != spKF.end()) |
| 897 | mvBackupMergeEdgesId.push_back(pKFi->mnId); |
| 898 | } |
| 899 | |
| 900 | //Camera data |
| 901 | mnBackupIdCamera = -1; |
| 902 | if(mpCamera && spCam.find(mpCamera) != spCam.end()) |
| 903 | mnBackupIdCamera = mpCamera->GetId(); |
| 904 | |