// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once // Included only under JFJOCH_USE_CUDA. Free of CUDA headers, so the host fit can hold one. #include #include #include #include "BackgroundBand.h" // The two passes over the pixels of the background beam-centre fit (FindBeamCenterFromBackground), // on the device: binning every usable pixel into its cell about a trial centre, and summing the // binned pixels again under a clip. They are all of the fit's cost; the fit itself stays on the host. // // Each cell is summed in the order the host sums it - pixel order within each of the host's row // blocks, the blocks then added in block order - so a pixel that lands in the same cell on both // sides adds the same rounding on both. Whatever differs comes from BackgroundBandCell (see there). class BeamCenterBackgroundGPU { struct Impl; std::unique_ptr impl; public: // block_row: the first row of each of the host's row blocks, and one past the last row at the end. // panels: where the image's panels are on the plane; empty when the image is the plane. BeamCenterBackgroundGPU(int width, int height, const std::vector &block_row, const std::vector &panels, const char *usable, const float *mean); ~BeamCenterBackgroundGPU(); // Bin the band about (beam_x, beam_y) and sum each cell: the values, their squares, the two // derivatives, and the count. void Bin(const BackgroundBand &band, float beam_x, float beam_y, std::vector &sum, std::vector &sum_sq, std::vector &sum_jx, std::vector &sum_jy, std::vector &count); // Sum the pixels the last Bin put in each cell again, leaving out those above the cell's // clip_limit and every pixel of a cell whose limit is negative. void Clip(const std::vector &clip_limit, std::vector &sum, std::vector &sum_sq, std::vector &count); };