forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added constructor for standalone execution
- Loading branch information
oscarkramer
committed
Jul 16, 2019
1 parent
216695b
commit 1894991
Showing
4 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
// OSSIM Open Source Geospatial Data Processing Library | ||
// See top level LICENSE.txt file for license information | ||
// | ||
// Author: [email protected] | ||
// | ||
//************************************************************************************************** | ||
|
||
#include <ossim/util/ossimRemapTool.h> | ||
|
@@ -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<<m_inputFilename<<endl; | ||
} | ||
if (m_productFilename.empty()) | ||
{ | ||
m_productFilename = m_inputFilename.fileNoExtension() + "-remap"; | ||
m_productFilename.setExtension(m_inputFilename.ext()); | ||
} | ||
|
||
try | ||
{ | ||
initProcessingChain(); | ||
|
@@ -168,6 +181,12 @@ void ossimRemapTool::initProcessingChain() | |
|
||
bool ossimRemapTool::execute() | ||
{ | ||
if (m_productFilename.empty()) | ||
{ | ||
m_productFilename = m_inputFilename.fileNoExtension() + "-remap"; | ||
m_productFilename.setExtension(m_inputFilename.ext()); | ||
} | ||
|
||
m_geom->getBoundingRect(m_aoiViewRect); | ||
|
||
// Parent class has service to create writer: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//************************************************************************************************** | ||
// | ||
// OSSIM Open Source Geospatial Data Processing Library | ||
// See top level LICENSE.txt file for license information | ||
// | ||
// Author: [email protected] | ||
// | ||
//************************************************************************************************** | ||
|
||
#include <ossim/base/ossimArgumentParser.h> | ||
#include <ossim/base/ossimException.h> | ||
#include <ossim/base/ossimFilename.h> | ||
#include <ossim/util/ossimRemapTool.h> | ||
#include <ossim/base/ossimNotify.h> | ||
#include <ossim/base/ossimRefPtr.h> | ||
#include <ossim/init/ossimInit.h> | ||
#include <getopt.h> | ||
#include <iostream> | ||
#include <memory> | ||
|
||
void usage(char* argv0, int exitCode, std::string errMsg="") | ||
{ | ||
if (!errMsg.empty()) | ||
std::cout<<"\n"<<errMsg<<std::endl; | ||
std::cout<< | ||
"\nPerforms remap to 8-bit including optional histogram stretch and saves the corresponding" | ||
"\nexternal geometry file. If output filename is omitted, the output will be <input-image>-remap.ext" | ||
"\n" | ||
"\nUsage: "<<argv0<<" [options] <input-image.ext> [<output-image>] " | ||
"\n" | ||
"\nOptions:" | ||
"\n -e <N> Entry index for multi-entry input files." | ||
"\n -h Dump this help." | ||
"\n -n Skip histogram stretch." | ||
"\n"<<std::endl; | ||
exit(exitCode); | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
ossimArgumentParser ap(&argc, argv); | ||
ossimInit::instance()->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; | ||
} |