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

#include <ossimShorelineTool.h>

Inheritance diagram for ossimShorelineTool:
ossimChipProcTool ossimTool ossimProcessInterface ossimListenerManager ossimObject ossim::JsonInterface ossimReferenced

Public Types

enum  AlgorithmId { UNKNOWN, NDWI, AWEI, PAN_THRESHOLD }
 
enum  ThresholdMode {
  NONE =0, MEAN =1, SIGMA =2, VARIANCE =3,
  VALUE =4
}
 
- 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
}
 

Public Member Functions

 ossimShorelineTool ()
 
 ~ossimShorelineTool ()
 
virtual void setUsage (ossimArgumentParser &ap)
 Initializes the aurgument parser with expected parameters and options. More...
 
virtual bool initialize (ossimArgumentParser &ap)
 Initial method to be ran prior to execute. More...
 
virtual void initialize (const ossimKeywordlist &kwl)
 This method is responsible for completely setting up the full processing chain according to the specifications given in the kwl passed in. More...
 
virtual ossimRefPtr< ossimImageDatagetChip (const ossimIrect &img_rect)
 The meat and potatos of this class. More...
 
virtual bool execute ()
 Performs the actual product write. More...
 
virtual ossimString getClassName () const
 
- Public Member Functions inherited from ossimChipProcTool
 ossimChipProcTool ()
 default constructor More...
 
virtual ~ossimChipProcTool ()
 virtual destructor More...
 
virtual void clear ()
 Disconnects and clears the dem and image layers. More...
 
virtual void abort ()
 
virtual bool isChipProcessor () const
 Overrides base class implementation to indicate this class supports getChip() calls. More...
 
virtual ossimListenerManagergetManager ()
 
virtual ossimObjectgetObject ()
 
virtual const ossimObjectgetObject () const
 
virtual ossimRefPtr< ossimImageDatagetChip (const ossimGrect &gnd_rect)
 
ossimRefPtr< ossimImageDatagetChip (const ossimDrect &map_bounding_rect, const ossimDpt &gsd)
 
ossimRefPtr< ossimImageDatagetChip ()
 Get chip method that assumes pre-initialized state. More...
 
const ossimFilenamegetProductFilename () const
 
- Public Member Functions inherited from ossimTool
 ossimTool ()
 
virtual ~ossimTool ()
 
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 const std::string & getResponse () const
 Fetch product as string (typically JSON) when applicable, otherwise passes back empty string. 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
 
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...
 
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 ()
 
- Public Member Functions inherited from ossimProcessInterface
 ossimProcessInterface ()
 
virtual ~ossimProcessInterface ()
 
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)
 

Static Public Attributes

static const char * DESCRIPTION
 Used by ossimUtilityFactory. More...
 

Protected Member Functions

virtual void initProcessingChain ()
 Derived classes initialize their custom chains here. More...
 
void initLandsat8 ()
 
 ossimShorelineTool (const ossimShorelineTool &obj)
 Hidden from use copy constructor. More...
 
const ossimShorelineTooloperator= (const ossimShorelineTool &rhs)
 Hidden from use assignment operator. More...
 
void usage (ossimArgumentParser &ap)
 Initializes arg parser and outputs usage. More...
 
void addArguments (ossimArgumentParser &ap)
 
void doThreshold ()
 
void autoComputeThreshold ()
 
- Protected Member Functions inherited from ossimChipProcTool
void processRemainingArgs (ossimArgumentParser &ap)
 Intended to be called after derived class has picked off its own options from the parser, and arguments remain (such as input and output filenames). More...
 
virtual void finalizeChain ()
 Called after initProcessingChain() to append common items to the processing chain. More...
 
virtual void loadImageFiles ()
 Creates chains for image entries associated with specified keyword. More...
 
virtual void loadDemFiles ()
 Loads all DEM files specified in master KWL into the elev manager's database. More...
 
ossimRefPtr< ossimSingleImageChaincreateInputChain (const ossimFilename &image_file, ossim_uint32 entry_index=0)
 Creates the ossimSingleImageChain from image filename and populates the chain with resampler and product output projection on view-side of resampler's IVT. More...
 
void createOutputProjection ()
 Creates the output or view projection. More...
 
ossimRefPtr< ossimMapProjectionnewIdentityProjection ()
 Sets the single image chain for identity operations view to a ossimImageViewAffineTransform. More...
 
ossimRefPtr< ossimMapProjectionnewUtmProjection ()
 Convenience method to get a utm projection. More...
 
virtual void initializeProjectionGsd ()
 Initializes the projection gsd. More...
 
virtual void initializeAOI ()
 Initializes m_aoiViewRect with the output area of interest as specified in master KWL. More...
 
bool getProjectionOrigin (ossimGpt &gpt)
 Reads the KWL for origin latitude and central meridian. More...
 
ossimRefPtr< ossimImageFileWriternewWriter ()
 Creates a new writer. More...
 
void propagateGeometryToChains ()
 Loops through all chains and sets the output projection. More...
 
ossimRefPtr< ossimImageSourcecombineLayers (std::vector< ossimRefPtr< ossimSingleImageChain > > &layers) const
 When multiple input sources are present, this method instantiates a combiner and adds inputs. More...
 
