WSF
WsfTerrain.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFTERRAIN_HPP
13#define WSFTERRAIN_HPP
14
15#include "wsf_export.h"
16
17#include <iosfwd>
18#include <string>
19#include <vector>
20
21#include "UtCallback.hpp"
22#include "UtLog.hpp"
23class GeoElevationTile;
24#include "GeoElevationTileManager.hpp"
25class GeodeticEarthDatabase;
26
27class UtInput;
28
29class VisualDatabase;
30
31class WsfCodedZone;
34class WsfZone;
35
36namespace wsf
37{
38
39class Terrain;
40
43{
44public:
46 {
50 // cGEOID_UNDULATED_DATABASE,
51 cGEODETIC_EARTH_DATABASE, // Support .eld database files
54 };
55
56
58 {
59 public:
60 bool ProcessRect(UtInput& aInput);
61
62 // protected:
63 int mSWLat;
64 int mSWLon;
65 int mNELat;
66 int mNELon;
67 };
68
69 struct DtedInput : public RectInput
70 {
71 std::string mDirName;
72 int mLevel;
73 bool mRaw;
74 };
75
76 struct FloatGridInput : public RectInput
77 {
79 std::string mDirName;
80 std::string mFileName;
81 };
82
83 struct GeotiffInput : public RectInput
84 {
85 std::string mDirName;
86 };
87
89 {
90 std::string mFileName;
91 };
92
93 struct Query
94 {
103
105 double mEarthRadius = 0.0;
106 double mLat = 0.0;
107 double mLon = 0.0;
108 double mAlt = 0.0;
109 double mLat2 = 0.0;
110 double mLon2 = 0.0;
111 double mAlt2 = 0.0;
113 };
114
115 friend class Terrain;
116
117 TerrainInterface(WsfScenario& aScenarioPtr);
119
120 static TerrainInterface* Get(const WsfScenario& aScenario);
121
122 bool ProcessInput(UtInput& aInput);
123 bool Initialize();
124
125 WsfScenario* GetScenario() { return mScenarioPtr; }
126
128
129 std::vector<int>* GetDTEDLevel() { return &mDTEDLevel; }
130 int GetDTEDLevelByIndex(size_t aIndex);
131 std::vector<std::string>* GetDTEDPath() { return &mDTEDPath; }
132 void GetDTEDPathByIndex(size_t aIndex, std::string& aPath);
133 const std::vector<DtedInput>& GetDTEDInputs() const { return mDtedInputs; }
135
137
138 const std::vector<GeotiffInput>& GetGeotiffInputs() const { return mGeotiffInputs; }
140
142
143 double GetEarthRadiusMultiplier() { return mEarthRadiusMultiplier; }
145
146 void PerformQueries(WsfSimulation& aSimulation);
147 bool IsEnabled() const { return mIsEnabled; }
148 bool IsVegetationEnabled() const { return mIsVegetationEnabled; }
149 bool IsGeodeticDatabase() const { return mGeodeticDatabase; }
150 bool IsDTED() const { return mDTED; }
151 bool IsBathymetryEnabled() const { return mIsBathymetryEnabled; }
152
156
157 GeoElevationTileManager& GetTileManager();
159
160 GeoElevationTileManager& GetVegetationManager();
161 GeoElevationTileManager& GetManager();
162 GeoElevationTileManager& GetBathymetryManager();
163
164 bool AddDtedDirectory(const std::string& aDirName, int aLevel);
165 bool AddRawDtedDirectory(const std::string& aDirName, int aLevel, int aSwLat, int aSwLon, int aNeLat, int aNeLon);
166
167 bool AddGeotiffDirectory(const std::string& aDirName);
168
169 bool AddBathymetry(const std::string& aFileName);
170
171 int GetElevApproxP(double aLat, double aLon, float& aElev, GeoElevationTileManager& aTileManager, GeoElevationTile*& aTilePtr);
172
173 void GetGeodeticElev(double aLat, double aLon, float& aElev);
174
175 void GeodeticComputeNormal(double aLat, double aLon, double aNormal[3]);
176
177 void GetNormalNED(double aLat, double aLon, double aNormal[3], GeoElevationTile*& aTilePtr);
178 void GetNormalENU(double aLat, double aLon, double aNormal[3], GeoElevationTile*& aTilePtr);
179
180 void DisableTerrain();
181 void EnableTerrain();
182
183 bool MaskedByTerrain(double aLat1,
184 double aLon1,
185 double aAlt1,
186 double aLat2,
187 double aLon2,
188 double aAlt2,
189 double aMaxRange,
190 double aRadiusScale = 1.0);
191
192 bool MaskedByVegetation(double aLat1,
193 double aLon1,
194 double aAlt1,
195 double aLat2,
196 double aLon2,
197 double aAlt2,
198 double aMaxRange,
199 double aRadiusScale = 1.0);
200
201 bool MaskedByUnderwaterTerrain(double aLat1,
202 double aLon1,
203 double aAlt1,
204 double aLat2,
205 double aLon2,
206 double aAlt2,
207 double aMaxRange,
208 double aRadiusScale = 1.0);
209
210protected:
211 void ValidateDTED();
212
213 bool SetFloatGridDirectory(const std::string& aDirName,
214 double aSwLat,
215 double aSwLon,
216 double aNeLat,
217 double aNeLon,
218 GeoElevationTileManager& aTileManager);
219
220 bool SetFloatGridFile(const std::string& aFileName, GeoElevationTileManager& aTileManager);
221
222 int GetElevInterpP(double aLat, double aLon, float& aElev, GeoElevationTileManager& aTileManager, GeoElevationTile*& aTilePtr);
223
224 bool MaskedByTerrainP(double aLat1,
225 double aLon1,
226 double aAlt1,
227 double aLat2,
228 double aLon2,
229 double aAlt2,
230 double aMaxRange,
231 GeoElevationTileManager& TileManager,
232 double aRadiusScale);
233
234 bool MaskedByTerrainFastP(double aLat1,
235 double aLon1,
236 double aAlt1,
237 double aLat2,
238 double aLon2,
239 double aAlt2,
240 double aMaxRange,
241 GeoElevationTileManager& aTileManager);
242
243 bool ListTheFiles(const std::string& aGeodeticEarthFilePathname);
244
245 bool DirectoryExists(const std::string& aDirName, const std::string& aCommand);
246 bool LoadTile(double aLat, double aLon, GeoElevationTile*& aTilePtr);
247
248 int LoadCME_File(const char* aCfgFile);
249 bool LoadCME_Terrain();
250
251 void ReadString(std::istream& aIn, std::string& aString);
252
253private:
254 WsfScenario* mScenarioPtr;
255
256 DataType mDataType = cDTED;
257 double mMinAllowableStepSize = 0.0; // meters
258 double mMaxTerrainHeight = 8850.0; // Height of Mt. Everest (in meters)
259 double mMaxDataSize = -1.0; // Not used by default
260 double mEarthRadiusMultiplier = 1.0;
261 bool mIgnoreMissingCME_Terrain = false;
262 bool mDisabledByUser = false;
263 // Terrain / Vegetation has been defined and hasn't been disabled by the user
264 bool mIsEnabled = false;
265 bool mIsVegetationEnabled = false;
266 // Terrain has been defined (implicitly or explicitly)
267 bool mIsDefined = false;
268 bool mDebugTerrainMasking = false;
269 bool mDebugTerrainExtrema = false;
270 bool mUseFastMaskingCheck = false;
271
272 std::vector<std::string> mDTEDPath; // path pointing to dted database
273 std::vector<int> mDTEDLevel; //
274
275 // added for reading .eld files for Mission System Lab databases
276 int mGeodeticEarthDBNumber = 4; // Geodetic earth database number
277 // Geodetic earth database name
278 std::string mGeodeticEarthDBName = "EDWARDS"; // Default EDWARDS data base
279 std::string mGeodeticEarthFilePathname;
280 unsigned int mGeodeticDatabaseType = 0;
281
282 std::string mVisualDBFile; // file name pointing to elevation database
283 bool mDTED = false;
284 bool mGeodeticDatabase = false;
285 std::vector<DtedInput> mDtedInputs;
286 std::vector<FloatGridInput> mFloatGridInputs;
287 std::vector<GeotiffInput> mGeotiffInputs;
288 bool mLoadCME_Terrain = false;
289 std::string mCME_Path;
290 bool mValidateDTED = false;
291 std::vector<Query> mQueryList;
292
293 VisualDatabase* mVisualDB_Ptr = nullptr;
294 GeodeticEarthDatabase* mGeodeticEarthDB_Ptr = nullptr; // Geodetic earth database class pointer
295
296 std::unique_ptr<GeoElevationTileManager> mGeoTileManagerPtr = nullptr;
297 std::unique_ptr<GeoElevationTileManager> mGeoTileVegetationManagerPtr = nullptr;
298 std::once_flag mGeoTileManagerFlag;
299 std::once_flag mGeoTileVegetationManagerFlag;
300
301 // Bathymetry
302 bool mBathymetryDefined = false;
303 bool mIsBathymetryEnabled = false;
304 std::vector<BathymetryInput> mBathmetryInputs;
305 std::unique_ptr<GeoElevationTileManager> mGeoTileBathymetryManagerPtr = nullptr;
306 std::once_flag mGeoTileBathymetryManagerFlag;
307};
308
334
336{
337public:
338 friend class TerrainInterface;
339
347
348 Terrain(TerrainInterface* aInterfacePtr);
349 Terrain(const Terrain& aSrc);
350 Terrain& operator=(const Terrain& aRhs) = delete;
351 ~Terrain();
352
353 bool Initialize(TerrainInterface* aInterfacePtr);
354 bool Initialize(WsfSimulation& aSimulation);
355
356 int GetElevApprox(double aLat, double aLon, float& aElev);
357
358 int GetElevApprox(const double aWCS[3], float& aElev);
359
360 int GetElevInterp(double aLat, double aLon, float& aElev);
361
362 int GetElevInterp(const double aWCS[3], float& aElev);
363
364 int GetVegElevApprox(double aLat, double aLon, float& aElev);
365
366 int GetVegElevInterp(double aLat, double aLon, float& aElev);
367
368 int GetBathymetryElevApprox(double aLat, double aLon, float& aElev);
369
370 int GetBathymetryElevInterp(double aLat, double aLon, float& aElev);
371
372 void GetNormalNED(double aLat, double aLon, double aNormal[3])
373 {
374 if (mInterfacePtr)
375 {
376 mInterfacePtr->GetNormalNED(aLat, aLon, aNormal, mTerrainTilePtr);
377 }
378 }
379
380 void GetNormalENU(double aLat, double aLon, double aNormal[3])
381 {
382 if (mInterfacePtr)
383 {
384 mInterfacePtr->GetNormalENU(aLat, aLon, aNormal, mTerrainTilePtr);
385 }
386 }
387
388 bool TerrainHitAlongLOS(const double aEyepointWCS[3], double aTerminusWCS[3]);
389
394
395 bool IsEnabled() { return (mInterfacePtr && mInterfacePtr->IsEnabled()); }
396
397 bool IsVegetationEnabled() { return (mInterfacePtr && mInterfacePtr->IsVegetationEnabled()); }
398
399 bool IsBathymetryEnabled() { return (mInterfacePtr && mInterfacePtr->IsBathymetryEnabled()); }
400
401 bool MaskedByTerrain(double aLat1,
402 double aLon1,
403 double aAlt1,
404 double aLat2,
405 double aLon2,
406 double aAlt2,
407 double aMaxRange,
408 double aRadiusScale = 1.0);
409
410 bool MaskedByTerrainFast(double aLat1, double aLon1, double aAlt1, double aLat2, double aLon2, double aAlt2, double aMaxRange);
411
412 bool MaskedByVegetation(double aLat1,
413 double aLon1,
414 double aAlt1,
415 double aLat2,
416 double aLon2,
417 double aAlt2,
418 double aMaxRange,
419 double aRadiusScale = 1.0);
420
421 bool MaskedByVegetationFast(double aLat1, double aLon1, double aAlt1, double aLat2, double aLon2, double aAlt2, double aMaxRange);
422
423 struct Post
424 {
425 double mHeightM = 0.0;
426 double mLatDeg = 0.0;
427 double mLonDeg = 0.0;
428 };
429
430 bool GetHeightExtremaIn(WsfSimulation& aSimulation, WsfZone* aZonePtr, Post& aMin, Post& aMax);
431
432 bool GetHeightExtremaIn(WsfSimulation& aSimulation,
433 double aLatSouth,
434 double aLonWest,
435 double aLatNorth,
436 double aLonEast,
437 Post& aMin,
438 Post& aMax,
439 WsfZone* aZonePtr = nullptr); // optional
440
441 // added for reading Flight Simulation geodetic databases
442 bool IsGeodeticDatabase() { return (mInterfacePtr && mInterfacePtr->IsGeodeticDatabase()); }
443 bool DTEDTypeDatabase() { return (mInterfacePtr && mInterfacePtr->IsDTED()); }
444
445protected:
446 GeoElevationTile* GetTilePtr() { return mTerrainTilePtr; }
447
448 GeoElevationTileManager& GetManager();
449
450 bool LoadTile(double aLat, double aLon) { return mInterfacePtr->LoadTile(aLat, aLon, mTerrainTilePtr); }
451
452 bool ComputeTerrainImpactP(double aLocationWCS_1[3], double aLocationWCS_2[3], bool aFirstPass = false);
453
454private:
455 void GetEdgeExtremaInZone(WsfZone* aZonePtr,
456 const std::vector<double>& aPostLatitudes,
457 const std::vector<double>& aPostLongitudes,
458 bool& aMinFound,
459 bool& aMaxFound,
460 float& aMinElevF,
461 float& aMaxElevF,
462 Post& aMin,
463 Post& aMax);
464
465 void CreateLocalsFromBoundaries(std::vector<double> aSortedValues,
466 double aStartValue,
467 double aEndValue,
468 std::vector<double>& aLocalValues);
469
470
471 GeoElevationTile* mTerrainTilePtr;
472 GeoElevationTile* mVegetationTilePtr;
473 GeoElevationTile* mBathymetryXYZ_TilePtr;
474
475 TerrainInterface* mInterfacePtr; // soft pointer
476};
477
478} // namespace wsf
479
480#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfCodedZone.hpp:24
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfZone.hpp:63
Definition WsfTerrain.hpp:58
int mSWLon
Definition WsfTerrain.hpp:64
bool ProcessRect(UtInput &aInput)
Definition WsfTerrain.cpp:490
int mNELon
Definition WsfTerrain.hpp:66
int mNELat
Definition WsfTerrain.hpp:65
int mSWLat
Definition WsfTerrain.hpp:63
Manages interface to terrain for a set of WsfTerrain objects.
Definition WsfTerrain.hpp:43
static TerrainInterface * Get(const WsfScenario &aScenario)
Definition WsfTerrain.cpp:2294
bool ProcessInput(UtInput &aInput)
Definition WsfTerrain.cpp:233
bool Initialize()
Definition WsfTerrain.cpp:2045
const std::vector< DtedInput > & GetDTEDInputs() const
Definition WsfTerrain.hpp:133
bool IsGeodeticDatabase() const
Definition WsfTerrain.hpp:149
bool IsEnabled() const
Definition WsfTerrain.hpp:147
double GetEarthRadiusMultiplier()
Access for Earth Radius Multiplier.
Definition WsfTerrain.hpp:143
friend class Terrain
Definition WsfTerrain.hpp:115
bool IsVegetationEnabled() const
Definition WsfTerrain.hpp:148
std::vector< int > * GetDTEDLevel()
Access for DTED DB Information.
Definition WsfTerrain.hpp:129
WsfScenario * GetScenario()
Definition WsfTerrain.hpp:125
bool IsDTED() const
Definition WsfTerrain.hpp:150
std::vector< std::string > * GetDTEDPath()
Definition WsfTerrain.hpp:131
bool IsBathymetryEnabled() const
Definition WsfTerrain.hpp:151
DataType
Definition WsfTerrain.hpp:46
@ cGEODETIC_EARTH_DATABASE
Definition WsfTerrain.hpp:51
@ cVISUAL_DATABASE
Definition WsfTerrain.hpp:49
@ cFLOAT_GRID
Definition WsfTerrain.hpp:48
@ cBATHYMETRY
Definition WsfTerrain.hpp:53
@ cGEOTIFF
Definition WsfTerrain.hpp:52
@ cDTED
Definition WsfTerrain.hpp:47
TerrainInterface(WsfScenario &aScenarioPtr)
Definition WsfTerrain.cpp:2282
const std::vector< GeotiffInput > & GetGeotiffInputs() const
Access for geotiff DB Information.
Definition WsfTerrain.hpp:138
Definition WsfTerrain.hpp:336
bool LoadTile(double aLat, double aLon)
Definition WsfTerrain.hpp:450
friend class TerrainInterface
Definition WsfTerrain.hpp:338
bool IsVegetationEnabled()
Definition WsfTerrain.hpp:397
bool GetHeightExtremaIn(WsfSimulation &aSimulation, WsfZone *aZonePtr, Post &aMin, Post &aMax)
Definition WsfTerrain.cpp:3035
void GetNormalENU(double aLat, double aLon, double aNormal[3])
Definition WsfTerrain.hpp:380
void GetNormalNED(double aLat, double aLon, double aNormal[3])
Definition WsfTerrain.hpp:372
int GetElevApprox(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:3755
Terrain & operator=(const Terrain &aRhs)=delete
bool Initialize(TerrainInterface *aInterfacePtr)
Definition WsfTerrain.cpp:3835
int GetVegElevInterp(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:2905
int GetBathymetryElevApprox(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:3813
int GetVegElevApprox(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:3794
bool IsGeodeticDatabase()
Definition WsfTerrain.hpp:442
int GetElevInterp(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:2860
GeoElevationTile * GetTilePtr()
Definition WsfTerrain.hpp:446
bool IsBathymetryEnabled()
Definition WsfTerrain.hpp:399
Terrain(TerrainInterface *aInterfacePtr)
Definition WsfTerrain.cpp:3635
bool DTEDTypeDatabase()
Definition WsfTerrain.hpp:443
ElevationType
Definition WsfTerrain.hpp:341
@ cTERRAIN
Definition WsfTerrain.hpp:343
@ cBATHYMETRY
Definition WsfTerrain.hpp:345
@ cVEGETATION
Definition WsfTerrain.hpp:344
@ cINVALID
Definition WsfTerrain.hpp:342
int GetBathymetryElevInterp(double aLat, double aLon, float &aElev)
Definition WsfTerrain.cpp:2927
bool IsEnabled()
Definition WsfTerrain.hpp:395
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfTerrain.hpp:89
std::string mFileName
Definition WsfTerrain.hpp:90
Definition WsfTerrain.hpp:70
bool mRaw
Definition WsfTerrain.hpp:73
std::string mDirName
Definition WsfTerrain.hpp:71
int mLevel
Definition WsfTerrain.hpp:72
Definition WsfTerrain.hpp:77
bool mVegetation
Definition WsfTerrain.hpp:78
std::string mFileName
Definition WsfTerrain.hpp:80
std::string mDirName
Definition WsfTerrain.hpp:79
Definition WsfTerrain.hpp:84
std::string mDirName
Definition WsfTerrain.hpp:85
Definition WsfTerrain.hpp:94
double mAlt
Definition WsfTerrain.hpp:108
QueryType
Definition WsfTerrain.hpp:96
@ cHORIZON
Definition WsfTerrain.hpp:99
@ cNONE
Definition WsfTerrain.hpp:97
@ cTEST_EXTREMA_IN_ZONE
Definition WsfTerrain.hpp:101
@ cHEIGHT
Definition WsfTerrain.hpp:98
@ cMASKING
Definition WsfTerrain.hpp:100
WsfCodedZone * mZonePtr
Definition WsfTerrain.hpp:112
double mEarthRadius
Definition WsfTerrain.hpp:105
double mLat
Definition WsfTerrain.hpp:106
double mLat2
Definition WsfTerrain.hpp:109
double mLon
Definition WsfTerrain.hpp:107
double mAlt2
Definition WsfTerrain.hpp:111
QueryType mType
Definition WsfTerrain.hpp:104
double mLon2
Definition WsfTerrain.hpp:110
Definition WsfTerrain.hpp:424
double mLonDeg
Definition WsfTerrain.hpp:427
double mLatDeg
Definition WsfTerrain.hpp:426
double mHeightM
Definition WsfTerrain.hpp:425
Copyrights Multiple, All Rights Reserved