71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
// RotationSpotAccumulator.h
|
|
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <cmath>
|
|
#include <mutex>
|
|
#include <optional>
|
|
|
|
#include "../common/SpotToSave.h"
|
|
#include "../common/GoniometerAxis.h"
|
|
#include "../common/DiffractionGeometry.h"
|
|
|
|
// Forward declaration
|
|
class RotationSpot3D {
|
|
float x = 0;
|
|
float y = 0;
|
|
float phi = 0;
|
|
float intensity = 0;
|
|
int64_t maxc = 0;
|
|
bool ice_ring = false;
|
|
|
|
int64_t first_image = INT64_MAX;
|
|
int64_t last_image = INT64_MIN;
|
|
|
|
public:
|
|
RotationSpot3D(SpotToSave s, float phi_deg, int64_t image);
|
|
void Add(const SpotToSave& s, float phi_deg, int64_t image);
|
|
|
|
float calcX() const;
|
|
float calcY() const;
|
|
float calcPhi() const;
|
|
float calcI() const;
|
|
int64_t calcMAXC() const;
|
|
int64_t getLastImage() const;
|
|
};
|
|
|
|
class RotationSpotAccumulator {
|
|
public:
|
|
struct Config {
|
|
float xy_tolerance_pxl_sq = 2.0f * 2.0f;
|
|
float grid_cell_size = 10.0f; // pixels
|
|
};
|
|
|
|
private:
|
|
mutable std::mutex mutex_;
|
|
|
|
const DiffractionGeometry& geom_;
|
|
const GoniometerAxis& axis_;
|
|
Config config_;
|
|
|
|
std::map<int64_t, std::vector<SpotToSave>> spots;
|
|
|
|
public:
|
|
RotationSpotAccumulator(const DiffractionGeometry& geom,
|
|
const GoniometerAxis& axis,
|
|
Config config)
|
|
: geom_(geom), axis_(axis), config_(config) {}
|
|
|
|
// Add spots from one image (thread-safe, handles out-of-order)
|
|
void AddImage(int64_t image, const std::vector<SpotToSave>& in_spots);
|
|
|
|
// Finalize all remaining spots (call at end of dataset)
|
|
std::vector<RotationSpot3D> FinalizeAll();
|
|
};
|