void computeAdjustedViewFromGrect ()
 Initializes m_aoiViewRect given m_aoiGroundRect. More...
 
void setAoiToInputs ()
 Assigns the AOI to be the bounding rect of the union of all inputs. More...
 
void getBandList (ossim_uint32 image_idx, std::vector< ossim_uint32 > &bandList) const
 Gets the band list if BANDS keyword is set. More...
 
void setReaderProps (ossimImageHandler *ih) const
 Passes reader properties to single image handler if any. More...
 
 ossimChipProcTool (const ossimChipProcTool &obj)
 Hidden from use copy constructor. More...
 
const ossimChipProcTooloperator= (const ossimChipProcTool &)
 Hidden from use assignment operator. More...
 
ossimRefPtr< ossimGeoPolygoncreateClipPolygon () const
 
void findCenterGpt (ossimGpt &gpt)
 Tries to determine the AOI center point based on KWL entries, else returns NaNs in gpt. More...
 
ossimRefPtr< ossimImageSourcemosaicDemSources ()
 Some utilities need to work on DEMs as images. More...
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 
- Protected Member Functions inherited from ossimListenerManager
 ossimListenerManager (const ossimListenerManager &rhs)
 

Protected Attributes

ossim_uint8 m_waterValue
 
ossim_uint8 m_marginalValue
 
ossim_uint8 m_landValue
 
ossimString m_sensor
 
double m_threshold
 
double m_tolerance
 
AlgorithmId m_algorithm
 
ThresholdMode m_thresholdMode
 
double m_smoothing
 
ossimFilename m_vectorFilename
 
ossimFilename m_indexFilename
 
ossimFilename m_threshFilename
 
ossimFilename m_maskFilename
 
std::map< ossimString, ossimStringm_geoJsonProps
 
bool m_noVector
 
- Protected Attributes inherited from ossimChipProcTool
ossimRefPtr< ossimImageGeometrym_geom
 
ossimIrect m_aoiViewRect
 
ossimGrect m_aoiGroundRect
 
std::vector< ossimRefPtr< ossimSingleImageChain > > m_imgLayers
 
std::vector< ossimFilenamem_demSources
 
ossimRefPtr< ossimImageFileWriterm_writer
 
ossimRefPtr< ossimImageChainm_procChain
 
ossimRefPtr< ossimRectangleCutFilterm_cutRectFilter
 
bool m_projIsIdentity
 
ossimDpt m_gsd
 
bool m_geoScaled
 
ossimFilename m_productFilename
 
ossimScalarType m_productScalarType
 
bool m_needCutRect
 
- Protected Attributes inherited from ossimTool
ossimKeywordlist m_kwl
 
std::ostream * m_consoleStream
 
bool m_helpRequested
 
std::string m_response
 
- 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
 

Detailed Description

Class for finding helicopter landing zones (HLZ) on a DEM given the final destination and max range from destination.

Definition at line 36 of file ossimShorelineTool.h.

Member Enumeration Documentation

◆ AlgorithmId

◆ ThresholdMode

Constructor & Destructor Documentation

◆ ossimShorelineTool() [1/2]

ossimShorelineTool::ossimShorelineTool ( )

Definition at line 49 of file ossimShorelineTool.cpp.

50 : m_waterValue (0),
51  m_marginalValue (128),
52  m_landValue (255),
53  m_sensor ("ls8"),
54  m_threshold (-1.0), // Flags auto-thresholding
55  m_tolerance(0.0),
58  m_smoothing(0),
59  m_noVector(false)
60 {
61 }
ossim_uint8 m_marginalValue
ThresholdMode m_thresholdMode

◆ ~ossimShorelineTool()

ossimShorelineTool::~ossimShorelineTool ( )

Definition at line 63 of file ossimShorelineTool.cpp.

64 {
65 }

◆ ossimShorelineTool() [2/2]

ossimShorelineTool::ossimShorelineTool ( const ossimShorelineTool obj)
protected

Hidden from use copy constructor.

Member Function Documentation

◆ addArguments()

void ossimShorelineTool::addArguments ( ossimArgumentParser ap)
protected

◆ autoComputeThreshold()

void ossimShorelineTool::autoComputeThreshold ( )
protected

Definition at line 503 of file ossimShorelineTool.cpp.

References ossimKMeansClustering::computeKmeans(), ossimHistogram::GetCounts(), ossimImageChain::getFirstSource(), ossimMultiResLevelHistogram::getHistogram(), ossimImageHandler::getImageHistogram(), ossimKMeansClustering::getMean(), ossimHistogram::GetRes(), ossimKMeansClustering::getSigma(), ossimHistogram::GetVals(), ossimChipProcTool::m_procChain, m_threshold, m_thresholdMode, MEAN, ossimKMeansClustering::setNumClusters(), ossimKMeansClustering::setPopulations(), ossimKMeansClustering::setSamples(), SIGMA, ossimRefPtr< T >::valid(), and VARIANCE.

Referenced by doThreshold().

