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

#include <ossimViewshedTool.h>

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

Classes

class  Radial
 

Public Member Functions

 ossimViewshedTool ()
 
 ~ossimViewshedTool ()
 
virtual void setUsage (ossimArgumentParser &ap)
 Initializes the aurgument parser with expected parameters and options. More...
 
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 ossimRefPtr< ossimImageDatagetChip (const ossimIrect &img_rect)
 Computes the viewshed for the area represented by argument AOI. More...
 
virtual bool execute ()
 Writes product to output file. More...
 
virtual void clear ()
 Disconnects and clears the DEM and image layers. More...
 
virtual ossimString getClassName () const
 
void test ()
 For engineering/debug. More...
 
- Public Member Functions inherited from ossimChipProcTool
 ossimChipProcTool ()
 default constructor More...
 
virtual ~ossimChipProcTool ()
 virtual destructor 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...
 
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...
 
void paintReticle ()
 
void initRadials ()
 
bool writeHorizonProfile ()
 
void computeRadius ()
 
bool optimizeFOV ()
 
bool computeViewshed ()
 
- 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...
 
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

ossimGpt m_observerGpt
 
ossimDpt m_observerVpt
 
double m_obsHgtAbvTer
 
double m_visRadius
 
Radial ** m_radials
 
bool m_obsInsideAoi
 
bool m_displayAsRadar
 
ossim_uint32 m_halfWindow
 
ossimRefPtr< ossimImageDatam_outBuffer
 
ossimRefPtr< ossimMemoryImageSourcem_memSource
 
ossim_uint8 m_visibleValue
 
ossim_uint8 m_hiddenValue
 
ossim_uint8 m_overlayValue
 
ossim_int32 m_reticleSize
 
bool m_simulation
 
std::shared_ptr< ossimJobMultiThreadQueuem_jobMtQueue
 
ossim_uint32 m_numThreads
 
double m_startFov
 
double m_stopFov
 
bool m_threadBySector
 
ossimFilename m_horizonFile
 
std::map< double, double > m_horizonMap
 
double d_accumT
 
std::mutex d_mutex
 
- 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
 

Friends

class SectorProcessorJob
 
class RadialProcessorJob
 
class RadialProcessor
 

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

Class for computing the viewshed on a DEM given the viewer location and max range of visibility

Definition at line 21 of file ossimViewshedTool.h.

Constructor & Destructor Documentation

◆ ossimViewshedTool()

ossimViewshedTool::ossimViewshedTool ( )

Definition at line 47 of file ossimViewshedTool.cpp.

References m_observerGpt, and ossimGpt::makeNan().

48 : m_obsHgtAbvTer (1.5),
49  m_visRadius (0.0),
50  m_radials (0),
51  m_obsInsideAoi (true),
52  m_displayAsRadar (false),
53  m_halfWindow (0),
54  m_outBuffer (NULL),
55  m_visibleValue (1),
56  m_hiddenValue (128),
57  m_overlayValue (255),
58  m_reticleSize(25),
59  m_simulation (false),
60  m_numThreads(1),
61  m_startFov(0),
62  m_stopFov(0),
63  m_threadBySector(false),
64  d_accumT(0)
65 {
67 }
ossim_uint8 m_overlayValue
void makeNan()
Definition: ossimGpt.h:130
ossim_uint8 m_visibleValue
ossim_uint8 m_hiddenValue
ossim_int32 m_reticleSize
ossimRefPtr< ossimImageData > m_outBuffer
ossim_uint32 m_halfWindow
ossim_uint32 m_numThreads

◆ ~ossimViewshedTool()

ossimViewshedTool::~ossimViewshedTool ( )

Definition at line 69 of file ossimViewshedTool.cpp.

References m_radials.

70 {
71  if (m_radials)
72  {
73  for (int i=0; i<4; ++i)
74  delete [] m_radials[i];
75  delete [] m_radials;
76  }
77 }

Member Function Documentation

◆ clear()

void ossimViewshedTool::clear ( )
virtual

Disconnects and clears the DEM and image layers.

Leaves OSSIM initialized.

Reimplemented from ossimChipProcTool.

Definition at line 305 of file ossimViewshedTool.cpp.

References ossimChipProcTool::clear(), m_horizonMap, m_jobMtQueue, m_observerGpt, m_outBuffer, m_visRadius, and ossimGpt::makeNan().

306 {
308  m_visRadius = 0;
309  m_outBuffer = 0;
310  m_horizonMap.clear();
311  m_jobMtQueue = 0;
313 }
std::shared_ptr< ossimJobMultiThreadQueue > m_jobMtQueue
void makeNan()
Definition: ossimGpt.h:130
virtual void clear()
Disconnects and clears the dem and image layers.
ossimRefPtr< ossimImageData > m_outBuffer
std::map< double, double > m_horizonMap

◆ computeRadius()

void ossimViewshedTool::computeRadius ( )
protected

Definition at line 700 of file ossimViewshedTool.cpp.

References ossimGpt::distanceTo(), ossimIrect::hasNans(), ossimGrect::ll(), ossimGrect::lr(), ossimChipProcTool::m_aoiGroundRect, ossimChipProcTool::m_aoiViewRect, m_observerGpt, m_visRadius, ossimGrect::ul(), and ossimGrect::ur().

Referenced by initProcessingChain().

