2022-04-16 08:10:25 +02:00
|
|
|
#include "radiation_handler.h"
|
2023-09-25 23:36:38 -04:00
|
|
|
#include "imgui/pfd/pfd_utils.h"
|
2022-04-16 08:10:25 +02:00
|
|
|
#include "resources.h"
|
2022-10-17 00:51:02 +02:00
|
|
|
#include "core/module.h"
|
2022-12-05 00:22:59 +01:00
|
|
|
#include "core/style.h"
|
2022-12-05 20:24:19 +01:00
|
|
|
#include "common/projection/reprojector.h"
|
2024-01-24 13:09:24 -05:00
|
|
|
#include "common/widgets/themed_widgets.h"
|
2023-10-19 15:42:54 -04:00
|
|
|
#include "main_ui.h"
|
2023-07-31 22:06:35 -04:00
|
|
|
|
2022-04-16 08:10:25 +02:00
|
|
|
namespace satdump
|
|
|
|
|
{
|
|
|
|
|
void RadiationViewerHandler::init()
|
|
|
|
|
{
|
|
|
|
|
products = (RadiationProducts *)ViewerHandler::products;
|
|
|
|
|
|
2022-05-12 18:19:01 +02:00
|
|
|
for (int c = 0; c < (int)products->channel_counts.size(); c++)
|
2022-10-17 00:44:03 +02:00
|
|
|
select_channel_image_str += products->get_channel_name(c) + '\0';
|
2022-04-16 08:10:25 +02:00
|
|
|
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-04-16 08:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-22 14:52:06 -04:00
|
|
|
RadiationViewerHandler::~RadiationViewerHandler()
|
|
|
|
|
{
|
|
|
|
|
handler_thread_pool.stop();
|
|
|
|
|
for (int i = 0; i < handler_thread_pool.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (handler_thread_pool.get_thread(i).joinable())
|
|
|
|
|
handler_thread_pool.get_thread(i).join();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 08:10:25 +02:00
|
|
|
void RadiationViewerHandler::update()
|
|
|
|
|
{
|
|
|
|
|
if (selected_visualization_id == 0)
|
|
|
|
|
{
|
2023-10-22 14:52:06 -04:00
|
|
|
handler_thread_pool.clear_queue();
|
|
|
|
|
handler_thread_pool.push([this](int)
|
2023-10-19 15:53:22 -04:00
|
|
|
{ async_image_mutex.lock();
|
|
|
|
|
is_updating = true;
|
|
|
|
|
logger->info("Update map...");
|
|
|
|
|
|
|
|
|
|
RadiationMapCfg cfg;
|
|
|
|
|
cfg.channel = select_channel_image_id + 1;
|
|
|
|
|
cfg.radius = 5;
|
|
|
|
|
cfg.min = map_min;
|
|
|
|
|
cfg.max = map_max;
|
|
|
|
|
map_img = make_radiation_map(*products, cfg);
|
|
|
|
|
image_view.update(map_img);
|
|
|
|
|
|
|
|
|
|
logger->info("Done");
|
|
|
|
|
is_updating = false;
|
|
|
|
|
async_image_mutex.unlock(); });
|
|
|
|
|
|
2022-04-16 08:10:25 +02:00
|
|
|
}
|
|
|
|
|
else if (selected_visualization_id == 1)
|
|
|
|
|
{
|
2022-09-09 22:12:42 +02:00
|
|
|
graph_values.clear();
|
2022-04-16 08:10:25 +02:00
|
|
|
graph_values.resize(products->channel_counts.size());
|
2022-05-12 18:19:01 +02:00
|
|
|
for (int c = 0; c < (int)products->channel_counts.size(); c++)
|
2022-04-16 08:10:25 +02:00
|
|
|
{
|
2022-05-12 18:19:01 +02:00
|
|
|
for (int i = 0; i < (int)products->channel_counts[c].size(); i++)
|
2022-04-16 08:10:25 +02:00
|
|
|
graph_values[c].push_back(products->channel_counts[c][i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RadiationViewerHandler::drawMenu()
|
|
|
|
|
{
|
2022-12-10 12:54:33 +01:00
|
|
|
if (ImGui::CollapsingHeader("View"))
|
2022-04-16 08:10:25 +02:00
|
|
|
{
|
2022-09-13 15:06:09 -07:00
|
|
|
if (ImGui::RadioButton(u8"\uf84c Map", &selected_visualization_id, 0))
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-09-13 15:06:09 -07:00
|
|
|
if (ImGui::RadioButton(u8"\uf437 Graph", &selected_visualization_id, 1))
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-04-16 08:10:25 +02:00
|
|
|
|
|
|
|
|
if (selected_visualization_id == 0)
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::Combo("###mapchannelcomboid", &select_channel_image_id, select_channel_image_str.c_str()))
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-10-12 22:29:58 +02:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() / 2);
|
2022-09-09 22:28:43 +02:00
|
|
|
if (ImGui::DragInt("##Min", &map_min, 1.0f, 0, 255, "Min: %d", ImGuiSliderFlags_AlwaysClamp))
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-09-09 22:28:43 +02:00
|
|
|
ImGui::SameLine();
|
2022-10-12 22:29:58 +02:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() / 2);
|
|
|
|
|
if (ImGui::DragInt("##Max", &map_max, 1.0f, 0, 255, "Max: %d", ImGuiSliderFlags_AlwaysClamp))
|
2023-10-19 15:53:22 -04:00
|
|
|
update();
|
2022-04-16 08:10:25 +02:00
|
|
|
}
|
2022-12-05 00:22:59 +01:00
|
|
|
|
2023-10-19 15:42:54 -04:00
|
|
|
bool save_disabled = selected_visualization_id != 0 || is_updating;
|
|
|
|
|
if (save_disabled)
|
2022-12-05 00:22:59 +01:00
|
|
|
style::beginDisabled();
|
2023-10-19 15:42:54 -04:00
|
|
|
|
2022-12-05 00:22:59 +01:00
|
|
|
if (ImGui::Button("Save"))
|
|
|
|
|
{
|
2023-10-22 14:52:06 -04:00
|
|
|
handler_thread_pool.push([this](int)
|
2023-10-19 15:42:54 -04:00
|
|
|
{ async_image_mutex.lock();
|
|
|
|
|
is_updating = true;
|
|
|
|
|
logger->info("Saving Image...");
|
2023-10-26 18:26:57 -04:00
|
|
|
std::string default_path = config::main_cfg["satdump_directories"]["default_image_output_directory"]["value"].get<std::string>();
|
|
|
|
|
std::string saved_at = save_image_dialog(products->instrument_name + "_map", default_path, "Save Map", &map_img, &viewer_app->save_type);
|
2022-12-05 00:22:59 +01:00
|
|
|
|
2023-10-19 15:42:54 -04:00
|
|
|
if (saved_at == "")
|
|
|
|
|
logger->info("Save cancelled");
|
|
|
|
|
else
|
|
|
|
|
logger->info("Saved current map at %s", saved_at.c_str());
|
|
|
|
|
is_updating = false;
|
|
|
|
|
async_image_mutex.unlock(); });
|
2022-12-05 00:22:59 +01:00
|
|
|
}
|
2023-10-19 15:42:54 -04:00
|
|
|
if (save_disabled)
|
2022-12-05 00:22:59 +01:00
|
|
|
style::endDisabled();
|
2022-12-05 20:24:19 +01:00
|
|
|
|
|
|
|
|
if (!canBeProjected())
|
|
|
|
|
style::beginDisabled();
|
|
|
|
|
ImGui::Checkbox("Project", &should_project);
|
|
|
|
|
if (!canBeProjected())
|
|
|
|
|
style::endDisabled();
|
2022-04-16 08:10:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RadiationViewerHandler::drawContents(ImVec2 win_size)
|
|
|
|
|
{
|
|
|
|
|
if (selected_visualization_id == 0)
|
|
|
|
|
{
|
|
|
|
|
image_view.draw(win_size);
|
|
|
|
|
}
|
|
|
|
|
else if (selected_visualization_id == 1)
|
|
|
|
|
{
|
2022-10-17 00:44:03 +02:00
|
|
|
ImGui::BeginChild("RadiationPlot");
|
2022-10-12 22:29:58 +02:00
|
|
|
for (int i = 0; i < (int)products->channel_counts.size(); i++)
|
|
|
|
|
{
|
2022-12-05 00:22:59 +01:00
|
|
|
ImGui::BeginChild(("RadiationPlotChild##" + std::to_string(i)).c_str(), ImVec2(ImGui::GetWindowWidth(), 50 * ui_scale));
|
2024-01-24 13:09:24 -05:00
|
|
|
widgets::ThemedPlotLines(style::theme.plot_bg.Value, products->get_channel_name(i).c_str(), graph_values[i].data(),
|
|
|
|
|
graph_values[i].size(), 0, NULL, 0, 255, ImVec2(ImGui::GetWindowWidth() - 100 * ui_scale, 30 * ui_scale));
|
2022-09-09 22:12:42 +02:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Spacing();
|
2022-10-17 00:44:03 +02:00
|
|
|
ImGui::EndChild();
|
2022-09-09 22:12:42 +02:00
|
|
|
}
|
2022-04-16 08:10:25 +02:00
|
|
|
ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float RadiationViewerHandler::drawTreeMenu()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-12-05 20:24:19 +01:00
|
|
|
|
|
|
|
|
bool RadiationViewerHandler::canBeProjected()
|
|
|
|
|
{
|
|
|
|
|
return selected_visualization_id == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RadiationViewerHandler::hasProjection()
|
|
|
|
|
{
|
|
|
|
|
return projection_ready && should_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RadiationViewerHandler::shouldProject()
|
|
|
|
|
{
|
|
|
|
|
return should_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RadiationViewerHandler::updateProjection(int width, int height, nlohmann::json settings, float *progess)
|
|
|
|
|
{
|
|
|
|
|
if (canBeProjected())
|
|
|
|
|
{
|
|
|
|
|
RadiationMapCfg cfg;
|
|
|
|
|
cfg.channel = select_channel_image_id + 1;
|
|
|
|
|
cfg.radius = 5;
|
|
|
|
|
cfg.min = map_min;
|
|
|
|
|
cfg.max = map_max;
|
|
|
|
|
auto map_img = make_radiation_map(*products, cfg, true);
|
|
|
|
|
|
|
|
|
|
reprojection::ReprojectionOperation op;
|
|
|
|
|
op.source_prj_info = nlohmann::json::parse("{\"type\":\"equirectangular\",\"tl_lon\":-180,\"tl_lat\":90,\"br_lon\":180,\"br_lat\":-90}");
|
|
|
|
|
op.target_prj_info = settings;
|
|
|
|
|
op.img = map_img;
|
|
|
|
|
|
|
|
|
|
op.output_width = width;
|
|
|
|
|
op.output_height = height;
|
|
|
|
|
|
|
|
|
|
reprojection::ProjectionResult res = reprojection::reproject(op, progess);
|
|
|
|
|
projected_img = res.img;
|
|
|
|
|
projection_ready = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->error("Current image can't be projected!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image::Image<uint16_t> &RadiationViewerHandler::getProjection()
|
|
|
|
|
{
|
|
|
|
|
return projected_img;
|
|
|
|
|
}
|
2023-09-26 00:02:27 -04:00
|
|
|
}
|