504 {
505  // Use the K-means classifier to determine the threshold point based on the histogram clustering
506  // into two groups: land and water.
507 
508  // If an input histogram was provided, use it. Otherwise compute one:
509  ossimImageHandler* handler = dynamic_cast<ossimImageHandler*>(m_procChain->getFirstSource());
510  ostringstream xmsg;
511  if (!handler)
512  {
513  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" No input handler in procession chain.";
514  throw ossimException(xmsg.str());
515  }
517  if (!multi_histo.valid())
518  {
519  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Could not establish an index histogram.";
520  throw ossimException(xmsg.str());
521  }
522 
523  ossimRefPtr<ossimHistogram> band_histo = multi_histo->getHistogram(0);
524  if (!band_histo.valid())
525  {
526  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Null band histogram returned!";
527  throw ossimException(xmsg.str());
528  }
529 
531  //classifier->setVerbose(); // TODO: Remove verbose mode
532  classifier->setNumClusters(2);
533  classifier->setSamples(band_histo->GetVals(), band_histo->GetRes());
534  classifier->setPopulations(band_histo->GetCounts(), band_histo->GetRes());
535  if (!classifier->computeKmeans())
536  {
537  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" K-means clustering of histogram failed. Cannot "
538  "auto-compute threshold point.";
539  throw ossimException(xmsg.str());
540  }
541 
542  double mean0 = classifier->getMean(0);
543  double mean1 = classifier->getMean(1);
544  double sigma0 = classifier->getSigma(0);
545  double sigma1 = classifier->getSigma(1);
546  switch (m_thresholdMode)
547  {
548  case MEAN:
549  m_threshold = (mean0 + mean1)/2.0;
550  break;
551  case SIGMA:
552  m_threshold = (sigma1*mean0 + sigma0*mean1)/(sigma0 + sigma1);
553  break;
554  case VARIANCE:
555  m_threshold = (sigma1*sigma1*mean0 + sigma0*sigma0*mean1)/(sigma0*sigma0 + sigma1*sigma1);
556  break;
557  default:
558  break;
559  }
560 
561  cout.precision(8);
562  cout<<"ossimShorelineUtil::autoComputeThreshold(): Using threshold = "<<m_threshold<<endl;
563 }
ossimRefPtr< ossimHistogram > getHistogram(ossim_uint32 band, ossim_uint32 resLevel=0)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual ossimImageSource * getFirstSource()
Return the first source which is the one that first receives the getTile request. ...
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimMultiResLevelHistogram > getImageHistogram() const
Fetches the current entry image&#39;s histogram.
void setSamples(T *samples, ossim_uint32 num_entries)
ossimRefPtr< ossimImageChain > m_procChain
int GetRes() const
void setNumClusters(ossim_uint32 K)
This class defines an abstract Handler which all image handlers(loaders) should derive from...
float * GetCounts()
float * GetVals()
void setPopulations(T *populations, ossim_uint32 num_entries)
double getSigma(ossim_uint32 groupId) const
double getMean(ossim_uint32 groupId) const
ThresholdMode m_thresholdMode

◆ doThreshold()

void ossimShorelineTool::doThreshold ( )
protected

Definition at line 430 of file ossimShorelineTool.cpp.

References ossimKeywordlist::add(), ossimImageChain::add(), autoComputeThreshold(), ossimString::chars(), ossimChipProcTool::execute(), FLT_EPSILON, ossimRefPtr< T >::get(), ossimImageHandlerRegistry::instance(), ossimBandLutFilter::loadState(), m_algorithm, m_indexFilename, m_landValue, m_marginalValue, ossimChipProcTool::m_procChain, ossimChipProcTool::m_productFilename, m_threshFilename, m_threshold, m_thresholdMode, m_tolerance, m_waterValue, ossimImageHandlerRegistry::open(), PAN_THRESHOLD, ossimString::toString(), ossimRefPtr< T >::valid(), and VALUE.

Referenced by execute().