701 {
702  ostringstream xmsg ("ossimViewshedUtil::computeRadius() -- ");
703 
704  // AOI is required for computing R
705  if (m_aoiViewRect.hasNans())
706  {
707  xmsg<<"AOI undefined. Cannot compute visibility radius." << ends;
708  throw ossimException(xmsg.str());
709  }
710 
711  // Compute distance from observer to farthest corner of AOI. This is the radius
714  if (d > m_visRadius)
715  m_visRadius = d;
717  if (d > m_visRadius)
718  m_visRadius = d;
720  if (d > m_visRadius)
721  m_visRadius = d;
722 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimGrect m_aoiGroundRect
double distanceTo(const ossimGpt &arg_gpt) const
METHOD: distanceTo(ossimGpt) Computes straight-line distance in meters between this and arg gpt: ...
Definition: ossimGpt.cpp:431
const ossimGpt & ul() const
Definition: ossimGrect.h:252
ossimGpt ur() const
Definition: ossimGrect.h:257
bool hasNans() const
Definition: ossimIrect.h:337
const ossimGpt & lr() const
Definition: ossimGrect.h:269
ossimGpt ll() const
Definition: ossimGrect.h:263

◆ computeViewshed()

bool ossimViewshedTool::computeViewshed ( )
protected

Definition at line 486 of file ossimViewshedTool.cpp.

References ossimImageDataFactory::create(), d_accumT, ossimImageData::fill(), ossimImageChain::getNullPixelValue(), ossim::getNumberOfThreads(), ossimIrect::height(), ossimImageData::initialize(), initRadials(), ossimImageDataFactory::instance(), ossimChipProcTool::m_aoiViewRect, m_halfWindow, m_jobMtQueue, m_memSource, m_numThreads, m_outBuffer, ossimChipProcTool::m_procChain, m_radials, m_threadBySector, ossimProcessInterface::needsAborting(), optimizeFOV(), OSSIM_UINT8, ossimNotify(), ossimNotifyLevel_INFO, paintReticle(), ossimMemoryImageSource::setImage(), ossimImageData::setImageRectangle(), ossim::Thread::sleepInMicroSeconds(), ossimRefPtr< T >::valid(), and ossimIrect::width().

Referenced by execute(), and getChip().

487 {
488  // Allocate the output image buffer:
491 
492  ostringstream xmsg;
493  if (!m_outBuffer.valid() || !m_memSource.valid())
494  {
495  xmsg<<"ossimViewshedUtil:"<<__LINE__<<" Error encountered allocating output image buffer.";
496  throw ossimException(xmsg.str());
497  }
498 
499  // Initialize the image with all points hidden:
504 
505  // Initialize the radials after intersecting the requested FOV with the FOV required to see the
506  // full AOI (not applicable if observer inside AOI). Skip radial init if no intersection found:
507  if (!optimizeFOV())
508  return false;
509  initRadials();
510 
511  // The viewshed process necessarily first fills the output buffer with the complete result before
512  // the writer requests a tile. Control is passed later to the base class execute() for writing.
513  d_accumT = 0;
514 
515  if (m_numThreads == 0)
517 
518  if (m_numThreads > 1)
519  {
520  std::shared_ptr<ossimJobQueue> jobQueue = std::make_shared<ossimJobQueue>();
521  for (int sector=0; sector<8; ++sector)
522  {
523  if (m_radials[sector] == 0)
524  continue;
525 
526  if (m_threadBySector)
527  {
528  std::shared_ptr<SectorProcessorJob> job = std::make_shared<SectorProcessorJob>(this, sector, m_halfWindow);
529  jobQueue->add(job, false);
530  }
531  else
532  {
533  for (ossim_uint32 r=0; r<=m_halfWindow; ++r)
534  {
535  std::shared_ptr<RadialProcessorJob> job = std::make_shared<RadialProcessorJob>(this, sector, r, m_halfWindow);
536  jobQueue->add(job, false);
537  }
538  }
539  if (needsAborting())
540  return 0;
541  }
542 
543  ossimNotify(ossimNotifyLevel_INFO) << "\nSubmitting "<<jobQueue->size()<<" jobs..."<<endl;
544  m_jobMtQueue = std::make_shared<ossimJobMultiThreadQueue>(jobQueue, m_numThreads);
545 
546  // Wait until all radials have been processed before proceeding:
547  ossimNotify(ossimNotifyLevel_INFO) << "Waiting for job threads to finish..."<<endl;
548  while (m_jobMtQueue->hasJobsToProcess() || m_jobMtQueue->numberOfBusyThreads())
550  }
551  else
552  {
553  // Unthreaded processing:
554  ossimNotify(ossimNotifyLevel_INFO) << "\nProcessing radials (non-threaded)..."<<endl;
555 
556  // Loop over pixels in layer for each sector:
557  for (int sector=0; sector<8; ++sector)
558  {
559  if (m_radials[sector] == 0)
560  continue;
561 
562  std::shared_ptr<SectorProcessorJob> spj = std::make_shared<SectorProcessorJob>(this, sector, m_halfWindow);
563  spj->start();
564 
565  if (needsAborting())
566  return false;
567 
568  } // end loop over sectors
569  }
570 
571  ossimNotify(ossimNotifyLevel_INFO) << "Finished processing radials."<<endl;
572  paintReticle();
573 
574  return true;
575 }
std::shared_ptr< ossimJobMultiThreadQueue > m_jobMtQueue
void fill(ossim_uint32 band, ossim_float64 value)
will fill the entire band with the value.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void setImageRectangle(const ossimIrect &rect)
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint32 height() const
Definition: ossimIrect.h:487
void setImage(ossimRefPtr< ossimImageData > image)
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
ossimRefPtr< ossimMemoryImageSource > m_memSource
static void sleepInMicroSeconds(ossim_uint64 micros)
Utility method to allow one to sleep in microseconds.
Definition: Thread.cpp:83
virtual void initialize()
Initialize the data buffer.
ossimRefPtr< ossimImageChain > m_procChain
OSSIM_DLL ossim_uint32 getNumberOfThreads()
Get the number threads to use from ossimPreferences or ossim::Thread.
static ossimImageDataFactory * instance()
unsigned int ossim_uint32
ossimRefPtr< ossimImageData > m_outBuffer
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossim_uint32 m_halfWindow
8 bit unsigned integer
ossim_uint32 m_numThreads
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ execute()

bool ossimViewshedTool::execute ( )
virtual

Writes product to output file.

Returns true if successful.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 472 of file ossimViewshedTool.cpp.

References computeViewshed(), ossimString::empty(), ossimChipProcTool::execute(), ossimTool::m_helpRequested, m_horizonFile, ossimNotify(), ossimNotifyLevel_INFO, and writeHorizonProfile().

473 {
474  if (m_helpRequested)
475  return true;
476 
477  if (!computeViewshed())
478  return false;
479 
481  ossimNotify(ossimNotifyLevel_INFO) << "Wrote horizon profile to <"<<m_horizonFile<<">" <<endl;
482 
484 }
bool m_helpRequested
Definition: ossimTool.h:150
ossimFilename m_horizonFile
bool empty() const
Definition: ossimString.h:411
virtual bool execute()
Performs the actual product write.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getChip()

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

Computes the viewshed for the area represented by argument AOI.

Reimplemented from ossimChipProcTool.

Definition at line 449 of file ossimViewshedTool.cpp.

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

450 {
451  cerr<<"ossimViewshedUtil:"<<__LINE__<<endl;//TODO:remove debug
452  ostringstream xmsg;
453  if (!m_geom.valid())
454  return 0;
455 
456  cerr<<"ossimViewshedUtil:"<<__LINE__<<endl;//TODO:remove debug
457  m_aoiViewRect = bounding_irect;
460 
461  cerr<<"ossimViewshedUtil:"<<__LINE__<<endl;//TODO:remove debug
462  if (computeViewshed())
463  {
464  // The memory source has been populated, now do the getTile on the full chain to pick up
465  // other filters inserted after the memsource:
466  return m_procChain->getTile( m_aoiViewRect, 0 );
467  }
468  // else:
469  return 0;
470 }
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 ossimViewshedTool::getClassName ( ) const
inlinevirtual

Reimplemented from ossimTool.

Definition at line 58 of file ossimViewshedTool.h.

58 { return "ossimViewshedUtil"; }

◆ initialize() [1/2]

bool ossimViewshedTool::initialize ( ossimArgumentParser ap)
virtual

Initializes from command line arguments.

Returns
FALSE if –help option requested or no params provided, so that derived classes can
Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 133 of file ossimViewshedTool.cpp.

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

134 {
135  ostringstream xmsg;
136  xmsg<<"ossimViewshedUtil::initialize(ossimArgumentParser) -- ";
137 
138  int numArgsExpected = 4;
139 
140  // Base class first:
142  return false;
143  if (m_helpRequested)
144  return true;
145 
146  string ts1;
148  string ts2;
150  string ts3;
152 
153  if ( ap.read("--fov", sp1, sp2) )
154  {
155  double startFov = ossimString(ts1).toDouble();
156  if (startFov < 0)
157  startFov += 360.0;
158  ostringstream value;
159  value<<startFov<<" "<<ts2;
160  m_kwl.addPair( FOV_KW, value.str() );
161  }
162 
163  if ( ap.read("--hgt-of-eye", sp1) || ap.read("--height-of-eye", sp1) )
164  m_kwl.addPair( HEIGHT_OF_EYE_KW, ts1 );
165 
166  if ( ap.read("--horizon", sp1) || ap.read("--horizon-file", sp1))
167  m_kwl.addPair( HORIZON_FILE_KW, ts1 );
168 
169  if ( ap.read("--observer", sp1, sp2) )
170  {
171  ostringstream value;
172  value<<ts1<<" "<<ts2;
173  m_kwl.addPair( OBSERVER_KW, value.str() );
174  numArgsExpected -= 2;
175  }
176 
177  if ( ap.read("--radius", sp1) )
178  m_kwl.addPair( VISIBILITY_RADIUS_KW, ts1 );
179 
180  if ( ap.read("--reticle", sp1) )
181  m_kwl.addPair( RETICLE_SIZE_KW, ts1 );
182 
183  if ( ap.read("--values", sp1, sp2, sp3) || ap.read("--viewshed-coding", sp1, sp2, sp3))
184  {
185  ostringstream value;
186  value<<ts1<<" "<<ts2<<" "<<ts3;
187  m_kwl.addPair( VIEWSHED_CODING_KW, value.str() );
188  }
189 
190  if ( ap.read("--threads", sp1) )
191  {
192  m_kwl.addPair( THREADS_KW, ts1 );
193  }
194 
195  // The remaining options are available only via command line (i.e., no KWL entries defined)
196  if ( ap.read("--tbs") )
197  m_threadBySector = true;
198 
199  if ( ap.read("--simulation") )
200  m_simulation = true;
201 
202  // Moved to: ossimViewshedTool::initialize(const ossimKeywordlist& kwl)
203  // if ( ap.read("--threads", sp1) )
204  // m_numThreads = ossimString(ts1).toUInt32();
205 
206  if ( ap.argc() < numArgsExpected )
207  {
208  xmsg<<"Expecting more arguments.";
209  throw(ossimException(xmsg.str()));
210  }
211  else
212  {
213  ossimString latstr = ap[1];
214  ossimString lonstr = ap[2];
215  ostringstream value;
216  value<<latstr<<" "<<lonstr;
217  m_kwl.addPair( OBSERVER_KW, value.str() );
218  ap.remove(1,2);
220  }
221 
222  return true;
223 }
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
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 processRemainingArgs(ossimArgumentParser &ap)
Intended to be called after derived class has picked off its own options from the parser...
double toDouble() const
void remove(int pos, int num=1)
remove one or more arguments from the argv argument list, and decrement the argc respectively.
int & argc()
return the argument count.

◆ initialize() [2/2]

void ossimViewshedTool::initialize ( const ossimKeywordlist kwl)
virtual

Reads processing params from KWL and prepares for execute.

Returns TRUE if successful.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 225 of file ossimViewshedTool.cpp.

References ossimKeywordlist::findKey().

226 {
227  ossimString value;
228 
229  value = kwl.findKey(THREADS_KW);
230  {
231  if ( value.size() )
232  {
233  m_numThreads = ossimString(value).toUInt32();
234  }
235  }
236 
237  value = kwl.findKey(FOV_KW);
238  if (!value.empty())
239  {
240  vector <ossimString> coordstr;
241  value.split(coordstr, ossimString(" ,"), false);
242  if (coordstr.size() == 2)
243  {
244  m_startFov = coordstr[0].toDouble();
245  m_stopFov = coordstr[1].toDouble();
246  if (m_startFov < 0)
247  m_startFov += 360.0;
248  }
249  }
250 
251  value = kwl.findKey(HEIGHT_OF_EYE_KW);
252  if (!value.empty())
253  m_obsHgtAbvTer = value.toDouble();
254 
255  m_horizonFile = kwl.findKey(HORIZON_FILE_KW);
256 
257  value = kwl.findKey(OBSERVER_KW);
258  if (!value.empty())
259  {
260  vector <ossimString> coordstr;
261  value.split(coordstr, ossimString(" ,"), false);
262  if (coordstr.size() == 2)
263  {
264  m_observerGpt.lat = coordstr[0].toDouble();
265  m_observerGpt.lon = coordstr[1].toDouble();
266  m_observerGpt.hgt = 0.0;
267  }
268  }
269 
270  value = kwl.findKey(RETICLE_SIZE_KW);
271  if (!value.empty())
272  m_reticleSize = value.toInt32();
273 
274  value = kwl.findKey(VIEWSHED_CODING_KW);
275  if (!value.empty())
276  {
277  vector <ossimString> coordstr;
278  value.split(coordstr, ossimString(" ,"), false);
279  if (coordstr.size() == 3)
280  {
281  m_visibleValue = coordstr[0].toUInt8();
282  m_hiddenValue = coordstr[1].toUInt8();
283  m_overlayValue = coordstr[2].toUInt8();
284  }
285  }
286 
287  value = kwl.findKey(VISIBILITY_RADIUS_KW);
288  if (!value.empty())
289  {
290  m_visRadius = value.toDouble();
291  m_displayAsRadar = true;
292  }
293 
294  // If running simulation, clear out all pre-loaded elevation databases:
295  if (m_simulation)
296  {
299  }
300 
301  // Base class does most work:
303 }
virtual bool initialize(ossimArgumentParser &ap)
Initial method to be ran prior to execute.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
void setUseGeoidIfNullFlag(bool flag)
ossim_uint8 m_overlayValue
ossim_uint8 m_visibleValue
ossim_uint8 m_hiddenValue
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.
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
ossim_uint32 toUInt32() const
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossim_int32 toInt32() const
ossim_float64 lon
Definition: ossimGpt.h:266
std::string::size_type size() const
Definition: ossimString.h:405
ossim_int32 m_reticleSize
double toDouble() const
ossimFilename m_horizonFile
bool empty() const
Definition: ossimString.h:411
ossim_float64 lat
Definition: ossimGpt.h:265
ossim_uint32 m_numThreads

◆ initializeAOI()

void ossimViewshedTool::initializeAOI ( )
protectedvirtual

Initializes m_aoiViewRect with the output area of interest as specified in master KWL.

Initialization will either come from user defined cut options or the source bounding rect with user options taking precidence.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 336 of file ossimViewshedTool.cpp.

References ossimKeywordlist::hasKey(), ossimGrect::hasNans(), ossimGpt::hasNans(), ossimChipProcTool::initializeAOI(), ossimChipProcTool::m_aoiGroundRect, ossimTool::m_kwl, m_observerGpt, m_visRadius, and ossimGrect::midPoint().

337 {
339  if (!m_aoiGroundRect.hasNans())
340  {
341  // AOI established by base class, nothing to do except take this opportunity to set the
342  // observer location to AOI center if not already defined:
343  if (m_observerGpt.hasNans())
345  return;
346  }
347 
348  // Not enough info available to base class to determine AOI, maybe can determine from observer
349  // position and radius:
350  if ((m_visRadius == 0) && m_kwl.hasKey(AOI_SIZE_METERS_KW))
351  {
352  ossimString lookup = m_kwl.findKey( AOI_SIZE_METERS_KW );
353  lookup.trim();
354  m_visRadius = 0.5*(lookup.before(" ").toDouble() + lookup.after(" ").toDouble());
355  m_displayAsRadar = true;
356  }
357  if (m_observerGpt.hasNans())
359 
360  if ((m_visRadius != 0) && !m_observerGpt.hasNans())
361  {
362  ossimMapProjection* proj = dynamic_cast<ossimMapProjection*>(m_geom->getProjection());
363  if (!proj)
364  return;
365 
366  ossimDpt metersPerDegree (m_observerGpt.metersPerDegree());
367  double dlat = m_visRadius/metersPerDegree.y;
368  double dlon = m_visRadius/metersPerDegree.x;
369  ossimGpt ulg (m_observerGpt.lat + dlat, m_observerGpt.lon - dlon);
370  ossimGpt lrg (m_observerGpt.lat - dlat, m_observerGpt.lon + dlon);
371 
372  m_aoiGroundRect = ossimGrect(ulg, lrg);
373  proj->setUlTiePoints(ulg);
374 
376  }
377 }
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...
void computeAdjustedViewFromGrect()
Initializes m_aoiViewRect given m_aoiGroundRect.
ossimRefPtr< ossimImageGeometry > m_geom
ossimGrect m_aoiGroundRect
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
bool hasKey(const std::string &key) const
Checks for key in map.
ossimKeywordlist m_kwl
Definition: ossimTool.h:148
bool hasNans() const
Definition: ossimGrect.h:298
ossim_float64 lon
Definition: ossimGpt.h:266
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
ossimGpt midPoint() const
Definition: ossimGrect.h:178
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual void initializeAOI()
Initializes m_aoiViewRect with the output area of interest as specified in master KWL...
bool hasNans() const
Definition: ossimGpt.h:135
void findCenterGpt(ossimGpt &gpt)
Tries to determine the AOI center point based on KWL entries, else returns NaNs in gpt...
virtual void setUlTiePoints(const ossimGpt &gpt)
ossimDpt metersPerDegree() const
Definition: ossimGpt.cpp:498
ossim_float64 lat
Definition: ossimGpt.h:265
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.

◆ initializeProjectionGsd()

void ossimViewshedTool::initializeProjectionGsd ( )
protectedvirtual

Initializes the projection gsd.

This loops through all chains to find the minimum gsd.

Note
Throws ossimException on error.

Reimplemented from ossimChipProcTool.

Definition at line 315 of file ossimViewshedTool.cpp.

References ossimElevManager::getHeightAboveEllipsoid(), ossimElevManager::getMeanSpacingMeters(), ossimImageGeometry::getProjection(), ossimDpt::hasNans(), ossimGpt::hasNans(), ossimChipProcTool::initializeProjectionGsd(), ossimElevManager::instance(), ossimChipProcTool::m_geom, ossimChipProcTool::m_geoScaled, ossimChipProcTool::m_gsd, m_observerGpt, ossimMapProjection::setMetersPerPixel(), ossimMapProjection::setOrigin(), ossimDpt::x, and ossimDpt::y.

316 {
317  // First try normal base class initialization. If that doesn't work, then probably no DEM
318  // or input images were provided, so need to use elev manager resoltion at observer point.
319 
321  if (!m_gsd.hasNans() || m_observerGpt.hasNans())
322  return;
323 
324  ossimMapProjection* proj = dynamic_cast<ossimMapProjection*>(m_geom->getProjection());
325  if (!proj)
326  return;
327 
331  if (m_geoScaled)
332  proj->setOrigin(m_observerGpt);
333  proj->setMetersPerPixel(m_gsd);
334 }
virtual double getMeanSpacingMeters() const
Returns the mean post spacing (in meters) for the highest resolution DEM in the list or NaN if no DEM...
ossimRefPtr< ossimImageGeometry > m_geom
double y
Definition: ossimDpt.h:165
virtual void setOrigin(const ossimGpt &origin)
Sets theOrigin to origin.
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
virtual void initializeProjectionGsd()
Initializes the projection gsd.
virtual void setMetersPerPixel(const ossimDpt &gsd)
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
bool hasNans() const
Definition: ossimDpt.h:67
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
bool hasNans() const
Definition: ossimGpt.h:135
double x
Definition: ossimDpt.h:164

◆ initProcessingChain()

void ossimViewshedTool::initProcessingChain ( )
protectedvirtual

Derived classes initialize their custom chains here.

Implements ossimChipProcTool.

Definition at line 379 of file ossimViewshedTool.cpp.

References ossimImageChain::add(), ossimIrect::area(), ossimIrect::clipToRect(), ossimChipProcTool::combineLayers(), computeRadius(), ossimConnectableObject::connectMyInputTo(), ossimRefPtr< T >::get(), ossimElevManager::getHeightAboveEllipsoid(), ossimImageGeometry::getProjection(), ossimGpt::hasNans(), ossimIrect::hasNans(), ossimIrect::height(), ossimGpt::hgt, ossimImageDataFactory::instance(), ossimElevManager::instance(), ossimImageGeometry::localToWorld(), ossimChipProcTool::m_aoiGroundRect, ossimChipProcTool::m_aoiViewRect, ossimChipProcTool::m_geom, ossimChipProcTool::m_gsd, m_halfWindow, ossimChipProcTool::m_imgLayers, m_memSource, m_observerGpt, m_observerVpt, m_obsHgtAbvTer, m_outBuffer, ossimChipProcTool::m_procChain, m_visRadius, OSSIM_UINT8, ossimMemoryImageSource::setImage(), ossimMemoryImageSource::setImageGeometry(), ossimImageData::setImageRectangle(), ossimImageGeometry::setImageSize(), ossimIrect::size(), size, ossimRefPtr< T >::valid(), ossimIrect::width(), ossimImageGeometry::worldToLocal(), and ossimDpt::x.

380 {
381  ostringstream xmsg;
382 
383  if (m_observerGpt.hasNans())
384  {
385  xmsg<<"ossimViewshedUtil:"<<__LINE__<<" Observer ground position has not been set."<<ends;
386  throw ossimException(xmsg.str());
387  }
388 
390 
391  // Initialize the height of eye component of observer position:
395 
397  dynamic_cast<ossimMapProjection*>(m_geom->getProjection());
398 
399  // If no radius specified, need to compute R large enough to cover the requested AOI:
400  if (m_visRadius == 0)
401  computeRadius();
402  if (m_halfWindow == 0)
403  m_halfWindow = ossim::round<ossim_int32, double>(m_visRadius/m_gsd.x);
405 
406  // If no AOI defined, just use the visibility rectangle:
408  if (m_aoiViewRect.hasNans())
409  {
410  m_aoiViewRect = visRect;
413  }
414 
415  // Allocate the output image buffer:
416  ossimIrect bufViewRect = visRect.clipToRect(m_aoiViewRect);
417  if (bufViewRect.area() == 0)
418  {
419  xmsg<<"ossimViewshedUtil:"<<__LINE__<<" The requested AOI rect is outside the visibility range." << ends;
420  throw ossimException(xmsg.str());
421  }
423  create(0, OSSIM_UINT8, 1, m_aoiViewRect.width(), m_aoiViewRect.height());
424  if(!m_outBuffer.valid())
425  {
426  xmsg<<"ossimViewshedUtil:"<<__LINE__<<" Output buffer allocation failed." << ends;
427  throw ossimException(xmsg.str());
428  }
430 
431  // The processing chain for this class is simply a memory source containing the output buffer:
435 
436  // If input image(s) provided, need to combine them with the product:
437  if (m_imgLayers.empty())
438  {
440  }
441  else
442  {
444  combiner->connectMyInputTo(m_memSource.get());
445  m_procChain->add(combiner.get());
446  }
447 }
ossimRefPtr< ossimImageGeometry > m_geom
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void setImageRectangle(const ossimIrect &rect)
ossimGrect m_aoiGroundRect
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint32 height() const
Definition: ossimIrect.h:487
void setImage(ossimRefPtr< ossimImageData > image)
ossimRefPtr< ossimImageSource > combineLayers(std::vector< ossimRefPtr< ossimSingleImageChain > > &layers) const
When multiple input sources are present, this method instantiates a combiner and adds inputs...
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossimRefPtr< ossimMemoryImageSource > m_memSource
void setImageSize(const ossimIpt &size)
ossimIpt size() const
Definition: ossimIrect.h:510
ossimRefPtr< ossimImageChain > m_procChain
static ossimImageDataFactory * instance()
yy_size_t size
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
unsigned int ossim_uint32
std::vector< ossimRefPtr< ossimSingleImageChain > > m_imgLayers
ossimRefPtr< ossimImageData > m_outBuffer
virtual void setImageGeometry(ossimImageGeometry *geom)
Default implementation sets geometry of the first input to the geometry specified.
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
ossim_uint32 m_halfWindow
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
bool hasNans() const
Definition: ossimGpt.h:135
ossim_uint32 area() const
Definition: ossimIrect.h:396
double x
Definition: ossimDpt.h:164
bool hasNans() const
Definition: ossimIrect.h:337
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
8 bit unsigned integer

◆ initRadials()

void ossimViewshedTool::initRadials ( )
protected

Definition at line 724 of file ossimViewshedTool.cpp.

References ossimViewshedTool::Radial::azimuth, m_halfWindow, m_radials, m_startFov, and m_stopFov.

Referenced by computeViewshed().

725 {
726  // All eaight sectors' radials have the same azimuths except that the abscissa and ordinate are
727  // reversed between the N-S and E-W sectors, i.e., the N and S sectors use the y-axis as the
728  // abscissa (u) and the x-axis is the ordinate (v). The azimuth (dv/du) is therefore DX/DY for
729  // the north and south, while the azimuth is DY/DX for the east and west sectors. Nevertheless,
730  // each sectors radials must be maintained separately as they contain the max elevation angle.
731 
732  // First determine which sectors are involved given the desired FOV:
733  bool* sectorInFov = new bool[8];
734  memset(sectorInFov, false, 8);
735  bool crossed_north = true;
736  if (m_stopFov <= m_startFov) // Crosses 0 azimuth
737  crossed_north = false;
738  double azimuth = m_startFov;
739  for (int i=0; (i < 8) && ((azimuth < m_stopFov) || !crossed_north); ++i)
740  {
741  if ((azimuth >= 0) && (azimuth < 45.0))
742  sectorInFov[0] = true;
743  else if (azimuth < 90.0)
744  sectorInFov[1] = true;
745  else if (azimuth < 135.0)
746  sectorInFov[2] = true;
747  else if (azimuth < 180.0)
748  sectorInFov[3] = true;
749  else if (azimuth < 225.0)
750  sectorInFov[4] = true;
751  else if (azimuth < 270.0)
752  sectorInFov[5] = true;
753  else if (azimuth < 315.0)
754  sectorInFov[6] = true;
755  else if (azimuth < 360.0)
756  sectorInFov[7] = true;
757 
758  azimuth += 45.0;
759  if (azimuth > 360.0)
760  {
761  azimuth -= 360.0;
762  crossed_north = true;
763  }
764  }
765 
766  // Compute the azimuth slopes for each radial in the sector.
767  m_radials = new Radial* [8];
768  double du = m_halfWindow;
769  for (int sector=0; sector<8; ++sector)
770  {
771  if (!sectorInFov[sector])
772  {
773  m_radials[sector] = 0;
774  continue;
775  }
776 
777  ossim_uint32 ridx = 0;
778  m_radials[sector] = new Radial [m_halfWindow+1];
779  for (ossim_int32 dv = 0; dv <= (ossim_int32) m_halfWindow; ++dv)
780  {
781  if (sector & 1) // odd-numbered sector, azimuths computed in reverse order
782  m_radials[sector][m_halfWindow-ridx].azimuth = ((double)dv)/du;
783  else
784  m_radials[sector][ridx].azimuth = ((double)dv)/du;
785  ++ridx;
786  }
787  }
788 
789  // Cleanup:
790  delete [] sectorInFov;
791  sectorInFov = 0;
792 }
unsigned int ossim_uint32
ossim_uint32 m_halfWindow
int ossim_int32

◆ optimizeFOV()

bool ossimViewshedTool::optimizeFOV ( )
protected

Definition at line 577 of file ossimViewshedTool.cpp.

References ossimGpt::azimuthTo(), ossimGpt::lat, ossimGrect::ll(), ossimGpt::lon, ossimGrect::lr(), ossimChipProcTool::m_aoiGroundRect, m_observerGpt, m_startFov, m_stopFov, ossimNotify(), ossimNotifyLevel_INFO, ossimGrect::pointWithin(), ossimGrect::ul(), and ossimGrect::ur().

Referenced by computeViewshed(), and test().

578 {
579  bool intersects = false;
580 
581  // If the observer position lies outside of the requested AOI, we can reduce the search arc:
583  return true;
584 
585  // Determine cardinal region (N, NE, E, ...) of observer relative to AOI:
586  enum CardinalDirections { N=1, S=2, E=4, W=8, NE=5, NW=9, SE=6, SW=10 };
587  int direction = 0;
589  direction = (int) N;
590  else if (m_observerGpt.lat < m_aoiGroundRect.ll().lat)
591  direction = (int) S;
593  direction += (int) W;
594  else if (m_observerGpt.lon > m_aoiGroundRect.ur().lon)
595  direction += (int) E;
596 
597  // Calculate start and stop FOV depending on region:
598  double start, stop;
599  switch ((CardinalDirections) direction)
600  {
601  case N:
604  break;
605  case NE:
608  break;
609  case E:
612  break;
613  case SE:
616  break;
617  case S:
620  break;
621  case SW:
624  break;
625  case W:
628  break;
629  case NW:
630  default:
633  break;
634  }
635 
636  // Now need to intersect this arc with the requested FOV:
637  if (m_startFov == m_stopFov)
638  {
639  // There was no requested FOV (i.e, FOV = 360). So use the optimized FOV straight away:
640  m_startFov = start;
641  m_stopFov = stop;
642  intersects = true;
643  }
644  else
645  {
646  // Pick m_startFov as reference, and make sure all others are greater:
647  double a1 = m_stopFov;
648  double a2 = start;
649  double a3 = stop;
650  if (m_startFov > m_stopFov)
651  a1 += 360;
652  if (m_startFov > start)
653  a2 += 360;
654  if (m_startFov > stop)
655  a3 += 360;
656 
657  // Map to sort remaining azimuths by increasing angle clockwise:
658  map<double, int> angle_map;
659  angle_map.insert(pair<double, int>(a1, 1));
660  angle_map.insert(pair<double, int>(a2, 2));
661  angle_map.insert(pair<double, int>(a3, 3));
662 
663  map<double, int>::iterator iter = angle_map.begin();
664  if (iter->second == 1)
665  {
666  ++iter;
667  if (iter->second == 3)
668  intersects = true;
669  }
670  else if (iter->second == 2)
671  {
672  m_startFov = start;
673  intersects = true;
674  ++iter;
675  if (iter->second == 3)
676  m_stopFov = stop;
677  }
678  else
679  {
680  intersects = true;
681  m_stopFov = stop;
682  }
683  }
684 
685  if (!intersects)
686  {
688  "ossimViewshedUtil::optimizeFOV() -- No FOV intersection found. Nothing to do."<<endl;
689  }
690  else
691  {
692  ossimNotify(ossimNotifyLevel_INFO)<<"ossimViewshedUtil::optimizeFOV() -- "
693  "The start and stop FOV azimuths have been optimized to "<<m_startFov<<" -> "
694  <<m_stopFov<<" deg."<<endl;
695  }
696 
697  return intersects;
698 }
double azimuthTo(const ossimGpt &arg_gpt) const
METHOD: azimuthTo(ossimGpt) Computes the great-circle starting azimuth (i.e., at this gpt) to the arg...
Definition: ossimGpt.cpp:446
ossimGrect m_aoiGroundRect
bool pointWithin(const ossimGpt &gpt, bool considerHgt=false) const
METHOD: pointWithin(ossimGpt)
Definition: ossimGrect.h:232
ossim_float64 lon
Definition: ossimGpt.h:266
const ossimGpt & ul() const
Definition: ossimGrect.h:252
ossimGpt ur() const
Definition: ossimGrect.h:257
ossim_float64 lat
Definition: ossimGpt.h:265
const ossimGpt & lr() const
Definition: ossimGrect.h:269
ossimGpt ll() const
Definition: ossimGrect.h:263
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ paintReticle()

void ossimViewshedTool::paintReticle ( )
protected

Definition at line 794 of file ossimViewshedTool.cpp.

References ossimIrect::lr(), ossimChipProcTool::m_aoiViewRect, m_displayAsRadar, ossimChipProcTool::m_geom, m_observerGpt, m_observerVpt, m_outBuffer, m_overlayValue, m_reticleSize, ossimIrect::pointWithin(), ossimImageData::setValue(), ossimIrect::ul(), ossimImageGeometry::worldToLocal(), ossimIpt::x, ossimDpt::x, x, ossimIpt::y, ossimDpt::y, and y.

Referenced by computeViewshed().

795 {
796  if (m_reticleSize == 0)
797  return;
798 
799  // Highlight the observer position with X reticle:
800  ossimDpt obsViewPt;
801  m_geom->worldToLocal(m_observerGpt, obsViewPt);
802  if (m_aoiViewRect.pointWithin(ossimIpt(obsViewPt)))
803  {
804  for (int i=-m_reticleSize; i<=m_reticleSize; ++i)
805  {
810  }
811  }
812 
813  // Paint boundary rectangle if no visibility radius painted:
814  if (!m_displayAsRadar)
815  {
816  for (int y=m_aoiViewRect.ul().y; y<=m_aoiViewRect.lr().y; y++)
817  {
820  }
821  for (int x=m_aoiViewRect.ul().x; x<=m_aoiViewRect.lr().x; x++)
822  {
825  }
826  }
827 }
ossim_uint32 x
virtual void setValue(ossim_int32 x, ossim_int32 y, ossim_float64 color)
ossimRefPtr< ossimImageGeometry > m_geom
ossim_uint32 y
double y
Definition: ossimDpt.h:165
ossim_uint8 m_overlayValue
const ossimIpt & ul() const
Definition: ossimIrect.h:274
ossim_int32 m_reticleSize
ossimRefPtr< ossimImageData > m_outBuffer
const ossimIpt & lr() const
Definition: ossimIrect.h:276
ossim_int32 y
Definition: ossimIpt.h:142
double x
Definition: ossimDpt.h:164
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
ossim_int32 x
Definition: ossimIpt.h:141
bool pointWithin(const ossimIpt &pt) const
Definition: ossimIrect.h:729

◆ setUsage()

void ossimViewshedTool::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>);

