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

#include <ossimEquationUtil.h>

Inheritance diagram for ossimEquationUtil:
ossimObject ossimProcessInterface ossimListenerManager ossimReferenced

Public Member Functions

 ossimEquationUtil (ossimArgumentParser &ap)
 
 ~ossimEquationUtil ()
 
virtual bool execute ()
 Returns true if successful. More...
 
virtual ossimObjectgetObject ()
 
virtual const ossimObjectgetObject () const
 
virtual ossimListenerManagergetManager ()
 
- 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 ossimString getClassName () 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 ossimProcessInterface
 ossimProcessInterface ()
 
virtual ~ossimProcessInterface ()
 
virtual void abort ()
 
bool needsAborting () const
 
bool isAbortRequested () const
 
bool isAborted () const
 
bool isExecuting () const
 
ossimProcessStatus getProcessStatus () const
 
virtual void setProcessStatus (ossimProcessStatus processStatus)
 
virtual double getPercentComplete () const
 
virtual void setPercentComplete (double percentComplete)
 
void enableEvents ()
 
void disableEvents ()
 
void setCurrentMessage (const ossimString &message)
 
virtual std::ostream & print (std::ostream &out) const
 
- Public Member Functions inherited from ossimListenerManager
 ossimListenerManager ()
 
virtual ~ossimListenerManager ()
 
virtual void fireEvent (ossimEvent &event)
 
virtual bool addListener (ossimListener *listener)
 
virtual bool removeListener (ossimListener *listener)
 
virtual bool findListener (ossimListener *listener)
 

Protected Member Functions

 ossimEquationUtil ()
 
void addArguments (ossimArgumentParser &ap)
 
void outputTemplateKeywordlist (const ossimFilename &templateFilename)
 
bool parseKwl (const ossimFilename &kwl_file, std::vector< ossimFilename > &inputs, ossimString &equationSpec, ossimFilename &output, ossimString &writerType)
 
bool initInputSources (std::vector< ossimFilename > &fileList)
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 
- Protected Member Functions inherited from ossimListenerManager
 ossimListenerManager (const ossimListenerManager &rhs)
 

Protected Attributes

ossimArgumentParserm_argumentParser
 
ossimApplicationUsage m_usage
 
ossimConnectableObject::ConnectableObjectList m_inputSources
 
ossimRefPtr< ossimImageGeometrym_prodGeometry
 
- Protected Attributes inherited from ossimProcessInterface
double thePercentComplete
 
ossimProcessStatus theProcessStatus
 
ossimString theMessage
 
bool theEventFlag
 
- Protected Attributes inherited from ossimListenerManager
std::list< ossimListener * > theListenerList
 
bool theEnabledFlag
 
std::list< ossimListener * > theDelayedAdd
 
std::list< ossimListener * > theDelayedRemove
 
bool theFireEventFlag
 

Additional Inherited Members

- Public Types inherited from ossimProcessInterface
enum  ossimProcessStatus {
  PROCESS_STATUS_UNKNOWN = 0, PROCESS_STATUS_EXECUTING = 1, PROCESS_STATUS_ABORTED = 2, PROCESS_STATUS_ABORT_REQUEST = 3,
  PROCESS_STATUS_NOT_EXECUTING = 4
}
 

Detailed Description

Definition at line 23 of file ossimEquationUtil.h.

Constructor & Destructor Documentation

◆ ossimEquationUtil() [1/2]

ossimEquationUtil::ossimEquationUtil ( ossimArgumentParser ap)

Definition at line 156 of file ossimEquationUtil.cpp.

References ossimApplicationUsage::addCommandLineOption(), ossimArgumentParser::getApplicationName(), m_usage, ossimApplicationUsage::setApplicationName(), ossimApplicationUsage::setCommandLineUsage(), and ossimApplicationUsage::setDescription().

158 {
161  " Takes a list of images and performs the specified equation. The inputs"
162  "must be in the same projection as the operations are done at the pixel"
163  "level with no renderer in th chain. The output file will contain the same"
164  "geospatial header info as the first image in the input list.");
166  " \"<equation spec>\" <input_file1> <input_file2> <input_file...> <output_file>");
167  m_usage.addCommandLineOption("-h or --help","Display this information");
168  m_usage.addCommandLineOption("-k <filename>", "keyword list to load from");
169  m_usage.addCommandLineOption("-w <type>", "Writer type (tiff_strip, jpeg, etc... see ossim-info --writers) (default=tiff_strip)");
170  m_usage.addCommandLineOption("--writer-prop <string>", "Adds a property to send to the writer. format is name=value");
171  m_usage.addCommandLineOption("-t <filename>", "output a keyword list template");
172 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
ossimApplicationUsage m_usage
void setCommandLineUsage(const ossimString &explanation)
ossimArgumentParser * m_argumentParser
void setApplicationName(const ossimString &name)
void setDescription(const ossimString &desc)

