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

#include <ossimDtedRecord.h>

Inheritance diagram for ossimDtedRecord:
ossimErrorStatusInterface

Public Types

enum  {
  DATA_LENGTH = 12, DATA_BLOCK_COUNT = 2, DATA_LON_COUNT = 4, DATA_LAT_COUNT = 6,
  DATA_ELEV_START = 8, DATA_BYTES_PER_POINT = 2
}
 

Public Member Functions

 ossimDtedRecord (std::istream &in, ossim_int32 offest, ossim_int32 num_points)
 
 ~ossimDtedRecord ()
 
ossimString recognitionSentinel () const
 
ossim_int32 dataBlockCount () const
 
ossim_int32 lonCount () const
 
ossim_int32 latCount () const
 
ossim_uint32 checkSum () const
 
ossim_uint32 computedCheckSum () const
 
ossim_int32 numPoints () const
 
ossim_int32 getPoint (ossim_int32 i) const
 
ossim_uint16 getPointData (ossim_int32 i) const
 
ossim_int32points () const
 
ossim_uint16pointsData () const
 
ossim_int32 startOffset () const
 
ossim_int32 stopOffset () const
 
void parse (std::istream &in)
 
- Public Member Functions inherited from ossimErrorStatusInterface
 ossimErrorStatusInterface ()
 
virtual ~ossimErrorStatusInterface ()
 
virtual ossimErrorCode getErrorStatus () const
 
virtual ossimString getErrorStatusString () const
 
virtual void setErrorStatus (ossimErrorCode error_status) const
 
virtual void setErrorStatus () const
 
virtual void clearErrorStatus () const
 
bool hasError () const
 
virtual std::ostream & print (std::ostream &out) const
 Outputs theErrorStatus as an ossimErrorCode and an ossimString. More...
 

Private Member Functions

 ossimDtedRecord (const ossimDtedRecord &source)
 
bool validateCheckSum (std::istream &in)
 

Private Attributes

ossim_int32 theFile
 
ossimString theRecSen
 
ossim_int32 theDataBlockCount
 
ossim_int32 theLonCount
 
ossim_int32 theLatCount
 
ossim_uint32 theCheckSum
 
ossim_int32thePoints
 
ossim_uint16thePointsData
 
ossim_uint32 theComputedCheckSum
 
ossim_int32 theNumPoints
 
ossim_int32 theStartOffset
 
ossim_int32 theStopOffset
 

Friends

OSSIM_DLL std::ostream & operator<< (std::ostream &os, const ossimDtedRecord &rec)
 

Additional Inherited Members

- Protected Attributes inherited from ossimErrorStatusInterface
ossimErrorCode theErrorStatus
 

Detailed Description

Definition at line 31 of file ossimDtedRecord.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DATA_LENGTH 
DATA_BLOCK_COUNT 
DATA_LON_COUNT 
DATA_LAT_COUNT 
DATA_ELEV_START 
DATA_BYTES_PER_POINT 

Definition at line 55 of file ossimDtedRecord.h.

Constructor & Destructor Documentation

◆ ossimDtedRecord() [1/2]

ossimDtedRecord::ossimDtedRecord ( std::istream &  in,
ossim_int32  offest,
ossim_int32  num_points 
)

Definition at line 50 of file ossimDtedRecord.cpp.

53  :
54  theRecSen("170"),
56  theLonCount(0),
57  theLatCount(0),
58  theCheckSum(0),
59  thePoints(new ossim_int32[num_points]),
60  thePointsData(new ossim_uint16[num_points]),
62  theNumPoints(num_points),
63  theStartOffset(offset),
64  theStopOffset(offset + RECORD_HDR_LENGTH + (num_points*BYTES_PER_POINT))
65 {
66  // Verify we are at a cell record by checking the Recognition Sentinel.
67  ossim_uint8 buf[1];
68  in.seekg(theStartOffset, std::ios::beg);
69  in.read((char*)buf, 1);
70 
71 #if 0
72  printf("\nBuf: %02X", (int)buf[0]); // Display in HEX
73 #endif
74 
75  if(buf[0] != DATA_RECOGNITION_SENTINEL)
76  {
78  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimDtedRecord::ossimDtedRecord: reading DTED's data record at: " << theStartOffset
79  << std::endl;
80  return;
81  }
82 
83  // Valid data record, so let's process on.
84  parse(in);
85 
86  //***
87  // Note: The validateCheckSum method works; however, our in-house
88  // dted has bad stored check sums even though the post are good.
89  // So this in temporarily shut off.
90  //***
91  // Verify Check Sum for uncorrupted elevation data.
92  if(validateCheckSum(in) == false)
93  {
94  //***
95  // Note: The validateCheckSum method works; however, our in-house
96  // dted has bad stored check sums even though the posts are good.
97  // So this in temporarily shut off.
98  //***
101  << "FATAL ossimDtedRecord::ossimDtedRecord:"
102  << "\nInvalid checksum in data record at: "
103  << theStartOffset
104  << "\nParsed Check Sum = " << theCheckSum
105  << "\nComputed Check Sum = " << theComputedCheckSum
106  << "\nDTED Elevation File is considered corrupted."
107  << std::endl;
108  return;
109  }
110 }
void parse(std::istream &in)
ossim_int32 theNumPoints
ossim_int32 theStartOffset
ossim_int32 theLonCount
ossimString theRecSen
static const ossimErrorCode OSSIM_ERROR
unsigned short ossim_uint16
ossim_int32 theStopOffset
bool validateCheckSum(std::istream &in)
ossim_int32 theDataBlockCount
ossim_int32 theLatCount
ossim_uint32 theComputedCheckSum
ossim_int32 * thePoints
ossim_uint32 theCheckSum
ossim_uint16 * thePointsData
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

◆ ~ossimDtedRecord()

ossimDtedRecord::~ossimDtedRecord ( )

Definition at line 112 of file ossimDtedRecord.cpp.

References thePoints, and thePointsData.

113 {
114  if (thePoints)
115  {
116  delete [] thePoints;
117  thePoints = NULL;
118  }
119  if (thePointsData)
120  {
121  delete [] thePointsData;
122  thePointsData = NULL;
123  }
124 }
ossim_int32 * thePoints
ossim_uint16 * thePointsData

◆ ossimDtedRecord() [2/2]

ossimDtedRecord::ossimDtedRecord ( const ossimDtedRecord source)
private

Member Function Documentation

◆ checkSum()

ossim_uint32 ossimDtedRecord::checkSum ( ) const

Definition at line 226 of file ossimDtedRecord.cpp.

References theCheckSum.

227 {
228  return theCheckSum;
229 }
ossim_uint32 theCheckSum

◆ computedCheckSum()

ossim_uint32 ossimDtedRecord::computedCheckSum ( ) const

Definition at line 231 of file ossimDtedRecord.cpp.

References theComputedCheckSum.

232 {
233  return theComputedCheckSum;
234 }
ossim_uint32 theComputedCheckSum

◆ dataBlockCount()

ossim_int32 ossimDtedRecord::dataBlockCount ( ) const

Definition at line 211 of file ossimDtedRecord.cpp.

References theDataBlockCount.

212 {
213  return theDataBlockCount;
214 }
ossim_int32 theDataBlockCount

◆ getPoint()

ossim_int32 ossimDtedRecord::getPoint ( ossim_int32  i) const

Definition at line 241 of file ossimDtedRecord.cpp.

References thePoints.

242 {
243  return thePoints[i];
244 }
ossim_int32 * thePoints

◆ getPointData()

ossim_uint16 ossimDtedRecord::getPointData ( ossim_int32  i) const

Definition at line 246 of file ossimDtedRecord.cpp.

References thePointsData.

247 {
248  return thePointsData[i];
249 }
ossim_uint16 * thePointsData

◆ latCount()

ossim_int32 ossimDtedRecord::latCount ( ) const

Definition at line 221 of file ossimDtedRecord.cpp.

References theLatCount.

222 {
223  return theLatCount;
224 }
ossim_int32 theLatCount

◆ lonCount()

ossim_int32 ossimDtedRecord::lonCount ( ) const

Definition at line 216 of file ossimDtedRecord.cpp.

References theLonCount.

217 {
218  return theLonCount;
219 }
ossim_int32 theLonCount

◆ numPoints()

ossim_int32 ossimDtedRecord::numPoints ( ) const

Definition at line 236 of file ossimDtedRecord.cpp.

References theNumPoints.

237 {
238  return theNumPoints;
239 }
ossim_int32 theNumPoints

◆ parse()

void ossimDtedRecord::parse ( std::istream &  in)

Definition at line 129 of file ossimDtedRecord.cpp.

References ossim::byteOrder(), OSSIM_LITTLE_ENDIAN, theStartOffset, and true.