Reimplemented from ossimChipProcTool.

Definition at line 79 of file ossimViewshedTool.cpp.

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

80 {
81  // Set the general usage:
83  ossimString appName = ap.getApplicationName();
84  ossimString usageString = appName;
85  usageString += " viewshed [options] <obs_lat> <obs_lon> <output-image>";
86  au->setCommandLineUsage(usageString);
87 
88  // Set the command line options:
90  "--fov <start> <end>", "Optional arguments specifying the field-of"
91  "-view boundary azimuths (in degrees). By default, a 360 deg FOV is"
92  " computed. The arc is taken clockwise from start to end, so for a"
93  " FOV of 225 deg from W, through N to SE, start=270 and end=135");
95  "--height-of-eye <meters>", "Specifies the observers height-of-eye above the "
96  "terrain in meters. Defaults to 1.5 m.");
98  "--horizon <filename>", "Experimental. Outputs the max elevation angles "
99  "for all azimuths to <filename>, for horizon profiling.");
101  "--radius <meters>", "Specifies max visibility in meters. Required "
102  "unless --size is specified. This option constrains output to a circle, "
103  "similar to a radar display");
105  "--reticle <int>", "Specifies the size of the reticle at the observer"
106  "location in pixels from the center (i.e., the radius of the reticle). "
107  "Defaults to 2. A value of 0 hides the reticle. See --values option for "
108  "setting reticle color.");
110  "--simulation", "For engineering/debug purposes ");
112  "--tbs", "\"Thread By Sector\". For engineering/debug purposes ");
114  "--threads <n>", "Number of threads. Defaults to use all available cores. "
115  "For engineering/debug purposes ");
117  "--viewshed-coding <int int int>", "Specifies the pixel values (0-255) for the visible,"
118  " hidden and overlay pixels, respectively. Defaults to visible=null (0), "
119  "hidden=128, and overlay (observer position, reticle, and circumference) is "
120  "highlighted with 255.");
121 
122  // Base class has its own:
124 
125  ostringstream description;
126  description << DESCRIPTION << "\n\nExamples:\n\n"
127  " "<<appName<<" viewshed --radius 50 28.0 -80.5 output-hlz.tif\n"
128  "\nAn alternate command line provides switch for observer lat and lon:\n\n"
129  " "<<appName<<" viewshed --rlz 25 --observer 28.0 -80.5 output-hlz.tif \n";
130  au->setDescription(description.str());
131 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
static const char * DESCRIPTION
Used by ossimUtilityFactory.
void setDescription(const ossimString &desc)

