// Copyright (2019-2024) Paul Scherrer Institute #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& ROIMap::GetROIMap() const { return map; } const std::map &ROIMap::GetROINameMap() const { return roi_name_map; } void ROIMap::SetROIBox(const std::vector &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 &input) { if (circles.size() > circle_array_size) throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Limit of circular ROIs exceeded"); circles = input; UpdateMask(); } const std::vector &ROIMap::GetROIBox() const { return boxes; } const std::vector &ROIMap::GetROICircle() const { return circles; }