Skip to content

Commit

Permalink
Added constructor for standalone execution
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarkramer committed Jul 16, 2019
1 parent 216695b commit 1894991
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 7 deletions.
17 changes: 16 additions & 1 deletion include/ossim/util/ossimRemapTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@
#include <ossim/imaging/ossimSingleImageChain.h>

/*!
* 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 "<inputFile>-remap.<ext>"
* @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);
Expand Down
31 changes: 25 additions & 6 deletions src/util/ossimRemapTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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()
{
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

93 changes: 93 additions & 0 deletions test/src/util/ossim-remap-tool-test.cpp
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;
}

0 comments on commit 1894991

Please sign in to comment.