From 3b257ca5727a2a21b87f04364bbf92df8a6668a3 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 6 Dec 2025 11:28:48 +0100 Subject: [PATCH] RotationIndexer: Only one indexing try after enough rotation --- image_analysis/IndexAndRefine.cpp | 2 +- image_analysis/RotationIndexer.cpp | 26 +++++++------------------- image_analysis/RotationIndexer.h | 6 +++--- tests/RotationIndexerTest.cpp | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/image_analysis/IndexAndRefine.cpp b/image_analysis/IndexAndRefine.cpp index 4f500567..757fbac8 100644 --- a/image_analysis/IndexAndRefine.cpp +++ b/image_analysis/IndexAndRefine.cpp @@ -158,6 +158,6 @@ void IndexAndRefine::ProcessImage(DataMessage &msg, std::optional IndexAndRefine::Finalize() { if (rotation_indexer) - return rotation_indexer->Finalize(); + return rotation_indexer->GetLattice(); return {}; } diff --git a/image_analysis/RotationIndexer.cpp b/image_analysis/RotationIndexer.cpp index 2c1eb498..9d157bcc 100644 --- a/image_analysis/RotationIndexer.cpp +++ b/image_analysis/RotationIndexer.cpp @@ -41,6 +41,8 @@ void RotationIndexer::SetLattice(const CrystalLattice &lattice) { } void RotationIndexer::TryIndex() { + indexing_tried = true; + // Index std::vector v_sel; std::vector coords_sel; @@ -57,7 +59,6 @@ void RotationIndexer::TryIndex() { idx.begin() + max_spots, idx.end(), [this](std::size_t a, std::size_t b) { - // Replace `.intensity` with the actual SpotToSave intensity member return v_[a].intensity > v_[b].intensity; } ); @@ -111,7 +112,7 @@ std::optional RotationIndexer::ProcessImage(int64_t image const auto rot = axis_->GetTransformation(image); - if (!indexed_lattice && image >= last_accumulated_image + image_stride) { + if (!indexing_tried && image >= last_accumulated_image + image_stride) { v_.reserve(v_.size() + spots.size()); coords_.reserve(coords_.size() + spots.size()); @@ -125,29 +126,16 @@ std::optional RotationIndexer::ProcessImage(int64_t image accumulated_images++; last_accumulated_image = image; - if (!indexed_lattice && accumulated_images >= min_images_for_indexing && image >= first_image_to_try_indexing) { + if (accumulated_images >= min_images_for_indexing && image >= first_image_to_try_indexing) TryIndex(); - // If fails increase rotation range by a factor of two - if (!indexed_lattice) - first_image_to_try_indexing *= 2; - } } - if (indexed_lattice) { - return RotationIndexerResult{ - .lattice = indexed_lattice->Multiply(rot.transpose()), - .search_result = search_result_, - .geom = updated_geom_ - }; - } - return {}; + return GetLattice(); } -std::optional RotationIndexer::Finalize() { +std::optional RotationIndexer::GetLattice() { if (!indexed_lattice) - TryIndex(); - if (!indexed_lattice) - return std::nullopt; + return {}; return RotationIndexerResult{ .lattice = indexed_lattice.value(), .search_result = search_result_, diff --git a/image_analysis/RotationIndexer.h b/image_analysis/RotationIndexer.h index 0ff6e59c..437281ee 100644 --- a/image_analysis/RotationIndexer.h +++ b/image_analysis/RotationIndexer.h @@ -28,10 +28,11 @@ class RotationIndexer { mutable std::mutex m; const DiffractionExperiment& experiment; - constexpr static int64_t max_spots = 60000; + constexpr static int64_t max_spots = 10000; constexpr static int64_t min_images_for_indexing = 10; const bool index_ice_rings; + bool indexing_tried = false; std::vector v_; std::vector coords_; @@ -50,13 +51,12 @@ class RotationIndexer { std::optional indexed_lattice; - void TryIndex(); public: RotationIndexer(const DiffractionExperiment& x, IndexerThreadPool& indexer); void SetLattice(const CrystalLattice &lattice); std::optional ProcessImage(int64_t image, const std::vector& spots); - std::optional Finalize(); + std::optional GetLattice(); }; #endif //JFJOCH_ROTATIONINDEXER_H \ No newline at end of file diff --git a/tests/RotationIndexerTest.cpp b/tests/RotationIndexerTest.cpp index a0498748..aa4b1959 100644 --- a/tests/RotationIndexerTest.cpp +++ b/tests/RotationIndexerTest.cpp @@ -74,7 +74,7 @@ TEST_CASE("RotationIndexer") { CHECK(cnt == 20); - auto ret = indexer.Finalize(); + auto ret = indexer.GetLattice(); REQUIRE(ret.has_value()); auto uc = ret->lattice.GetUnitCell(); auto uc_ref = latt_base.GetUnitCell();