77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochImageReadingWorker.h"
|
|
#include <QVector>
|
|
#include <iostream>
|
|
|
|
JFJochImageReadingWorker::JFJochImageReadingWorker(JFJochHDF5Reader &reader,
|
|
QObject *parent) : QObject(parent), reader(reader) {}
|
|
|
|
void JFJochImageReadingWorker::LoadFile(const QString &filename) {
|
|
try {
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
reader.ReadFile(filename.toStdString());
|
|
total_images = reader.GetNumberOfImages();
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
|
logger.Info("Loaded file {} in {} ms", filename.toStdString(), duration);
|
|
|
|
current_image = -1;
|
|
current_summation = 1;
|
|
LoadImage(0, 1);
|
|
|
|
emit datasetLoaded();
|
|
} catch (std::exception &e) {
|
|
logger.Error("Error loading file {} {}", filename.toStdString(), e.what());
|
|
}
|
|
}
|
|
|
|
void JFJochImageReadingWorker::CloseFile() {
|
|
reader.Close();
|
|
current_image = -1;
|
|
current_summation = 1;
|
|
total_images = 0;
|
|
emit noImageLoaded();
|
|
}
|
|
|
|
void JFJochImageReadingWorker::LoadImage(int64_t image_number, int64_t summation) {
|
|
try {
|
|
if (image_number < 0
|
|
|| summation <= 0
|
|
|| image_number + summation > total_images
|
|
|| ((image_number == current_image) && (current_summation == summation)))
|
|
return;
|
|
|
|
std::vector<int32_t> image;
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
reader.LoadImage(image_number, summation);
|
|
current_image = image_number;
|
|
current_summation = summation;
|
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
|
logger.Info("Loaded image {} in {} ms", image_number, duration);
|
|
|
|
emit imageNumberChanged(total_images, current_image);
|
|
emit imageLoaded();
|
|
} catch (std::exception &e) {
|
|
logger.Error("Error loading image {}", image_number);
|
|
}
|
|
}
|
|
|
|
void JFJochImageReadingWorker::SetROIBox(QRect box) {
|
|
reader.SetROI(ROIBox("roi1", box.left(), box.right(), box.bottom(), box.top()));
|
|
emit imageStatsUpdated();
|
|
}
|
|
|
|
void JFJochImageReadingWorker::SetROICircle(double x, double y, double radius) {
|
|
if (radius <= 0)
|
|
reader.ClearROI();
|
|
else
|
|
reader.SetROI(ROICircle("roi1", x, y, radius));
|
|
emit imageStatsUpdated();
|
|
}
|