RotationIndexer: Separate ProcessImage and GetLattice

This commit is contained in:
2026-05-29 14:58:53 +02:00
parent a6f61b0d8a
commit 4b609a6e06
4 changed files with 38 additions and 30 deletions
+2 -1
View File
@@ -28,7 +28,8 @@ IndexAndRefine::IndexAndRefine(const DiffractionExperiment &x, IndexerThreadPool
IndexAndRefine::IndexingOutcome IndexAndRefine::DetermineLatticeAndSymmetryRotation(DataMessage &msg) {
IndexingOutcome outcome(experiment);
auto result = rotation_indexer->ProcessImage(msg.number, msg.spots);
rotation_indexer->ProcessImage(msg.number, msg.spots);
auto result = rotation_indexer->GetLattice();
if (result) {
// For rotation indexing, indexing rate is calculated only for frames, where "global" rotation indexing solution was found
msg.indexing_result = false;
+23 -22
View File
@@ -39,10 +39,24 @@ RotationIndexer::RotationIndexer(const DiffractionExperiment &x, IndexerThreadPo
}
}
void RotationIndexer::TryIndex() {
// Index
IndexerResult RotationIndexer::RunIndexing() const {
std::vector<Coord> coords;
coords.reserve(max_spots);
for (int i = 0; i < v_.size(); i++) {
const float angle_deg = axis_->GetAngle_deg(i) + axis_->GetWedge_deg() / 2.0f;
const auto rot = axis_->GetTransformationAngle(angle_deg);
for (const auto &s: v_[i])
coords.emplace_back(rot * s.ReciprocalCoord(geom_));
}
return indexer_.Run(experiment, coords);
}
void RotationIndexer::TryIndex() {
auto indexer_result = RunIndexing();
auto indexer_result = indexer_.Run(experiment, coords_);
if (!indexer_result.lattice.empty() && indexer_result.lattice[0].CalcVolume() > 1.0) {
auto sg = experiment.GetGemmiSpaceGroup();
if (sg) {
@@ -94,25 +108,19 @@ void RotationIndexer::TryIndex() {
}
}
std::optional<RotationIndexerResult> RotationIndexer::ProcessImage(int64_t image, const std::vector<SpotToSave> &spots) {
void RotationIndexer::ProcessImage(int64_t image, const std::vector<SpotToSave> &spots) {
std::unique_lock ul(m);
// For non-rotation just ignore the whole procedure
if (!axis_)
return {};
const float angle_deg = axis_->GetAngle_deg(image) + axis_->GetWedge_deg() / 2.0f;
const auto rot = axis_->GetTransformationAngle(angle_deg);
return;
if (!indexed_lattice && image >= last_accumulated_image + image_stride) {
v_[image].reserve(spots.size());
coords_.reserve(coords_.size() + spots.size());
for (const auto &s: spots) {
if (index_ice_rings || !s.ice_ring) {
if (index_ice_rings || !s.ice_ring)
v_[image].emplace_back(s);
coords_.emplace_back(rot * s.ReciprocalCoord(geom_));
}
}
accumulated_images++;
@@ -126,18 +134,11 @@ std::optional<RotationIndexerResult> RotationIndexer::ProcessImage(int64_t image
image >= next_image_to_try_indexing)
TryIndex();
}
if (!indexed_lattice)
return {};
return RotationIndexerResult{
.lattice = indexed_lattice.value(),
.search_result = search_result_,
.geom = updated_geom_,
.axis = axis_
};
}
std::optional<RotationIndexerResult> RotationIndexer::GetLattice() {
std::optional<RotationIndexerResult> RotationIndexer::GetLattice() const {
std::unique_lock ul(m);
if (!indexed_lattice)
return {};
return RotationIndexerResult{
+5 -3
View File
@@ -37,7 +37,7 @@ class RotationIndexer {
float angle_norm_deg = 1.0f;
std::vector<std::vector<SpotToSave>> v_;
std::vector<Coord> coords_;
std::optional<GoniometerAxis> axis_;
const DiffractionGeometry geom_;
DiffractionGeometry updated_geom_;
@@ -54,11 +54,13 @@ class RotationIndexer {
int64_t indexing_range_multiplier = 1;
std::optional<CrystalLattice> indexed_lattice;
IndexerResult RunIndexing() const;
void TryIndex();
public:
RotationIndexer(const DiffractionExperiment& x, IndexerThreadPool& indexer);
std::optional<RotationIndexerResult> ProcessImage(int64_t image, const std::vector<SpotToSave>& spots);
std::optional<RotationIndexerResult> GetLattice();
void ProcessImage(int64_t image, const std::vector<SpotToSave>& spots);
std::optional<RotationIndexerResult> GetLattice() const;
};
#endif //JFJOCH_ROTATIONINDEXER_H
+8 -4
View File
@@ -70,7 +70,9 @@ TEST_CASE("RotationIndexer") {
s.indexed = true;
spots.push_back(s);
}
if (indexer.ProcessImage(img, spots).has_value())
indexer.ProcessImage(img, spots);
auto result = indexer.GetLattice();
if (result.has_value())
cnt++;
}
@@ -147,8 +149,9 @@ TEST_CASE("RotationIndexer short scan indexes only at the end") {
s.indexed = true;
spots.push_back(s);
}
CHECK_FALSE(indexer.ProcessImage(img, spots).has_value());
indexer.ProcessImage(img, spots);
auto result = indexer.GetLattice();
CHECK_FALSE(result.has_value());
}
std::vector<SpotToSave> last_spots;
@@ -171,7 +174,8 @@ TEST_CASE("RotationIndexer short scan indexes only at the end") {
last_spots.push_back(s);
}
auto ret_last = indexer.ProcessImage(last_img, last_spots);
indexer.ProcessImage(last_img, last_spots);
auto ret_last = indexer.GetLattice();
REQUIRE(ret_last.has_value());
auto ret = indexer.GetLattice();