◆ ~ossimEquationUtil()

ossimEquationUtil::~ossimEquationUtil ( )
inline

Definition at line 29 of file ossimEquationUtil.h.

29 {}

◆ ossimEquationUtil() [2/2]

ossimEquationUtil::ossimEquationUtil ( )
inlineprotected

Definition at line 41 of file ossimEquationUtil.h.

41 : m_argumentParser(0) {}
ossimArgumentParser * m_argumentParser

Member Function Documentation

◆ addArguments()

void ossimEquationUtil::addArguments ( ossimArgumentParser ap)
protected

◆ execute()

bool ossimEquationUtil::execute ( )
virtual

Returns true if successful.

Implements ossimProcessInterface.

Definition at line 174 of file ossimEquationUtil.cpp.

References ossimArgumentParser::argc(), m_argumentParser, m_usage, ossimNotify(), ossimNotifyLevel_INFO, ossimArgumentParser::read(), and ossimApplicationUsage::write().

175 {
176  // Allocate some stuff up front for use later
177  ossimString writerType = "tiff_strip";
178  ossimString equationSpec;
179  std::string tempString;
180  ossimArgumentParser::ossimParameter stringParam(tempString);
181  std::map<ossimString, ossimString, ossimStringLtstr> writerPropertyMap;
182  vector<ossimFilename> infiles;
183  ossimFilename outfile;
184 
185  // Display Help
186  if (m_argumentParser->read("-h") || m_argumentParser->read("--help") || (m_argumentParser->argc() < 4))
187  {
189  ossimNotify(ossimNotifyLevel_INFO)<<EQ_SPEC<<endl;
190  return false;
191  }
192 
193  // Output KWL template
194  if (m_argumentParser->read("-t", stringParam))
195  {
196  ossimFilename templateFilename = tempString.c_str();
197  outputTemplateKeywordlist(templateFilename);
198  return false;
199  }
200 
201  // Keyword list to load from
202  if (m_argumentParser->read("-k", stringParam))
203  {
204  if (!parseKwl(tempString.c_str(), infiles, equationSpec, outfile, writerType))
205  return false;
206  }
207  else
208  {
209  // Everything on command line:
210  // user input writer props, should use those
211  while(m_argumentParser->read("--writer-prop", stringParam))
212  {
213  std::vector<ossimString> nameValue;
214  ossimString(tempString).split(nameValue, "=");
215  if(nameValue.size() == 2)
216  writerPropertyMap.insert(std::make_pair(nameValue[0], nameValue[1]));
217  }
218 
219  // User input a writer type
220  if (m_argumentParser->read("-w", stringParam))
221  writerType = tempString;
222 
223  int argCount = m_argumentParser->argc();
224  if (argCount < 4)
225  {
227  ossimNotify(ossimNotifyLevel_INFO)<<EQ_SPEC<<endl;
228  return false;
229  }
230 
231  // First the equation spec:
232  equationSpec = m_argumentParser->argv()[1];
233 
234  // Get the input files.
235  for (int i=2; i< (argCount-1); ++i)
236  infiles.push_back(ossimFilename(m_argumentParser->argv()[i]));
237 
238  // Get the output file.
239  outfile = m_argumentParser->argv()[argCount-1];
240  }
241 
242  if (!initInputSources(infiles))
243  return false;
244 
245  // Create combiner object
247  combiner->setEquation(equationSpec);
248 
249  // Create writer:
252  if(!writer.valid())
253  {
254  ossimNotify(ossimNotifyLevel_FATAL)<<"Could not create writer of type <"<<writerType<<">"<<endl;
255  return false;
256  }
257  writer->connectMyInputTo(combiner.get());
258  writer->setFilename(outfile);
259  ossimIrect bounding_irect;
260  m_prodGeometry->getBoundingRect(bounding_irect);
261  writer->setAreaOfInterest(bounding_irect);
262  writer->initialize();
263 
264  if ( writerPropertyMap.size() )
265  {
266  ossimPropertyInterface* propInterface = (ossimPropertyInterface*) writer.get();
267  std::map<ossimString, ossimString, ossimStringLtstr>::iterator iter = writerPropertyMap.begin();
268  while(iter!=writerPropertyMap.end())
269  {
270  propInterface->setProperty(iter->first, iter->second);
271  ++iter;
272  }
273  }
274 
275  // Execute:
276  ossimStdOutProgress listener;
277  writer->addListener(&listener);
278  if (!writer->execute())
279  {
280  ossimNotify(ossimNotifyLevel_WARN)<< "Error encountered writing file..."<<endl;
281  return false;
282  }
283 
284  writer->close();
285  return true;
286 }
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
ossimConnectableObject::ConnectableObjectList m_inputSources
virtual void close()=0
ossimApplicationUsage m_usage
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool addListener(ossimListener *listener)
Overrides base "addListener" this will capture the pointer and then call the base class "addListener"...
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...
void getBoundingRect(ossimIrect &bounding_rect) const
Get the bounding rect of (0, 0) to (imageSize.x-1, imageSize.y-1).
Will combine the input data based on a supplied equation.
static ossimImageWriterFactoryRegistry * instance()
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
ossimRefPtr< ossimImageGeometry > m_prodGeometry
virtual void setEquation(const ossimString &equ)
ossimArgumentParser * m_argumentParser
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual void setFilename(const ossimFilename &file)
bool parseKwl(const ossimFilename &kwl_file, std::vector< ossimFilename > &inputs, ossimString &equationSpec, ossimFilename &output, ossimString &writerType)
virtual void initialize()
Initialize method.
virtual void setProperty(const ossimString &name, const ossimString &value)
virtual void setAreaOfInterest(const ossimIrect &inputRect)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool initInputSources(std::vector< ossimFilename > &fileList)
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
char ** argv()
return the argument array.
void outputTemplateKeywordlist(const ossimFilename &templateFilename)
int & argc()
return the argument count.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()

