BordersData -------------------------------------------------------------------------------------
| 133 | |
| 134 | // BordersData ------------------------------------------------------------------------------------- |
| 135 | void BordersData::Init(std::string const & bordersDir) |
| 136 | { |
| 137 | LOG(LINFO, ("Borders path:", bordersDir)); |
| 138 | |
| 139 | // key - coordinates |
| 140 | // value - {border idx, point idx} |
| 141 | ankerl::unordered_dense::map<int64_t, std::vector<std::pair<size_t, size_t>>> index; |
| 142 | |
| 143 | std::vector<std::string> files; |
| 144 | Platform::GetFilesByExt(bordersDir, kBorderExtension, files); |
| 145 | |
| 146 | LOG(LINFO, ("Start reading data from .poly files.")); |
| 147 | size_t prevIndex = 0; |
| 148 | for (auto const & file : files) |
| 149 | { |
| 150 | auto const fullPath = base::JoinPath(bordersDir, file); |
| 151 | size_t polygonId = 1; |
| 152 | |
| 153 | borders::PolygonsList borders; |
| 154 | borders::LoadBorders(fullPath, borders); |
| 155 | for (auto & region : borders) |
| 156 | { |
| 157 | auto & points = region.MutableData(); |
| 158 | m_duplicatedPointsCount += RemoveDuplicatingPointImpl(points); |
| 159 | CHECK_GREATER(points.size(), 1, (fullPath)); |
| 160 | |
| 161 | // Some mwms have several polygons. For example, for Japan_Kanto_Tokyo that has 2 polygons we |
| 162 | // will write 2 files: |
| 163 | // Japan_Kanto_Tokyo.poly1 |
| 164 | // Japan_Kanto_Tokyo.poly2 |
| 165 | auto const fileCopy = file + std::to_string(polygonId); |
| 166 | |
| 167 | m_indexToPolyFileName[prevIndex] = fileCopy; |
| 168 | m_polyFileNameToIndex[fileCopy] = prevIndex++; |
| 169 | |
| 170 | size_t const borderIdx = m_bordersPolygons.size(); |
| 171 | for (size_t i = 0; i < points.size(); ++i) |
| 172 | index[PointToInt64Obsolete(points[i], kPointCoordBits)].emplace_back(borderIdx, i); |
| 173 | |
| 174 | ++polygonId; |
| 175 | m_bordersPolygons.emplace_back(region.GetRect(), points); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | for (auto const & [_, v] : index) |
| 180 | { |
| 181 | for (size_t i = 0; i < v.size() - 1; ++i) |
| 182 | for (size_t j = i + 1; j < v.size(); ++j) |
| 183 | { |
| 184 | m_bordersPolygons[v[i].first].m_points[v[i].second].AddLink(v[j].first, v[j].second); |
| 185 | m_bordersPolygons[v[j].first].m_points[v[j].second].AddLink(v[i].first, v[i].second); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | LOG(LINFO, ("Removed:", m_duplicatedPointsCount, "from input data.")); |
| 190 | } |
| 191 | |
| 192 | void BordersData::DumpPolyFiles(std::string const & targetDir) |