OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
ossimTool Class Referenceabstract

#include <ossimTool.h>

Inheritance diagram for ossimTool:
ossimObject ossim::JsonInterface ossimReferenced ATP::ossimAtpTool ossimChipProcTool ossimDemTool ossimInfo ossimPointCloudTool ossimVerticesFinderTool ossimBandMergeTool ossimHdf5Tool ossimHillshadeTool ossimHlzTool ossimOrthoTool ossimPotraceTool ossimRegTool ossimShorelineTool ossimSlopeTool ossimSubImageTool ossimViewshedTool

Public Member Functions

 ossimTool ()
 
virtual ~ossimTool ()
 
virtual bool initialize (ossimArgumentParser &ap)
 Initializes from command line arguments. More...
 
virtual void initialize (const ossimKeywordlist &kwl)
 Reads processing params from KWL and prepares for execute. More...
 
virtual void loadJSON (const Json::Value &json_request)
 Reads processing params from JSON object provided. More...
 
virtual void saveJSON (Json::Value &json) const
 Fetch product as JSON object when applicable Always returns true since using exception on error. More...
 
virtual bool execute ()=0
 Writes product to output file if applicable. More...
 
virtual const std::string & getResponse () const
 Fetch product as string (typically JSON) when applicable, otherwise passes back empty string. More...
 
virtual void clear ()
 Disconnects and clears the DEM and image layers. More...
 
virtual void abort ()
 Kills current (asynchronous) process. More...
 
virtual void getKwlTemplate (ossimKeywordlist &kwl)
 Assigns a template keywordlist to string for initializing derived classes. More...
 
void getAPI (std::string &out) const
 Outputs a JSON representation of the Utility's API. More...
 
std::string getAPI () const
 
virtual ossimString getClassName () const
 
void getBuildDate (std::string &s) const
 Gets build date. More...
 
void getRevision (std::string &s) const
 Gets revision. More...
 
void getVersion (std::string &s) const
 Gets version. More...
 
virtual bool isChipProcessor () const
 Overrides base class implementation to indicate this class supports getChip() calls. More...
 
void setOutputStream (std::ostream *os)
 Redirects any console output to the supplied stream for logging or JNI application. More...
 
bool helpRequested () const
 Returns true when the initialization detects a "--help" option, so caller can avoid subsequent execute() call. More...
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 
- Public Member Functions inherited from ossim::JsonInterface
 JsonInterface ()
 
virtual ~JsonInterface ()
 

Protected Member Functions

virtual void setUsage (ossimArgumentParser &ap)
 Initializes the aurgument parser with expected parameters and options. More...
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

ossimKeywordlist m_kwl
 
std::ostream * m_consoleStream
 
bool m_helpRequested
 
std::string m_response
 

Private Member Functions

bool readTextFile (const ossimFilename &filename, std::string &contents) const
 Used for reading text files of template and JSON API from disk ONLY. More...
 

Detailed Description

Base class for all OSSIM tool applications. These are utilities providing high-level functionality via the OSSIM library.

Definition at line 22 of file ossimTool.h.

Constructor & Destructor Documentation

◆ ossimTool()

ossimTool::ossimTool ( )

Definition at line 17 of file ossimTool.cpp.

18  : m_kwl(),
19  m_consoleStream (&cout),
20  m_helpRequested (false)
21 {
22 }
bool m_helpRequested
Definition: ossimTool.h:150
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
std::ostream * m_consoleStream
Definition: ossimTool.h:149

◆ ~ossimTool()

ossimTool::~ossimTool ( )
virtual

Definition at line 24 of file ossimTool.cpp.

25 {
26 }

Member Function Documentation

◆ abort()

void ossimTool::abort ( )
virtual

Kills current (asynchronous) process.

Defaults to do nothing.

Reimplemented in ossimChipProcTool.

Definition at line 32 of file ossimTool.cpp.

33 {
34 }

◆ clear()

void ossimTool::clear ( )
virtual

Disconnects and clears the DEM and image layers.

Leaves OSSIM initialized.

Reimplemented in ossimChipProcTool, and ossimViewshedTool.

Definition at line 28 of file ossimTool.cpp.

29 {
30 }

◆ execute()

virtual bool ossimTool::execute ( )
pure virtual

Writes product to output file if applicable.

The product may also beAlways returns true since using exception on error.

Note
Throws ossimException on error.