◆ test()

void ossimViewshedTool::test ( )

For engineering/debug.

Definition at line 1013 of file ossimViewshedTool.cpp.

References ossimChipProcTool::m_aoiGroundRect, m_observerGpt, m_startFov, m_stopFov, and optimizeFOV().

1014 {
1015  m_aoiGroundRect = ossimGrect(1.0, 0.0, 0.0, 1.0);
1016 
1017  m_observerGpt = ossimGpt(1.5, 0.5);
1018  m_startFov = 180;
1019  m_stopFov = 270;
1020  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1021  optimizeFOV();
1022  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1023 
1024  m_observerGpt = ossimGpt(1.5, 0.5);
1025  m_startFov = 335;
1026  m_stopFov = 180;
1027  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1028  optimizeFOV();
1029  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1030 
1031  m_observerGpt = ossimGpt(1.5, 0.5);
1032  m_startFov = 270;
1033  m_stopFov = 0;
1034  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1035  optimizeFOV();
1036  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1037 
1038  m_observerGpt = ossimGpt(-0.5, 0.5);
1039  m_startFov = 270;
1040  m_stopFov = 10;
1041  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1042  optimizeFOV();
1043  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1044 
1045  m_observerGpt = ossimGpt(-0.5, 0.5);
1046  m_startFov = 350;
1047  m_stopFov = 90;
1048  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1049  optimizeFOV();
1050  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1051 
1052  m_observerGpt = ossimGpt(-0.5, 0.5);
1053  m_startFov = 10;
1054  m_stopFov = 20;
1055  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1056  optimizeFOV();
1057  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1058 
1059  m_observerGpt = ossimGpt(-0.5, 0.5);
1060  m_startFov = 270;
1061  m_stopFov = 90;
1062  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1063  optimizeFOV();
1064  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1065 
1066  m_observerGpt = ossimGpt(-0.5, 0.5);
1067  m_startFov = 90;
1068  m_stopFov = 270;
1069  cout<<"Before: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<endl;
1070  optimizeFOV();
1071  cout<<"After: m_startFov="<<m_startFov<<" m_stopFov="<<m_stopFov<<"\n"<<endl;
1072 }
ossimGrect m_aoiGroundRect

◆ writeHorizonProfile()

bool ossimViewshedTool::writeHorizonProfile ( )
protected

Definition at line 829 of file ossimViewshedTool.cpp.

References ossim::atand(), ossimString::chars(), m_halfWindow, m_horizonFile, m_horizonMap, and m_radials.

Referenced by execute().

830 {
831  // Store the max elevation angles for horizon profiling:
832  double az_deg, arctan;
833  for (ossim_uint32 sector=0; sector<8; ++sector)
834  {
835  if (m_radials[sector] == 0)
836  continue;
837 
838  for (ossim_uint32 radial = 0; radial <= m_halfWindow; ++radial)
839  {
840  arctan = ossim::atand(m_radials[sector][radial].azimuth);
841  switch (sector)
842  {
843  case 0: // 0 - 45
844  az_deg = arctan;
845  break;
846  case 1: // 45 - 90
847  az_deg = 90 - arctan;
848  break;
849  case 2: // 90 - 135
850  az_deg = 90 + arctan;
851  break;
852  case 3: // 135 - 180
853  az_deg = 180 - arctan;
854  break;
855  case 4: // 180 - 225
856  az_deg = 180 + arctan;
857  break;
858  case 5: // 225 - 270
859  az_deg = 270 - arctan;
860  break;
861  case 6: // 270 - 315
862  az_deg = 270 + arctan;
863  break;
864  case 7: // 315 - 360
865  az_deg = 360 - arctan;
866  break;
867  default:
868  break;
869  }
870 
871  m_horizonMap.insert(pair<double, double>(az_deg, m_radials[sector][radial].elevation));
872  }
873  }
874 
875  // Open output file and write the map:
876  ofstream fstr (m_horizonFile.chars());
877  if (!fstr.is_open())
878  return false;
879  map<double, double>::iterator iter = m_horizonMap.begin();
880  while (iter != m_horizonMap.end())
881  {
882  fstr << iter->first << ", " << iter->second << endl;
883  ++iter;
884  }
885 
886  fstr.close();
887  return true;
888 }
unsigned int ossim_uint32
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
ossim_uint32 m_halfWindow
ossimFilename m_horizonFile
std::map< double, double > m_horizonMap
double atand(double x)
Definition: ossimCommon.h:266
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47

