Files
leonarski_fandClaude Opus 5.5 b9ada7914b
Build Packages / Create release (push) Successful in 22s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m59s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 15m44s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m6s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 21m48s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m39s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m26s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 25m57s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 15m45s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 17m54s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 17m31s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 22m33s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 26m35s
Build Packages / Generate python client (push) Successful in 23s
Build Packages / Build documentation (push) Successful in 1m15s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 29m39s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 25m18s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 19m20s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 25m50s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 19m0s
Build Packages / Unit tests (push) Successful in 1h41m33s
Build Packages / Validation Battery (push) Successful in 34m52s
DetectorModules.h: include <cstddef> for size_t
GCC 12 (the Ubuntu 22.04 CI job) does not pull size_t in through <cstdint>/<vector>, so the header failed
to compile there. Checked: all 601 project sources pass -fsyntax-only with GCC 12.2 (gcc-toolset-12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
2026-10-21 08:48:32 +02:00

77 lines
3.5 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstddef>
#include <cstdint>
#include <utility>
#include <vector>
#include "ModuleShift.h"
class DetectorGeometry;
// One detector module: where its pixels are in the image rugnux reads, and where they really are on the
// detector plane. The plane is the one DiffractionGeometry describes (beam centre, distance, tilt), in its
// pixel units, so a module placed exactly as the image has it maps every pixel onto itself.
//
// Image pixel (x, y) of the module, x0 <= x < x0 + width, y0 <= y < y0 + height, lies on the plane at
// (ox, oy) + (x - x0) (fx, fy) + (y - y0) (sx, sy)
// - the NXdetector_module description (data_origin, data_size, module_offset, fast_pixel_direction,
// slow_pixel_direction) taken in the plane. A pixel's centre is at its index, as everywhere in the image.
struct DetectorModule {
int64_t x0 = 0, y0 = 0, width = 0, height = 0;
double ox = 0, oy = 0;
double fx = 1, fy = 0;
double sx = 0, sy = 1;
// The module where the image has it: every pixel maps onto itself.
static DetectorModule AsImaged(int64_t x0, int64_t y0, int64_t width, int64_t height);
[[nodiscard]] bool ContainsImagePixel(double x, double y) const;
[[nodiscard]] std::pair<double, double> ImageToPlane(double x, double y) const;
[[nodiscard]] std::pair<double, double> PlaneToImage(double px, double py) const;
// Plane position of the module's centre.
[[nodiscard]] std::pair<double, double> PlaneCentre() const;
// Moved by a refinement's rigid step, which is expressed on the plane (ModuleShift: turn about
// (x0, y0) of the shift, then shift).
void Apply(const ModuleShift &shift);
};
// The modules of one detector. Empty means the image is one flat detector: every mapping is the identity.
class DetectorModules {
std::vector<DetectorModule> modules;
public:
DetectorModules() = default;
explicit DetectorModules(std::vector<DetectorModule> modules);
[[nodiscard]] bool empty() const;
[[nodiscard]] size_t size() const;
[[nodiscard]] const DetectorModule &operator[](size_t i) const;
[[nodiscard]] const std::vector<DetectorModule> &Get() const;
// True where some module is placed other than as imaged.
[[nodiscard]] bool Moved() const;
// Module of an image pixel, or -1 (a gap, or outside every module).
[[nodiscard]] int64_t ModuleOfImagePixel(double x, double y) const;
// Module whose placed footprint holds a plane point, or -1.
[[nodiscard]] int64_t ModuleOfPlanePoint(double px, double py) const;
// Image -> plane; a point on no module is left as it is.
[[nodiscard]] std::pair<double, double> ImageToPlane(double x, double y) const;
// Plane -> image; a point on no placed module is left as it is.
[[nodiscard]] std::pair<double, double> PlaneToImage(double px, double py) const;
// Each module moved by the shift whose centre is nearest its own plane centre (and within it).
void Apply(const std::vector<ModuleShift> &shifts);
// The modules as refinement starting points: their plane centres, no move.
[[nodiscard]] std::vector<ModuleShift> Centres() const;
};
// The modules of a modular (JUNGFRAU) detector where its assembled image puts them: one box per module,
// CONVERTED_MODULE_COLS x CONVERTED_MODULE_LINES turned the way the geometry turns it, placed as imaged.
// Empty for a detector of one module.
DetectorModules ModulesAsImaged(const DetectorGeometry &geom);