60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "FFBIDXIndexer.h"
|
|
|
|
void FFBIDXIndexer::SetupUnitCell(const std::optional<UnitCell> &cell) {
|
|
if (!cell.has_value())
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"FFBIDX requires unit cell");
|
|
CrystalLattice l1(cell.value());
|
|
|
|
Eigen::Matrix3f m;
|
|
indexer.iCellM() << l1.Vec0().x, l1.Vec0().y, l1.Vec0().z,
|
|
l1.Vec1().x, l1.Vec1().y, l1.Vec1().z,
|
|
l1.Vec2().x, l1.Vec2().y, l1.Vec2().z;
|
|
}
|
|
|
|
std::vector<CrystalLattice> FFBIDXIndexer::Run(const std::vector<Coord> &coord, size_t nspots) {
|
|
std::vector<CrystalLattice> ret;
|
|
|
|
if (nspots > coord.size())
|
|
nspots = coord.size();
|
|
|
|
if (nspots <= viable_cell_min_spots)
|
|
return ret;
|
|
|
|
assert(nspots <= MAX_SPOT_COUNT);
|
|
assert(coord.size() <= MAX_SPOT_COUNT);
|
|
|
|
for (int i = 0; i < coord.size(); i++) {
|
|
indexer.spotX(i) = coord[i].x;
|
|
indexer.spotY(i) = coord[i].y;
|
|
indexer.spotZ(i) = coord[i].z;
|
|
}
|
|
|
|
// Index
|
|
indexer.index(1, nspots);
|
|
|
|
fast_feedback::refine::indexer_ifssr<float>::refine(indexer.spotM().topRows(nspots),
|
|
indexer.oCellM(),
|
|
indexer.oScoreV(),
|
|
cifssr);
|
|
|
|
// Find cell most similar to the current one
|
|
for (unsigned i=0u; i<cpers.max_output_cells; i++)
|
|
indexer.oScore(i) += fast_feedback::refine::cell_similarity(indexer.oCell(i), indexer.iCell(0), 0.02f);
|
|
|
|
// Get best cell
|
|
auto id = fast_feedback::refine::best_cell(indexer.oScoreV());
|
|
|
|
auto cell = indexer.oCell(id).colwise().reverse();
|
|
fast_feedback::refine::make_right_handed(cell);
|
|
|
|
return { CrystalLattice(
|
|
Coord(cell(0,0), cell(0,1), cell(0,2)),
|
|
Coord(cell(1,0), cell(1,1), cell(1,2)),
|
|
Coord(cell(2,0), cell(2,1), cell(2,2))
|
|
)};
|
|
}
|