diff --git a/application/editormode.cpp b/application/editormode.cpp index 45d5689c5..3cfaa89bc 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -2587,6 +2587,7 @@ void editor_mode::load_orthophoto_settings() // the scenery's own line: whether the photo is on, the wizard writes it on, and the origin the editor wrote along std::optional scenery_on; std::optional marked_origin; + bool marked_aligned{false}; m_orthophoto_mark.clear(); if (auto const marked{scene::Layers.empty() ? std::vector{} : scene::Layers.marked(scene::layer_handle{1}, "//$o")}; false == marked.empty()) { @@ -2598,12 +2599,15 @@ void editor_mode::load_orthophoto_settings() scenery_on = on; if (mark.north != 0.0 || mark.east != 0.0) marked_origin = glm::dvec2{mark.north, mark.east}; + marked_aligned = mark.aligned; } } - // //$g of the scenery file first: an origin the editor remembers for a scenery of the same name made elsewhere doesn't move it - auto const origin{photo_rules::choose_origin(m_georeference ? std::optional{m_georeference_origin} : std::nullopt, marked_origin, remembered)}; + // //$g of the scenery file first: an origin the editor remembers for a scenery of the same name made elsewhere doesn't move it. One + // aligned by hand in the editor, //$o says so, goes before it + auto const origin{photo_rules::choose_origin(m_georeference ? std::optional{m_georeference_origin} : std::nullopt, marked_origin, remembered, marked_aligned)}; config.north = origin.origin.x; config.east = origin.origin.y; + config.aligned = marked_aligned && origin.from == photo_rules::origin_source::mark; m_georeference_differs = origin.differs > photo_rules::origin_tolerance ? origin.differs : 0.0; if (m_georeference_differs > 0.0) { @@ -2712,6 +2716,8 @@ void editor_mode::render_orthophoto_ui() { config.north = m_orthophoto_origin_edit.x; config.east = m_orthophoto_origin_edit.y; + // aligned by hand: kept so in //$o, which //$g of the scenery file doesn't override when the scenery is opened again + config.aligned = true; changed = true; persist = true; } @@ -2721,14 +2727,16 @@ void editor_mode::render_orthophoto_ui() ImGui::TextDisabled(STR_C("in the scenery file: Y (easting) %.0f m, X (northing) %.0f m"), m_georeference_origin.y, m_georeference_origin.x); if (config.north != m_georeference_origin.x || config.east != m_georeference_origin.y) { - // //$g goes first when the scenery is opened: an origin typed here is for this session - ImGui::TextColored(ImVec4(1.0f, 0.75f, 0.2f, 1.0f), "%s", STR_C("Opened again, the scenery is laid out by //$g of its file")); + // //$g goes first when the scenery is opened, unless the origin was aligned here by hand, which //$o keeps + if (false == config.aligned) + ImGui::TextColored(ImVec4(1.0f, 0.75f, 0.2f, 1.0f), "%s", STR_C("Opened again, the scenery is laid out by //$g of its file")); if (ImGui::SmallButton(STR_C("Use it"))) { m_orthophoto_origin_edit.x = m_georeference_origin.x; config.north = m_orthophoto_origin_edit.x; m_orthophoto_origin_edit.y = m_georeference_origin.y; config.east = m_orthophoto_origin_edit.y; + config.aligned = false; changed = true; persist = true; } @@ -2949,7 +2957,8 @@ double editor_mode::view_metres_per_pixel() const 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 + // service as the setting for them asks, the tile under the camera alone (the setting for them takes the 3 x 3 around it), so the zoom + // doesn't take some 0.75 GB of the memory of the graphics card by itself auto const wanted{m_orthophoto.enabled() && photo_rules::hires_wanted(view_metres_per_pixel(), m_orthophoto.zoom_hires())}; if (wanted != m_orthophoto.zoom_hires()) { diff --git a/editor/editorOrthophoto.cpp b/editor/editorOrthophoto.cpp index ac6b43383..05a30bc7b 100644 --- a/editor/editorOrthophoto.cpp +++ b/editor/editorOrthophoto.cpp @@ -762,12 +762,12 @@ bool editor_orthophoto::owns(gfx::geometry_handle const &Geometry) // the line of the scenery and its format: editor_records::orthophoto_line() and read_orthophoto() std::string editor_orthophoto::mark(config const &Config, bool const Enabled, bool const Origin) { - return editor_records::orthophoto_line(Enabled, Origin, Config.north, Config.east); + return editor_records::orthophoto_line(Enabled, Origin, Config.north, Config.east, Config.aligned); } bool editor_orthophoto::read_mark(std::string const &Text, config &Config, bool &Enabled) { - return editor_records::read_orthophoto(Text, Enabled, Config.north, Config.east); + return editor_records::read_orthophoto(Text, Enabled, Config.north, Config.east, &Config.aligned); } void editor_orthophoto::enabled(bool State) @@ -1044,11 +1044,11 @@ bool editor_orthophoto::outside_area(tile_key const &Key) const return false == m_area.empty() && 0 == m_area_tiles.count(Key); } -int editor_orthophoto::level_for(int Distance, bool Hires) +int editor_orthophoto::level_for(int Distance, int HiresReach) { // coarser imagery further away keeps the memory use of large radii in check - if (Distance <= 1) - return Hires ? hires_pixels : standard_pixels; + if (Distance <= HiresReach) + return hires_pixels; if (Distance <= 3) return standard_pixels; if (Distance <= 6) @@ -1056,6 +1056,13 @@ int editor_orthophoto::level_for(int Distance, bool Hires) return standard_pixels / 4; } +int editor_orthophoto::hires_reach() const +{ + if (m_config.hires) + return 1; + return m_zoom_hires ? 0 : -1; +} + editor_orthophoto::tile_key editor_orthophoto::camera_tile(glm::dvec3 const &Camera) const { double const east = m_config.east - Camera.x; @@ -1692,7 +1699,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 || m_zoom_hires)); + int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), hires_reach())); 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); @@ -2036,7 +2043,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 || m_zoom_hires))}; + auto const level{first_level(t, level_for(Distance, hires_reach()))}; 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 2a138d77a..7309a45ff 100644 --- a/editor/editorOrthophoto.hpp +++ b/editor/editorOrthophoto.hpp @@ -56,6 +56,7 @@ class editor_orthophoto { double north{0.0}; // PUWG 1992 X (northing) of the scenery origin double east{0.0}; // PUWG 1992 Y (easting) of the scenery origin + bool aligned{false}; // the origin aligned by hand in the editor: //$o says so, and //$g of the scenery file doesn't override it int radius{2}; // tiles loaded around the camera tile (Chebyshev distance) float height{0.0f}; // world Y of the layer (with drape: only where no ground was found) float opacity{0.6f}; // 0..1 @@ -261,7 +262,10 @@ class editor_orthophoto bool scene_dirty{true}; // the shape needs to be rebuilt }; - static int level_for(int Distance, bool Hires); + static int level_for(int Distance, int HiresReach); + // how many tiles away from the camera the 4K photos reach: 1 with the setting for them, the 3 x 3 tiles around it; 0 by the zoom + // alone, the tile under the camera, about 85 MB of the memory of the graphics card rather than 0.75 GB; -1 none + int hires_reach() const; // the level a tile is asked for at first: a tile showing nothing yet takes the standard image before the 4K one static int first_level(tile const &Tile, int Level); // the tile is outside the download area set, which then has no imagery asked for it diff --git a/editor/editorPhotoRules.cpp b/editor/editorPhotoRules.cpp index 9837fc8ce..67b092b50 100644 --- a/editor/editorPhotoRules.cpp +++ b/editor/editorPhotoRules.cpp @@ -138,9 +138,15 @@ std::vector outline_of(std::set const &Squares, double const } // namespace -origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered) +origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered, bool const MarkAligned) { origin_choice result; + if (MarkAligned && known(Mark)) + { + result.origin = *Mark; + result.from = origin_source::mark; + return result; + } if (known(Georeference)) { result.origin = *Georeference; diff --git a/editor/editorPhotoRules.hpp b/editor/editorPhotoRules.hpp index b2f3f05ca..88b742ea8 100644 --- a/editor/editorPhotoRules.hpp +++ b/editor/editorPhotoRules.hpp @@ -39,8 +39,9 @@ struct origin_choice }; // //$g goes first, as the file of the scenery says where it lies: an origin remembered by the editor for a scenery of the same name -// elsewhere, or one written into //$o with it, can't move it. Without //$g the editor's own //$o, then the one remembered -origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered); +// elsewhere, or one written into //$o with it, can't move it. Without //$g the editor's own //$o, then the one remembered. A //$o the +// user aligned by hand (MarkAligned, the word aligned in it) goes before //$g: the user moved the photo off it on purpose +origin_choice choose_origin(std::optional const &Georeference, std::optional const &Mark, std::optional const &Remembered, bool const MarkAligned = false); // the origins further apart than that are told of double constexpr origin_tolerance{1.0}; diff --git a/editor/editorRecords.cpp b/editor/editorRecords.cpp index 2bdf1825d..0795f1900 100644 --- a/editor/editorRecords.cpp +++ b/editor/editorRecords.cpp @@ -871,7 +871,7 @@ std::string camera_line(camera const &Camera) // //$o ------------------------------------------------------------------------------------------------------------------------------- // format of the line: on <0/1> [origin ] -std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East) +std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East, bool const Aligned) { // how the imagery is shown is the user's, kept with the editor (EditorSettings); the scenery keeps whether it's on and where the // scenery lies @@ -882,11 +882,13 @@ std::string orthophoto_line(bool const Enabled, bool const Origin, double const { std::snprintf(text, sizeof(text), " origin %.2f %.2f", North, East); result += text; + if (Aligned) + result += " aligned"; } return result; } -bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East) +bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East, bool *Aligned) { std::istringstream words{Line}; std::string key; @@ -898,6 +900,8 @@ bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, doub words >> Enabled; else if (key == "origin") words >> North >> East; + else if (key == "aligned" && Aligned != nullptr) + *Aligned = true; else continue; if (words.fail()) diff --git a/editor/editorRecords.hpp b/editor/editorRecords.hpp index 3cf25b761..e6e9dce29 100644 --- a/editor/editorRecords.hpp +++ b/editor/editorRecords.hpp @@ -136,8 +136,10 @@ std::string camera_line(camera const &Camera); // //$o, whether the orthophoto is on and, with Origin, where the scenery lies on the map, PUWG 1992 northing and easting; the settings // the older sceneries carry besides are passed over. returns: false if the line says none of it -std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East); -bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East); +// Aligned: the origin was aligned by hand in the editor, which //$g of the scenery file doesn't override; a release before it passes the +// word over +std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East, bool const Aligned = false); +bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East, bool *Aligned = nullptr); // //$z, the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing: none, below 3 points std::vector area_lines(std::vector const &Polygon); diff --git a/tests/unit/test_photo_rules.cpp b/tests/unit/test_photo_rules.cpp index 232e7a008..cc5008a08 100644 --- a/tests/unit/test_photo_rules.cpp +++ b/tests/unit/test_photo_rules.cpp @@ -2,6 +2,7 @@ #include "doctest.h" #include "editor/editorGeometry.hpp" #include "editor/editorPhotoRules.hpp" +#include "editor/editorRecords.hpp" #include "editor/editorSettings.hpp" #include @@ -92,6 +93,33 @@ TEST_CASE("photo: //$g wins over the origin remembered and the one of //$o, the CHECK(remembered.from == origin_source::remembered); CHECK(remembered.origin == glm::dvec2{3.0, 4.0}); CHECK(photo_rules::choose_origin(std::nullopt, std::nullopt, std::nullopt).from == origin_source::none); + + // a //$o aligned by hand goes before //$g: the user moved the photo off it on purpose + auto const aligned{photo_rules::choose_origin(g, glm::dvec2{500000.0, 600030.0}, glm::dvec2{510000.0, 600000.0}, true)}; + CHECK(aligned.from == origin_source::mark); + CHECK(aligned.origin == glm::dvec2{500000.0, 600030.0}); + CHECK(aligned.differs == doctest::Approx(0.0)); +} + +TEST_CASE("photo: //$o says the origin was aligned by hand, which a release before it passes over") { + auto const line{editor_records::orthophoto_line(true, true, 500000.0, 600030.0, true)}; + CHECK(line == "on 1 origin 500000.00 600030.00 aligned"); + bool on{false}; + double north{0.0}; + double east{0.0}; + bool aligned{false}; + REQUIRE(editor_records::read_orthophoto(line, on, north, east, &aligned)); + CHECK(on); + CHECK(north == doctest::Approx(500000.0)); + CHECK(east == doctest::Approx(600030.0)); + CHECK(aligned); + // read as before without the word, and the word passed over where it isn't asked for + CHECK(editor_records::orthophoto_line(true, true, 500000.0, 600030.0) == "on 1 origin 500000.00 600030.00"); + bool again{false}; + REQUIRE(editor_records::read_orthophoto("on 1 origin 1.00 2.00", on, north, east, &again)); + CHECK_FALSE(again); + REQUIRE(editor_records::read_orthophoto(line, on, north, east)); + CHECK(east == doctest::Approx(600030.0)); } TEST_CASE("photo: a tile which failed is tried again later and later, up to 5 min, never given up") {