// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once // Included only under JFJOCH_USE_CUDA. #include #include #include // What the mask is drawn about: the detector, the beam centre, and the geometry the rings and the // polarization factor are read off (ShadowFinder keeps it as a DiffractionGeometry; the device takes // it as numbers). struct ShadowMaskSetup { int width = 0, height = 0; float beam_x = 0.0f, beam_y = 0.0f; float det_matrix[9] = {}; // row major float pixel_size_mm = 0.0f; float distance_mm = 0.0f; bool has_polarization = false; float polarization = 0.0f; float gain = 1.0f; // detector units per photon (ShadowFinder::gain) }; // ShadowFinder::GetMask on the device, from the projection ShadowAccumulatorGPU holds there. Step for // step the host's algorithm - the same pooling, ring medians, components, morphology and arm search - // and the same answer wherever the arithmetic is exact: every integer, comparison, sort and component // is. What is not is the floating point the two compilers evaluate differently - the polarization // factor's trigonometry, the Poisson test's logarithm and the azimuth of the arm search - so a pixel // within a rounding of one of those thresholds can come out the other way. std::vector ShadowMaskOnDevice(const ShadowMaskSetup &setup, const std::vector &pixel_mask, const int64_t *max_value, const int64_t *sum_value, const uint32_t *valid_count, uint32_t frames, cudaStream_t stream); // The mean projection the host's GetMeanProjection makes, computed where the sums are: the same // division, so the same bits, and a quarter of the bytes to bring back. std::vector MeanProjectionOnDevice(const std::vector &pixel_mask, const int64_t *sum_value, const uint32_t *valid_count, size_t npixels, cudaStream_t stream);