Implemented in ossimChipProcTool, ossimInfo, ossimSubImageTool, ossimViewshedTool, ossimHdf5Tool, ossimShorelineTool, ossimHlzTool, ossimPointCloudTool, ATP::ossimAtpTool, ossimDemTool, ossimPotraceTool, ossimBandMergeTool, ossimVerticesFinderTool, and ossimRegTool.

Referenced by ossimDemTool::doOMG(), ossimShorelineTool::execute(), and ossimToolServer::runCommand().

◆ getAPI() [1/2]

void ossimTool::getAPI ( std::string &  out) const

Outputs a JSON representation of the Utility's API.

◆ getAPI() [2/2]

string ossimTool::getAPI ( ) const

Definition at line 124 of file ossimTool.cpp.

Referenced by initialize().

125 {
126  string result;
127  getAPI(result);
128  return result;
129 }
std::string getAPI() const
Definition: ossimTool.cpp:124

◆ getBuildDate()

void ossimTool::getBuildDate ( std::string &  s) const

Gets build date.

Parameters
sString to initialize.

Definition at line 161 of file ossimTool.cpp.

References OSSIM_BUILD_DATE.

162 {
163 #ifdef OSSIM_BUILD_DATE
164  s = OSSIM_BUILD_DATE;
165 #else
166  s = "unknown";
167 #endif
168 }
#define OSSIM_BUILD_DATE
Definition: ossimVersion.h:12

◆ getClassName()

ossimString ossimTool::getClassName ( ) const
virtual

◆ getKwlTemplate()

void ossimTool::getKwlTemplate ( ossimKeywordlist kwl)
virtual

Assigns a template keywordlist to string for initializing derived classes.

Reimplemented in ATP::ossimAtpTool, ossimDemTool, ossimPotraceTool, ossimVerticesFinderTool, ossimRegTool, and ossimBandMergeTool.

Definition at line 100 of file ossimTool.cpp.

References ossimKeywordlist::addFile(), ossimFilename::dirCat(), getClassName(), ossimPreferences::instance(), ossimNotify(), and ossimNotifyLevel_WARN.

Referenced by ossimBandMergeTool::getKwlTemplate(), and initialize().

101 {
103  preferencesKWL().findKey( std::string( "ossim_share_directory" ) );
104  ossimFilename classTemplate = "util/" + getClassName() + ".kwl";
105  ossimFilename kwl_path = share_dir.dirCat( classTemplate );
106 
107  if (!kwl.addFile(kwl_path))
108  {
109  ossimNotify(ossimNotifyLevel_WARN)<<"ossimTool::getKwlTemplate() -- Could not find <"
110  <<kwl_path<<">. Ignoring"<<endl;
111  }
112 }
bool addFile(const char *file)
virtual ossimString getClassName() const
Definition: ossimTool.cpp:36
static ossimPreferences * instance()
ossimFilename dirCat(const ossimFilename &file) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getResponse()

virtual const std::string& ossimTool::getResponse ( ) const
inlinevirtual

Fetch product as string (typically JSON) when applicable, otherwise passes back empty string.

Always returns true since using exception on error.

Returns
Returns non-empty string if valid response available.

Definition at line 72 of file ossimTool.h.

72 { return m_response; }
std::string m_response
Definition: ossimTool.h:151

◆ getRevision()

void ossimTool::getRevision ( std::string &  s) const

Gets revision.

Parameters
sString to initialize.

Definition at line 170 of file ossimTool.cpp.

References OSSIM_REVISION.

171 {
172 #ifdef OSSIM_REVISION
173  s = OSSIM_REVISION;
174 #else
175  s = "unknown";
176 #endif
177 }
#define OSSIM_REVISION
Definition: ossimVersion.h:9

◆ getVersion()

void ossimTool::getVersion ( std::string &  s) const

Gets version.

Parameters
sString to initialize.

Definition at line 179 of file ossimTool.cpp.

References OSSIM_VERSION.

180 {
181 #ifdef OSSIM_VERSION
182  s = OSSIM_VERSION;
183 #else
184  s = "unknown";
185 #endif
186 }
#define OSSIM_VERSION
Definition: ossimVersion.h:4

◆ helpRequested()

bool ossimTool::helpRequested ( ) const
inline

Returns true when the initialization detects a "--help" option, so caller can avoid subsequent execute() call.

If execute() is called, it will return true after trivial execute.

Definition at line 134 of file ossimTool.h.

Referenced by ossimToolServer::runCommand().

134 { return m_helpRequested; }
bool m_helpRequested
Definition: ossimTool.h:150

◆ initialize() [1/2]

bool ossimTool::initialize ( ossimArgumentParser ap)
virtual

