From 72eccf0199ccd4e56ec8d95fa1cff0e1f7aff3e6 Mon Sep 17 00:00:00 2001 From: Aang23 Date: Sun, 12 May 2024 22:09:30 +0200 Subject: [PATCH] Switch some proj stuff to double --- src-core/common/projection/reprojector.cpp | 14 +++++++------- src-core/common/projection/reprojector.h | 6 +++--- .../products/processor/image_processor.cpp | 16 ++++++++-------- src-testing/main.cpp | 18 +++++++++++++----- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src-core/common/projection/reprojector.cpp b/src-core/common/projection/reprojector.cpp index 0912ccc5e..2c0aad005 100644 --- a/src-core/common/projection/reprojector.cpp +++ b/src-core/common/projection/reprojector.cpp @@ -270,9 +270,9 @@ namespace satdump return result_img; } - std::function(double, double, int, int)> setupProjectionFunction(int width, int height, - nlohmann::json params, - bool rotate) + std::function(double, double, double, double)> setupProjectionFunction(double width, double height, + nlohmann::json params, + bool rotate) { rescaleProjectionScalarsIfNeeded(params, width, height); @@ -292,15 +292,15 @@ namespace satdump if (!proj::projection_setup(proj.get()) && !proj_err) { - return [proj, rotate](double lat, double lon, int h, int w) mutable -> std::pair + return [proj, rotate](double lat, double lon, double h, double w) mutable -> std::pair { double x, y; if (proj::projection_perform_fwd(proj.get(), lon, lat, &x, &y) || x < 0 || x >= w || y < 0 || y >= h) return {-1, -1}; else if (rotate) - return {w - 1 - (int)x, h - 1 - (int)y}; + return {w - 1 - x, h - 1 - y}; else - return {(int)x, (int)y}; + return {x, y}; }; } else @@ -309,7 +309,7 @@ namespace satdump std::shared_ptr transform = std::make_shared(); if (transform->init(gcps, true, false)) throw satdump_exception("Error generating TPS!"); - return [transform, rotate](double lat, double lon, int map_height, int map_width) mutable -> std::pair + return [transform, rotate](double lat, double lon, double map_height, double map_width) mutable -> std::pair { double x, y; transform->forward(lon, lat, x, y); diff --git a/src-core/common/projection/reprojector.h b/src-core/common/projection/reprojector.h index 75763e26a..d35345b61 100644 --- a/src-core/common/projection/reprojector.h +++ b/src-core/common/projection/reprojector.h @@ -20,9 +20,9 @@ namespace satdump image::Image reproject(ReprojectionOperation &op, float *progress = nullptr); - std::function(double, double, int, int)> setupProjectionFunction(int width, int height, - nlohmann::json params, - bool rotate = false); + std::function(double, double, double, double)> setupProjectionFunction(double width, double height, + nlohmann::json params, + bool rotate = false); struct ProjBounds { diff --git a/src-core/products/processor/image_processor.cpp b/src-core/products/processor/image_processor.cpp index 10f9368bc..07760398d 100644 --- a/src-core/products/processor/image_processor.cpp +++ b/src-core/products/processor/image_processor.cpp @@ -217,10 +217,10 @@ namespace satdump { logger->debug("Reprojecting composite %s", name.c_str()); image::Image retimg = projectImg(compo.value()["project"], - final_metadata, - rgb_image, - final_timestamps, - *img_products); + final_metadata, + rgb_image, + final_timestamps, + *img_products); std::string fmt = ""; if (compo.value()["project"]["config"].contains("img_format")) fmt += compo.value()["project"]["config"]["img_format"].get(); @@ -270,10 +270,10 @@ namespace satdump logger->debug("Reprojecting channel %s", img.channel_name.c_str()); image::Image retimg = projectImg(instrument_viewer_settings["project_channels"], - img_products->get_channel_proj_metdata(chanid), - img.image, - img_products->get_timestamps(chanid), - *img_products); + img_products->get_channel_proj_metdata(chanid), + img.image, + img_products->get_timestamps(chanid), + *img_products); std::string fmt = ""; if (instrument_viewer_settings["project_channels"]["config"].contains("img_format")) fmt += instrument_viewer_settings["project_channels"]["config"]["img_format"].get(); diff --git a/src-testing/main.cpp b/src-testing/main.cpp index db90dccac..69e66924f 100644 --- a/src-testing/main.cpp +++ b/src-testing/main.cpp @@ -11,15 +11,23 @@ **********************************************************************/ #include "logger.h" - -#include "common/tile_map/map.h" -#include "common/image/io.h" +#include "common/projection/reprojector.h" +#include "nlohmann/json_utils.h" int main(int argc, char *argv[]) { initLogger(); completeLoggerInit(); - image::Image img = downloadTileMap("https://tile.openstreetmap.org/{z}/{x}/{y}.png", /*48.7, 1.7, 48.9, 1.9, 17); */ -85.0511, -180, 85.0511, 180, 4); - image::save_tiff(img, argv[1]); + nlohmann::json proj_cfg = loadJsonFile(argv[1]); + int width = std::stoi(argv[2]); + int height = std::stoi(argv[3]); + + auto proj_func = satdump::reprojection::setupProjectionFunction(width, + height, + proj_cfg); + + auto p = proj_func(30, -90, width, height); + + logger->trace("%f %f", p.first, p.second); } \ No newline at end of file