◆ getManager()

virtual ossimListenerManager* ossimEquationUtil::getManager ( )
inlinevirtual

Reimplemented from ossimProcessInterface.

Definition at line 38 of file ossimEquationUtil.h.

38 { return this; };

◆ getObject() [1/2]

virtual ossimObject* ossimEquationUtil::getObject ( )
inlinevirtual

Implements ossimProcessInterface.

Definition at line 36 of file ossimEquationUtil.h.

36 { return this; }

◆ getObject() [2/2]

virtual const ossimObject* ossimEquationUtil::getObject ( ) const
inlinevirtual

Implements ossimProcessInterface.

Definition at line 37 of file ossimEquationUtil.h.

37 { return this; }

◆ initInputSources()

bool ossimEquationUtil::initInputSources ( std::vector< ossimFilename > &  fileList)
protected

Definition at line 357 of file ossimEquationUtil.cpp.

References ossimConnectableObject::connectMyInputTo(), ossimImageGeometry::dup(), ossimRefPtr< T >::get(), ossimImageHandler::getImageGeometry(), ossimImageGeometry::getMetersPerPixel(), ossimImageGeometry::getTiePoint(), ossimImageRenderer::initialize(), ossimImageHandlerRegistry::instance(), ossimImageGeometry::isAffectedByElevation(), m_inputSources, m_prodGeometry, ossimImageHandlerRegistry::open(), ossimImageViewProjectionTransform::setImageGeometry(), ossimImageRenderer::setImageViewTransform(), ossimMapProjection::setMetersPerPixel(), ossimMapProjection::setOrigin(), ossimImageGeometry::setProjection(), ossimImageViewProjectionTransform::setViewGeometry(), and ossimRefPtr< T >::valid().

358 {
359  bool result = true;
360  m_inputSources.clear();
362 
363  for(ossim_int32 index = 0; index < (ossim_int32)fileList.size();++index)
364  {
366  ossimImageHandlerRegistry::instance()->open(fileList[index]);
367  if(!handler.valid())
368  {
369  cerr << "Error: Unable to load image " << fileList[index] << endl;
370  result = false;
371  break;
372  }
373 
374  input_geom = handler->getImageGeometry();
375 
376  if (index == 0)
377  {
378  m_prodGeometry = (ossimImageGeometry*) input_geom->dup();
379  ossimGpt origin;
380  m_prodGeometry->getTiePoint(origin, false);
382 
384  {
385  // Need to ortho to UTM, so define output geometry shared by all input chains:
386  ossimMapProjection* prod_proj = new ossimUtmProjection;
387  prod_proj->setOrigin(origin);
389  m_prodGeometry->setProjection(prod_proj);
390  }
391  }
392 
393  // Set up the IVT for this input's renderer:
395  transform->setImageGeometry(input_geom.get());
396  transform->setViewGeometry(m_prodGeometry.get());
397 
399  renderer->connectMyInputTo(0, handler.get());
400  renderer->setImageViewTransform(transform.get());
401  renderer->initialize();
402 
403  m_inputSources.push_back(renderer.get());
404  }
405 
406  return result;
407 }
void setProjection(ossimProjection *projection)
Sets the projection to be used for local-to-world coordinate transformation.
ossimConnectableObject::ConnectableObjectList m_inputSources
bool isAffectedByElevation() const
Returns TRUE if this geometry is sensitive to elevation.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
bool valid() const
Definition: ossimRefPtr.h:75
virtual void setOrigin(const ossimGpt &origin)
Sets theOrigin to origin.
ossimRefPtr< ossimImageGeometry > m_prodGeometry
void setViewGeometry(ossimImageGeometry *g)
Assigns the geometry to use for output view. This object does NOT own the geometry.
void setImageViewTransform(ossimImageViewTransform *transform)
virtual void setMetersPerPixel(const ossimDpt &gsd)
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
ossimDpt getMetersPerPixel() const
Returns the GSD associated with this image in the active projection.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
void getTiePoint(ossimGpt &tie, bool edge) const
Get the latitude, longitude of the tie point.
static ossimImageHandlerRegistry * instance()
virtual ossimObject * dup() const
Creates a new instance of ossimImageGeometry with the same transform and projection.
void setImageGeometry(ossimImageGeometry *g)
Assigns the geometry to use for input image. This object does NOT own the geometry.
int ossim_int32

