Skip to content
Snippets Groups Projects
Commit 1d87353c authored by Mark Jenkinson's avatar Mark Jenkinson
Browse files

Added some error checking - :O

parent 0e4957b1
No related branches found
No related tags found
No related merge requests found
// fslroi.cc extract cuboid ROI and/or timeseries from image // fslroi.cc extract cuboid ROI and/or timeseries from image
// Stephen Smith and Matthew Webster, FMRIB Image Analysis Group // Stephen Smith, Matthew Webster and Mark Jenkinson, FMRIB Image Analysis Group
// Copyright (C) 1999-2005 University of Oxford // Copyright (C) 1999-2008 University of Oxford
// COPYRIGHT // COPYRIGHT
#include "newimage/newimageall.h" #include "newimage/newimageall.h"
...@@ -13,7 +13,7 @@ void print_usage(const string& progname) { ...@@ -13,7 +13,7 @@ void print_usage(const string& progname) {
cout << "Usage: fslroi <input> <output> <xmin> <xsize> <ymin> <ysize> <zmin> <zsize>" << endl; cout << "Usage: fslroi <input> <output> <xmin> <xsize> <ymin> <ysize> <zmin> <zsize>" << endl;
cout << " fslroi <input> <output> <tmin> <tsize>\n" << endl; cout << " fslroi <input> <output> <tmin> <tsize>\n" << endl;
cout << " fslroi <input> <output> <xmin> <xsize> <ymin> <ysize> <zmin> <zsize> <tmin> <tsize>" << endl; cout << " fslroi <input> <output> <xmin> <xsize> <ymin> <ysize> <zmin> <zsize> <tmin> <tsize>" << endl;
cout << "Note: counting (in both time and space) starts with 0 not 1!" << endl; cout << "Note: indexing (in both time and space) starts with 0 not 1!" << endl;
} }
...@@ -70,6 +70,12 @@ int fmrib_main(int argc, char *argv[]) ...@@ -70,6 +70,12 @@ int fmrib_main(int argc, char *argv[])
maxz+=minz-1; maxz+=minz-1;
maxt+=mint-1; maxt+=mint-1;
} }
// sanity check
if ((maxx<minx) || (maxy<miny) || (maxz<minz) || (maxt<mint)) {
imthrow("Invalid ROI dimensions",21);
}
// now transform these coordinates to newimage conventions // now transform these coordinates to newimage conventions
ColumnVector v(4); ColumnVector v(4);
v << minx << miny << minz << 1.0; v << minx << miny << minz << 1.0;
...@@ -99,15 +105,21 @@ int main(int argc,char *argv[]) ...@@ -99,15 +105,21 @@ int main(int argc,char *argv[])
Tracer tr("main"); Tracer tr("main");
string progname=argv[0]; try {
if (argc !=5 && argc !=9 && argc !=11) string progname=argv[0];
{ if (argc !=5 && argc !=9 && argc !=11)
print_usage(progname); {
return 1; print_usage(progname);
} return 1;
}
string iname=string(argv[1]);
return call_fmrib_main(dtype(iname),argc,argv); string iname=string(argv[1]);
return call_fmrib_main(dtype(iname),argc,argv);
} catch(std::exception &e) {
cerr << e.what() << endl;
} catch(Exception &e) {
exit(EXIT_FAILURE);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment