Files
Jungfraujoch/reader/JFJochReader.cpp
2025-05-12 14:17:24 +02:00

63 lines
1.8 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochReader.h"
#include "../common/PixelMask.h"
void JFJochReader::LoadImage(int64_t image_number, int64_t summation_factor) {
// It would be a mess to load two images at the same time
// so loading is protected via mutex
// yet copying share_ptr pointer is atomic and needs no mutex protection
std::unique_lock ul(current_image_mutex);
auto image = LoadImageInternal(image_number);
if (image) {
for (int i = 1; i < summation_factor; i++) {
auto tmp = LoadImageInternal(image_number + i);
if (tmp)
image->AddImage(*tmp);
}
}
current_image = image;
CalcROI();
}
std::shared_ptr<JFJochReaderImage> JFJochReader::CopyImage() {
return current_image;
}
void JFJochReader::CalcROI() {
if (!current_image)
return;
current_image->CalcROI(roi.get());
}
void JFJochReader::ClearROI() {
std::unique_lock lg(current_image_mutex);
roi = {};
CalcROI();
}
void JFJochReader::SetROI(const ROIBox &input) {
std::unique_lock lg(current_image_mutex);
roi = std::make_unique<ROIBox>(input);
CalcROI();
}
void JFJochReader::SetROI(const ROICircle &input) {
std::unique_lock lg(current_image_mutex);
roi = std::make_unique<ROICircle>(input);
CalcROI();
}
void JFJochReader::SetStartMessage(const std::shared_ptr<JFJochReaderDataset> &val) {
std::unique_lock ul(start_message_mutex);
start_message = val;
}
std::shared_ptr<JFJochReaderDataset> JFJochReader::GetStartMessage() const {
std::unique_lock ul(start_message_mutex);
if (!start_message)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "File not loaded");
return start_message;
}