// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include #include "../../common/JFJochMessages.h" #include "../image_preprocessing/ImagePreprocessorBuffer.h" class DiffractionExperiment; // Computes per-ROI statistics over an assembled image: sum, sum of squares, // good-pixel count, maximum and intensity-weighted centre of mass. Each pixel // carries a 16-bit mask selecting which of up to 16 ROIs it belongs to, so a // single pixel can contribute to none, one, or several ROIs at once. This is // the software counterpart of the FPGA roi_calc kernel. class ROIIntegration { protected: std::vector roi_map; // per-pixel ROI bitmask, assembled (converted) geometry size_t width; // assembled image width, to recover x/y from a pixel index size_t npixel; uint16_t roi_count; std::vector roi_name; // ROI name indexed by bit position // Result accumulators, filled by Run() in the derived class std::vector roi_sum; std::vector roi_sum2; std::vector roi_pixels; std::vector roi_x_weighted; std::vector roi_y_weighted; std::vector roi_max; void Export(std::map &out) const; public: explicit ROIIntegration(const DiffractionExperiment &experiment); virtual ~ROIIntegration() = default; [[nodiscard]] uint16_t Count() const { return roi_count; } [[nodiscard]] bool empty() const { return roi_count == 0; } virtual void Run(const ImagePreprocessorBuffer &image, std::map &out) = 0; };