Friends And Related Function Documentation

◆ RadialProcessor

friend class RadialProcessor
friend

Definition at line 25 of file ossimViewshedTool.h.

◆ RadialProcessorJob

friend class RadialProcessorJob
friend

Definition at line 24 of file ossimViewshedTool.h.

◆ SectorProcessorJob

friend class SectorProcessorJob
friend

Definition at line 23 of file ossimViewshedTool.h.

Member Data Documentation

◆ d_accumT

double ossimViewshedTool::d_accumT
protected

Definition at line 112 of file ossimViewshedTool.h.

Referenced by computeViewshed().

◆ d_mutex

std::mutex ossimViewshedTool::d_mutex
protected

Definition at line 113 of file ossimViewshedTool.h.

◆ DESCRIPTION

const char * ossimViewshedTool::DESCRIPTION
static
Initial value:
=
"Computes bitmap image representing the viewshed from specified location using only "
"DEM information."

Used by ossimUtilityFactory.

Definition at line 61 of file ossimViewshedTool.h.

Referenced by ossimToolFactory::getCapabilities(), and setUsage().

◆ m_displayAsRadar

bool ossimViewshedTool::m_displayAsRadar
protected

Definition at line 94 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial(), and paintReticle().

◆ m_halfWindow

ossim_uint32 ossimViewshedTool::m_halfWindow
protected