431 {
432  ostringstream xmsg;
433 
434  // Open the index file (unless doing pan thresholding) to use as the input:
435  if (m_algorithm != PAN_THRESHOLD)
436  {
438  ossimRefPtr<ossimImageHandler> indexImage =
440  if (!indexImage.valid())
441  {
442  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Error encountered reading index image at <"
443  <<m_indexFilename<<">.";
444  throw ossimException(xmsg.str());
445  }
446  m_procChain->add(indexImage.get());
447  }
448 
449  // Some form of auto-thresholding was specified:
450  if (m_thresholdMode != VALUE)
452 
453  // Set up threshold filter using a simple LUT remapper:
454  double del = FLT_EPSILON;
459  ossimString thresholdValueLo2 = ossimString::toString(m_threshold-m_tolerance+del, 9).chars();
461  ossimString thresholdValueHi2 = ossimString::toString(m_threshold+m_tolerance+del, 9).chars();
462  ossimKeywordlist remapper_kwl;
463  remapper_kwl.add("type", "ossimBandLutFilter");
464  remapper_kwl.add("enabled", "1");
465  remapper_kwl.add("mode", "interpolated");
466  remapper_kwl.add("scalar_type", "U8");
467  remapper_kwl.add("entry0.in", "0.0");
468  remapper_kwl.add("entry0.out", landValue.chars());
469  remapper_kwl.add("entry1.in", thresholdValueLo1.chars());
470  remapper_kwl.add("entry1.out", landValue.chars());
471  if (m_tolerance == 0)
472  {
473  remapper_kwl.add("entry2.in", thresholdValueLo2.chars());
474  remapper_kwl.add("entry2.out", waterValue.chars());
475  remapper_kwl.add("entry3.in", "1.0");
476  remapper_kwl.add("entry3.out", waterValue.chars());
477  }
478  else
479  {
480  remapper_kwl.add("entry2.in", thresholdValueLo2.chars());
481  remapper_kwl.add("entry2.out", marginalValue.chars());
482  remapper_kwl.add("entry3.in", thresholdValueHi1.chars());
483  remapper_kwl.add("entry3.out", marginalValue.chars());
484  remapper_kwl.add("entry4.in", thresholdValueHi2.chars());
485  remapper_kwl.add("entry4.out", waterValue.chars());
486  remapper_kwl.add("entry5.in", "1.0");
487  remapper_kwl.add("entry5.out", waterValue.chars());
488  }
489 
491  remapper->loadState(remapper_kwl);
492  m_procChain->add(remapper.get());
493 
496  {
497  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Error encountered creating threshold image at <"
498  <<m_threshFilename<<">.";
499  throw ossimException(xmsg.str());
500  }
501 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_uint8 m_marginalValue
ossimRefPtr< ossimImageChain > m_procChain
ossimFilename m_threshFilename
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimFilename m_productFilename
#define FLT_EPSILON
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
ossimFilename m_indexFilename
static ossimImageHandlerRegistry * instance()
ThresholdMode m_thresholdMode
virtual bool execute()
Performs the actual product write.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.

◆ execute()

bool ossimShorelineTool::execute ( )
virtual

Performs the actual product write.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 351 of file ossimShorelineTool.cpp.

References ossimKeywordlist::add(), ossimImageChain::add(), ossimString::chars(), ossimToolRegistry::createTool(), doThreshold(), ossimTool::execute(), ossimChipProcTool::execute(), ossimFilename::ext(), ossimRefPtr< T >::get(), ossimTool::initialize(), ossimImageChain::initialize(), ossimToolRegistry::instance(), m_algorithm, ossimTool::m_consoleStream, ossimTool::m_helpRequested, ossimChipProcTool::m_imgLayers, m_indexFilename, m_maskFilename, m_noVector, ossimChipProcTool::m_procChain, ossimChipProcTool::m_productFilename, m_smoothing, m_threshFilename, m_thresholdMode, m_vectorFilename, NONE, ossimNotify(), ossimNotifyLevel_INFO, ossimNotifyLevel_WARN, ossimKeywordNames::OUTPUT_FILE_KW, PAN_THRESHOLD, ossimFilename::setExtension(), ossimImageGaussianFilter::setGaussStd(), ossimTool::setOutputStream(), ossimErosionFilter::setWindowSize(), status, and ossimRefPtr< T >::valid().

352 {
353  if (m_helpRequested)
354  return true;
355 
356  bool status = true;
357 
358  // Base class handles the thresholded image generation. May throw exception. Output written to
359  // m_productFilename. Note that if PAN mode selected, there is no intermediate index file:
362  return false;
363 
364  if (m_thresholdMode != NONE)
365  doThreshold();
366  else
367  return true;
368 
369  if (m_noVector)
370  return status;
371 
372  // Now for vector product, need services of a plugin utility. Check if available:
373  ossimRefPtr<ossimTool> potrace =
374  ossimToolRegistry::instance()->createTool(string("potrace"));
375  if (!potrace.valid())
376  {
377  ossimNotify(ossimNotifyLevel_WARN)<<"ossimShorelineUtil:"<<__LINE__<<" Need the "
378  "ossim-potrace plugin to perform vectorization. Only the thresholded image is "
379  "available at <"<<m_productFilename<<">."<<endl;
380  return false;
381  }
382 
383  // Need a mask image representing an eroded version of the input image:
385  m_procChain->add(m_imgLayers[0].get());
386  if (m_smoothing > 0)
387  {
388  // Set up gaussian filter:
390  smoother->setGaussStd(m_smoothing);
391  m_procChain->add(smoother.get());
392  }
394  eroder->setWindowSize(10);
395  m_procChain->add(eroder.get());
398  status = ossimChipProcTool::execute(); // generates mask
399  if (m_productFilename.ext() != "JSON")
401 
402  // Convey possible redirection of console out:
404 
405  ossimKeywordlist potrace_kwl;
406  potrace_kwl.add("image_file0", m_threshFilename.chars());
407  potrace_kwl.add("image_file1", m_maskFilename.chars());
409  potrace_kwl.add("mode", "linestring");
410  potrace_kwl.add("alphamax", "1.0");
411  potrace_kwl.add("turdsize", "4");
412 
413  potrace->initialize(potrace_kwl);
414 
415  status = potrace->execute();
416 
417 #if OSSIM_HAS_JSONCPP
418  if (status)
419  status = addPropsToJSON();
420 #endif
421 
422  if (status)
423  ossimNotify(ossimNotifyLevel_INFO)<<"Wrote vector product to <"<<m_productFilename<<">"<<endl;
424  else
425  ossimNotify(ossimNotifyLevel_WARN)<<"Error encountered writing vector product to <"<<m_productFilename<<">"<<endl;
426 
427  return status;
428 }
static const char * OUTPUT_FILE_KW
Represents serializable keyword/value map.
bool m_helpRequested
Definition: ossimTool.h:150
bool valid() const
Definition: ossimRefPtr.h:75
ossimFilename m_vectorFilename
void setWindowSize(ossim_uint32 windowSize)
Size of resampling kernel width & height.
virtual void initialize()
void setOutputStream(std::ostream *os)
Redirects any console output to the supplied stream for logging or JNI application.
Definition: ossimTool.h:128
ossimRefPtr< ossimImageChain > m_procChain
ossimFilename m_threshFilename
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ossimTool * createTool(const std::string &typeName) const
static ossimToolRegistry * instance()
ossimFilename m_productFilename
class for symmetric Gaussian filtering implemented as two separable horizontal/vertical gaussian filt...
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
std::vector< ossimRefPtr< ossimSingleImageChain > > m_imgLayers
virtual bool initialize(ossimArgumentParser &ap)
Initializes from command line arguments.
Definition: ossimTool.cpp:58
virtual bool execute()=0
Writes product to output file if applicable.
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
void setGaussStd(const ossim_float64 &v)
ossimFilename m_indexFilename
std::ostream * m_consoleStream
Definition: ossimTool.h:149
return status
ossimFilename m_maskFilename
ossimString ext() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
ThresholdMode m_thresholdMode
virtual bool execute()
Performs the actual product write.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getChip()

ossimRefPtr< ossimImageData > ossimShorelineTool::getChip ( const ossimIrect img_rect)
virtual

The meat and potatos of this class.

Performs an execute on specified rect.

Reimplemented from ossimChipProcTool.

Definition at line 334 of file ossimShorelineTool.cpp.

References ossimImageChain::getTile(), ossimImageGeometry::localToWorld(), ossimChipProcTool::m_aoiGroundRect, ossimChipProcTool::m_aoiViewRect, ossimChipProcTool::m_geom, ossimChipProcTool::m_procChain, ossimImageGeometry::setImageSize(), ossimIrect::size(), and ossimRefPtr< T >::valid().

335 {
336  // NOTE:
337  // getChip only performs the index and thresholding (and possibly edge). For vector output,
338  // execute must be called.
339 
340  ostringstream xmsg;
341  if (!m_geom.valid())
342  return 0;
343 
344  m_aoiViewRect = bounding_irect;
347 
348  return m_procChain->getTile( m_aoiViewRect, 0 );
349 }
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Within the image chain will pass the head of the list.
ossimRefPtr< ossimImageGeometry > m_geom
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimGrect m_aoiGroundRect
bool valid() const
Definition: ossimRefPtr.h:75
void setImageSize(const ossimIpt &size)
ossimIpt size() const
Definition: ossimIrect.h:510
ossimRefPtr< ossimImageChain > m_procChain
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.

◆ getClassName()

virtual ossimString ossimShorelineTool::getClassName ( ) const
inlinevirtual

Reimplemented from ossimTool.

Definition at line 51 of file ossimShorelineTool.h.

51 { return "ossimShorelineUtil"; }

◆ initialize() [1/2]

bool ossimShorelineTool::initialize ( ossimArgumentParser ap)
virtual

Initial method to be ran prior to execute.

Intended for command-line app usage.

Parameters
apArg parser to initialize from.
Returns
FALSE if –help option requested or no params provided, so that derived classes can
Note
Throws ossimException on error.
A throw with an error message of "usage" is used to get out when a usage is printed.

Reimplemented from ossimChipProcTool.

Definition at line 113 of file ossimShorelineTool.cpp.

References ossimKeywordlist::addPair(), ossimChipProcTool::initialize(), ossimTool::m_helpRequested, ossimTool::m_kwl, and ossimArgumentParser::read().

114 {
116  return false;
117  if (m_helpRequested)
118  return true;
119 
120  ossimString ts1;
122  ossimString ts2;
124  ossimString ts3;
126 
127  if ( ap.read("--algorithm", sp1))
128  m_kwl.addPair(ALGORITHM_KW, ts1);
129 
130  if (ap.read("--color-coding", sp1, sp2, sp3))
131  {
132  ostringstream value;
133  value<<ts1<<" "<<ts2<<" "<<ts3;
134  m_kwl.addPair( COLOR_CODING_KW, value.str() );
135  }
136 
137  if ( ap.read("--no-vector"))
138  m_noVector = true;
139 
140  if ( ap.read("--sensor", sp1))
142 
143  if ( ap.read("--smooth", sp1))
144  m_kwl.addPair(SMOOTHING_KW, ts1);
145 
146  if ( ap.read("--threshold", sp1))
147  m_kwl.addPair(THRESHOLD_KW, ts1);
148 
149  if ( ap.read("--tmode", sp1))
150  m_kwl.addPair(TMODE_KW, ts1);
151 
152  if ( ap.read("--tolerance", sp1))
153  m_kwl.addPair(TOLERANCE_KW, ts1);
154 
155  // Added for "beachfront" to allow passing properties (keyword:value pairs) through to the
156  // GeoJSON vector output
157  while (ap.read("--prop", sp1))
158  {
159  m_geoJsonProps.insert(pair<ossimString, ossimString>(ts1.before(":"), ts1.after(":")));
160  }
161 
162  // Fake the base class into thinking there is a default output filename to avoid it complaining,
163  // since this utility will stream vector output to console if no output file name provided:
164  m_kwl.add( ossimKeywordNames::OUTPUT_FILE_KW, DUMMY_OUTPUT_FILENAME.c_str());
165 
167  return true;
168 }
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static const char * OUTPUT_FILE_KW
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...
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const char * SENSOR_ID_KW
std::map< ossimString, ossimString > m_geoJsonProps
void processRemainingArgs(ossimArgumentParser &ap)
Intended to be called after derived class has picked off its own options from the parser...
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
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.

◆ initialize() [2/2]

void ossimShorelineTool::initialize ( const ossimKeywordlist kwl)
virtual

This method is responsible for completely setting up the full processing chain according to the specifications given in the kwl passed in.

If the utility is run from a command line, the initialize(ossimArgumentParser) will assign the member master KWL and pass it to this method. Web service calls will fill a KWL and pass it.

This base class implementation should be called by the derived class implementation (assuming the derived class needs to pull some parameters out of the KWL before the chains are set up.

This method will instantiate the output projection and define the output bounding rect and product size in pixels. The processing chain (stored in m_procChain) will be completely initialized and ready for calls to getTile(). Then either getChip() or execute() can be called depending on usage to fetch product.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 170 of file ossimShorelineTool.cpp.

References ossimKeywordlist::addList(), ossimKeywordlist::clear(), ossimKeywordlist::findKey(), and ossimTool::m_kwl.

171 {
172  ossimString value;
173  ostringstream xmsg;
174 
175  // Don't copy KWL if member KWL passed in:
176  if (&kwl != &m_kwl)
177  {
178  // Start with clean options keyword list.
179  m_kwl.clear();
180  m_kwl.addList( kwl, true );
181  }
182 
183  value = m_kwl.findKey(ALGORITHM_KW);
184  if (!value.empty())
185  {
186  if (value=="ndwi")
187  m_algorithm = NDWI;
188  else if (value=="awei")
189  m_algorithm = AWEI;
190  else if (value=="pan-threshold")
192  else
193  {
194  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Bad value encountered for keyword <"
195  <<ALGORITHM_KW<<">.";
196  throw ossimException(xmsg.str());
197  }
198  }
199 
200  value = m_kwl.findKey(COLOR_CODING_KW);
201  if (!value.empty())
202  {
203  vector<ossimString> values = value.split(" ");
204  if (values.size() == 3)
205  {
206  m_waterValue = values[0].toUInt8();
207  m_marginalValue = values[1].toUInt8();
208  m_landValue = values[2].toUInt8();
209  }
210  else
211  {
212  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Unexpected number of values encountered for keyword <"
213  <<COLOR_CODING_KW<<">.";
214  throw ossimException(xmsg.str());
215  }
216  }
217 
219  if (!value.empty())
220  m_sensor = value;
221 
222  value = m_kwl.findKey(SMOOTHING_KW);
223  if (!value.empty())
224  m_smoothing = value.toDouble();
225 
226  value = m_kwl.findKey(TMODE_KW);
227  if (!value.empty())
228  {
229  int tmode = value.toInt();
230  if ((tmode >= 0) && (tmode <= 4))
231  m_thresholdMode = (ThresholdMode) tmode;
232  }
233 
234  value = m_kwl.findKey(THRESHOLD_KW);
235  if (!value.empty())
236  {
237  m_threshold = value.toDouble();
239  }
240 
241  value = m_kwl.findKey(TOLERANCE_KW);
242  if (!value.empty())
243  m_tolerance = value.toDouble();
244 
245  // Output filename specifies the vector output, while base class interprets as raster, correct:
247  if (m_vectorFilename == DUMMY_OUTPUT_FILENAME)
248  {
249  m_vectorFilename = "";
250  m_indexFilename = TEMP_INDEX_FILENAME;
251  m_threshFilename = TEMP_THRESHOLD_FILENAME;
252  m_maskFilename = TEMP_MASK_FILENAME;
253  }
254  else
255  {
259  }
261 
262  // Unless an output projection was specifically requested, use the input:
263  m_kwl.add(ossimKeywordNames::PROJECTION_KW, "identity", false);
264 
266 }
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
static const char * PROJECTION_KW
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static const char * OUTPUT_FILE_KW
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
const char * find(const char *key) const
ossimFilename m_vectorFilename
void addList(const ossimKeywordlist &src, bool overwrite=true)
ossim_uint8 m_marginalValue
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
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.
ossimFilename m_threshFilename
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const char * SENSOR_ID_KW
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
double toDouble() const
ossimFilename m_indexFilename
ossimFilename fileNoExtension() const
bool empty() const
Definition: ossimString.h:411
ossimFilename m_maskFilename
ThresholdMode m_thresholdMode
int toInt() const

◆ initLandsat8()

void ossimShorelineTool::initLandsat8 ( )
protected

◆ initProcessingChain()

void ossimShorelineTool::initProcessingChain ( )
protectedvirtual

Derived classes initialize their custom chains here.

Implements ossimChipProcTool.

Definition at line 268 of file ossimShorelineTool.cpp.

References ossimImageChain::add(), AWEI, ossimRefPtr< T >::get(), ossimGrect::hasNans(), ossimIrect::hasNans(), m_algorithm, ossimChipProcTool::m_aoiGroundRect, ossimChipProcTool::m_aoiViewRect, ossimChipProcTool::m_imgLayers, ossimChipProcTool::m_procChain, m_smoothing, NDWI, OSSIM_NORMALIZED_DOUBLE, PAN_THRESHOLD, ossimEquationCombiner::setEquation(), ossimImageGaussianFilter::setGaussStd(), and ossimEquationCombiner::setOutputScalarType().

269 {
270  // The processing chain to produce the index image is assembled here. The thresholding part is
271  // done during execute().
272  ostringstream xmsg;
273 
275  {
276  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Encountered NaNs in AOI."<<ends;
277  throw ossimException(xmsg.str());
278  }
279 
280  ossim_uint32 reqdNumInputs = 0;
281  ossimString equationSpec;
282  switch (m_algorithm)
283  {
284  case NDWI:
285  reqdNumInputs = 2;
286  equationSpec = "in[0]/(in[0]+in[1])";
287  break;
288  case AWEI:
289  reqdNumInputs = 4;
290  equationSpec = "4*(in[0]+in[1]) - 0.25*in[2] - 2.75*in[3]";
291  break;
292  case PAN_THRESHOLD:
293  reqdNumInputs = 1;
294  break;
295  default:
296  break;
297  }
298 
299  if (m_imgLayers.size() < reqdNumInputs)
300  {
301  xmsg<<"ossimShorelineUtil:"<<__LINE__<<" Expected "<< reqdNumInputs << " input images"
302  " but only found "<<m_imgLayers.size()<<"."<<ends;
303  throw ossimException(xmsg.str());
304  }
305 
306  if ((m_algorithm==NDWI) || (m_algorithm==AWEI))
307  {
308  // Set up equation combiner:
310  for (ossim_uint32 i=0; i<reqdNumInputs; ++i)
311  connectable_list.push_back(m_imgLayers[i].get());
312  ossimRefPtr<ossimEquationCombiner> eqFilter = new ossimEquationCombiner(connectable_list);
314  eqFilter->setEquation(equationSpec);
315  m_procChain->add(eqFilter.get());
316  }
317  else
318  {
319  // Just add input connection for pan thresholding:
320  m_procChain->add(m_imgLayers[0].get());
321  }
322 
323  if (m_smoothing > 0)
324  {
325  // Set up gaussian filter:
327  smoother->setGaussStd(m_smoothing);
328  m_procChain->add(smoother.get());
329  }
330 
331  return;
332 }
virtual void setOutputScalarType(ossimScalarType scalarType)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimGrect m_aoiGroundRect
Will combine the input data based on a supplied equation.
virtual void setEquation(const ossimString &equ)
bool hasNans() const
Definition: ossimGrect.h:298
ossimRefPtr< ossimImageChain > m_procChain
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
class for symmetric Gaussian filtering implemented as two separable horizontal/vertical gaussian filt...
unsigned int ossim_uint32
std::vector< ossimRefPtr< ossimSingleImageChain > > m_imgLayers
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
void setGaussStd(const ossim_float64 &v)
64 bit normalized floating point
bool hasNans() const
Definition: ossimIrect.h:337

◆ operator=()

const ossimShorelineTool& ossimShorelineTool::operator= ( const ossimShorelineTool rhs)
protected

Hidden from use assignment operator.

◆ setUsage()

void ossimShorelineTool::setUsage ( ossimArgumentParser ap)
virtual

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 from ossimChipProcTool.

Definition at line 67 of file ossimShorelineTool.cpp.

References ossimApplicationUsage::addCommandLineOption(), ossimArgumentParser::getApplicationName(), ossimArgumentParser::getApplicationUsage(), ossimApplicationUsage::setCommandLineUsage(), ossimApplicationUsage::setDescription(), and ossimChipProcTool::setUsage().

68 {
69  // Add global usage options.
71 
72  // Set the general usage:
74  ossimString usageString = ap.getApplicationName();
75  usageString += " shoreline [options] [<output-vector-filename>]";
76  au->setCommandLineUsage(usageString);
77  au->setDescription("Computes vector shoreline from raster imagery. The vectors are output "
78  "in GeoJSON format. If an output filename is specified, the JSON is written to it. "
79  "Otherwise it is written to the console. The supported algorithms are (where A, B, etc are ordered input band files): \n"
80  " NDWI = (A - B) / (A + B) \n"
81  " AWEI = 4*(A + B) - 0.25*C - 2.75*D \n"
82  " PAN-THRESHOLD = A (no equation applied). The input single-band image is thresholded directly. \n");
83 
84  // Set the command line options:
85  au->addCommandLineOption("--algorithm <name>",
86  "Specifies detection algorithm to apply. Supported names are: "
87  "\"ndwi\", \"aewi\", \"pan-threshold\"");
88  au->addCommandLineOption("--color-coding <water> <marginal> <land>",
89  "Specifies the pixel values (0-255) for the output product corresponding to water, marginal, "
90  "and land zones. Defaults to 0, 128, and 255, respectively.");
91  au->addCommandLineOption("--no-vector",
92  "Outputs the raster, thresholded indexed image instead of a vector product. For engineering purposes.");
93  au->addCommandLineOption("--sensor <string>",
94  "Sensor used to compute Modified Normalized Difference Water Index. Currently only "
95  "\"ls8\" supported (default).");
96  au->addCommandLineOption("--smooth <sigma>",
97  "Applies gaussian filter to index raster file. The filter sigma must be specified (0.2 is good). Sigma=0 "
98  "indicates no smoothing.");
99  au->addCommandLineOption("--threshold <0.0-1.0>",
100  "Normalized threshold for converting the image to bitmap. Defaults to 0.55. If none specified, an optimized threshold"
101  " is computed.");
102  au->addCommandLineOption("--tmode <1|2|3>",
103  "Mode to use for computing threshold from k-means statistics, where:\n"
104  " 0 = no auto-thresholding,\n"
105  " 1 = unweighted mean of means,\n"
106  " 2 = sigma-weighted mean of means (default),\n"
107  " 3 = variance-weighted mean of means."
108  "If \"--threshold\" option is specified, this option is ignored.\n");
109  au->addCommandLineOption("--tolerance <float>",
110  "tolerance +- deviation from threshold for marginal classifications. Defaults to 0.01.");
111 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
void setDescription(const ossimString &desc)

◆ usage()

void ossimShorelineTool::usage ( ossimArgumentParser ap)
protected

Initializes arg parser and outputs usage.

Member Data Documentation

◆ DESCRIPTION

const char * ossimShorelineTool::DESCRIPTION
static
Initial value:
=
"Computes bitmap of water versus land areas in an input image."

Used by ossimUtilityFactory.

Definition at line 54 of file ossimShorelineTool.h.

Referenced by ossimToolFactory::getCapabilities().

◆ m_algorithm

AlgorithmId ossimShorelineTool::m_algorithm
protected

Definition at line 83 of file ossimShorelineTool.h.

Referenced by doThreshold(), execute(), and initProcessingChain().

◆ m_geoJsonProps

std::map<ossimString, ossimString> ossimShorelineTool::m_geoJsonProps
protected

Definition at line 90 of file ossimShorelineTool.h.

◆ m_indexFilename

ossimFilename ossimShorelineTool::m_indexFilename
protected

Definition at line 87 of file ossimShorelineTool.h.

Referenced by doThreshold(), and execute().

◆ m_landValue

ossim_uint8 ossimShorelineTool::m_landValue
protected

Definition at line 79 of file ossimShorelineTool.h.

Referenced by doThreshold().

◆ m_marginalValue

ossim_uint8 ossimShorelineTool::m_marginalValue
protected

Definition at line 78 of file ossimShorelineTool.h.

Referenced by doThreshold().

◆ m_maskFilename

ossimFilename ossimShorelineTool::m_maskFilename
protected

Definition at line 89 of file ossimShorelineTool.h.

Referenced by execute().

◆ m_noVector

bool ossimShorelineTool::m_noVector
protected

Definition at line 91 of file ossimShorelineTool.h.

Referenced by execute().

◆ m_sensor

ossimString ossimShorelineTool::m_sensor
protected

Definition at line 80 of file ossimShorelineTool.h.

◆ m_smoothing

double ossimShorelineTool::m_smoothing
protected

Definition at line 85 of file ossimShorelineTool.h.

Referenced by execute(), and initProcessingChain().

◆ m_threshFilename

ossimFilename ossimShorelineTool::m_threshFilename
protected

Definition at line 88 of file ossimShorelineTool.h.

Referenced by doThreshold(), and execute().

◆ m_threshold

double ossimShorelineTool::m_threshold
protected

Definition at line 81 of file ossimShorelineTool.h.

Referenced by autoComputeThreshold(), and doThreshold().

◆ m_thresholdMode

ThresholdMode ossimShorelineTool::m_thresholdMode
protected

Definition at line 84 of file ossimShorelineTool.h.

Referenced by autoComputeThreshold(), doThreshold(), and execute().

◆ m_tolerance

double ossimShorelineTool::m_tolerance
protected

Definition at line 82 of file ossimShorelineTool.h.

Referenced by doThreshold().

◆ m_vectorFilename

ossimFilename ossimShorelineTool::m_vectorFilename
protected

Definition at line 86 of file ossimShorelineTool.h.

Referenced by execute().

◆ m_waterValue

ossim_uint8 ossimShorelineTool::m_waterValue
protected

Definition at line 77 of file ossimShorelineTool.h.

Referenced by doThreshold().


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