Indexing improvements
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Copyright (2019-2023) Paul Scherrer Institute
|
||||
// Copyright (2019-2024) Paul Scherrer Institute
|
||||
|
||||
#include "IndexerWrapper.h"
|
||||
#define MAX_SPOT_COUNT_INDEXING 50
|
||||
|
||||
void IndexerWrapper::Setup(const UnitCell &cell) {
|
||||
#ifdef JFJOCH_USE_CUDA
|
||||
@@ -8,16 +9,18 @@ void IndexerWrapper::Setup(const UnitCell &cell) {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<IndexingResult> IndexerWrapper::Run(const std::vector<Coord> &coord) {
|
||||
std::vector<IndexingResult> IndexerWrapper::Run(const std::vector<Coord> &coord, float indexing_threshold) {
|
||||
#ifdef JFJOCH_USE_CUDA
|
||||
std::vector<IndexingResult> ret;
|
||||
|
||||
if (coord.size() <= min_spots)
|
||||
return ret;
|
||||
|
||||
size_t nspots = std::min<size_t>(MAX_SPOT_COUNT, coord.size());
|
||||
assert(coord.size() < MAX_SPOT_COUNT);
|
||||
|
||||
for (int i = 0; i < nspots; i++) {
|
||||
size_t nspots = std::min<size_t>(MAX_SPOT_COUNT_INDEXING, coord.size());
|
||||
|
||||
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;
|
||||
@@ -26,28 +29,40 @@ std::vector<IndexingResult> IndexerWrapper::Run(const std::vector<Coord> &coord)
|
||||
// Index
|
||||
indexer.index(1, nspots);
|
||||
|
||||
fast_feedback::refine::indexer_ifssr<float>::refine(indexer.spotM().topRows(coord.size()),
|
||||
indexer.oCellM(),
|
||||
indexer.oScoreV(),
|
||||
fast_feedback::refine::config_ifssr<float>{});
|
||||
|
||||
// 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());
|
||||
|
||||
// get indexed spots
|
||||
using M3x = Eigen::MatrixX3<float>;
|
||||
M3x resid = indexer.Spots() * indexer.oCell(id).transpose();
|
||||
const M3x miller = round(resid.array());
|
||||
resid -= miller;
|
||||
auto arr = resid.rowwise().norm().array() < threshold;
|
||||
|
||||
auto indexed_spot_count = arr.count();
|
||||
bool indexed = fast_feedback::refine::is_viable_cell(indexer.oCell(id), indexer.Spots(), indexing_threshold, 9);
|
||||
|
||||
// Check if result is viable
|
||||
if (indexed_spot_count > min_spots) {
|
||||
if (indexed) {
|
||||
auto cell = indexer.oCell(id).colwise().reverse();
|
||||
fast_feedback::refine::make_right_handed(cell);
|
||||
|
||||
// get indexed spots
|
||||
using M3x = Eigen::MatrixX3<float>;
|
||||
M3x resid = indexer.spotM().topRows(coord.size()) * cell.transpose();
|
||||
const M3x miller = round(resid.array());
|
||||
const M3x predicted = miller * cell.transpose().inverse();
|
||||
|
||||
IndexingResult result;
|
||||
result.l = CrystalLattice(indexer.oCell(id));
|
||||
result.l = CrystalLattice(cell);
|
||||
|
||||
result.indexed_spots.resize(coord.size());
|
||||
for (int i = 0; i < arr.size(); i++)
|
||||
result.indexed_spots[i] = arr[i];
|
||||
result.predicted_spots.resize(coord.size());
|
||||
|
||||
result.indexed_spots_count = indexed_spot_count;
|
||||
for (int i = 0; i < coord.size(); i++)
|
||||
result.predicted_spots[i] = Coord(predicted.coeff(i, 0),
|
||||
predicted.coeff(i, 1),
|
||||
predicted.coeff(i, 2));
|
||||
|
||||
ret.emplace_back(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user