◆ m_hiddenValue

ossim_uint8 ossimViewshedTool::m_hiddenValue
protected

Definition at line 99 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial().

◆ m_horizonFile

ossimFilename ossimViewshedTool::m_horizonFile
protected

Definition at line 108 of file ossimViewshedTool.h.

Referenced by execute(), and writeHorizonProfile().

◆ m_horizonMap

std::map<double, double> ossimViewshedTool::m_horizonMap
protected

Definition at line 109 of file ossimViewshedTool.h.

Referenced by clear(), and writeHorizonProfile().

◆ m_jobMtQueue

std::shared_ptr<ossimJobMultiThreadQueue> ossimViewshedTool::m_jobMtQueue
protected

Definition at line 103 of file ossimViewshedTool.h.

Referenced by clear(), and computeViewshed().

◆ m_memSource

ossimRefPtr<ossimMemoryImageSource> ossimViewshedTool::m_memSource
protected

Definition at line 97 of file ossimViewshedTool.h.

Referenced by computeViewshed(), and initProcessingChain().

◆ m_numThreads

ossim_uint32 ossimViewshedTool::m_numThreads
protected

Definition at line 104 of file ossimViewshedTool.h.

Referenced by computeViewshed().

◆ m_observerGpt

ossimGpt ossimViewshedTool::m_observerGpt
protected

