mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-07-11 18:31:51 +02:00
refactor command line parsing of roi
This commit is contained in:
@ -22,6 +22,7 @@ class Caller {
|
||||
int GetLevelAndInsertIntoArgs(std::string levelSeparatedCommand);
|
||||
void WrongNumberOfParameters(size_t expected);
|
||||
std::vector<defs::ROI> parseRoiVector(const std::string &input);
|
||||
defs::ROI parseRoi(const std::vector<std::string> &args);
|
||||
|
||||
template <typename V> std::string OutStringHex(const V &value) {
|
||||
if (value.equal())
|
||||
|
@ -22,6 +22,7 @@ class Caller {
|
||||
int GetLevelAndInsertIntoArgs(std::string levelSeparatedCommand);
|
||||
void WrongNumberOfParameters(size_t expected);
|
||||
std::vector<defs::ROI> parseRoiVector(const std::string &input);
|
||||
defs::ROI parseRoi(const std::vector<std::string> &args);
|
||||
|
||||
template <typename V> std::string OutStringHex(const V &value) {
|
||||
if (value.equal())
|
||||
|
@ -770,18 +770,8 @@ std::string Caller::rx_roi(int action) {
|
||||
try {
|
||||
// single roi in previous format: [xmin,xmax,ymin,ymax]
|
||||
if (!isVectorInput) {
|
||||
if (args.size() == 2 || args.size() == 4) {
|
||||
defs::ROI t;
|
||||
t.xmin = StringTo<int>(args[0]);
|
||||
t.xmax = StringTo<int>(args[1]);
|
||||
if (args.size() == 4) {
|
||||
t.ymin = StringTo<int>(args[2]);
|
||||
t.ymax = StringTo<int>(args[3]);
|
||||
}
|
||||
rois.emplace_back(t);
|
||||
} else {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
auto t = parseRoi(args);
|
||||
rois.emplace_back(t);
|
||||
}
|
||||
// multiple roi or single roi with brackets
|
||||
// multiple roi: multiple args with bracketed ROIs, or single arg
|
||||
@ -831,22 +821,28 @@ std::vector<defs::ROI> Caller::parseRoiVector(const std::string &input) {
|
||||
parts.push_back(num);
|
||||
}
|
||||
|
||||
if (parts.size() != 2 && parts.size() != 4) {
|
||||
throw RuntimeError("ROI must have 2 or 4 comma-separated integers");
|
||||
}
|
||||
|
||||
defs::ROI roi;
|
||||
roi.xmin = StringTo<int>(parts[0]);
|
||||
roi.xmax = StringTo<int>(parts[1]);
|
||||
if (parts.size() == 4) {
|
||||
roi.ymin = StringTo<int>(parts[2]);
|
||||
roi.ymax = StringTo<int>(parts[3]);
|
||||
}
|
||||
auto roi = parseRoi(parts);
|
||||
rois.emplace_back(roi);
|
||||
}
|
||||
return rois;
|
||||
}
|
||||
|
||||
defs::ROI Caller::parseRoi(const std::vector<std::string> &parts) {
|
||||
if (parts.size() != 2 && parts.size() != 4) {
|
||||
throw RuntimeError(
|
||||
"Could not parse ROI. A ROI must have 2 or 4 integers");
|
||||
}
|
||||
|
||||
defs::ROI roi;
|
||||
roi.xmin = StringTo<int>(parts[0]);
|
||||
roi.xmax = StringTo<int>(parts[1]);
|
||||
if (parts.size() == 4) {
|
||||
roi.ymin = StringTo<int>(parts[2]);
|
||||
roi.ymax = StringTo<int>(parts[3]);
|
||||
}
|
||||
return roi;
|
||||
}
|
||||
|
||||
std::string Caller::ratecorr(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == defs::HELP_ACTION) {
|
||||
|
Reference in New Issue
Block a user