From 3083d516998b91a5316efdc81d2ae9a66f11f421 Mon Sep 17 00:00:00 2001 From: Mazzoleni Alice Francesca Date: Tue, 1 Apr 2025 17:50:11 +0200 Subject: [PATCH] merge conflict --- include/aare/CalculateEta.hpp | 6 ++++-- include/aare/ClusterVector.hpp | 22 +++++++++---------- src/ClusterFile.test.cpp | 39 +++++++++++++++------------------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/include/aare/CalculateEta.hpp b/include/aare/CalculateEta.hpp index 29c5cc4..57c1460 100644 --- a/include/aare/CalculateEta.hpp +++ b/include/aare/CalculateEta.hpp @@ -152,8 +152,10 @@ template Eta2 calculate_eta2(const Cluster &cl) { template Eta2 calculate_eta2(const Cluster &cl) { Eta2 eta{}; - eta.x = static_cast(cl.data[1]) / (cl.data[0] + cl.data[1]); - eta.y = static_cast(cl.data[2]) / (cl.data[0] + cl.data[2]); + if ((cl.data[0] + cl.data[1]) != 0) + eta.x = static_cast(cl.data[1]) / (cl.data[0] + cl.data[1]); + if ((cl.data[0] + cl.data[2]) != 0) + eta.y = static_cast(cl.data[2]) / (cl.data[0] + cl.data[2]); eta.sum = cl.data[0] + cl.data[1] + cl.data[2] + cl.data[3]; eta.c = cBottomLeft; // TODO! This is not correct, but need to put something return eta; diff --git a/include/aare/ClusterVector.hpp b/include/aare/ClusterVector.hpp index 4ab0aa7..188b018 100644 --- a/include/aare/ClusterVector.hpp +++ b/include/aare/ClusterVector.hpp @@ -272,25 +272,25 @@ class ClusterVector> { m_size = new_size; } - void apply_gain_map(const NDView gain_map){ - //in principle we need to know the size of the image for this lookup - //TODO! check orientations + // TODO: Generalize !!!! + void apply_gain_map(const NDView gain_map) { + // in principle we need to know the size of the image for this lookup + // TODO! check orientations std::array xcorr = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; std::array ycorr = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; - for (size_t i=0; i(i); + for (size_t i = 0; i < m_size; i++) { + auto &cl = at(i); - if (cl.x > 0 && cl.y > 0 && cl.x < gain_map.shape(1)-1 && cl.y < gain_map.shape(0)-1){ - for (size_t j=0; j<9; j++){ + if (cl.x > 0 && cl.y > 0 && cl.x < gain_map.shape(1) - 1 && + cl.y < gain_map.shape(0) - 1) { + for (size_t j = 0; j < 9; j++) { size_t x = cl.x + xcorr[j]; size_t y = cl.y + ycorr[j]; cl.data[j] = static_cast(cl.data[j] * gain_map(y, x)); } - }else{ - memset(cl.data, 0, 9*sizeof(T)); //clear edge clusters + } else { + memset(cl.data, 0, 9 * sizeof(T)); // clear edge clusters } - - } } diff --git a/src/ClusterFile.test.cpp b/src/ClusterFile.test.cpp index a0eed04..ccc0170 100644 --- a/src/ClusterFile.test.cpp +++ b/src/ClusterFile.test.cpp @@ -1,33 +1,32 @@ #include "aare/ClusterFile.hpp" #include "test_config.hpp" - #include "aare/defs.hpp" #include #include - - - +using aare::Cluster; using aare::ClusterFile; TEST_CASE("Read one frame from a a cluster file", "[.integration]") { - //We know that the frame has 97 clusters - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + // We know that the frame has 97 clusters + auto fpath = + test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); - ClusterFile f(fpath); + ClusterFile> f(fpath); auto clusters = f.read_frame(); REQUIRE(clusters.size() == 97); REQUIRE(clusters.frame_number() == 135); } TEST_CASE("Read one frame using ROI", "[.integration]") { - //We know that the frame has 97 clusters - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + // We know that the frame has 97 clusters + auto fpath = + test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); - ClusterFile f(fpath); + ClusterFile> f(fpath); aare::ROI roi; roi.xmin = 0; roi.xmax = 50; @@ -38,43 +37,39 @@ TEST_CASE("Read one frame using ROI", "[.integration]") { REQUIRE(clusters.size() == 49); REQUIRE(clusters.frame_number() == 135); - //Check that all clusters are within the ROI + // Check that all clusters are within the ROI for (size_t i = 0; i < clusters.size(); i++) { - auto c = clusters.at(i); + auto c = clusters.at(i); REQUIRE(c.x >= roi.xmin); REQUIRE(c.x <= roi.xmax); REQUIRE(c.y >= roi.ymin); REQUIRE(c.y <= roi.ymax); } - } - TEST_CASE("Read clusters from single frame file", "[.integration]") { - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + auto fpath = + test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); SECTION("Read fewer clusters than available") { - ClusterFile f(fpath); + ClusterFile> f(fpath); auto clusters = f.read_clusters(50); REQUIRE(clusters.size() == 50); - REQUIRE(clusters.frame_number() == 135); + REQUIRE(clusters.frame_number() == 135); } SECTION("Read more clusters than available") { - ClusterFile f(fpath); + ClusterFile> f(fpath); // 100 is the maximum number of clusters read auto clusters = f.read_clusters(100); REQUIRE(clusters.size() == 97); REQUIRE(clusters.frame_number() == 135); } SECTION("Read all clusters") { - ClusterFile f(fpath); + ClusterFile> f(fpath); auto clusters = f.read_clusters(97); REQUIRE(clusters.size() == 97); REQUIRE(clusters.frame_number() == 135); } - - - }