59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
|
|
#include "IndexerWrapper.h"
|
|
|
|
void IndexerWrapper::Setup(const UnitCell &cell) {
|
|
#ifdef JFJOCH_USE_CUDA
|
|
indexer.iCellM() = CrystalLattice(cell).GetEigenMatrix();
|
|
#endif
|
|
}
|
|
|
|
std::vector<IndexingResult> IndexerWrapper::Run(const std::vector<Coord> &coord) {
|
|
#ifdef JFJOCH_USE_CUDA
|
|
std::vector<IndexingResult> ret;
|
|
|
|
if (coord.size() <= min_spots)
|
|
return ret;
|
|
|
|
size_t nspots = std::min<size_t>(MAX_SPOTS_TO_INDEX, coord.size());
|
|
|
|
for (int i = 0; i < nspots; i++) {
|
|
indexer.spotX(i) = coord[i].x;
|
|
indexer.spotY(i) = coord[i].y;
|
|
indexer.spotZ(i) = coord[i].z;
|
|
}
|
|
|
|
// Index
|
|
indexer.index(1, nspots);
|
|
|
|
// 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();
|
|
|
|
// Check if result is viable
|
|
if (indexed_spot_count > min_spots) {
|
|
IndexingResult result;
|
|
result.l = CrystalLattice(indexer.oCell(id));
|
|
|
|
result.indexed_spots.resize(coord.size());
|
|
for (int i = 0; i < arr.size(); i++)
|
|
result.indexed_spots[i] = arr[i];
|
|
|
|
result.indexed_spots_count = indexed_spot_count;
|
|
|
|
ret.emplace_back(result);
|
|
}
|
|
|
|
return ret;
|
|
#else
|
|
return {};
|
|
#endif
|
|
} |