◆ outputTemplateKeywordlist()

void ossimEquationUtil::outputTemplateKeywordlist ( const ossimFilename templateFilename)
protected

Definition at line 288 of file ossimEquationUtil.cpp.

References ossimString::c_str(), ossimNotify(), and ossimNotifyLevel_NOTICE.

289 {
290  ofstream out(templateFilename.c_str());
291 
292  out << "file1.filename: <full path and file name>" << endl
293  << "file2.filename: <full path and file name>" << endl
294  << "// :\n"
295  << "// :\n"
296  << "// fileN.filename:: <full path and file name>" << endl
297  << "\n// currently this option has been tested\n"
298  << "// with ossimTiffWriter and ossimJpegWriter\n"
299  << "writer.type: tiff_strip" << endl
300  << "writer.filename: <full path to output file>" << endl
301  << "\n// Equation specification:\n"
302  << "equation: <equation spec string>"<<endl;
303 
304  ossimNotify(ossimNotifyLevel_NOTICE) << "Wrote file: " << templateFilename << std::endl;
305 }
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ parseKwl()

bool ossimEquationUtil::parseKwl ( const ossimFilename kwl_file,
std::vector< ossimFilename > &  inputs,
ossimString equationSpec,
ossimFilename output,
ossimString writerType 
)
protected

Definition at line 307 of file ossimEquationUtil.cpp.

References ossimKeywordlist::addFile(), ossimString::c_str(), ossimString::empty(), ossimKeywordlist::find(), ossimKeywordlist::getNumberOfSubstringKeys(), ossimNotify(), ossimNotifyLevel_FATAL, and ossimString::toString().

312 {
313  ossimKeywordlist kwl;
314  if (!kwl.addFile(kwl_file))
315  return false;
316 
317  ossim_int32 index = 0;
318  ossim_int32 result = kwl.getNumberOfSubstringKeys("file[0-9]+\\.filename");
319  const char* lookup = NULL;
320  ossim_int32 numberOfMatches = 0;
321 
322  while(numberOfMatches < result)
323  {
324  ossimString searchValue = "file" + ossimString::toString(index);
325 
326  ossimString filename = searchValue + ".filename";
327  lookup = kwl.find(filename.c_str());
328  if(lookup)
329  {
330  inputs.push_back(ossimFilename(lookup));
331  ++numberOfMatches;
332  }
333  ++index;
334  }
335 
336  equationSpec = kwl.find("equation");
337  if (equationSpec.empty())
338  {
339  ossimNotify(ossimNotifyLevel_FATAL)<<"No equation specified in KWL"<<endl;
340  return false;
341  }
342 
343  output = kwl.find("writer.filename");
344  if (output.empty())
345  {
346  ossimNotify(ossimNotifyLevel_FATAL)<<"No output filename specified in KWL"<<endl;
347  return false;
348  }
349 
350  writerType = kwl.find("writer.type");
351  if (writerType.empty())
352  writerType = "tiff_strip";
353 
354  return true;
355 }
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
Represents serializable keyword/value map.
bool addFile(const char *file)
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

Member Data Documentation

◆ m_argumentParser

ossimArgumentParser* ossimEquationUtil::m_argumentParser
protected

Definition at line 52 of file ossimEquationUtil.h.

Referenced by execute().

◆ m_inputSources

ossimConnectableObject::ConnectableObjectList ossimEquationUtil::m_inputSources
protected

Definition at line 54 of file ossimEquationUtil.h.

Referenced by initInputSources().

◆ m_prodGeometry

ossimRefPtr<ossimImageGeometry> ossimEquationUtil::m_prodGeometry
protected

Definition at line 55 of file ossimEquationUtil.h.

Referenced by initInputSources().

◆ m_usage

ossimApplicationUsage ossimEquationUtil::m_usage
protected

Definition at line 53 of file ossimEquationUtil.h.

Referenced by execute(), and ossimEquationUtil().


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