Initializes from command line arguments.

This base class has some common arguments to read. The derived class should call this implementation in addition to setting its own arguments.

Parameters
apRepresents command line.
Returns
FALSE if –help option requested or no params provided, so that derived classes can exit without error.
Note
Throws ossimException on error.

Reimplemented in ossimChipProcTool, ossimInfo, ossimShorelineTool, ossimHdf5Tool, ossimHillshadeTool, ossimSubImageTool, ossimHlzTool, ossimViewshedTool, ossimOrthoTool, ossimSlopeTool, ossimPointCloudTool, ATP::ossimAtpTool, ossimDemTool, ossimPotraceTool, ossimBandMergeTool, ossimVerticesFinderTool, and ossimRegTool.

Definition at line 58 of file ossimTool.cpp.

References getAPI(), ossimArgumentParser::getApplicationUsage(), getKwlTemplate(), m_helpRequested, ossimNotify(), ossimNotifyLevel_INFO, ossimArgumentParser::read(), setUsage(), and ossimApplicationUsage::write().

Referenced by ossimShorelineTool::execute(), ossimVerticesFinderTool::initialize(), ossimRegTool::initialize(), ossimPotraceTool::initialize(), ATP::ossimAtpTool::initialize(), ossimDemTool::initialize(), ossimSubImageTool::initialize(), ossimChipProcTool::initialize(), and ossimToolServer::runCommand().

59 {
60  m_helpRequested = false;
61  if (ap.read("-h") || ap.read("--help") )
62  {
63  // Write usage.
64  setUsage(ap);
66  m_helpRequested = true;
67  return true;
68  }
69 
70  std::string ts1;
72 
73  if ( ap.read("--write-api", sp1))
74  {
75  ofstream ofs ( ts1.c_str() );
76  ossimString json_str;
77  getAPI(json_str);
78  ofs << json_str <<endl;
79  return true;
80  }
81 
82  if ( ap.read("--write-template", sp1))
83  {
84  ofstream ofs ( ts1.c_str() );
85  ossimKeywordlist kwl;
86  getKwlTemplate(kwl);
87  ofs << kwl <<endl;
88  return true;
89  }
90 
91  return true;
92 }
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
Represents serializable keyword/value map.
bool m_helpRequested
Definition: ossimTool.h:150
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
virtual void getKwlTemplate(ossimKeywordlist &kwl)
Assigns a template keywordlist to string for initializing derived classes.
Definition: ossimTool.cpp:100
ossimApplicationUsage * getApplicationUsage()
std::string getAPI() const
Definition: ossimTool.cpp:124
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
Definition: ossimTool.cpp:41
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ initialize() [2/2]

void ossimTool::initialize ( const ossimKeywordlist kwl)
virtual

Reads processing params from KWL and prepares for execute.

Returns TRUE if successful.

Parameters
kwlFull keyword-list representing state
Note
Throws ossimException on error.

Reimplemented in ossimChipProcTool, ossimHdf5Tool, ossimSubImageTool, ossimShorelineTool, ossimOrthoTool, ossimSlopeTool, ossimViewshedTool, ossimHlzTool, ossimPotraceTool, ossimBandMergeTool, ossimVerticesFinderTool, and ossimRegTool.

Definition at line 94 of file ossimTool.cpp.

References m_helpRequested, and m_kwl.

95 {
96  m_helpRequested = false;
97  m_kwl = kwl;
98 }
bool m_helpRequested
Definition: ossimTool.h:150
ossimKeywordlist m_kwl
Definition: ossimTool.h:148

◆ isChipProcessor()

virtual bool ossimTool::isChipProcessor ( ) const
inlinevirtual

Overrides base class implementation to indicate this class supports getChip() calls.

Can be done with dynamic cast and pointer test, but not sure how that is supported in SWIG (OLK 11/2015).

Reimplemented in ossimChipProcTool.

Definition at line 123 of file ossimTool.h.

Referenced by ossimToolServer::runCommand().

123 { return false; }

◆ loadJSON()

virtual void ossimTool::loadJSON ( const Json::Value &  json_request)
inlinevirtual

Reads processing params from JSON object provided.

If all good, the object is ready for subsequent call to execute().

Note
Throws ossimException on error.

Implements ossim::JsonInterface.

Reimplemented in ATP::ossimAtpTool, ossimDemTool, and ossimPointCloudTool.

Definition at line 52 of file ossimTool.h.

Referenced by ossimDemTool::doOMG().

52 {};

◆ readTextFile()

