Files
Jungfraujoch/image_analysis/indexing/FFTIndexer.h
T
2025-06-10 18:14:04 +02:00

77 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#ifndef JFJOCH_FFTINDEXER_H
#define JFJOCH_FFTINDEXER_H
// This include should be only included in sections of the code, where it is certain that CUDA is present
// so with JFJOCH_USE_CUDA preprocessor definition, given this file is included in the source only in this case
#include <vector>
#include <mutex>
#include "../../common/Coord.h"
#include "../../common/CrystalLattice.h"
#include "Indexer.h"
#include "../common/IndexingSettings.h"
#include <cufft.h>
#define FFT_MAX_SPOTS (64*1024)
struct FFTResult {
float magnitude;
int32_t direction;
float length;
};
class FFTIndexer : public Indexer {
float min_length_A;
float max_length_A;
float histogram_spacing;
int64_t histogram_size;
std::vector<Coord> direction_vectors;
size_t input_size;
size_t output_size;
float *d_dir_x = nullptr;
float *d_dir_y = nullptr;
float *d_dir_z = nullptr;
float *d_spot_x = nullptr;
float *d_spot_y = nullptr;
float *d_spot_z = nullptr;
float *spot_x = nullptr;
float *spot_y = nullptr;
float *spot_z = nullptr;
float *d_input_fft = nullptr;
cufftComplex *d_output_fft = nullptr;
cufftHandle plan;
FFTResult *d_result_fft = nullptr;
FFTResult *result_fft = nullptr;
cudaStream_t stream;
std::optional<UnitCell> reference_unit_cell;
void SetupUnitCell(const std::optional<UnitCell> &cell) override;
void SetupDirectionVectors(int64_t nPoints);
void ExecuteFFT(const std::vector<Coord> &coord, size_t nspots);
std::vector<Coord> FilterFFTResults() const;
std::vector<CrystalLattice> ReduceResults(const std::vector<Coord> &result) const;
std::vector<CrystalLattice> Refine(const std::vector<Coord> &in_spots, size_t nspots, const std::vector<CrystalLattice> &lattices) const;
public:
explicit FFTIndexer(const IndexingSettings& settings);
FFTIndexer(const FFTIndexer &i) = delete;
const FFTIndexer &operator=(const FFTIndexer &i) = delete;
~FFTIndexer() override;
std::vector<CrystalLattice> Run(const std::vector<Coord> &coord, size_t nspots) override;
};
#endif //JFJOCH_FFTINDEXER_H