From 604c61976f4ae07bc8640252b6e3f50a4d2f67db Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:06:04 +0100 Subject: [PATCH] feat(editor): the downloads of the aerial photo look after themselves: the area grown at its edge, the failures told and tried again, 4K zoomed in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The download area grows by itself where the camera or the laying comes within a tile of its edge: the tiles of 5 x 5 around them added to its tiles, as one outline along the grid with its holes filled, now and then (5 s apart at least) and not past 1600 tiles; the status line tells it, and the limit once. The area is saved with the scenery as before. A tile which failed is tried again later and later, up to 5 min apart, and never given up for good, around the camera and in the area alike. The ones failed are outlined red in the view, and the status bar tells how many with the reason in plain words (no connection, the server didn't answer, ...) in place of the code of WinHTTP, and Retry (Ponów) at once. The 4K photos (6 cm/px) of the tiles next to the camera come by themselves with the view zoomed in to 15 cm a pixel, and go again past 25 cm, within the limits on the 4K downloads as they were; the area is put into the cache in the products of the setting alone. --- application/editormode.cpp | 127 ++++++++++++++++++++++++++++++++++ application/editormode.h | 11 +++ application/editoruilayer.cpp | 2 + application/editoruilayer.h | 3 + editor/editorOrthophoto.cpp | 77 +++++++++++++++++++-- editor/editorOrthophoto.hpp | 13 ++++ lang/editor_pl.po | 57 +++++++++++++++ 7 files changed, 283 insertions(+), 7 deletions(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index 42c9ecf28..ff1742edf 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -633,6 +633,7 @@ editor_mode::editor_mode() { road_select(nullptr); ground_sources(m_orthophoto); ui()->set_base_layers([this]() { render_base_layers(); }); + ui()->set_status_extra([this]() { render_orthophoto_status(); }); editor_track::observe(this); } @@ -1647,6 +1648,8 @@ bool editor_mode::update() m_ortho_resident = resident; m_ortho_waiting = waiting; steps.step("terrain"); + orthophoto_zoom(); + area_grow(); m_orthophoto.update(Camera.Pos); steps.step("orthophoto"); update_wms_layers(); @@ -1658,6 +1661,7 @@ bool editor_mode::update() auto *background{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())}; background->PushClipRect(ImVec2(editor_ui::view_min().x, editor_ui::view_min().y), ImVec2(editor_ui::view_max().x, editor_ui::view_max().y), true); draw_orthophoto(); + draw_orthophoto_failures(); draw_nmt_pending(); area_update(); draw_download_area(); @@ -2870,6 +2874,8 @@ void editor_mode::render_orthophoto_ui() changed = true; persist = true; } + if (false == config.hires) + ImGui::TextDisabled("%s", STR_C("With the view zoomed in to 15 cm a pixel they come by themselves next to the camera")); if (ImGui::IsItemHovered()) ImGui::SetTooltip(STR_C("4096 px tiles (~6 cm/px) from the high-resolution orthophoto, for the tiles around the camera.\n" "Areas it doesn't cover use the standard imagery. Each 4K tile takes ~85 MB of video memory.")); @@ -2913,6 +2919,127 @@ void editor_mode::draw_orthophoto() (*layer)->draw(projection, Camera.Pos, io.DisplaySize.x, io.DisplaySize.y); } +double editor_mode::view_metres_per_pixel() const +{ + auto const &io{ImGui::GetIO()}; + if (io.DisplaySize.y <= 0.0f) + return 0.0; + if (Global.EditorOrtho) + return 2.0 * static_cast(Global.EditorOrthoExtent) / io.DisplaySize.y; + // in the 3d view the ground under the camera, as far below it as the terrain or the photo there is + double ground{static_cast(m_orthophoto.settings().height)}; + if (double height; EditorTerrain.height_at(Camera.Pos.x, Camera.Pos.z, height)) + ground = height; + auto const above{Camera.Pos.y - ground}; + if (above <= 0.0) + return 0.0; + return above * 2.0 * std::tan(glm::radians(Global.FieldOfView / Global.ZoomFactor) * 0.5) / io.DisplaySize.y; +} + +void editor_mode::orthophoto_zoom() +{ + // the 4K photos of the tiles around the camera by themselves once the view shows the ground at 15 cm a pixel or finer; asked of the + // service as the setting for them asks, the few tiles next to the camera, a few at a time + auto const wanted{m_orthophoto.enabled() && photo_rules::hires_wanted(view_metres_per_pixel(), m_orthophoto.zoom_hires())}; + if (wanted != m_orthophoto.zoom_hires()) + { + m_orthophoto.zoom_hires(wanted); + WriteLog(format("Editor: the 4K photos around the camera %s, the view at %.3f m a pixel", wanted ? "on" : "off", view_metres_per_pixel())); + } +} + +void editor_mode::area_grow() +{ + // the area is carried along where the photo is looked at or the tracks are laid, now and then: the tiles added go to the disk + // cache in the background, a few at a time, as the rest of the area + auto const now{ImGui::GetTime()}; + if (now - m_area_grow_time < 5.0 || m_area_drawing.active || m_orthophoto.area().empty() || (false == m_orthophoto.enabled() && false == m_lay.active)) + return; + auto const &config{m_orthophoto.settings()}; + if (config.north == 0.0 && config.east == 0.0) + return; + std::vector points{{Camera.Pos.x, Camera.Pos.z}}; + if (m_lay.active) + { + points.emplace_back(m_lay.mouse.x, m_lay.mouse.z); + if (false == m_lay.points.empty()) + points.emplace_back(m_lay.points.back().x, m_lay.points.back().z); + } + std::size_t constexpr limit{1600}; // tiles of 256 m: about 105 sq km + for (auto const &point : points) + { + auto const grown{photo_rules::grow_area(m_orthophoto.area(), m_orthophoto.to_puwg(point), editor_orthophoto::tile_size, 1, 2, limit)}; + if (grown.limited) + { + if (false == m_area_grow_limited) + { + m_area_grow_limited = true; + m_area_grow_time = now; + ui()->set_status(format(STR_C("Photo: the download area is at its limit of %zu tiles; draw it again where it's needed, in Map > Orthophoto settings..."), limit)); + } + return; + } + if (grown.polygon.empty()) + continue; + m_area_grow_time = now; + m_orthophoto.area(grown.polygon); + WriteLog(format("Editor: the download area grown by %zu tiles at %.0f %.0f, %zu in all", grown.added, point.x, point.y, grown.total)); + ui()->set_status(format(STR_P("Photo: the download area grown by %zu tile at its edge, %zu in all", "Photo: the download area grown by %zu tiles at its edge, %zu in all", grown.added), grown.added, grown.total)); + return; + } +} + +void editor_mode::draw_orthophoto_failures() const +{ + if (false == m_orthophoto.enabled()) + return; + auto const failed{m_orthophoto.failed()}; + if (failed.empty()) + return; + // the tiles which failed outlined in red, with a cross over them: there's no photo there yet, it's tried again by itself + screen_projection const projection; + auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())}; + auto const height{static_cast(m_orthophoto.settings().height)}; + auto const colour{IM_COL32(240, 70, 60, 210)}; + std::size_t drawn{0}; + for (auto const &[low, high] : failed) + { + if (++drawn > 400) + break; + glm::dvec3 const corners[]{{low.x, height, low.y}, {high.x, height, low.y}, {high.x, height, high.y}, {low.x, height, high.y}}; + for (int i = 0; i < 4; ++i) + projection.line(drawlist, corners[i], corners[(i + 1) % 4], colour, 2.0f); + projection.line(drawlist, corners[0], corners[2], (colour & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 110), 1.5f); + projection.line(drawlist, corners[1], corners[3], (colour & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 110), 1.5f); + } +} + +void editor_mode::render_orthophoto_status() +{ + // in the status bar, after the status: the tiles which failed, why, and the button trying them again at once + if (false == m_orthophoto.enabled()) + return; + auto const stats{m_orthophoto.stats()}; + auto const count{static_cast(stats.failed + stats.area_failed)}; + if (count == 0) + return; + ImGui::SameLine(0.0f, ImGui::GetFontSize()); + auto text{format(STR_P("Photos: %zu tile not downloaded", "Photos: %zu tiles not downloaded", count), count)}; + if (auto const reason{m_orthophoto.last_failure()}; false == reason.empty()) + text += std::string{" ("} + STR(reason) + ")"; + ImGui::TextColored(ImVec4(1.0f, 0.55f, 0.35f, 1.0f), "%s", text.c_str()); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", STR_C("They're marked red in the view and tried again by themselves, later and later, up to 5 min apart")); + ImGui::SameLine(); + ImGui::TextDisabled("%s", "\xc2\xb7"); + ImGui::SameLine(); + if (ImGui::SmallButton(STR_C("Retry##photos"))) + { + m_orthophoto.retry_failed(); + orthophoto_hurry(); + } +} + void editor_mode::draw_ortho_compass() const { if (false == Global.EditorOrtho) diff --git a/application/editormode.h b/application/editormode.h index 18d33b33b..ddac0564d 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -919,6 +919,17 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool m_orthophoto_chosen{false}; // the user turns the orthophoto on or off: kept with the editor, for the scenery void choose_orthophoto(bool const On); + // the 4K photos by themselves while the view is zoomed in to 15 cm a pixel; the m a pixel of the view, the top view's or of the + // ground under the camera + void orthophoto_zoom(); + double view_metres_per_pixel() const; + // the download area carried along where the camera or the laying comes near its edge, told in the status line + void area_grow(); + double m_area_grow_time{-100.0}; + bool m_area_grow_limited{false}; + // the tiles of the photo which failed: marked red in the view, counted in the status bar with the button trying them again + void draw_orthophoto_failures() const; + void render_orthophoto_status(); int m_orthophoto_frame{-10}; bool orthophoto_settings_open() const; // view menu: the top view, the lanes of the roads, the structure gauge, the environment diff --git a/application/editoruilayer.cpp b/application/editoruilayer.cpp index 35bc83045..57fec257e 100644 --- a/application/editoruilayer.cpp +++ b/application/editoruilayer.cpp @@ -659,6 +659,8 @@ void editor_ui::render_() else ImGui::TextUnformatted(m_layerspanel.status.c_str()); } + if (m_statusextra) + m_statusextra(); if (m_node != nullptr) { auto const name{m_node->name().empty() ? std::string{STR_C("(no name)")} : m_node->name()}; diff --git a/application/editoruilayer.h b/application/editoruilayer.h index a6bbbf6ec..0f90060d1 100644 --- a/application/editoruilayer.h +++ b/application/editoruilayer.h @@ -196,6 +196,8 @@ class editor_ui : public ui_layer // what the cursor tells while it's shown, and the status line; for the expectations of the self-test std::string refusal_shown() const; std::string const &status_line() const { return m_layerspanel.status; } + // what the mode draws in the status bar after the status, a lasting state with a button of its own + void set_status_extra(std::function Renderer) { m_statusextra = std::move(Renderer); } private: // methods @@ -251,6 +253,7 @@ class editor_ui : public ui_layer double m_refusaltime{-100.0}; bool m_refusalnotice{false}; // a warning rather than a refusal double m_statustime{-100.0}; + std::function m_statusextra; int m_savequeued{0}; // the frame of a save asked for from a field being typed in bool m_tooloptionsopen{true}; bool m_inspectoropen{true}; diff --git a/editor/editorOrthophoto.cpp b/editor/editorOrthophoto.cpp index 4f41cf81b..35caa78cb 100644 --- a/editor/editorOrthophoto.cpp +++ b/editor/editorOrthophoto.cpp @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include "editor/editorOrthophoto.hpp" #include "editor/editorHttp.hpp" #include "editor/editorGeometry.hpp" +#include "editor/editorPhotoRules.hpp" #include "editor/editorRecords.hpp" #include "rendering/renderer.h" @@ -860,6 +861,7 @@ void editor_orthophoto::restart_prefetch() m_prefetch = std::move(keys); m_prefetch_next = 0; m_prefetch_failed.clear(); + m_prefetch_retry.clear(); m_prefetch_cached.clear(); m_prefetch_source = source{m_config.year, m_config.hires, m_config.service, m_config.layers}; ++m_prefetch_generation; @@ -978,10 +980,39 @@ void editor_orthophoto::retry_failed() for (auto const &key : m_prefetch_failed) m_prefetch.push_back(key); m_prefetch_failed.clear(); + m_prefetch_retry.clear(); + m_last_error.clear(); } m_wakeup.notify_all(); } +std::vector> editor_orthophoto::failed() const +{ + std::vector> result; + if (false == m_enabled) + return result; + std::set keys; + for (auto const &[key, t] : m_tiles) + if (t.failures > 0 && t.level == 0 && false == t.empty) + keys.insert(key); + { + std::lock_guard lock(m_mutex); + keys.insert(m_prefetch_failed.begin(), m_prefetch_failed.end()); + } + for (auto const &key : keys) + { + glm::dvec2 const corner = tile_corner(key); + result.emplace_back(corner - glm::dvec2{tile_size}, corner); + } + return result; +} + +std::string editor_orthophoto::last_failure() const +{ + std::lock_guard lock(m_mutex); + return m_last_error.empty() ? std::string{} : photo_rules::failure_reason(m_last_error); +} + editor_orthophoto::statistics editor_orthophoto::stats() const { statistics out; @@ -1088,7 +1119,7 @@ void editor_orthophoto::schedule(tile_key const &Key, tile &Tile, int Level, std { std::lock_guard lock(m_mutex); m_queue.erase(std::remove_if(m_queue.begin(), m_queue.end(), [&](job const &Job) { return Job.key == Key; }), m_queue.end()); - m_queue.push_back(job{Key, Level, Alpha, source{m_config.year, m_config.hires, m_config.service, m_config.layers}, m_generation.load()}); + m_queue.push_back(job{Key, Level, Alpha, source{m_config.year, m_config.hires || m_zoom_hires, m_config.service, m_config.layers}, m_generation.load()}); } Tile.requested = Level; Tile.requested_alpha = Alpha; @@ -1117,8 +1148,9 @@ std::size_t editor_orthophoto::apply(result &Result, double Now) { if (current) { + // tried again later and later, never given up: the service comes back, or the connection does ++t.failures; - t.retry_at = (t.failures >= 5) ? std::numeric_limits::max() : Now + std::min(120.0, 5.0 * std::pow(2.0, t.failures - 1)); + t.retry_at = Now + photo_rules::retry_delay(t.failures); } return 0; } @@ -1592,11 +1624,24 @@ void editor_orthophoto::update(glm::dvec3 const &Camera) return; tile_key const centre = camera_tile(Camera); - if (centre != m_camera_tile) { - m_camera_tile = centre; std::lock_guard lock(m_mutex); - m_focus = centre; + if (centre != m_camera_tile) + { + m_camera_tile = centre; + m_focus = centre; + } + // the tiles of the area which failed, tried again once their time comes + bool again{false}; + for (auto it = m_prefetch_retry.begin(); it != m_prefetch_retry.end(); ++it) + if (it->second.second <= now && m_prefetch_failed.erase(it->first) > 0) + { + m_prefetch.push_back(it->first); + it->second.second = std::numeric_limits::max(); + again = true; + } + if (again) + m_wakeup.notify_all(); } int const radius = m_config.radius; auto const distance = [&](tile_key const &Key) { return std::max(std::abs(Key.first - centre.first), std::abs(Key.second - centre.second)); }; @@ -1650,7 +1695,7 @@ void editor_orthophoto::update(glm::dvec3 const &Camera) tile &t = m_tiles[key]; if (!in_service_area(key.first, key.second)) t.empty = true; - int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), m_config.hires)); + int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), m_config.hires || m_zoom_hires)); if (t.empty || (t.level == level && t.alpha == m_alpha) || (t.requested == level && t.requested_alpha == m_alpha) || now < t.retry_at) continue; schedule(key, t, level, m_alpha); @@ -1761,9 +1806,20 @@ void editor_orthophoto::worker() if (prefetchgeneration == m_prefetch_generation) { if (ok) + { m_prefetch_cached.insert(*prefetch); + m_prefetch_retry.erase(*prefetch); + } else + { + // tried again later and later, up to 5 min apart, never given up m_prefetch_failed.insert(*prefetch); + auto &retry{m_prefetch_retry[*prefetch]}; + ++retry.first; + retry.second = steady_seconds() + photo_rules::retry_delay(retry.first); + if (error != "cancelled") + m_last_error = error; + } } continue; } @@ -1794,7 +1850,14 @@ void editor_orthophoto::worker() if (m_stop) return; if (!out.ok && error != "superseded") + { ErrorLog(std::string("Editor orthophoto: tile ") + std::to_string(current.key.second) + "_" + std::to_string(current.key.first) + " failed: " + error); + if (error != "cancelled") + { + std::lock_guard lock(m_mutex); + m_last_error = error; + } + } if (out.ok && current.alpha < 255) for (std::size_t i = 3; i < picture.rgba.size(); i += 4) picture.rgba[i] = static_cast((picture.rgba[i] * current.alpha + 127u) / 255u); @@ -1975,7 +2038,7 @@ bool editor_orthophoto::hurry_tile(tile_key const &Key, int const Distance) t.empty = true; if (t.empty) return false; - auto const level{first_level(t, level_for(Distance, m_config.hires))}; + auto const level{first_level(t, level_for(Distance, m_config.hires || m_zoom_hires))}; t.retry_at = 0.0; if (t.level == level && t.alpha == m_alpha) return false; // already shown as it should be diff --git a/editor/editorOrthophoto.hpp b/editor/editorOrthophoto.hpp index b56052e7e..b6b1f2c8b 100644 --- a/editor/editorOrthophoto.hpp +++ b/editor/editorOrthophoto.hpp @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. #include #include #include +#include #include #include #include @@ -122,6 +123,14 @@ class editor_orthophoto // being laid out at the height of the layer; elsewhere it lies on whatever ground there is, or on the guess, as without it using coming_query = std::function; void coming_source(coming_query Query) { m_coming = std::move(Query); } + // the 4K photos asked for around the camera by themselves, the view zoomed in (see photo_rules::hires_wanted), besides the setting + // for them; the download area is put into the cache in the products of the setting alone + void zoom_hires(bool const Hires) { m_zoom_hires = Hires; } + bool zoom_hires() const { return m_zoom_hires; } + // the tiles around the camera, and the ones of the area, which failed and wait to be tried again: their rectangles (x, z) + std::vector> failed() const; + // why the last download that failed did, in plain words (an English message, see photo_rules::failure_reason); empty: none failed + std::string last_failure() const; // the area the imagery is downloaded in, a polygon of PUWG 1992 (easting, northing): its tiles go to the disk cache in the // background, the products the settings ask for, and no tile outside it is asked for around the camera. Empty: no area, the // tiles around the camera as before @@ -292,6 +301,7 @@ class editor_orthophoto height_query m_height; height_query m_guess; coming_query m_coming; + bool m_zoom_hires{false}; scene::basic_region *m_region{nullptr}; // region the scene geometry was put into std::multimap m_free_chunks; // geometry chunks by capacity, reused between tiles // the scene opacity is baked into the textures, which means reading the tiles again; applied once the value settles @@ -316,7 +326,10 @@ class editor_orthophoto std::vector m_prefetch; std::size_t m_prefetch_next{0}; std::set m_prefetch_failed; + // of the ones which failed, how many times they did and when they're tried again + std::map> m_prefetch_retry; std::set m_prefetch_cached; + std::string m_last_error; // the last failure, as the service or the connection told it bool m_prefetch_paused{false}; source m_prefetch_source; std::uint32_t m_prefetch_generation{0}; diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 96cf504cf..c5c75b459 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -15380,3 +15380,60 @@ msgstr "Zdjęcie: ułożone według //$g pliku scenerii; zapamiętany wcześniej msgid "Opened again, the scenery is laid out by //$g of its file" msgstr "Po ponownym otwarciu sceneria będzie ułożona według //$g swojego pliku" + +msgid "With the view zoomed in to 15 cm a pixel they come by themselves next to the camera" +msgstr "Przy zbliżeniu widoku do 15 cm na piksel włączają się same przy kamerze" + +msgid "Photo: the download area is at its limit of %zu tiles; draw it again where it's needed, in Map > Orthophoto settings..." +msgstr "Zdjęcie: obszar pobierania doszedł do limitu %zu kafli; narysuj go na nowo tam, gdzie trzeba, w Mapa > Ustawienia ortofotomapy..." + +msgid "Photo: the download area grown by %zu tile at its edge, %zu in all" +msgid_plural "Photo: the download area grown by %zu tiles at its edge, %zu in all" +msgstr[0] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafel, razem %zu" +msgstr[1] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafle, razem %zu" +msgstr[2] "Zdjęcie: obszar pobierania powiększony przy krawędzi o %zu kafli, razem %zu" + +msgid "Photos: %zu tile not downloaded" +msgid_plural "Photos: %zu tiles not downloaded" +msgstr[0] "Zdjęcia: %zu kafla nie pobrano" +msgstr[1] "Zdjęcia: %zu kafli nie pobrano" +msgstr[2] "Zdjęcia: %zu kafli nie pobrano" + +msgid "They're marked red in the view and tried again by themselves, later and later, up to 5 min apart" +msgstr "Są zaznaczone w widoku na czerwono i ponawiane same, coraz rzadziej, najwyżej co 5 min" + +msgid "no connection to the internet: the name of the server isn't found" +msgstr "brak połączenia z internetem: nie znaleziono nazwy serwera" + +msgid "the server didn't answer in time" +msgstr "serwer nie odpowiedział na czas" + +msgid "the server can't be reached" +msgstr "nie można połączyć się z serwerem" + +msgid "the secure connection to the server failed" +msgstr "nie udało się nawiązać bezpiecznego połączenia z serwerem" + +msgid "the server is busy or out of order" +msgstr "serwer jest przeciążony albo nie działa" + +msgid "the server has no photo of the place" +msgstr "serwer nie ma zdjęcia tego miejsca" + +msgid "the server refused the request" +msgstr "serwer odrzucił żądanie" + +msgid "the server sent an error in place of the photo" +msgstr "serwer przysłał błąd zamiast zdjęcia" + +msgid "the photo came damaged" +msgstr "zdjęcie przyszło uszkodzone" + +msgid "the photo came too large" +msgstr "zdjęcie przyszło za duże" + +msgid "the download failed" +msgstr "pobieranie się nie udało" + +msgid "Retry##photos" +msgstr "Ponów##photos"