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>
92 lines
4.1 KiB
C++
92 lines
4.1 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <mutex>
|
|
|
|
#include "../common/SpotToSave.h"
|
|
#include "../common/Reflection.h"
|
|
#include "../common/DiffractionExperiment.h"
|
|
#include "../common/PixelMask.h"
|
|
#include "PreviewCounter.h"
|
|
#include "../common/ColorScale.h"
|
|
|
|
enum class PreviewImageFormat {JPEG, TIFF};
|
|
|
|
struct PreviewImageSettings {
|
|
std::optional<float> saturation_value = 10;
|
|
std::optional<float> background_value = 0;
|
|
int64_t jpeg_quality = 70;
|
|
bool show_beam_center = true;
|
|
bool show_spots = true;
|
|
bool show_predictions = false;
|
|
bool show_roi = false;
|
|
bool show_user_mask = true;
|
|
bool show_res_est = false;
|
|
std::optional<float> resolution_ring;
|
|
ColorScaleEnum scale = ColorScaleEnum::Indigo;
|
|
PreviewImageFormat format = PreviewImageFormat::JPEG;
|
|
};
|
|
|
|
class PreviewImage {
|
|
mutable std::mutex m;
|
|
DiffractionExperiment experiment;
|
|
|
|
std::vector<uint8_t> mask;
|
|
|
|
std::vector<SpotToSave> spots;
|
|
size_t xpixel = 0;
|
|
size_t ypixel = 0;
|
|
// The picture being drawn on, in detector-plane pixels: its top-left pixel and size. The stored image
|
|
// for a flat detector, the image gathered onto the plane (AssembleToPlane) for one with a panel table.
|
|
// Set by GenerateRGB under m, and the overlays are drawn there in plane coordinates.
|
|
mutable int64_t canvas_x0 = 0, canvas_y0 = 0, canvas_width = 0, canvas_height = 0;
|
|
size_t pixel_depth_bytes = 2;
|
|
bool pixel_is_signed = false;
|
|
|
|
constexpr static uint8_t MaskGap = 1;
|
|
constexpr static uint8_t MaskUsr = 2;
|
|
constexpr static uint8_t MaskDet = 3;
|
|
|
|
constexpr static float auto_foreground_range = 0.001f;
|
|
|
|
template<class T>
|
|
std::vector<rgb> GenerateRGB(const uint8_t* value,
|
|
int64_t special_value,
|
|
int64_t sat_value,
|
|
const ColorScale &scale,
|
|
const PreviewImageSettings& settings) const;
|
|
std::vector<rgb> GenerateRGB(const PreviewImageSettings& settings, const DataMessage &msg,
|
|
size_t &width, size_t &height) const;
|
|
|
|
void AddResolutionRing(std::vector<rgb> &rgb_image, float d) const;
|
|
void AddBeamCenter(std::vector<rgb> &rgb_image) const;
|
|
void AddSpots(std::vector<rgb> &rgb_image, const std::vector<SpotToSave>& spots) const;
|
|
void AddPredictions(std::vector<rgb> &rgb_image, const std::vector<Reflection>& reflections, char centering) const;
|
|
void AddROI(std::vector<rgb> &rgb_image) const;
|
|
|
|
// Trace a fixed-resolution arc through the geometry (a circular arc on an untilted detector,
|
|
// a conic one on a tilted detector) by sweeping azimuth from phi_start to phi_end and joining
|
|
// the samples. A full ring uses phi_start=0, phi_end=2*pi.
|
|
void DrawArc(std::vector<rgb> &rgb_image, const DiffractionGeometry &geom, float d,
|
|
float phi_start, float phi_end, const rgb &color, int halfwidth) const;
|
|
void DrawThickLine(std::vector<rgb> &rgb_image, float x0, float y0, float x1, float y1,
|
|
const rgb &color, int halfwidth) const;
|
|
void DrawCircleOutline(std::vector<rgb> &rgb_image, float cx, float cy, float radius,
|
|
int width, const rgb &color) const;
|
|
|
|
void color_pixel(std::vector<rgb>& ret, int64_t xpixel, int64_t ypixel, const rgb &color) const;
|
|
void spot(std::vector<rgb>& ret, int64_t xpixel, int64_t ypixel, const rgb &color) const;
|
|
void roi(std::vector<rgb>& ret, int64_t xpixel, int64_t ypixel, int64_t roi_number) const;
|
|
std::string GenerateImage(const PreviewImageSettings& settings, const DataMessage &msg) const;
|
|
|
|
void ConfigurePixel(const std::vector<uint32_t> &mask, size_t pixel_begin, size_t pixel_end);
|
|
public:
|
|
void Configure(const DiffractionExperiment& experiment, const PixelMask& mask, size_t nthreads = 0);
|
|
|
|
[[nodiscard]] std::string GenerateImage(const PreviewImageSettings& settings, const std::vector<uint8_t>& cbor_format);
|
|
[[nodiscard]] static std::string GenerateTIFF(const std::vector<uint8_t>& cbor_format) ;
|
|
};
|