diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f9839d..154a4fd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,6 +345,7 @@ set(PUBLICHEADERS include/aare/hist/PixelHistogramImpl.hpp include/aare/hist/PedestalTrackingPixelHistogram.hpp include/aare/GainMap.hpp + include/aare/ROI.hpp include/aare/ROIGeometry.hpp include/aare/DetectorGeometry.hpp include/aare/JungfrauDataFile.hpp @@ -361,14 +362,14 @@ set(PUBLICHEADERS include/aare/VarClusterFinder.hpp include/aare/utils/task.hpp include/aare/utils/ifstream_helpers.hpp - include/aare/utils/math_helpers.hpp - include/aare/utils/utility_functions.hpp) + include/aare/utils/math_helpers.hpp) set(SourceFiles ${CMAKE_CURRENT_SOURCE_DIR}/src/calibration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/CtbRawFile.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/decode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ROI.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/ROIGeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/DetectorGeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/hist/PedestalTrackingPixelHistogram.cpp @@ -456,8 +457,8 @@ if(AARE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/RawFile.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/RawSubFile.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ROI.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/task.test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/utils/utility_functions.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/to_string.test.cpp) target_sources(tests PRIVATE ${TestSources}) endif() diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index 885d4b45..04afa2ba 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -5,7 +5,7 @@ #include "aare/ClusterVector.hpp" #include "aare/GainMap.hpp" #include "aare/NDArray.hpp" -#include "aare/defs.hpp" +#include "aare/ROI.hpp" #include "aare/logger.hpp" #include diff --git a/include/aare/DetectorGeometry.hpp b/include/aare/DetectorGeometry.hpp index 34ab5f7e..f5032482 100644 --- a/include/aare/DetectorGeometry.hpp +++ b/include/aare/DetectorGeometry.hpp @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MPL-2.0 #pragma once +#include "aare/ROI.hpp" #include "aare/ROIGeometry.hpp" #include "aare/RawMasterFile.hpp" //ROI refactor away -#include "aare/defs.hpp" #include namespace aare { diff --git a/include/aare/utils/utility_functions.hpp b/include/aare/ROI.hpp similarity index 76% rename from include/aare/utils/utility_functions.hpp rename to include/aare/ROI.hpp index 28d60d47..81c2a84e 100644 --- a/include/aare/utils/utility_functions.hpp +++ b/include/aare/ROI.hpp @@ -1,13 +1,35 @@ #pragma once -#include "aare/DetectorGeometry.hpp" #include "aare/defs.hpp" #include +#include #include #include +#include #include namespace aare { +class ROIGeometry; // forward declaration to avoid circular dependency +class DetectorGeometry; // forward declaration to avoid circular dependency + +struct ROI { + ssize_t xmin{}; + ssize_t xmax{}; + ssize_t ymin{}; + ssize_t ymax{}; + + ssize_t height() const { return ymax - ymin; } + ssize_t width() const { return xmax - xmin; } + bool contains(ssize_t x, ssize_t y) const { + return x >= xmin && x < xmax && y >= ymin && y < ymax; + } + + bool operator==(const ROI &other) const { + return xmin == other.xmin && xmax == other.xmax && ymin == other.ymin && + ymax == other.ymax; + } +}; + /** * @brief Merge all consecutive ROIs in a vector into a single ROI. * @param rois vector of ROIs to merge @@ -97,35 +119,14 @@ std::vector merge_consecutive_rois(std::vector &rois) { * @param geometry Detector geometry * @return true if the ROI covers the entire detector geometry, false otherwise */ -inline bool complete_ROI(const ROI &roi, const DetectorGeometry &geometry) { - return roi.xmin == 0 && - roi.xmax == static_cast(geometry.pixels_x()) && - roi.ymin == 0 && - roi.ymax == static_cast(geometry.pixels_y()); -} +bool complete_ROI(const ROI &roi, const DetectorGeometry &geometry); -inline bool complete_ROI(const std::vector &rois, - const DetectorGeometry &geometry) { - if (rois.empty() or rois.size() > 1) { - return false; - } else { - return complete_ROI(rois[0], geometry); - } -} +bool complete_ROI(const std::vector &rois, + const DetectorGeometry &geometry); -inline bool complete_ROI(const ROIGeometry &roi, - const DetectorGeometry &geometry) { - return roi.pixels_x() == geometry.pixels_x() && - roi.pixels_y() == geometry.pixels_y(); -} +bool complete_ROI(const ROIGeometry &roi, const DetectorGeometry &geometry); -inline bool complete_ROI(const std::vector &rois, - const DetectorGeometry &geometry) { - if (rois.empty() or rois.size() > 1) { - return false; - } else { - return complete_ROI(rois[0], geometry); - } -} +bool complete_ROI(const std::vector &rois, + const DetectorGeometry &geometry); } // namespace aare \ No newline at end of file diff --git a/include/aare/ROIGeometry.hpp b/include/aare/ROIGeometry.hpp index 05450df5..2efbba2c 100644 --- a/include/aare/ROIGeometry.hpp +++ b/include/aare/ROIGeometry.hpp @@ -1,6 +1,8 @@ #pragma once #include "aare/DetectorGeometry.hpp" -#include "aare/defs.hpp" +#include "aare/ROI.hpp" +#include +#include namespace aare { diff --git a/include/aare/RawMasterFile.hpp b/include/aare/RawMasterFile.hpp index 7b8283b6..8ddf44e1 100644 --- a/include/aare/RawMasterFile.hpp +++ b/include/aare/RawMasterFile.hpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #pragma once -#include "aare/defs.hpp" +#include "aare/ROI.hpp" #include #include #include diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 6686ac3b..058399dd 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -94,24 +94,6 @@ template struct t_xy { }; using xy = t_xy; -struct ROI { - ssize_t xmin{}; - ssize_t xmax{}; - ssize_t ymin{}; - ssize_t ymax{}; - - ssize_t height() const { return ymax - ymin; } - ssize_t width() const { return xmax - xmin; } - bool contains(ssize_t x, ssize_t y) const { - return x >= xmin && x < xmax && y >= ymin && y < ymax; - } - - bool operator==(const ROI &other) const { - return xmin == other.xmin && xmax == other.xmax && ymin == other.ymin && - ymax == other.ymax; - } -}; - /// @brief Chip specifications for Matterhorn1 struct Matterhorn10 { constexpr static size_t nRows = 256; diff --git a/python/src/file.hpp b/python/src/file.hpp index ccb62d1f..9cebef5e 100644 --- a/python/src/file.hpp +++ b/python/src/file.hpp @@ -2,6 +2,7 @@ #include "aare/CtbRawFile.hpp" #include "aare/File.hpp" #include "aare/Frame.hpp" +#include "aare/ROI.hpp" #include "aare/RawFile.hpp" #include "aare/RawMasterFile.hpp" #include "aare/RawSubFile.hpp" diff --git a/src/ROI.cpp b/src/ROI.cpp new file mode 100644 index 00000000..9cb37961 --- /dev/null +++ b/src/ROI.cpp @@ -0,0 +1,43 @@ +#include "aare/ROI.hpp" +#include "aare/DetectorGeometry.hpp" +#include "aare/ROIGeometry.hpp" + +namespace aare { + +/** + * @brief Check if the ROI covers the entire detector geometry + * @param roi Region of interest + * @param geometry Detector geometry + * @return true if the ROI covers the entire detector geometry, false otherwise + */ +bool complete_ROI(const ROI &roi, const DetectorGeometry &geometry) { + return roi.xmin == 0 && + roi.xmax == static_cast(geometry.pixels_x()) && + roi.ymin == 0 && + roi.ymax == static_cast(geometry.pixels_y()); +} + +bool complete_ROI(const std::vector &rois, + const DetectorGeometry &geometry) { + if (rois.empty() or rois.size() > 1) { + return false; + } else { + return complete_ROI(rois[0], geometry); + } +} + +bool complete_ROI(const ROIGeometry &roi, const DetectorGeometry &geometry) { + return roi.pixels_x() == geometry.pixels_x() && + roi.pixels_y() == geometry.pixels_y(); +} + +bool complete_ROI(const std::vector &rois, + const DetectorGeometry &geometry) { + if (rois.empty() or rois.size() > 1) { + return false; + } else { + return complete_ROI(rois[0], geometry); + } +} + +} // namespace aare \ No newline at end of file diff --git a/src/utils/utility_functions.test.cpp b/src/ROI.test.cpp similarity index 97% rename from src/utils/utility_functions.test.cpp rename to src/ROI.test.cpp index a98fe6ed..6cc7bb26 100644 --- a/src/utils/utility_functions.test.cpp +++ b/src/ROI.test.cpp @@ -1,4 +1,4 @@ -#include "aare/utils/utility_functions.hpp" +#include "aare/ROI.hpp" #include namespace aare { diff --git a/src/RawFile.cpp b/src/RawFile.cpp index 1a8520c8..a88a289a 100644 --- a/src/RawFile.cpp +++ b/src/RawFile.cpp @@ -2,11 +2,11 @@ #include "aare/RawFile.hpp" #include "aare/DetectorGeometry.hpp" #include "aare/PixelMap.hpp" +#include "aare/ROI.hpp" #include "aare/ROIGeometry.hpp" #include "aare/algorithm.hpp" #include "aare/defs.hpp" #include "aare/logger.hpp" -#include "aare/utils/utility_functions.hpp" #include #include