◆ m_observerVpt

ossimDpt ossimViewshedTool::m_observerVpt
protected

◆ m_obsHgtAbvTer

double ossimViewshedTool::m_obsHgtAbvTer
protected

Definition at line 90 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial(), and initProcessingChain().

◆ m_obsInsideAoi

bool ossimViewshedTool::m_obsInsideAoi
protected

Definition at line 93 of file ossimViewshedTool.h.

◆ m_outBuffer

ossimRefPtr<ossimImageData> ossimViewshedTool::m_outBuffer
protected

◆ m_overlayValue

ossim_uint8 ossimViewshedTool::m_overlayValue
protected

Definition at line 100 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial(), and paintReticle().

◆ m_radials

Radial** ossimViewshedTool::m_radials
protected

◆ m_reticleSize

ossim_int32 ossimViewshedTool::m_reticleSize
protected

Definition at line 101 of file ossimViewshedTool.h.

Referenced by paintReticle().

◆ m_simulation

bool ossimViewshedTool::m_simulation
protected

Definition at line 102 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial().

◆ m_startFov

double ossimViewshedTool::m_startFov
protected

Definition at line 105 of file ossimViewshedTool.h.

Referenced by initRadials(), optimizeFOV(), and test().

◆ m_stopFov

double ossimViewshedTool::m_stopFov
protected

Definition at line 106 of file ossimViewshedTool.h.

Referenced by initRadials(), optimizeFOV(), and test().

◆ m_threadBySector

bool ossimViewshedTool::m_threadBySector
protected

Definition at line 107 of file ossimViewshedTool.h.

Referenced by computeViewshed().

◆ m_visibleValue

ossim_uint8 ossimViewshedTool::m_visibleValue
protected

Definition at line 98 of file ossimViewshedTool.h.

Referenced by RadialProcessor::doRadial().

◆ m_visRadius

double ossimViewshedTool::m_visRadius
protected

Definition at line 91 of file ossimViewshedTool.h.

Referenced by clear(), computeRadius(), initializeAOI(), and initProcessingChain().


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