Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m11s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 10m32s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 18m26s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m11s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 23m32s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 25m36s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 27m28s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 28m10s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 28m10s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 29m24s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 21m45s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / Build documentation (push) Successful in 1m21s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 24m2s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 29m25s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m27s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 27m12s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 32m20s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 33m36s
Build Packages / Unit tests (push) Successful in 2h7m18s
Build Packages / Validation Battery (push) Successful in 33m19s
* Rugnux: Stills processing needs only the unit cell and space group beyond what the file records - detector distance, beam centre, tilt, panel placement, saturation level, gain and polarisation plane are found from the images - and is up to twice as fast. * Rugnux: Stills can be indexed without a GPU, with a CPU implementation of the fast-feedback indexer (macOS, computers without a GPU). * Rugnux: Rotation and stills data are integrated in the detector's own units with one gain model, improving data from CCD detectors. * Web frontend: The Rugnux live page shows the placed model with its electron density and anomalous difference map in a Mol* viewer. Reviewed-on: #90 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
69 lines
3.7 KiB
C++
69 lines
3.7 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "DetectorModules.h"
|
|
|
|
// The detector plane as a picture: raster pixel (i, j) is the plane point (x0 + i, y0 + j). For the
|
|
// algorithms that need the detector as it really is - a beam-stop shadow and the gaps it crosses, the point
|
|
// symmetry about the beam, a picture of the detector - and not as the panels are stored.
|
|
struct PlaneRaster {
|
|
int64_t x0 = 0, y0 = 0, width = 0, height = 0;
|
|
};
|
|
|
|
// The raster holding every panel. It starts at the plane origin, so plane and raster coordinates agree,
|
|
// unless a panel lies left of or above it. Empty table: the image itself.
|
|
PlaneRaster PlaneRasterOf(const DetectorModules &modules, int64_t width, int64_t height);
|
|
|
|
// The image (width x height) as the plane raster: each raster pixel takes the image pixel nearest its centre
|
|
// on the panel it falls on, and `gap` where it falls on none. Empty table, with the image's own raster: a copy.
|
|
template<class T>
|
|
std::vector<T> AssembleToPlane(const DetectorModules &modules, const std::vector<T> &image,
|
|
int64_t width, int64_t height, const PlaneRaster &raster, T gap) {
|
|
std::vector<T> out(static_cast<size_t>(raster.width * raster.height), gap);
|
|
const auto put = [&](const DetectorModule &m, int64_t i0, int64_t i1, int64_t j0, int64_t j1) {
|
|
for (int64_t j = std::max<int64_t>(j0, 0); j < std::min(j1, raster.height); j++)
|
|
for (int64_t i = std::max<int64_t>(i0, 0); i < std::min(i1, raster.width); i++) {
|
|
const auto [x, y] = m.PlaneToImage(static_cast<double>(raster.x0 + i),
|
|
static_cast<double>(raster.y0 + j));
|
|
if (m.ContainsImagePixel(x, y))
|
|
out[j * raster.width + i] = image[static_cast<size_t>(std::floor(y + 0.5)) * width
|
|
+ static_cast<size_t>(std::floor(x + 0.5))];
|
|
}
|
|
};
|
|
if (modules.empty()) {
|
|
put(DetectorModule::AsImaged(0, 0, width, height), -raster.x0, width - raster.x0, -raster.y0,
|
|
height - raster.y0);
|
|
return out;
|
|
}
|
|
// Panel by panel, over the raster pixels of its footprint's box. Panels do not overlap.
|
|
for (const auto &m: modules.Get()) {
|
|
const PlaneBox box = DetectorModules({m}).PlaneBounds(width, height);
|
|
put(m, static_cast<int64_t>(std::floor(box.x0)) - raster.x0, static_cast<int64_t>(std::ceil(box.x1)) - raster.x0,
|
|
static_cast<int64_t>(std::floor(box.y0)) - raster.y0, static_cast<int64_t>(std::ceil(box.y1)) - raster.y0);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// The reverse, for a result computed on the raster: each image pixel on a panel takes the raster pixel
|
|
// nearest its centre on the plane, `outside` where that is off the raster; a pixel on no panel (a gap)
|
|
// is `outside` too. Empty table, with the image's own raster: a copy.
|
|
template<class T>
|
|
std::vector<T> GatherFromPlane(const DetectorModules &modules, const std::vector<T> &plane,
|
|
const PlaneRaster &raster, int64_t width, int64_t height, T outside) {
|
|
std::vector<T> out(static_cast<size_t>(width * height), outside);
|
|
modules.ForEachPixel(width, height, [&](int64_t, size_t index, double px, double py) {
|
|
const auto i = static_cast<int64_t>(std::floor(px + 0.5)) - raster.x0;
|
|
const auto j = static_cast<int64_t>(std::floor(py + 0.5)) - raster.y0;
|
|
if (i >= 0 && i < raster.width && j >= 0 && j < raster.height)
|
|
out[index] = plane[j * raster.width + i];
|
|
});
|
|
return out;
|
|
}
|