rugnux finds the beam stop and its holder in a projection of 60 images and marks them in the pixel mask as bit 9 (--detect-beam-stop[=N|off], on by default). Reflections behind the stop are attenuated but not flagged, so they integrate low with a plausible sigma and nothing downstream catches them: the signal-box gate requires 100% valid pixels and shadow pixels are valid, the background clip is high-side only, and the |zeta| cut applies only to the space-group search merge. The detection compares each pixel's background against the typical background at the same radius on two channels. An azimuthal one (the ring median) finds the holder arm, which is a minority of its ring; a radial one (the background just outside) finds the disk, which the ring median cannot see because inside a fully blocked ring the median is the shadow itself. Pixels are pooled over a 5x5 box and tested only where the background has actually been counted, so low-background data no longer masks the whole detector. Recorded reflections are carved back out - a beam stop cannot block a reflection that was measured. Bit 9 belongs to the run that found it, not to the dataset: it is cleared when a run starts, so a mask read back from a file that carries one starts clear. The user mask (bit 8) is left alone. Scaling and merging gain a low-resolution limit, default 50 A (--scaling-low-resolution <num>, 0 removes it), applied per observation before scaling so it also protects the per-frame scale fit and the space-group search. 50 A is the value XDS configurations use; rugnux_vs_xds.py now matches both of XDS's resolution limits instead of only the high one, so the lowest shell is the same shell in the two programs. The viewer draws the detected shadow in coral with a "Show beam stop" switch in the side panel, exposes the low-resolution limit in the settings dock, and offers detection in its processing jobs. Adding an image marker meant giving the reader a MIN_REAL_PXL_VALUE, because several places classify a pixel by range rather than by equality and would otherwise read the new marker as a very negative intensity. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
145 lines
5.6 KiB
C++
145 lines
5.6 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include "JFJochImage.h"
|
|
#include "../../reader/JFJochReaderImage.h"
|
|
#include "../../common/ROIDefinition.h"
|
|
|
|
class ROIAzimuthal;
|
|
class DiffractionGeometry;
|
|
|
|
class JFJochDiffractionImage : public JFJochImage {
|
|
Q_OBJECT
|
|
|
|
QColor spot_color = Qt::green;
|
|
QColor prediction_color = Qt::darkRed;
|
|
QColor ice_ring_color = Qt::cyan;
|
|
QColor second_lattice_color = QColor(0xFA, 0x72, 0x68); // coral, the viewer "finishing" accent
|
|
|
|
float hover_resolution = NAN;
|
|
// The "d = ... A" readout is painted in drawForeground() in viewport pixels rather than kept
|
|
// as a scene item, so updating it dirties only its own rect. hover_text_rect_ is where it
|
|
// currently sits, in viewport coordinates.
|
|
QRect hover_text_rect_;
|
|
[[nodiscard]] QString HoverResolutionLabel() const;
|
|
// Counts are exact integers: label them from the int32 image rather than from a float copy,
|
|
// which both avoids materialising that copy and cannot round large summed values.
|
|
[[nodiscard]] QString PixelLabel(int x, int y) const override;
|
|
|
|
// This is the view that has detector counts, so it is the one that offers an ROI
|
|
[[nodiscard]] bool AllowROI() const override { return true; }
|
|
|
|
void drawForeground(QPainter *painter, const QRectF &rect) override;
|
|
// The readout sits at a fixed viewport position, but QGraphicsView scrolls by blitting the
|
|
// viewport, which carries the painted text along with it - so its old and new places both have
|
|
// to be repainted when the view pans.
|
|
void scrollContentsBy(int dx, int dy) override;
|
|
public:
|
|
enum class RingMode {Auto, Estimation, Manual, None, IceRings};
|
|
Q_ENUM(RingMode)
|
|
|
|
JFJochDiffractionImage(QWidget *parent = nullptr);
|
|
private:
|
|
|
|
void addCustomOverlay() override;
|
|
void LoadImageInternal();
|
|
// Colour straight from the int32 detector image; no float copy of it is ever built
|
|
void ColorRow(size_t y, const PixelColorMap &map, QRgb *out) const override;
|
|
|
|
void DrawResolutionRings();
|
|
void DrawROIs();
|
|
void DrawAzimuthalROI(const ROIAzimuthal &az, const QColor &color, const DiffractionGeometry &geom);
|
|
void AddROILabel(const std::string &name, const QColor &color, float px, float py);
|
|
|
|
// Interactive editing of the selected (named) ROI: move box/circle for now.
|
|
bool roiEditPress(const QPointF &scenePos) override;
|
|
void roiEditMove(const QPointF &scenePos) override;
|
|
void roiEditRelease() override;
|
|
void roiScratchDrawn() override;
|
|
void keyPressEvent(QKeyEvent *event) override; // Delete removes the selected ROI
|
|
[[nodiscard]] ROIDefinition BuildEditedROIDefinition() const; // current ROIs with the edit applied
|
|
[[nodiscard]] ResizeHandle hitTestBoxHandle(const QRectF &r, const QPointF &p, qreal tol) const;
|
|
// Grab points for an azimuthal ROI: inner/outer arc (resize Q/d) and the two phi
|
|
// edges (rotate). The phi handles are only meaningful for a sector (HasPhi()).
|
|
void azimuthalHandles(const ROIAzimuthal &az, const DiffractionGeometry &geom,
|
|
QPointF &inner, QPointF &outer, QPointF &phimin, QPointF &phimax) const;
|
|
|
|
QString selected_roi_;
|
|
enum class RoiEdit { None, MoveBox, ResizeBox, MoveCircle, ResizeCircle,
|
|
AzimInner, AzimOuter, RotatePhiMin, RotatePhiMax };
|
|
RoiEdit roi_edit_ = RoiEdit::None;
|
|
ResizeHandle box_handle_ = ResizeHandle::None;
|
|
QString edit_name_;
|
|
QRectF edit_box_;
|
|
QPointF edit_center_;
|
|
double edit_radius_ = 0;
|
|
float edit_d_min_ = 0, edit_d_max_ = 0, edit_phi_min_ = 0, edit_phi_max_ = 0; // azimuthal edit state
|
|
bool edit_has_phi_ = false;
|
|
QPointF move_last_;
|
|
bool live_pending_ = false; // a live edit is being recomputed; throttles emissions
|
|
|
|
void DrawSpots();
|
|
void DrawPredictions();
|
|
void DrawBeamCenter();
|
|
void DrawTopPixels();
|
|
void DrawSaturation();
|
|
void DrawResolutionText();
|
|
void DrawCross(float x, float y, float size, float width, float z = 1);
|
|
|
|
void UpdateForeground();
|
|
void leaveEvent(QEvent *event) override;
|
|
|
|
std::shared_ptr<const JFJochReaderImage> image;
|
|
|
|
int32_t show_highest_pixels = 0;
|
|
|
|
QVector<float> res_ring = {};
|
|
|
|
// Constant-d contours traced for res_ring, kept across overlay rebuilds; see DrawResolutionRings
|
|
QVector<float> ring_cache_key_ = {};
|
|
QVector<std::pair<float, QPainterPath>> ring_cache_ = {};
|
|
|
|
RingMode ring_mode = RingMode::Estimation;
|
|
|
|
bool show_spots = false;
|
|
bool show_predictions = false;
|
|
|
|
bool show_roi_labels = false;
|
|
bool show_roi_fill = false;
|
|
|
|
bool highlight_ice_rings = true;
|
|
|
|
void mouseHover(const QPointF &scenePos, Qt::KeyboardModifiers modifiers) override;
|
|
|
|
signals:
|
|
void roiGeometryEdited(ROIDefinition rois);
|
|
void roiSelected(QString name); // user picked an ROI by clicking it on the image
|
|
public slots:
|
|
void setSelectedROI(QString name);
|
|
void loadImage(std::shared_ptr<const JFJochReaderImage> image);
|
|
void setAutoForeground(bool input);
|
|
void setResolutionRing(QVector<float> v);
|
|
void setResolutionRingMode(RingMode mode);
|
|
|
|
void showSpots(bool input);
|
|
void showPredictions(bool input);
|
|
|
|
void showROILabels(bool input);
|
|
void showROIFill(bool input);
|
|
|
|
void setSpotColor(QColor input);
|
|
void setPredictionColor(QColor input);
|
|
|
|
void showHighestPixels(int32_t v);
|
|
void showSaturation(bool input);
|
|
void showBeamStop(bool input);
|
|
|
|
void highlightIceRings(bool input);
|
|
void setHDRMode(bool input);
|
|
};
|
|
|