mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-25 02:51:08 +02:00
wip to parse vector of rois at command line
This commit is contained in:
@ -5,7 +5,6 @@
|
||||
target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-slsDetector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-Roi.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Caller/test-Caller.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Caller/test-Caller-rx.cpp
|
||||
|
@ -494,6 +494,42 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
||||
REQUIRE_THROWS(caller.call("rx_roi", {"-1", "-1"}, -1, PUT));
|
||||
REQUIRE_THROWS(
|
||||
caller.call("rx_roi", {"10", "15", "25", "30"}, -1, PUT));
|
||||
// vector of rois
|
||||
{
|
||||
std::ostringstream oss;
|
||||
caller.call("rx_roi", {"[5, 10, -1, -1]; [25, 20, -1, -1]"}, -1,
|
||||
PUT, oss);
|
||||
REQUIRE(oss.str() ==
|
||||
"rx_roi [5, 10, -1, -1]; [25, 20, -1, -1]\n");
|
||||
}
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, -1, -1; 25, 30 -1, -1]"}, -1, PUT));
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, -1]; [25, 30 -1, -1]"}, -1, PUT));
|
||||
// separated by space is allowed
|
||||
REQUIRE_NOTHROW(caller.call(
|
||||
"rx_roi", {"[5, 10, -1, -1]", "[25, 28, -1, -1]"}, -1, PUT));
|
||||
REQUIRE_NOTHROW(caller.call("rx_roi",
|
||||
{"[0, 10, -1, -1];[20, 30, -1, -1];[9, "
|
||||
"10, -1, -1];[40, 50, -1, -1]"},
|
||||
-1, PUT));
|
||||
// overlapping rois
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[0, 10,-1, -1];[5, 15, -1, -1]"}, 0, PUT));
|
||||
// xmin > xmax
|
||||
REQUIRE_THROWS(caller.call("rx_roi", {"[12, 8, -1, -1]"}, 0, PUT));
|
||||
// outside detector bounds
|
||||
REQUIRE_THROWS(
|
||||
caller.call("rx_roi", {"[95, 105, -1, -1]"}, 0, PUT));
|
||||
// module level not allowed
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 10, -1, -1]; [25, 28, -1, -1]"}, 0, PUT));
|
||||
// square brackets missing
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, -1, -1; 25, 30, -1, -1]"}, -1, PUT));
|
||||
// invalid roi, 4 parts expected
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, -1]; [25, 30, -1, -1]"}, -1, PUT));
|
||||
}
|
||||
// 2d
|
||||
else {
|
||||
@ -521,6 +557,39 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
||||
}
|
||||
REQUIRE_THROWS(
|
||||
caller.call("rx_roi", {"-1", "-1", "-1", "-1"}, -1, PUT));
|
||||
// vector of rois
|
||||
{
|
||||
std::ostringstream oss;
|
||||
caller.call("rx_roi", {"[5, 10, 20, 30]; [25, 28, 14, 15]"}, -1,
|
||||
PUT, oss);
|
||||
REQUIRE(oss.str() ==
|
||||
"rx_roi [5, 10, 20, 30];[25, 28, 14, 15]\n");
|
||||
}
|
||||
// separated by space is allowed
|
||||
REQUIRE_NOTHROW(caller.call(
|
||||
"rx_roi", {"[5, 10, 20, 30]", "[25, 28, 14, 15]"}, -1, PUT));
|
||||
REQUIRE_NOTHROW(caller.call("rx_roi",
|
||||
{"[0, 10, 0, 10];[20, 30, 0, 10];[0, "
|
||||
"10, 20, 30];[40, 50, 0, 10]"},
|
||||
-1, PUT));
|
||||
// overlapping rois
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[0, 10, 0, 10];[5, 15, 0, 10]"}, 0, PUT));
|
||||
// xmin > xmax
|
||||
REQUIRE_THROWS(caller.call("rx_roi", {"[12, 8, 0, 10]"}, 0, PUT));
|
||||
// ymin > ymax
|
||||
REQUIRE_THROWS(caller.call("rx_roi", {"[0, 10, 20, 5]"}, 0, PUT));
|
||||
// outside detector bounds
|
||||
REQUIRE_THROWS(caller.call("rx_roi", {"[95, 105, 0, 10]"}, 0, PUT));
|
||||
// module level not allowed
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 10, 20, 30]; [25, 28, 14, 15]"}, 0, PUT));
|
||||
// square brackets missing
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, 20, 30; 25, 30, 14, 15]"}, -1, PUT));
|
||||
// invalid roi, 4 parts expected
|
||||
REQUIRE_THROWS(caller.call(
|
||||
"rx_roi", {"[5, 20, 20]; [25, 30, 14, 15]"}, -1, PUT));
|
||||
}
|
||||
|
||||
for (int i = 0; i != det.size(); ++i) {
|
||||
|
@ -1,84 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
#include <string>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "DetectorImpl.h"
|
||||
#include "sls/Detector.h"
|
||||
#include "Module.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace sls {
|
||||
|
||||
TEST_CASE("ROI validation") {
|
||||
DetectorImpl det(0, false, false);
|
||||
det.addTestModule(slsDetectorDefs::JUNGFRAU);
|
||||
std::cout << "size:"<< det.size() << std::endl;
|
||||
DetectorImpl detector(0, false, false);
|
||||
|
||||
SECTION("Valid non-overlapping ROIs") {
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{0, 10, 0, 10},
|
||||
{20, 30, 0, 10},
|
||||
{0, 10, 20, 30},
|
||||
{40, 50, 0, 10}
|
||||
};
|
||||
REQUIRE_NOTHROW(DetectorImplTestHelper::testValidateRois(detector, rois));
|
||||
}
|
||||
|
||||
SECTION("Overlapping ROIs should throw") {
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{0, 10, 0, 10},
|
||||
{5, 15, 0, 10}
|
||||
};
|
||||
REQUIRE_THROWS_AS(DetectorImplTestHelper::testValidateRois(detector, rois),
|
||||
sls::RuntimeError);
|
||||
}
|
||||
|
||||
SECTION("Invalid ROI (xmin > xmax)") {
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{12, 8, 0, 10}
|
||||
};
|
||||
REQUIRE_THROWS_AS(DetectorImplTestHelper::testValidateRois(detector, rois),
|
||||
sls::RuntimeError);
|
||||
}
|
||||
|
||||
SECTION("Invalid ROI (ymin > ymax)") {
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{0, 10, 20, 5}
|
||||
};
|
||||
REQUIRE_THROWS_AS(DetectorImplTestHelper::testValidateRois(detector, rois),
|
||||
sls::RuntimeError);
|
||||
}
|
||||
|
||||
SECTION("Invalid ROI (outside detector bounds)") {
|
||||
// Assuming detector has 100x100 dimensions
|
||||
detector.setNumberOfChannels({100, 100});
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{95, 105, 0, 10} // xmax out of bounds
|
||||
};
|
||||
REQUIRE_THROWS_AS(DetectorImplTestHelper::testValidateRois(detector, rois),
|
||||
sls::RuntimeError);
|
||||
}
|
||||
|
||||
SECTION("Valid ROI for 1D detector") {
|
||||
detector.setNumberOfChannels({100, 1});
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{10, 20, -1, -1}
|
||||
};
|
||||
REQUIRE_NOTHROW(DetectorImplTestHelper::testValidateRois(detector, rois));
|
||||
}
|
||||
|
||||
SECTION("Invalid Y for 1D detector") {
|
||||
detector.setNumberOfChannels({100, 1});
|
||||
std::vector<slsDetectorDefs::ROI> rois = {
|
||||
{10, 20, 0, 10} // Y should be -1 for 1D
|
||||
};
|
||||
REQUIRE_THROWS_AS(DetectorImplTestHelper::testValidateRois(detector, rois),
|
||||
sls::RuntimeError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace sls
|
Reference in New Issue
Block a user