71 lines
2.4 KiB
C++
71 lines
2.4 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <iostream>
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
#include "../image_analysis//RotationSpotAccumulator.h"
|
|
|
|
TEST_CASE("RotationSpotAccumulator") {
|
|
DiffractionGeometry geometry;
|
|
geometry.BeamX_pxl(1000).BeamY_pxl(1000).DetectorDistance_mm(100);
|
|
|
|
GoniometerAxis axis("U", 0, 0.1, Coord{1, 0, 0}, std::nullopt);
|
|
|
|
RotationSpotAccumulator::Config config{};
|
|
RotationSpotAccumulator accumulator(geometry, axis, config);
|
|
|
|
accumulator.AddImage(2, {
|
|
SpotToSave{.x = 500, .y = 500, .intensity = 100},
|
|
SpotToSave{.x = 101, .y = 101, .intensity = 50}
|
|
});
|
|
|
|
accumulator.AddImage(0, {
|
|
SpotToSave{.x = 100, .y = 100, .intensity = 50},
|
|
SpotToSave{.x = 200, .y = 200, .intensity = 50}
|
|
});
|
|
|
|
accumulator.AddImage(1, {
|
|
SpotToSave{.x = 500, .y = 500, .intensity = 100},
|
|
SpotToSave{.x = 101, .y = 100, .intensity = 100}
|
|
});
|
|
|
|
accumulator.AddImage(4, {
|
|
SpotToSave{.x = 500, .y = 500, .intensity = 100}
|
|
});
|
|
|
|
auto v = accumulator.FinalizeAll();
|
|
|
|
struct Expect {
|
|
float x, y, phi, I;
|
|
};
|
|
|
|
std::vector<Expect> expected = {
|
|
{200.0f, 200.0f, 0.05f, 50.0f},
|
|
{500.0f, 500.0f, 0.2f, 200.0f},
|
|
{100.75f, 100.25f, 0.15f, 200.0f},
|
|
{500.0f, 500.0f, 0.45f, 100.0f}
|
|
};
|
|
|
|
auto key = [](const Expect& e) { return std::pair<float,float>(e.x, e.y); };
|
|
|
|
std::vector<Expect> got;
|
|
got.reserve(v.size());
|
|
for (const auto& s : v) {
|
|
got.push_back({s.calcX(), s.calcY(), s.calcPhi(), s.calcI()});
|
|
}
|
|
|
|
std::sort(expected.begin(), expected.end(),
|
|
[&](const Expect& a, const Expect& b){ return key(a) < key(b); });
|
|
std::sort(got.begin(), got.end(),
|
|
[&](const Expect& a, const Expect& b){ return key(a) < key(b); });
|
|
|
|
REQUIRE(got.size() == expected.size());
|
|
for (size_t i = 0; i < got.size(); ++i) {
|
|
CHECK(got[i].x == Catch::Approx(expected[i].x));
|
|
CHECK(got[i].y == Catch::Approx(expected[i].y));
|
|
CHECK(got[i].phi == Catch::Approx(expected[i].phi));
|
|
CHECK(got[i].I == Catch::Approx(expected[i].I));
|
|
}
|
|
}
|