OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVerticesFinderTool.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
8 #include <ossim/init/ossimInit.h>
11 #include <ossim/base/ossimNotify.h>
19 #include <iostream>
20 
21 using namespace std;
22 
24  "Utility for determining the active image corner vertices inside larger null-filled image "
25  "rectangle.";
26 
28 : m_entryIndex (0)
29 {
30 }
31 
33 {
34 }
35 
37 {
38  // Add options.
40  ossimString usageString = ap.getApplicationName();
41  usageString += " vertices [options] <input-image> [<output-vertices.kwl>]";
42  au->setCommandLineUsage(usageString);
43 
44  // Set the command line options:
46 
47  // Base class has its own:
49 
50  au->addCommandLineOption("-e or --entry",
51  "<entry> For multi image handlers which entry do you wish to extract. "
52  "For list of entries use: \"ossim-info -i <your_image>\" ");
53 }
54 
56 {
57  if (!ossimTool::initialize(ap))
58  return false;
59  if (m_helpRequested)
60  return true;
61 
62  std::string tempString1;
63  ossimArgumentParser::ossimParameter stringParam1(tempString1);
64 
65  if ( ap.read("-e", stringParam1) || ap.read("--entry", stringParam1) )
66  m_kwl.addPair( std::string(ossimKeywordNames::ENTRY_KW), tempString1 );
67 
68  cout<<ap.argc()<<endl;//TODO:REMOVE
69 
70  if ( ap.argc() > 1 )
71  {
73  ap.remove(1);
74  }
75  if ( ap.argc() > 1 )
76  {
78  ap.remove(1);
79  }
80  if ( ap.argc() > 1 )
81  {
82  ossimNotify(ossimNotifyLevel_NOTICE)<<"ossimVerticesFinderUtil:"<<__LINE__<<" Too many "
83  "arguments provided on command line. Ignoring superfluous entries.";
84  }
85 
87  return true;
88 }
89 
91 {
92  ostringstream errMsg;
93 
94  // Don't copy KWL if member KWL passed in:
95  if (&kwl != &m_kwl)
96  {
97  // Start with clean options keyword list.
98  m_kwl.clear();
99  m_kwl.addList( kwl, true );
100  }
101 
103 
105 
107  if (!value.empty())
108  m_entryIndex = value.toUInt32();
109 
110  // See if an LUT is requested:
112  {
113  errMsg<<"ERROR ossimVerticesFinderUtil:"<<__LINE__<<" Input filename was not provided or "
114  " file <"<<m_inputFile <<"> is not readable. "<<ends;
115  throw ossimException(errMsg.str());
116  }
117 
118  if (m_outputFile.empty())
119  {
122  m_outputFile += "_vertices.kwl";
123  }
124 }
125 
127 {
128  if (m_helpRequested)
129  return true;
130 
131  ostringstream errMsg;
132 
133  // Get an image handler for the input file.
135  if (ih.valid())
136  {
138  }
139  else
140  {
141  errMsg<<"ERROR ossimVerticesFinderUtil:"<<__LINE__<<" Unsupported image file format for <"
142  << m_inputFile<<">. Cannot open file.";
143  throw ossimException(errMsg.str());
144  }
145 
146  // Give the image handler to the vertex extractor as an input source.
148 
149  // Set the file name.
151 
152  // Set the area of interest to the full bounding rect of the source.
154 
155  // Add a listener for the percent complete to standard output.
156  ossimStdOutProgress prog(0, true);
157  ve->addListener(&prog);
158 
159  // Start the extraction...
160  bool success = ve->execute();
161  return success;
162 }
163 
164 
166 {
167  kwl.add(ossimKeywordNames::ENTRY_KW, "<sub-image entry index>");
168  kwl.add(ossimKeywordNames::IMAGE_FILE_KW, "<input-raster-file>");
169  kwl.add(ossimKeywordNames::OUTPUT_FILE_KW, "<output-vertices-file>");
170 }
171 
static const char * DESCRIPTION
Used by ossimUtilityFactory.
virtual bool addListener(ossimListener *listener)
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void setAreaOfInterest(const ossimIrect &rect)
Class ossimVertexExtractor.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static const char * OUTPUT_FILE_KW
virtual bool initialize(ossimArgumentParser &ap)
Initializes from command line arguments.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
Represents serializable keyword/value map.
bool m_helpRequested
Definition: ossimTool.h:150
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
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 setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
void addList(const ossimKeywordlist &src, bool overwrite=true)
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
ossim_uint32 toUInt32() const
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
virtual void getKwlTemplate(ossimKeywordlist &kwl)
Assigns a template keywordlist to string for initializing derived classes.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void setOutputName(const ossimString &filename)
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
Definition: ossimTool.cpp:41
virtual bool initialize(ossimArgumentParser &ap)
Initializes from command line arguments.
Definition: ossimTool.cpp:58
virtual bool execute()
Writes product to output file if applicable.
bool isReadable() const
static const char * ENTRY_KW
void remove(int pos, int num=1)
remove one or more arguments from the argv argument list, and decrement the argc respectively.
void setDescription(const ossimString &desc)
ossimFilename fileNoExtension() const
ossimFilename dirCat(const ossimFilename &file) const
bool empty() const
Definition: ossimString.h:411
static ossimImageHandlerRegistry * instance()
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
static const char * IMAGE_FILE_KW
virtual bool setCurrentEntry(ossim_uint32 entryIdx)
int & argc()
return the argument count.
ossimFilename path() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)