| 1 | /********************************************************************** |
| 2 | test1.cc: test app for jiblib |
| 3 | Author(s): [email protected] |
| 4 | Copyright (C) 2016-2020 European Union (Joint Research Centre) |
| 5 | |
| 6 | This file is part of jiplib. |
| 7 | |
| 8 | jiplib is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | jiplib is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with jiplib. If not, see <https://www.gnu.org/licenses/>. |
| 20 | ***********************************************************************/ |
| 21 | #include <memory> |
| 22 | #include "base/Optionjl.h" |
| 23 | #include "algorithms/Filter2d.h" |
| 24 | #include "apps/AppFactory.h" |
| 25 | #include "imageclasses/ImgCollection.h" |
| 26 | #include "jim.h" |
| 27 | |
| 28 | using namespace std; |
| 29 | |
| 30 | int main(int argc, char *argv[]) |
| 31 | { |
| 32 | Optionjl<string> input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created"); |
| 33 | Optionjl<unsigned short> nodata_opt("nodata", "nodata", "Nodata value to check in image.",0); |
| 34 | Optionjl<unsigned long int> memory_opt("mem", "mem", "Buffer size (in MB) to read image data blocks in memory",0,1); |
| 35 | |
| 36 | memory_opt.setHide(1); |
| 37 | |
| 38 | bool doProcess;//stop process when program was invoked with help option (-h --help) |
| 39 | try{ |
| 40 | doProcess=input_opt.retrieveOption(argc,argv); |
| 41 | // output_opt.retrieveOption(argc,argv); |
| 42 | nodata_opt.retrieveOption(argc,argv); |
| 43 | memory_opt.retrieveOption(argc,argv); |
| 44 | } |
| 45 | catch(string predefinedString){ |
| 46 | std::cout << predefinedString << std::endl; |
| 47 | exit(0); |
| 48 | } |
| 49 | if(doProcess){ |
| 50 | if(input_opt.empty()){ |
| 51 | std::cerr << "Error: no input file provided (use option -i). Use --help for help information" << std::endl; |
| 52 | exit(1); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | app::AppFactory app(argc,argv); |
| 57 | // app.setOption("dx","100"); |
| 58 | // app.setOption("dy","100"); |
| 59 | |
| 60 | filter2d::Filter2d filter; |
| 61 | try{ |
| 62 | Jim inputImg(input_opt[0]); |
| 63 | shared_ptr<Jim> mask=make_shared<Jim>(inputImg,true); |
| 64 | shared_ptr<Jim> marker=make_shared<Jim>(inputImg,false); |
| 65 | mask->pushNoDataValue(1); |
| 66 | mask->setThreshold(nodata_opt[0],nodata_opt[0],0); |
| 67 | int theValue=1; |
| 68 | marker->writeData(theValue,static_cast<unsigned int>(1),static_cast<unsigned int>(1),static_cast<unsigned int>(0)); |
| 69 | marker->rdil(mask,8,1); |
| 70 | if(marker!=mask) |
| 71 | std::cout << "Error: check not passed for image " << input_opt[0] << std::endl; |
| 72 | else |
| 73 | std::cout << "Check passed for image " << input_opt[0] << std::endl; |
| 74 | inputImg.close(); |
| 75 | mask->close(); |
| 76 | marker->close(); |
| 77 | } |
| 78 | catch(string helpString){//help was invoked |
| 79 | std::cout << helpString << std::endl; |
| 80 | return(1); |
| 81 | } |
| 82 | return(0); |
| 83 | } |