69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ROIMap.h"
|
|
#include "JFJochException.h"
|
|
|
|
ROIMap::ROIMap(int64_t in_xpixel, int64_t in_ypixel)
|
|
: map(in_xpixel * in_ypixel, UINT16_MAX),
|
|
xpixel(in_xpixel), ypixel(in_ypixel) {
|
|
}
|
|
|
|
ROIMap::ROIMap(const DetectorSetup &setup)
|
|
: ROIMap(setup.GetGeometry().GetWidth(), setup.GetGeometry().GetHeight()) {}
|
|
|
|
void ROIMap::UpdateMask() {
|
|
roi_name_map.clear();
|
|
|
|
for (auto &i: map)
|
|
i = UINT16_MAX;
|
|
|
|
for (int i = 0; i < boxes.size(); i++) {
|
|
boxes[i].MarkROI(map, i, xpixel, ypixel);
|
|
roi_name_map[boxes[i].GetName()] = i;
|
|
}
|
|
|
|
for (int i = 0; i < circles.size(); i++) {
|
|
size_t id = boxes.size() + i;
|
|
circles[i].MarkROI(map, id, xpixel, ypixel);
|
|
roi_name_map[circles[i].GetName()] = id;
|
|
}
|
|
}
|
|
|
|
const std::vector<uint16_t>& ROIMap::GetROIMap() const {
|
|
return map;
|
|
}
|
|
|
|
const std::map<std::string, uint16_t> &ROIMap::GetROINameMap() const {
|
|
return roi_name_map;
|
|
}
|
|
|
|
void ROIMap::SetROIBox(const std::vector<ROIBox> &input) {
|
|
if (boxes.size() > box_array_size)
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Limit of box ROIs exceeded");
|
|
for (const auto &i: input) {
|
|
if (i.GetXMax() >= xpixel)
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "ROI box X coordinate out of detector bounds");
|
|
if (i.GetYMax() >= ypixel)
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "ROI box Y coordinate out of detector bounds");
|
|
}
|
|
boxes = input;
|
|
UpdateMask();
|
|
|
|
}
|
|
|
|
void ROIMap::SetROICircle(const std::vector<ROICircle> &input) {
|
|
if (circles.size() > circle_array_size)
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Limit of circular ROIs exceeded");
|
|
circles = input;
|
|
UpdateMask();
|
|
}
|
|
|
|
const std::vector<ROIBox> &ROIMap::GetROIBox() const {
|
|
return boxes;
|
|
}
|
|
|
|
const std::vector<ROICircle> &ROIMap::GetROICircle() const {
|
|
return circles;
|
|
}
|