OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDtedHandler.h
Go to the documentation of this file.
1 //*****************************************************************************
2 // FILE: ossimDtedHandler.h
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // DESCRIPTION:
7 // Contains declaration of class ossimDtedHandler. This class derives from
8 // ossimElevHandler. It is responsible for loading an individual DTED cell
9 // from disk. This elevation files are memory mapped.
10 //
11 // SOFTWARE HISTORY:
12 //>
13 // 05Feb2001 Ken Melero
14 // Initial coding of ossimDted.h
15 // 19Apr2001 Oscar Kramer
16 // Derived from ossimElevCellHandler.
17 //<
18 //*****************************************************************************
19 // $Id: ossimDtedHandler.h 23497 2015-08-28 15:28:59Z okramer $
20 
21 #ifndef ossimDtedHandler_HEADER
22 #define ossimDtedHandler_HEADER
23 
24 #include <fstream>
25 
27 #include <ossim/base/ossimString.h>
35 
36 #include <mutex>
58 {
59 public:
60 
61  // number of Dted posts per point.
62  static const int TOTAL_POSTS = 4;
63  // number of Dted posts per block
64  static const int NUM_POSTS_PER_BLOCK= 2;
65 
70  {
71  }
72 
82  ossimDtedHandler(const ossimFilename& dted_file, bool memoryMapFlag=false);
83 
84  enum
85  {
86  DATA_RECORD_OFFSET_TO_POST = 8, // bytes
87  DATA_RECORD_CHECKSUM_SIZE = 4, // bytes
88  POST_SIZE = 2, // bytes
89  NULL_POST = -32767 // Fixed by DTED specification.
90  };
91 
101  virtual bool open(const ossimFilename& file, bool memoryMapFlag=false);
102 
114  virtual bool open(std::shared_ptr<ossim::istream>& fileStr, const std::string& connectionString, bool memoryMapFlag=false);
115  virtual void close();
116 
122  virtual double getHeightAboveMSL(const ossimGpt& gpt);
123 
129  virtual ossimIpt getSizeOfElevCell() const;
130 
136  virtual double getPostValue(const ossimIpt& gridPt) const;
137 
138  ossimString edition() const;
139  ossimString productLevel() const;
140  ossimString compilationDate() const;
141 
142  virtual bool isOpen()const;
143 
144  virtual bool getAccuracyInfo(ossimElevationAccuracyInfo& info, const ossimGpt& gpt) const;
145 
146  const ossimDtedVol& vol()const
147  {
148  return *m_vol;
149  }
150  const ossimDtedHdr& hdr()const
151  {
152  return *m_hdr;
153  }
154  const ossimDtedUhl& uhl()const
155  {
156  return *m_uhl;
157  }
158  const ossimDtedDsi& dsi()const
159  {
160  return *m_dsi;
161  }
162  const ossimDtedAcc& acc()const
163  {
164  return *m_acc;
165  }
166 
167  virtual ossimObject* dup () const
168  {
169  return new ossimDtedHandler(this->getFilename(), (m_memoryMap.size() != 0));
170  }
171 
172  virtual ~ossimDtedHandler();
173 
174 protected:
175 
177  class DtedPost
178  {
179  public:
180  // constructor - initialise variables
182  m_height(0),
183  m_weight(0),
184  m_status(false)
185  {
186  }
187  // destructor
188  virtual ~DtedPost();
189  // member variables
190  double m_height;
191  double m_weight;
192  bool m_status;
193  };
194 
198  {
199  public:
200  // constructor
201  DtedHeight();
202  // destructor
203  virtual ~DtedHeight();
204  // calculate the interpolated Height for the posts
205  double calcHeight();
206  // debug
207  void debug();
208  // post data
209  DtedPost m_posts[TOTAL_POSTS];
210  };
211 
212 
213  // Disallow operator= and copy construction...
214  const ossimDtedHandler& operator=(const ossimDtedHandler& rhs);
216 
224  void gatherStatistics();
225 
226  ossim_sint16 convertSignedMagnitude(ossim_uint16& s) const;
227  virtual double getHeightAboveMSL(const ossimGpt&, bool readFromFile);
228 
234  void readPostsFromFile(DtedHeight &postData, int offset);
235 
236  mutable std::mutex m_fileStrMutex;
237  // mutable std::ifstream m_fileStr;
238  mutable std::shared_ptr<ossim::istream> m_fileStr;
239  mutable std::string m_connectionString;
240 
241  ossim_int32 m_numLonLines; // east-west dir
242  ossim_int32 m_numLatPoints; // north-south
248  double m_latSpacing; // degrees
249  double m_lonSpacing; // degrees
250  ossimDpt m_swCornerPost; // cell origin;
251 
252  // Indicates whether byte swapping is needed.
254 
255  mutable std::mutex m_memoryMapMutex;
256  mutable std::vector<ossim_uint8> m_memoryMap;
257 
258  std::shared_ptr<ossimDtedVol> m_vol;
259  std::shared_ptr<ossimDtedHdr> m_hdr;
260  std::shared_ptr<ossimDtedUhl> m_uhl;
261  std::shared_ptr<ossimDtedDsi> m_dsi;
262  std::shared_ptr<ossimDtedAcc> m_acc;
263 
264  TYPE_DATA
265 };
266 
268 {
269  // DATA_VALUE_MASK 0x7fff = 0111 1111 1111 1111
270  // DATA_SIGN_MASK 0x8000 = 1000 0000 0000 0000
271 
272  // First check to see if the bytes need swapped.
273  s = (m_swapBytesFlag ? ( ((s & 0x00ff) << 8) | ((s & 0xff00) >> 8) ) : s);
274 
275  // If the sign bit is set, mask it out then multiply by negative one.
276  if (s & 0x8000)
277  {
278  return (static_cast<ossim_sint16>(s & 0x7fff) * -1);
279  }
280 
281  return static_cast<ossim_sint16>(s);
282 }
283 
284 inline bool ossimDtedHandler::isOpen()const
285 {
286 
287  if(!m_memoryMap.empty()) return true;
288  std::lock_guard<std::mutex> lock(m_fileStrMutex);
289 
290  return (m_fileStr != 0);
291 }
292 
294 {
295  m_fileStr.reset();
296  m_memoryMap.clear();
297 }
298 
299 #endif
virtual double getHeightAboveMSL(const ossimGpt &)=0
Height access methods:
std::shared_ptr< ossimDtedVol > m_vol
virtual const ossimFilename & getFilename() const
ossimString m_productLevel
const ossimDtedVol & vol() const
std::shared_ptr< ossimDtedUhl > m_uhl
virtual void close()
ossim_int32 m_numLonLines
std::vector< ossim_uint8 > m_memoryMap
unsigned short ossim_uint16
std::shared_ptr< ossimDtedHdr > m_hdr
virtual bool getAccuracyInfo(ossimElevationAccuracyInfo &info, const ossimGpt &gpt) const
std::shared_ptr< ossimDtedDsi > m_dsi
virtual bool isOpen() const
std::mutex m_fileStrMutex
const ossimDtedHdr & hdr() const
DtedHeight is a class for storing DTED information.
ossimString m_compilationDate
virtual bool open(const ossimFilename &, bool=false)
signed short ossim_sint16
std::shared_ptr< ossim::istream > m_fileStr
#define TYPE_DATA
Definition: ossimRtti.h:339
virtual double getPostValue(const ossimIpt &gridPt) const =0
METHOD: getPostValue Returns the value at a given grid point as a double.
const ossimDtedAcc & acc() const
the DTED handler is an elevation source that allows for handling of a single cell of data...
ossim_int32 m_numLatPoints
ossim_sint16 convertSignedMagnitude(ossim_uint16 &s) const
const ossimSource & operator=(const ossimSource &rhs)
ossim_int32 m_offsetToFirstDataRecord
ossim_int32 m_dtedRecordSizeInBytes
const ossimDtedDsi & dsi() const
#define OSSIM_DLL
std::shared_ptr< ossimDtedAcc > m_acc
virtual ossimObject * dup() const
std::mutex m_memoryMapMutex
const ossimDtedUhl & uhl() const
ossimString m_edition
ossimDtedHandler()
Constructor.
std::string m_connectionString
virtual ossimIpt getSizeOfElevCell() const =0
METHOD: getSizeOfElevCell Returns the number of post in the cell.
DtedPost, this class contains the height, weighting factor and status.
int ossim_int32