diff --git a/include/ossim/util/ossimRemapTool.h b/include/ossim/util/ossimRemapTool.h index d2ae5d46b..637577dee 100644 --- a/include/ossim/util/ossimRemapTool.h +++ b/include/ossim/util/ossimRemapTool.h @@ -15,12 +15,27 @@ #include /*! - * Class for Performing histo ans scalar-based remapping. + * ossimTool class for performing histo ans scalar-based remapping. */ class OSSIMDLLEXPORT ossimRemapTool : public ossimChipProcTool { public: ossimRemapTool(); + + /** This constructor packages up all the remap functionality into one "call". There is no need to + * call execute() if this constructor is invoked. The remapped file will be accompanied by an + * OSSIM geom file that echoes the original input image geometry. + * @param inputFile The image file to be remapped. + * @param entry_index For multi-entry input files, specifies the entry to be remapped + * @param skipHistoStretch Set to true to bypass histogram stretch + * @param outputFile If left blank, the output will be "-remap." + * @throws ossimException on error. Use ossimException::what() to get error description. + */ + ossimRemapTool(const ossimFilename& inputFile, + int entryIndex=0, + bool doHistoStretch=true, + ossimFilename outputFile=""); + ~ossimRemapTool(); virtual bool initialize(ossimArgumentParser& ap); diff --git a/src/util/ossimRemapTool.cpp b/src/util/ossimRemapTool.cpp index 08f6fd7ea..ce6ae8cff 100644 --- a/src/util/ossimRemapTool.cpp +++ b/src/util/ossimRemapTool.cpp @@ -3,6 +3,8 @@ // OSSIM Open Source Geospatial Data Processing Library // See top level LICENSE.txt file for license information // +// Author: oscar.kramer@maxar.com +// //************************************************************************************************** #include @@ -34,6 +36,23 @@ ossimRemapTool::ossimRemapTool() theStdOutProgress.setFlushStreamFlag(true); } +ossimRemapTool::ossimRemapTool(const ossimFilename& inputFile, + int entryIndex, + bool doHistoStretch, + ossimFilename outputFile) + : m_inputFilename (inputFile), + m_entry (entryIndex), + m_doHistoStretch(doHistoStretch) +{ + m_productFilename = outputFile; + theStdOutProgress.setFlushStreamFlag(true); + + initProcessingChain(); + + if (!execute()) + throw ossimException("Error encountered writing remap image."); +} + ossimRemapTool::~ossimRemapTool() { } @@ -90,12 +109,6 @@ bool ossimRemapTool::initialize(ossimArgumentParser& ap) m_productFilename = ap[2]; cout<getBoundingRect(m_aoiViewRect); // Parent class has service to create writer: diff --git a/test/src/util/CMakeLists.txt b/test/src/util/CMakeLists.txt index 7fb383482..ca8686bb8 100644 --- a/test/src/util/CMakeLists.txt +++ b/test/src/util/CMakeLists.txt @@ -4,4 +4,5 @@ OSSIM_SETUP_APPLICATION(ossim-chipper-test INSTALL COMMAND_LINE COMPONENT_NAME o OSSIM_SETUP_APPLICATION(ossim-info-test INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ossim-info-test.cpp) OSSIM_SETUP_APPLICATION(ossim-viewshed-test INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ossim-viewshed-test.cpp) OSSIM_SETUP_APPLICATION(ossim-tools-test INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ossim-tools-test.cpp) +OSSIM_SETUP_APPLICATION(ossim-remap-tool-test INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ossim-remap-tool-test.cpp) diff --git a/test/src/util/ossim-remap-tool-test.cpp b/test/src/util/ossim-remap-tool-test.cpp new file mode 100644 index 000000000..e6a0c45cf --- /dev/null +++ b/test/src/util/ossim-remap-tool-test.cpp @@ -0,0 +1,93 @@ +//************************************************************************************************** +// +// OSSIM Open Source Geospatial Data Processing Library +// See top level LICENSE.txt file for license information +// +// Author: oscar.kramer@maxar.com +// +//************************************************************************************************** + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(char* argv0, int exitCode, std::string errMsg="") +{ + if (!errMsg.empty()) + std::cout<<"\n"<-remap.ext" + "\n" + "\nUsage: "< [] " + "\n" + "\nOptions:" + "\n -e Entry index for multi-entry input files." + "\n -h Dump this help." + "\n -n Skip histogram stretch." + "\n"<initialize(ap); + ostringstream msg; + int entryIndex=0, c=0; + bool doHistoStretch=true; + + // USAGE: + // Parse command line: + while ((c = getopt(argc, argv, "e:hn")) != -1) + { + switch (c) + { + case 'e': + entryIndex = atoi(optarg); + break; + case 'h': + usage(argv[0], 0); + break; + case 'n': + doHistoStretch = false; + break; + case '?': + msg << "Unknown option '" << (char) optopt << "' specified."; + usage(argv[0], 1, msg.str()); + break; + default: + abort(); + } + } + + int numArgs = argc - optind; + if (numArgs < 1) + usage(argv[0], 1, "Input filename required."); + + ossimFilename inputFilename (argv[optind++]); + ossimFilename outputFilename; + if (numArgs > 1) + outputFilename = argv[optind]; + + try + { + // Constructor does everything or throws exception: + ossimRemapTool ort (inputFilename, entryIndex, doHistoStretch, outputFilename); + } + catch (const ossimException& e) + { + std::cerr << e.what() << std::endl; + return 1; + } + + return 0; +}