/** * @brief Convert a trackId to a vector of indexed Matches. * * @param[in] map_tracks: set of tracks with only 2 elements * (image A and image B) in each submapTrack. * @param[in] vec_filterIndex: the track indexes to retrieve. * Only track indexes contained in this filter vector are kept. * @param[out] pvec_index: list of matches * (feature index in image A, feature index in image B). * * @warning The input tracks must be composed of only two images index. * @warning Image index are considered sorted (increasing order). */ static void TracksToIndexedMatches ( const STLMAPTracks & map_tracks, const std::vector<IndexT> & vec_filterIndex, std::vector<IndMatch> * pvec_index ) { std::vector<IndMatch> & vec_indexref = *pvec_index; vec_indexref.clear(); for ( const auto & filter_index : vec_filterIndex ) { // Retrieve the track information from the current index i. auto itF = find_if(map_tracks.begin(), map_tracks.end(), FunctorMapFirstEqual( filter_index ) ) ; // The current track. const submapTrack & map_ref = itF->second; // We have 2 elements for a track. assert(map_ref.size() == 2); const IndexT indexI = (map_ref.begin())->second; const IndexT indexJ = (++map_ref.begin())->second; vec_indexref.emplace_back(indexI, indexJ); } }
/** * @brief Convert a trackId to a vector of indexed Matches. * * @param[in] map_tracks: set of tracks with only 2 elements * (image A and image B) in each submapTrack. * @param[in] vec_filterIndex: the track indexes to retrieve. * Only track indexes contained in this filter vector are kept. * @param[out] pvec_index: list of matches * (feature index in image A, feature index in image B). * * @warning The input tracks must be composed of only two images index. * @warning Image index are considered sorted (increasing order). */ static void TracksToIndexedMatches ( const STLMAPTracks & map_tracks, const std::vector<IndexT> & vec_filterIndex, std::vector<matching::IndMatch> * pvec_index ) { std::vector<matching::IndMatch> & vec_indexref = *pvec_index; vec_indexref.clear(); for ( const auto & id : vec_filterIndex ) { // Retrieve the track information from the current index id. auto itF = find_if( map_tracks.begin(), map_tracks.end(), [id] (const std::pair<uint32_t, submapTrack> & s) { return (id == s.first); } ); // The current track. const submapTrack & map_ref = itF->second; // We have 2 elements for a track. assert(map_ref.size() == 2); const IndexT indexI = (map_ref.begin())->second; const IndexT indexJ = (++map_ref.begin())->second; vec_indexref.emplace_back(indexI, indexJ); } }
/** * @brief Find common tracks between images. * * @param[in] set_imageIndex: set of images we are looking for common tracks * @param[in] map_tracksIn: all tracks of the scene * @param[out] map_tracksOut: output with only the common tracks */ static bool GetTracksInImages ( const std::set<size_t> & set_imageIndex, const STLMAPTracks & map_tracksIn, STLMAPTracks & map_tracksOut ) { map_tracksOut.clear(); // Go along the tracks for ( const auto & iterT : map_tracksIn ) { // Look if the track contains the provided view index & save the point ids submapTrack map_temp; bool bTest = true; for (auto iterIndex = set_imageIndex.begin(); iterIndex != set_imageIndex.end() && bTest; ++iterIndex) { auto iterSearch = iterT.second.find(*iterIndex); if (iterSearch != iterT.second.end()) map_temp[iterSearch->first] = iterSearch->second; else bTest = false; } if (!map_temp.empty() && map_temp.size() == set_imageIndex.size()) map_tracksOut[iterT.first] = std::move(map_temp); } return !map_tracksOut.empty(); }
/// Return the tracksId as a set (sorted increasing) static void GetTracksIdVector( const STLMAPTracks & map_tracks, std::set<size_t> * set_tracksIds) { set_tracksIds->clear(); for (STLMAPTracks::const_iterator iterT = map_tracks.begin(); iterT != map_tracks.end(); ++iterT) { set_tracksIds->insert(iterT->first); } }
/// Return a set containing the image Id considered in the tracks container. static void ImageIdInTracks(const STLMAPTracks & map_tracks, std::set<size_t> & set_imagesId) { for (STLMAPTracks::const_iterator iterT = map_tracks.begin(); iterT != map_tracks.end(); ++iterT) { const submapTrack & map_ref = iterT->second; for (submapTrack::const_iterator iter = map_ref.begin(); iter != map_ref.end(); ++iter) { set_imagesId.insert(iter->first); } } }
/// Return the occurrence of tracks length. static void TracksLength(const STLMAPTracks & map_tracks, std::map<size_t, size_t> & map_Occurence_TrackLength) { for (STLMAPTracks::const_iterator iterT = map_tracks.begin(); iterT != map_tracks.end(); ++iterT) { const size_t trLength = iterT->second.size(); if (map_Occurence_TrackLength.end() == map_Occurence_TrackLength.find(trLength)) { map_Occurence_TrackLength[trLength] = 1; } else { map_Occurence_TrackLength[trLength] += 1; } } }
/// Get feature index PerView and TrackId static bool GetFeatIndexPerViewAndTrackId( const STLMAPTracks & map_tracks, const std::set<size_t> & set_trackId, size_t nImageIndex, std::vector<size_t> * pvec_featIndex) { for (STLMAPTracks::const_iterator iterT = map_tracks.begin(); iterT != map_tracks.end(); ++iterT) { const size_t trackId = iterT->first; if (set_trackId.find(trackId) != set_trackId.end()) { //try to find imageIndex const submapTrack & map_ref = iterT->second; submapTrack::const_iterator iterSearch = map_ref.find(nImageIndex); if (iterSearch != map_ref.end()) { pvec_featIndex->emplace_back(iterSearch->second); } } } return !pvec_featIndex->empty(); }
/// Get feature index PerView and TrackId static bool GetFeatIndexPerViewAndTrackId ( const STLMAPTracks & tracks, const std::set<uint32_t> & track_ids, size_t nImageIndex, std::vector<uint32_t> * feat_ids ) { feat_ids->reserve(tracks.size()); for (const uint32_t & trackId: track_ids) { const auto iterT = tracks.find(trackId); if (iterT != tracks.end()) { // Look if the desired image index exists in the track visibility const auto iterSearch = iterT->second.find(nImageIndex); if (iterSearch != iterT->second.end()) { feat_ids->emplace_back(iterSearch->second); } } } return !feat_ids->empty(); }
/// Export tracks as a map (each entry is a sequence of imageId and featureIndex): /// {TrackIndex => {(imageIndex, featureIndex), ... ,(imageIndex, featureIndex)} void ExportToSTL(STLMAPTracks & map_tracks) { map_tracks.clear(); for (unsigned int k = 0; k < map_node_to_index.size(); ++k) { const auto & feat = map_node_to_index[k]; const unsigned int track_id = uf_tree.m_cc_parent[k]; if ( // ensure never add rejected elements (track marked as invalid) track_id != std::numeric_limits<unsigned int>::max() // ensure never add 1-length track element (it's not a track) && uf_tree.m_cc_size[track_id] > 1 ) { map_tracks[track_id].insert(feat.first); } } }
/** * @brief Find the shared tracks between some images ids. * * @param[in] image_ids: images id to consider * @param[out] tracks: tracks shared by the input images id */ bool GetTracksInImages ( const std::set<uint32_t> & image_ids, STLMAPTracks & tracks ) { tracks.clear(); if (image_ids.empty()) return false; // Collect the shared tracks ids by the views std::set<uint32_t> common_track_ids; { // Compute the intersection of all the track ids of the view's track ids. // 1. Initialize the track_id with the view first tracks // 2. Iteratively collect the common id of the remaining requested view auto image_index_it = image_ids.cbegin(); if (track_ids_per_view_.count(*image_index_it)) { common_track_ids = track_ids_per_view_[*image_index_it]; } bool merged = false; std::advance(image_index_it, 1); while (image_index_it != image_ids.cend()) { if (track_ids_per_view_.count(*image_index_it)) { const auto ids_per_view_it = track_ids_per_view_.find(*image_index_it); const auto & track_ids = ids_per_view_it->second; std::set<uint32_t> tmp; std::set_intersection( common_track_ids.cbegin(), common_track_ids.cend(), track_ids.cbegin(), track_ids.cend(), std::inserter(tmp, tmp.begin())); common_track_ids.swap(tmp); merged = true; } std::advance(image_index_it, 1); } if (image_ids.size() > 1 && !merged) { // If more than one image id is required and no merge operation have been done // we need to reset the common track id common_track_ids.clear(); } } // Collect the selected {img id, feat id} data for the shared track ids for (const auto track_ids_it : common_track_ids) { const auto track_it = tracks_.find(track_ids_it); const auto & track = track_it->second; // Find the corresponding output track and update it submapTrack& trackFeatsOut = tracks[track_it->first]; for (const auto img_index: image_ids) { const auto track_view_info = track.find(img_index); trackFeatsOut[img_index] = track_view_info->second; } } return !tracks.empty(); }