bool ossimTool::readTextFile ( const ossimFilename filename,
std::string &  contents 
) const
private

Used for reading text files of template and JSON API from disk ONLY.

Definition at line 131 of file ossimTool.cpp.

References ossimFilename::append(), ossimString::chars(), ossimNotify(), and ossimNotifyLevel_WARN.

132 {
133  contents.clear();
134 
135  std::ifstream is(filename.chars());
136  if (!is)
137  {
138  ossimNotify(ossimNotifyLevel_WARN)<<"ossimTool::readTextFile() -- Could not find <"
139  <<filename<<">. Ignoring."<<endl;
140  return false;
141  }
142 
143  // get length of file:
144  is.seekg (0, is.end);
145  int length = is.tellg();
146  is.seekg (0, is.beg);
147 
148  // allocate memory:
149  char *buffer = new char [length];
150 
151  // read data as a block:
152  is.read (buffer,length);
153  is.close();
154 
155  contents.append(buffer);
156  delete [] buffer;
157 
158  return true;
159 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
ossimFilename & append(const ossimString &append_this_to_filename)
Convenience method to append a string to the base-name portion of the filename.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ saveJSON()

virtual void ossimTool::saveJSON ( Json::Value &  json) const
inlinevirtual

Fetch product as JSON object when applicable Always returns true since using exception on error.

Parameters
jsonReturns non-empty object if valid response available.

Implements ossim::JsonInterface.

Reimplemented in ATP::ossimAtpTool, ossimDemTool, and ossimPointCloudTool.

Definition at line 59 of file ossimTool.h.

Referenced by ossimDemTool::doOMG().

59 { json.clear(); }

◆ setOutputStream()

void ossimTool::setOutputStream ( std::ostream *  os)
inline

Redirects any console output to the supplied stream for logging or JNI application.

Definition at line 128 of file ossimTool.h.

Referenced by ossimShorelineTool::execute().

128 { m_consoleStream = os; }
std::ostream * m_consoleStream
Definition: ossimTool.h:149

◆ setUsage()

void ossimTool::setUsage ( ossimArgumentParser ap)
protectedvirtual

Initializes the aurgument parser with expected parameters and options.

It does not output anything. To see the usage, the caller will need to do something like:

ap.getApplicationUsage()->write(<ostream>);

This base class has some common arguments to add. The derived class should call this implementation in addition to setting its own arguments.

Reimplemented in ossimChipProcTool, ossimInfo, ossimShorelineTool, ossimHillshadeTool, ossimHlzTool, ossimHdf5Tool, ossimViewshedTool, ossimSubImageTool, ossimOrthoTool, ossimSlopeTool, ATP::ossimAtpTool, ossimDemTool, ossimPotraceTool, ossimBandMergeTool, ossimVerticesFinderTool, and ossimRegTool.

Definition at line 41 of file ossimTool.cpp.

References ossimApplicationUsage::addCommandLineOption(), ossimInit::addOptions(), ossimArgumentParser::getApplicationName(), ossimArgumentParser::getApplicationUsage(), ossimInit::instance(), and ossimApplicationUsage::setApplicationName().

Referenced by initialize(), ossimVerticesFinderTool::setUsage(), ossimRegTool::setUsage(), ossimPotraceTool::setUsage(), ATP::ossimAtpTool::setUsage(), ossimDemTool::setUsage(), ossimSubImageTool::setUsage(), and ossimChipProcTool::setUsage().

42 {
43  // Add global usage options.
45 
46  std::string appName = ap.getApplicationName();
48  au->setApplicationName( ossimString( appName ) );
49 
51  "--write-api <filename>",
52  "Writes a JSON API specification to the specified filename.");
54  "--write-template <filename>",
55  "Writes a template keyword-list to the specified filename.");
56 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void addOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:100
ossimApplicationUsage * getApplicationUsage()
void setApplicationName(const ossimString &name)
static ossimInit * instance()
Definition: ossimInit.cpp:89

Member Data Documentation

◆ m_consoleStream

std::ostream* ossimTool::m_consoleStream
protected

Definition at line 149 of file ossimTool.h.

Referenced by ossimShorelineTool::execute(), and ossimPotraceTool::writeGeoJSON().

◆ m_helpRequested

bool ossimTool::m_helpRequested
protected

◆ m_kwl

ossimKeywordlist ossimTool::m_kwl
protected

◆ m_response

std::string ossimTool::m_response
protected

Definition at line 151 of file ossimTool.h.


The documentation for this class was generated from the following files: