86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ROIBox.h"
|
|
#include "JFJochException.h"
|
|
#include "../fpga/pcie_driver/jfjoch_fpga.h"
|
|
|
|
ROIBox::ROIBox(const std::string &in_name, int64_t in_x_min, int64_t in_x_max, int64_t in_y_min, int64_t in_y_max)
|
|
: ROIElement(in_name) {
|
|
if ((in_x_min < 0) || (in_x_max < 0))
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "ROI rectangle X negative");
|
|
if ((in_y_min < 0) || (in_y_max < 0))
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "ROI rectangle Y negative");
|
|
|
|
if (in_x_max < in_x_min) {
|
|
x_min = in_x_max;
|
|
x_max = in_x_min;
|
|
} else {
|
|
x_min = in_x_min;
|
|
x_max = in_x_max;
|
|
}
|
|
|
|
if (in_y_max < in_y_min) {
|
|
y_min = in_y_max;
|
|
y_max = in_y_min;
|
|
} else {
|
|
y_min = in_y_min;
|
|
y_max = in_y_max;
|
|
}
|
|
}
|
|
|
|
int64_t ROIBox::GetXMin() const {
|
|
return x_min;
|
|
}
|
|
|
|
int64_t ROIBox::GetXMax() const {
|
|
return x_max;
|
|
}
|
|
|
|
int64_t ROIBox::GetYMin() const {
|
|
return y_min;
|
|
}
|
|
|
|
int64_t ROIBox::GetYMax() const {
|
|
return y_max;
|
|
}
|
|
|
|
int64_t ROIBox::GetWidth() const {
|
|
return x_max - x_min;
|
|
}
|
|
|
|
int64_t ROIBox::GetHeight() const {
|
|
return y_max - y_min;
|
|
}
|
|
|
|
int64_t ROIBox::GetArea() const {
|
|
return GetWidth() * GetHeight();
|
|
}
|
|
|
|
void ROIBox::MarkROI(std::vector<uint16_t> &v, uint16_t value_to_mark, int64_t xpixel, int64_t ypixel) const {
|
|
if (v.size() < xpixel * ypixel) // Handle test case of v larger than xpixel * ypixel (to look for out-of-bounds access)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"ROIRectangle: MarkROI mismatch in input array size");
|
|
|
|
if (value_to_mark >= 16)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"ROIRectangle: Only 16-bit available for ROI");
|
|
|
|
if ((y_min >= ypixel) || (x_min >= xpixel))
|
|
return;
|
|
|
|
for (int64_t y = y_min; y <= std::min(y_max, ypixel); y++) {
|
|
for (int64_t x = x_min; x <= std::min(x_max, xpixel); x++) {
|
|
v[y * xpixel + x] |= (1<<value_to_mark);
|
|
}
|
|
}
|
|
}
|
|
|
|
ROIConfig ROIBox::ExportMetadata() const {
|
|
return ROIConfig{
|
|
.type = ROIConfig::ROIType::Box,
|
|
.name = name,
|
|
.box = ROIConfigBox{.xmin = x_min, .xmax = x_max, .ymin = y_min, .ymax = y_max}
|
|
};
|
|
}
|