| 226 | } |
| 227 | |
| 228 | std::shared_ptr<CountriesFilesIndexAffiliation::Tree> CountriesFilesIndexAffiliation::BuildIndex( |
| 229 | std::vector<m2::RectD> const & net) |
| 230 | { |
| 231 | ankerl::unordered_dense::map<borders::CountryPolygons const *, std::vector<m2::RectD>> countriesRects; |
| 232 | std::mutex countriesRectsMutex; |
| 233 | std::vector<Value> treeCells; |
| 234 | std::mutex treeCellsMutex; |
| 235 | auto const numThreads = GetPlatform().CpuCores(); |
| 236 | { |
| 237 | base::ComputationalThreadPool pool(numThreads); |
| 238 | for (auto const & rect : net) |
| 239 | { |
| 240 | pool.SubmitWork([&, rect]() |
| 241 | { |
| 242 | std::vector<std::reference_wrapper<borders::CountryPolygons const>> countries; |
| 243 | m_countryPolygonsTree.ForEachCountryInRect(rect, |
| 244 | [&](auto const & country) { countries.emplace_back(country); }); |
| 245 | if (m_haveBordersForWholeWorld && countries.size() == 1) |
| 246 | { |
| 247 | borders::CountryPolygons const & country = countries.front(); |
| 248 | std::lock_guard<std::mutex> lock(countriesRectsMutex); |
| 249 | countriesRects[&country].emplace_back(rect); |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | auto const box = affiliation::MakeBox(rect); |
| 254 | std::vector<std::reference_wrapper<borders::CountryPolygons const>> interCountries; |
| 255 | for (borders::CountryPolygons const & cp : countries) |
| 256 | { |
| 257 | cp.ForAnyPolygon([&](auto const & polygon) |
| 258 | { |
| 259 | if (!boost::geometry::intersects(polygon.Data(), box)) |
| 260 | return false; |
| 261 | interCountries.emplace_back(cp); |
| 262 | return true; |
| 263 | }); |
| 264 | } |
| 265 | if (interCountries.empty()) |
| 266 | return; |
| 267 | if (interCountries.size() == 1) |
| 268 | { |
| 269 | borders::CountryPolygons const & country = interCountries.front(); |
| 270 | std::lock_guard<std::mutex> lock(countriesRectsMutex); |
| 271 | countriesRects[&country].emplace_back(rect); |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | std::lock_guard<std::mutex> lock(treeCellsMutex); |
| 276 | treeCells.emplace_back(box, std::move(interCountries)); |
| 277 | } |
| 278 | } |
| 279 | }); |
| 280 | } |
| 281 | } |
| 282 | { |
| 283 | base::ComputationalThreadPool pool(numThreads); |
| 284 | for (auto & pair : countriesRects) |
| 285 | { |
nothing calls this directly
no test coverage detected