130 {
131  // DTED is stored in big endian byte order so swap the bytes if needed.
132  bool swap_bytes = ossim::byteOrder() == OSSIM_LITTLE_ENDIAN ? true : false;
133 
134  ossim_sint16 s;
135 
136  // parse data block count
137  in.seekg(theStartOffset + BLOCK_COUNT_OFFSET, std::ios::beg);
138  in.read((char*)&s, 2);
140  (swap_bytes ? ( ( (s & 0x00ff) << 8) | ( (s & 0xff00) >> 8) ) : s);
141 
142  // parse lon count
143  in.seekg(theStartOffset + LON_INDEX_OFFSET, std::ios::beg);
144  in.read((char*)&s, 2);
145  theLonCount =
146  (swap_bytes ? ( ( (s & 0x00ff) << 8) | ( (s & 0xff00) >> 8) ) : s);
147 
148  // parse lat count
149  in.seekg(theStartOffset + LAT_INDEX_OFFSET, std::ios::beg);
150  in.read((char*)&s, 2);
151  theLatCount =
152  (swap_bytes ? ( ( (s & 0x00ff) << 8) | ( (s & 0xff00) >> 8) ) : s);
153 
154  // Parse all elevation points.
155  in.seekg(theStartOffset + ELEV_DATA_OFFSET, std::ios::beg);
156  for(int i = 0; i < theNumPoints; ++i)
157  {
158  in.read((char*)&s, 2);
159  s = (swap_bytes ? ( ( (s & 0x00ff) << 8) | ( (s & 0xff00) >> 8) ) : s);
160  if (s & DATA_SIGN_MASK)
161  {
162  s = (s & DATA_VALUE_MASK) * -1;
163  }
164  thePoints[i] = static_cast<ossim_int32>(s);
165  thePointsData[i] = s;
166  }
167 }
ossim_int32 theNumPoints
ossim_int32 theStartOffset
ossim_int32 theLonCount
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
signed short ossim_sint16
ossim_int32 theDataBlockCount
ossim_int32 theLatCount
ossim_int32 * thePoints
ossim_uint16 * thePointsData
int ossim_int32

◆ points()

ossim_int32 * ossimDtedRecord::points ( ) const

Definition at line 251 of file ossimDtedRecord.cpp.

References thePoints.

252 {
253  return thePoints;
254 }
ossim_int32 * thePoints

◆ pointsData()

ossim_uint16 * ossimDtedRecord::pointsData ( ) const

Definition at line 256 of file ossimDtedRecord.cpp.

References thePointsData.

257 {
258  return thePointsData;
259 }
ossim_uint16 * thePointsData

◆ recognitionSentinel()

ossimString ossimDtedRecord::recognitionSentinel ( ) const

Definition at line 206 of file ossimDtedRecord.cpp.

References theRecSen.

207 {
208  return theRecSen;
209 }
ossimString theRecSen

◆ startOffset()

ossim_int32 ossimDtedRecord::startOffset ( ) const

Definition at line 261 of file ossimDtedRecord.cpp.

References theStartOffset.

262 {
263  return theStartOffset;
264 }
ossim_int32 theStartOffset

◆ stopOffset()

ossim_int32 ossimDtedRecord::stopOffset ( ) const

Definition at line 266 of file ossimDtedRecord.cpp.

References theStopOffset.

267 {
268  return theStopOffset;
269 }
ossim_int32 theStopOffset

◆ validateCheckSum()

bool ossimDtedRecord::validateCheckSum ( std::istream &  in)
private

Compute the check sum for the Data Record and compare against the parsed check sum from the data record. This must be correct to be a valid data record. If not, there is a chance of a corrupted elevation cell.

Returns
true if check sum validates, false if not.

Definition at line 172 of file ossimDtedRecord.cpp.

References ossim::byteOrder(), OSSIM_LITTLE_ENDIAN, theComputedCheckSum, theNumPoints, theStartOffset, and true.

173 {
174  // DTED is stored in big endian byte order so swap the bytes if needed.
175  bool swap_bytes = ossim::byteOrder() == OSSIM_LITTLE_ENDIAN ? true : false;
176 
177  // Compute the check sum.
178  in.seekg(theStartOffset, std::ios::beg);
180  ossim_int32 bytesToRead = (theNumPoints * 2) + ELEV_DATA_OFFSET;
181  int i = 0;
182 
183  for(i = 0; i < bytesToRead; i++)
184  {
185  ossim_uint8 c;
186  in.read((char*)&c, 1);
187  theComputedCheckSum += static_cast<ossim_uint32>(c);
188  }
189 
190  // Read the stored check sum and swap the byte if needed.
191  in.read((char*)&theCheckSum, 4);
192  if (swap_bytes)
193  {
194  ossimEndian swapper;
195  swapper.swap(theCheckSum);
196  }
197 
198  // Compare computed and parsed checksums.
200  {
201  return false;
202  }
203  return true;
204 }
ossim_int32 theNumPoints
ossim_int32 theStartOffset
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
unsigned int ossim_uint32
ossim_uint32 theComputedCheckSum
ossim_uint32 theCheckSum
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
unsigned char ossim_uint8
int ossim_int32

Friends And Related Function Documentation

◆ operator<<

OSSIM_DLL std::ostream& operator<< ( std::ostream &  os,
const ossimDtedRecord rec 
)
friend

Definition at line 274 of file ossimDtedRecord.cpp.

275 {
276  os << "\nDTED Record:"
277  << "\n-------------------------------"
278  << "\n Recognition Sentinel: " << rec.theRecSen
279  << "\nData Block Count: " << rec.theDataBlockCount
280  << "\nLon Count: " << rec.theLonCount
281  << "\nLat Count: " << rec.theLatCount
282  << "\nNum Points: " << rec.theNumPoints
283  << "\nParsed Check Sum: " << rec.theCheckSum
284  << "\nComputed Check Sum " << rec.theComputedCheckSum
285  << "\nStart Offset: " << rec.theStartOffset
286  << "\nStop Offset: " << rec.theStopOffset
287  << std::endl;
288  int i = 0;
289 
290  for(i = 0; i < rec.theNumPoints; i++)
291  {
292  os << "\nPoint[" << i << "]: " << rec.thePoints[i];
293  }
294 
295  os << std::endl;
296 
297  return os;
298 }
ossim_int32 theNumPoints
ossim_int32 theStartOffset
ossim_int32 theLonCount
ossimString theRecSen
ossim_int32 theStopOffset
ossim_int32 theDataBlockCount
ossim_int32 theLatCount
ossim_uint32 theComputedCheckSum
ossim_int32 * thePoints
ossim_uint32 theCheckSum

Member Data Documentation

◆ theCheckSum

ossim_uint32 ossimDtedRecord::theCheckSum
private

Algebraic addition of contents of block. The checksum is computed algebraically using integer arithmetic by summing all header and elevation bytes contained int the record as 8-bit values. Each byte is considered an unsigned, 8-bit value for checksum calculation.

Definition at line 125 of file ossimDtedRecord.h.

Referenced by checkSum(), and operator<<().

◆ theComputedCheckSum

ossim_uint32 ossimDtedRecord::theComputedCheckSum
private

Our computed check sum. This should match the checksum at the end of the Data Record.

Definition at line 143 of file ossimDtedRecord.h.

Referenced by computedCheckSum(), operator<<(), and validateCheckSum().

◆ theDataBlockCount

ossim_int32 ossimDtedRecord::theDataBlockCount
private

Sequential count of the block within the file.

Definition at line 102 of file ossimDtedRecord.h.

Referenced by dataBlockCount(), and operator<<().

◆ theFile

ossim_int32 ossimDtedRecord::theFile
private

Definition at line 92 of file ossimDtedRecord.h.

◆ theLatCount

ossim_int32 ossimDtedRecord::theLatCount
private

Count of the parallel. True latitude = latitude count x data interval + origin (Offset from the SW corner latitude)

Definition at line 116 of file ossimDtedRecord.h.

Referenced by latCount(), and operator<<().

◆ theLonCount

ossim_int32 ossimDtedRecord::theLonCount
private

Count of the meridian. True longitude = longitude count x data interval + origin (Offset from the SW corner longitude)

Definition at line 109 of file ossimDtedRecord.h.

Referenced by lonCount(), and operator<<().

◆ theNumPoints

ossim_int32 ossimDtedRecord::theNumPoints
private

The number of points in a longitudinal line.

Definition at line 148 of file ossimDtedRecord.h.

Referenced by numPoints(), operator<<(), and validateCheckSum().

◆ thePoints

ossim_int32* ossimDtedRecord::thePoints
private

All the elevation points in a Data Record as ints. (ie. all the latitudal points in a longitudinal line)

Definition at line 131 of file ossimDtedRecord.h.

Referenced by getPoint(), operator<<(), points(), and ~ossimDtedRecord().

◆ thePointsData

ossim_uint16* ossimDtedRecord::thePointsData
private

All the elevation points in a Data Record as unsigned shorts. (ie. all the latitudal points in a longitudinal line)

Definition at line 137 of file ossimDtedRecord.h.

Referenced by getPointData(), pointsData(), and ~ossimDtedRecord().

◆ theRecSen

ossimString ossimDtedRecord::theRecSen
private

252 (8 bit)

Definition at line 97 of file ossimDtedRecord.h.

Referenced by operator<<(), and recognitionSentinel().

◆ theStartOffset

ossim_int32 ossimDtedRecord::theStartOffset
private

Definition at line 150 of file ossimDtedRecord.h.

Referenced by operator<<(), parse(), startOffset(), and validateCheckSum().

◆ theStopOffset

ossim_int32 ossimDtedRecord::theStopOffset
private

Definition at line 151 of file ossimDtedRecord.h.

Referenced by operator<<(), and stopOffset().


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