34 "Computes bitmap image representing the viewshed from specified location using only " 36 static const string FOV_KW =
"fov";
37 static const string HEIGHT_OF_EYE_KW =
"height_of_eye";
38 static const string HORIZON_FILE_KW =
"horizon_file";
39 static const string OBSERVER_KW =
"observer";
40 static const string VISIBILITY_RADIUS_KW =
"visibility_radius";
41 static const string RETICLE_SIZE_KW =
"reticle_size";
42 static const string VIEWSHED_CODING_KW =
"viewshed_coding";
43 static const string AOI_SIZE_METERS_KW =
"aoi_size_meters";
44 static const string THREADS_KW =
"threads";
48 : m_obsHgtAbvTer (1.5),
51 m_obsInsideAoi (
true),
52 m_displayAsRadar (false),
63 m_threadBySector(false),
73 for (
int i=0; i<4; ++i)
85 usageString +=
" viewshed [options] <obs_lat> <obs_lon> <output-image>";
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.");
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";
136 xmsg<<
"ossimViewshedUtil::initialize(ossimArgumentParser) -- ";
138 int numArgsExpected = 4;
153 if ( ap.
read(
"--fov", sp1, sp2) )
159 value<<startFov<<
" "<<ts2;
163 if ( ap.
read(
"--hgt-of-eye", sp1) || ap.
read(
"--height-of-eye", sp1) )
166 if ( ap.
read(
"--horizon", sp1) || ap.
read(
"--horizon-file", sp1))
169 if ( ap.
read(
"--observer", sp1, sp2) )
172 value<<ts1<<
" "<<ts2;
174 numArgsExpected -= 2;
177 if ( ap.
read(
"--radius", sp1) )
180 if ( ap.
read(
"--reticle", sp1) )
183 if ( ap.
read(
"--values", sp1, sp2, sp3) || ap.
read(
"--viewshed-coding", sp1, sp2, sp3))
186 value<<ts1<<
" "<<ts2<<
" "<<ts3;
190 if ( ap.
read(
"--threads", sp1) )
196 if ( ap.
read(
"--tbs") )
199 if ( ap.
read(
"--simulation") )
206 if ( ap.
argc() < numArgsExpected )
208 xmsg<<
"Expecting more arguments.";
216 value<<latstr<<
" "<<lonstr;
229 value = kwl.
findKey(THREADS_KW);
240 vector <ossimString> coordstr;
242 if (coordstr.size() == 2)
251 value = kwl.
findKey(HEIGHT_OF_EYE_KW);
257 value = kwl.
findKey(OBSERVER_KW);
260 vector <ossimString> coordstr;
262 if (coordstr.size() == 2)
270 value = kwl.
findKey(RETICLE_SIZE_KW);
274 value = kwl.
findKey(VIEWSHED_CODING_KW);
277 vector <ossimString> coordstr;
279 if (coordstr.size() == 3)
287 value = kwl.
findKey(VISIBILITY_RADIUS_KW);
385 xmsg<<
"ossimViewshedUtil:"<<__LINE__<<
" Observer ground position has not been set."<<ends;
417 if (bufViewRect.
area() == 0)
419 xmsg<<
"ossimViewshedUtil:"<<__LINE__<<
" The requested AOI rect is outside the visibility range." << ends;
426 xmsg<<
"ossimViewshedUtil:"<<__LINE__<<
" Output buffer allocation failed." << ends;
451 cerr<<
"ossimViewshedUtil:"<<__LINE__<<endl;
456 cerr<<
"ossimViewshedUtil:"<<__LINE__<<endl;
461 cerr<<
"ossimViewshedUtil:"<<__LINE__<<endl;
495 xmsg<<
"ossimViewshedUtil:"<<__LINE__<<
" Error encountered allocating output image buffer.";
520 std::shared_ptr<ossimJobQueue> jobQueue = std::make_shared<ossimJobQueue>();
521 for (
int sector=0; sector<8; ++sector)
528 std::shared_ptr<SectorProcessorJob> job = std::make_shared<SectorProcessorJob>(
this, sector,
m_halfWindow);
529 jobQueue->add(job,
false);
535 std::shared_ptr<RadialProcessorJob> job = std::make_shared<RadialProcessorJob>(
this, sector, r,
m_halfWindow);
536 jobQueue->add(job,
false);
557 for (
int sector=0; sector<8; ++sector)
562 std::shared_ptr<SectorProcessorJob> spj = std::make_shared<SectorProcessorJob>(
this, sector,
m_halfWindow);
579 bool intersects =
false;
586 enum CardinalDirections { N=1, S=2, E=4, W=8, NE=5, NW=9, SE=6, SW=10 };
593 direction += (
int) W;
595 direction += (
int) E;
599 switch ((CardinalDirections) direction)
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));
663 map<double, int>::iterator iter = angle_map.begin();
664 if (iter->second == 1)
667 if (iter->second == 3)
670 else if (iter->second == 2)
675 if (iter->second == 3)
688 "ossimViewshedUtil::optimizeFOV() -- No FOV intersection found. Nothing to do."<<endl;
693 "The start and stop FOV azimuths have been optimized to "<<
m_startFov<<
" -> " 702 ostringstream xmsg (
"ossimViewshedUtil::computeRadius() -- ");
707 xmsg<<
"AOI undefined. Cannot compute visibility radius." << ends;
733 bool* sectorInFov =
new bool[8];
734 memset(sectorInFov,
false, 8);
735 bool crossed_north =
true;
737 crossed_north =
false;
739 for (
int i=0; (i < 8) && ((azimuth <
m_stopFov) || !crossed_north); ++i)
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;
762 crossed_north =
true;
769 for (
int sector=0; sector<8; ++sector)
771 if (!sectorInFov[sector])
790 delete [] sectorInFov;
832 double az_deg, arctan;
847 az_deg = 90 - arctan;
850 az_deg = 90 + arctan;
853 az_deg = 180 - arctan;
856 az_deg = 180 + arctan;
859 az_deg = 270 - arctan;
862 az_deg = 270 + arctan;
865 az_deg = 360 - arctan;
879 map<double, double>::iterator iter =
m_horizonMap.begin();
882 fstr << iter->first <<
", " << iter->second << endl;
921 for (u=1.0; u <= (double) vsUtil->
m_halfWindow; u += 1.0)
virtual double getMeanSpacingMeters() const
Returns the mean post spacing (in meters) for the highest resolution DEM in the list or NaN if no DEM...
void fill(ossim_uint32 band, ossim_float64 value)
will fill the entire band with the value.
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
double azimuthTo(const ossimGpt &arg_gpt) const
METHOD: azimuthTo(ossimGpt) Computes the great-circle starting azimuth (i.e., at this gpt) to the arg...
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...
virtual void setValue(ossim_int32 x, ossim_int32 y, ossim_float64 color)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
Within the image chain will pass the head of the list.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
virtual void setImageRectangle(const ossimIrect &rect)
bool needsAborting() const
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
void setUseGeoidIfNullFlag(bool flag)
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
virtual void setOrigin(const ossimGpt &origin)
Sets theOrigin to origin.
ossim_uint32 height() const
bool hasKey(const std::string &key) const
Checks for key in map.
virtual void run()
Abstract method and must be overriden by the base class.
void setImage(ossimRefPtr< ossimImageData > image)
const ossimIpt & ul() const
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.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
ossim_float64 hgt
Height in meters above the ellipsiod.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
ossim_uint32 toUInt32() const
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
void setImageSize(const ossimIpt &size)
double distanceTo(const ossimGpt &arg_gpt) const
METHOD: distanceTo(ossimGpt) Computes straight-line distance in meters between this and arg gpt: ...
static void sleepInMicroSeconds(ossim_uint64 micros)
Utility method to allow one to sleep in microseconds.
virtual void initialize()
Initialize the data buffer.
virtual void setMetersPerPixel(const ossimDpt &gsd)
OSSIM_DLL ossim_uint32 getNumberOfThreads()
Get the number threads to use from ossimPreferences or ossim::Thread.
ossim_int32 toInt32() const
bool pointWithin(const ossimGpt &gpt, bool considerHgt=false) const
METHOD: pointWithin(ossimGpt)
static ossimImageDataFactory * instance()
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
std::string::size_type size() const
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
unsigned int ossim_uint32
virtual void run()
Abstract method and must be overriden by the base class.
ossimViewshedTool * m_vsUtil
const char * chars() const
For backward compatibility.
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
ossimViewshedTool * m_vsUtil
const ossimGpt & ul() const
virtual void setImageGeometry(ossimImageGeometry *geom)
Default implementation sets geometry of the first input to the geometry specified.
static void doRadial(ossimViewshedTool *vs, ossim_uint32 s, ossim_uint32 r)
const ossimIpt & lr() const
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
static std::mutex m_bufMutex
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
ossimIrect clipToRect(const ossimIrect &rect) const
ossimGpt midPoint() const
void remove(int pos, int num=1)
remove one or more arguments from the argv argument list, and decrement the argc respectively.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
void setDescription(const ossimString &desc)
ossim_uint32 m_numRadials
ossim_uint32 area() const
virtual void setUlTiePoints(const ossimGpt &gpt)
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
ossimDpt metersPerDegree() const
std::basic_ofstream< char > ofstream
Class for char output file streams.
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
const ossimGpt & lr() const
int & argc()
return the argument count.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool pointWithin(const ossimIpt &pt) const
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.