From 35f6ffdde980cdc54ac73973043c628b5b8e1aef Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Fri, 19 Jun 2026 11:15:59 +0200 Subject: [PATCH] viewer: draw loaded ROIs on the diffraction image When a file with ROI definitions is opened (read into experiment.ROI() by the HDF5 reader), the diffraction image now overlays the configured box and circle ROIs as distinct colour-coded outlines, alongside the existing resolution rings and spots. This is the first step of the ROI-map-based multi-ROI canvas: showing the ROIs loaded from a file. Azimuthal ROIs (wedge rendering) and per-ROI statistics from the bitmap follow in subsequent steps. Co-Authored-By: Claude Opus 4.8 --- .../image_viewer/JFJochDiffractionImage.cpp | 33 +++++++++++++++++++ viewer/image_viewer/JFJochDiffractionImage.h | 1 + 2 files changed, 34 insertions(+) diff --git a/viewer/image_viewer/JFJochDiffractionImage.cpp b/viewer/image_viewer/JFJochDiffractionImage.cpp index 9b744348..435cfceb 100644 --- a/viewer/image_viewer/JFJochDiffractionImage.cpp +++ b/viewer/image_viewer/JFJochDiffractionImage.cpp @@ -313,6 +313,7 @@ void JFJochDiffractionImage::DrawTopPixels() { void JFJochDiffractionImage::addCustomOverlay() { DrawResolutionRings(); + DrawROIs(); DrawTopPixels(); DrawBeamCenter(); @@ -326,6 +327,38 @@ void JFJochDiffractionImage::addCustomOverlay() { DrawResolutionText(); } +void JFJochDiffractionImage::DrawROIs() { + if (!image) + return; + + const auto &rois = image->Dataset().experiment.ROI().GetROIDefinition(); + + // Distinct colours per ROI; loaded ROIs use solid lines (the interactively + // drawn scratch ROI keeps its dashed feature_color). + static const QColor palette[] = {Qt::cyan, Qt::yellow, QColor(0xff, 0x57, 0x22), + Qt::green, Qt::magenta, QColor(0x21, 0x96, 0xf3)}; + const int palette_size = sizeof(palette) / sizeof(palette[0]); + int color_index = 0; + auto roi_pen = [&]() { + QPen pen(palette[color_index % palette_size], 2); + pen.setCosmetic(true); + color_index++; + return pen; + }; + + for (const auto &b : rois.boxes) { + auto *rect = scene()->addRect(b.GetXMin(), b.GetYMin(), b.GetWidth(), b.GetHeight(), roi_pen()); + addOverlayItem(rect); + } + + for (const auto &c : rois.circles) { + const float r = c.GetRadius_pxl(); + auto *ell = scene()->addEllipse(c.GetX() - r, c.GetY() - r, 2 * r, 2 * r, roi_pen()); + addOverlayItem(ell); + } + // Azimuthal ROIs are drawn as wedges in a later step. +} + void JFJochDiffractionImage::UpdateForeground() { if (!image || !auto_fg) diff --git a/viewer/image_viewer/JFJochDiffractionImage.h b/viewer/image_viewer/JFJochDiffractionImage.h index 80e7871e..49ba0172 100644 --- a/viewer/image_viewer/JFJochDiffractionImage.h +++ b/viewer/image_viewer/JFJochDiffractionImage.h @@ -25,6 +25,7 @@ private: void addCustomOverlay() override; void LoadImageInternal(); void DrawResolutionRings(); + void DrawROIs(); void DrawSpots(); void DrawPredictions(); void DrawBeamCenter();