Files
Jungfraujoch/common/ROIMap.cpp
T
leonarski_fandClaude Opus 5.5 dcad4104ce Dense per-pixel maps through the panel table (panel layout stage 1)
Every dense map that needs geometry now evaluates each image pixel at its
place on the detector plane (DetectorModules), so it is right for a stacked
panel layout and picks up refined module placements:

- AzimuthalIntegrationMapping: bins, resolution, solid-angle/polarisation
  corrections built per pixel through the table; a pixel on no panel is left
  as a masked one. The geometry cache key now includes the panel table, so a
  mapping built after the stills module placement is rebuilt rather than
  served from the cache. ResolutionMaskBits follows (it is a lookup).
- ROIMap / ExportROIMap: azimuthal ROIs on the plane (box and circle ROIs
  stay in image pixels).
- ROIIntegration CPU+GPU: the weighted sums are taken per ROI and panel in
  image pixels and placed on the plane at the end (exact; the affine commutes
  with a weighted mean).
- HotPixelFinder: ring/sector keys and the zeta of the persistence rule on
  the plane.
- Background beam-centre walk CPU+GPU: pixels binned at their plane position;
  host and device share BackgroundPlanePoint so they stay bit-identical.

New common/PanelRows.h: ForEachPixelInRows, ForEachPixel cut to a band of
rows in index order, for the row-parallel builders.

An empty table takes the old arithmetic in the old order: rotation sets and
every single-panel input are unchanged. [PanelLayout] AzintMapping and
ResolutionMask enabled (+ azimuthal ROI map and ROI centroid on the plane);
new BeamCenterFromBackground_BinsOnThePlane and
ROIIntegrationGPU_MatchesCPU_Panels.

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

99 lines
3.0 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochMath.h"
#include "ROIMap.h"
#include "JFJochException.h"
#include "PanelRows.h"
std::vector<uint16_t> ROIMap::GetROIMap(const DiffractionGeometry &geom, const DetectorModules &modules,
size_t xpixel, size_t ypixel) const {
std::vector<uint16_t> map(xpixel * ypixel, 0);
std::vector<float> resolution_map(xpixel * ypixel, 0);
std::vector<float> phi_map;
if (!rois.azimuthal.empty()) {
phi_map.resize(xpixel * ypixel, 0);
// A pixel on no panel keeps resolution and angle 0.
ForEachPixelInRows(modules, static_cast<int64_t>(xpixel), 0, static_cast<int64_t>(ypixel),
[&](int64_t, size_t i, double px, double py) {
const auto x = static_cast<float>(px), y = static_cast<float>(py);
resolution_map[i] = geom.PxlToRes(x, y);
phi_map[i] = geom.Phi_rad(x, y) * 180.0f / static_cast<float>(PI);
});
}
uint16_t roi_id = 0;
for (const auto & box : rois.boxes) {
box.MarkROI(map, roi_id, xpixel, ypixel, resolution_map, phi_map);
roi_id++;
}
for (const auto & circle : rois.circles) {
circle.MarkROI(map, roi_id, xpixel, ypixel, resolution_map, phi_map);
roi_id++;
}
for (const auto &az : rois.azimuthal) {
az.MarkROI(map, roi_id, xpixel, ypixel, resolution_map, phi_map);
roi_id++;
}
return map;
}
std::map<std::string, uint16_t> ROIMap::GetROINameMap() const {
std::map<std::string, uint16_t> roi_name_map;
uint16_t roi_id = 0;
for (auto & box : rois.boxes) {
roi_name_map[box.GetName()] = roi_id;
roi_id++;
}
for (auto & circle : rois.circles) {
roi_name_map[circle.GetName()] = roi_id;
roi_id++;
}
for (auto & az : rois.azimuthal) {
roi_name_map[az.GetName()] = roi_id;
roi_id++;
}
return roi_name_map;
}
void ROIMap::SetROI(const ROIDefinition &input) {
if (input.boxes.size() + input.circles.size() + input.azimuthal.size() > roi_limit)
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Limit of box ROIs exceeded");
rois = input;
}
const ROIDefinition &ROIMap::GetROIDefinition() const {
return rois;
}
bool ROIMap::empty() const {
return rois.boxes.empty() && rois.circles.empty() && rois.azimuthal.empty();
}
size_t ROIMap::size() const {
return rois.boxes.size() + rois.circles.size() + rois.azimuthal.size();
}
std::vector<ROIConfig> ROIMap::ExportMetadata() const {
std::vector<ROIConfig> ret;
for (auto &r : rois.boxes)
ret.emplace_back(r.ExportMetadata());
for (auto &r : rois.circles)
ret.emplace_back(r.ExportMetadata());
for (auto &r : rois.azimuthal)
ret.emplace_back(r.ExportMetadata());
return ret;
}