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

Generic geoid source which uses a image handler for reading the grid. More...

#include <ossimGeoidImage.h>

Inheritance diagram for ossimGeoidImage:
ossimGeoid ossimObject ossimErrorStatusInterface ossimReferenced

Public Member Functions

 ossimGeoidImage ()
 default constructor More...
 
virtual ~ossimGeoidImage ()
 destructor More...
 
virtual bool open (const ossimFilename &file, ossimByteOrder byteOrder=OSSIM_BIG_ENDIAN)
 open method More...
 
virtual ossimString getShortName () const
 
void setShortName (const std::string &geoidTypeName)
 Sets the geoid type name string. More...
 
bool getMemoryMapFlag () const
 Gets the memory map flag. More...
 
void setMemoryMapFlag (bool flag)
 Set the memory map flag. More...
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 Method to save the state of the object to a keyword list. More...
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 Method to the load (recreate) the state of the object from a keyword list. More...
 
virtual double offsetFromEllipsoid (const ossimGpt &gpt)
 
bool getEnableFlag () const
 
void setEnableFlag (bool flag)
 
- Public Member Functions inherited from ossimGeoid
 ossimGeoid ()
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () 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 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 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...
 

Protected Member Functions

template<class T >
double offsetFromEllipsoidTemplate (T dummy, const ossimGpt &gpt)
 
- Protected Member Functions inherited from ossimGeoid
virtual ~ossimGeoid ()
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

ossimRefPtr< ossimImageGeometrym_geom
 
ossimRefPtr< ossimImageHandlerm_handler
 
ossimRefPtr< ossimImageDatam_cacheTile
 
std::string m_connectionString
 
ossimString m_geoidTypeName
 
bool m_memoryMapFlag
 
bool m_enabledFlag
 
ossimIrect m_imageRect
 
ossimScalarType m_scalarType
 
- Protected Attributes inherited from ossimErrorStatusInterface
ossimErrorCode theErrorStatus
 

Detailed Description

Generic geoid source which uses a image handler for reading the grid.

The settable keyword "geoid.type", e.g. "egm2008" is used to attach a given geoid to an elevation source.

The keyword "type" is fixed for this object as "geoid_image".

Definition at line 35 of file ossimGeoidImage.h.

Constructor & Destructor Documentation

◆ ossimGeoidImage()

ossimGeoidImage::ossimGeoidImage ( )

default constructor

Definition at line 28 of file ossimGeoidImage.cpp.

29  : m_geom(0),
30  m_handler(0),
31  m_cacheTile(0),
33  m_memoryMapFlag(false),
34  m_enabledFlag(true),
35  m_imageRect()
36 {
37 }
ossimString m_geoidTypeName
ossimRefPtr< ossimImageData > m_cacheTile
ossimRefPtr< ossimImageGeometry > m_geom
ossimIrect m_imageRect
ossimRefPtr< ossimImageHandler > m_handler

◆ ~ossimGeoidImage()

ossimGeoidImage::~ossimGeoidImage ( )
virtual

destructor

Definition at line 39 of file ossimGeoidImage.cpp.

References m_cacheTile, m_geom, and m_handler.

40 {
41  m_geom = 0;
42  m_handler = 0;
43  m_cacheTile = 0;
44 }
ossimRefPtr< ossimImageData > m_cacheTile
ossimRefPtr< ossimImageGeometry > m_geom
ossimRefPtr< ossimImageHandler > m_handler

Member Function Documentation

◆ getEnableFlag()

bool ossimGeoidImage::getEnableFlag ( ) const

◆ getMemoryMapFlag()

bool ossimGeoidImage::getMemoryMapFlag ( ) const

Gets the memory map flag.

Returns
true if geoid image is memory mapped; else, false.

Definition at line 137 of file ossimGeoidImage.cpp.

References m_memoryMapFlag.

138 {
139  return m_memoryMapFlag;
140 }

◆ getShortName()

ossimString ossimGeoidImage::getShortName ( ) const
virtual
Returns
The short name which represents the "geoid.type" keyword which is used by ossimGeoidFactory.

Reimplemented from ossimObject.

Definition at line 127 of file ossimGeoidImage.cpp.

References m_geoidTypeName.

128 {
129  return m_geoidTypeName;
130 }
ossimString m_geoidTypeName

◆ loadState()

bool ossimGeoidImage::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Method to the load (recreate) the state of the object from a keyword list.

Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 178 of file ossimGeoidImage.cpp.

References ossimKeywordNames::ENABLED_KW, ossimKeywordlist::findKey(), m_connectionString, m_enabledFlag, m_geoidTypeName, m_memoryMapFlag, open(), ossimString::toBool(), and ossimKeywordNames::TYPE_KW.

180 {
181  bool result = false;
182 
183  std::string myPrefix = prefix ? prefix : "";
184 
185  // Check the type name:
186  std::string key = ossimKeywordNames::TYPE_KW;
187  std::string value = kwl.findKey( myPrefix, key );
188 
189  if ( (value == "geoid_image" ) || ( value == "ossimGeoidImage" ) )
190  {
191  // Get the geoid type name:
192  key = "geoid.type";
193  m_geoidTypeName = kwl.findKey( myPrefix, key );
194 
195  // Get the memory map flag:
196  key = "memory_map";
197  value = kwl.findKey( myPrefix, key );
198  m_memoryMapFlag = ossimString( value ).toBool();
199 
200  // Get the enabled flag:
202  value = kwl.findKey( myPrefix, key );
203  m_enabledFlag = ossimString( value ).toBool();
204 
205  // Get the connection string:
206  std::string key = "connection_string";
207  m_connectionString = kwl.findKey( myPrefix, key );
208  if ( m_connectionString.size() )
209  {
210  result = open( ossimFilename( m_connectionString ) );
211  }
212  }
213 
214  return result;
215 }
ossimString m_geoidTypeName
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
std::string m_connectionString
virtual bool open(const ossimFilename &file, ossimByteOrder byteOrder=OSSIM_BIG_ENDIAN)
open method
static const char * TYPE_KW
bool toBool() const
String to numeric methods.
static const char * ENABLED_KW

◆ offsetFromEllipsoid()

double ossimGeoidImage::offsetFromEllipsoid ( const ossimGpt gpt)
virtual
Returns
The offset from the ellipsoid to the geoid or ossim::nan() (IEEE NAN) if grid does not contain the point.

Implements ossimGeoid.

Definition at line 218 of file ossimGeoidImage.cpp.

References ossimLookUpTable::getEntryString(), ossimScalarTypeLut::instance(), m_cacheTile, m_enabledFlag, m_geom, m_handler, m_memoryMapFlag, m_scalarType, ossim::nan(), offsetFromEllipsoidTemplate(), OSSIM_FLOAT32, OSSIM_FLOAT64, OSSIM_SINT16, ossimNotify(), ossimNotifyLevel_WARN, and ossimRefPtr< T >::valid().

219 {
220  double offset = ossim::nan();
221 
222  if ( m_enabledFlag )
223  {
224  if ( m_geom.valid() &&
225  ( m_handler.valid() ||
227  )
228  )
229  {
230  switch(m_scalarType)
231  {
232  case OSSIM_SINT16:
233  {
234  offset = offsetFromEllipsoidTemplate((ossim_sint16)0, gpt);
235  break;
236  }
237  case OSSIM_FLOAT32:
238  {
239  offset = offsetFromEllipsoidTemplate((ossim_float32)0, gpt);
240  break;
241  }
242  case OSSIM_FLOAT64:
243  {
244  offset = offsetFromEllipsoidTemplate((ossim_float64)0, gpt);
245  break;
246  }
247  default:
248  {
250  << "ossimGeoidImage::offsetFromEllipsoid ERROR:\n"
251  << "Unhandled scalar type: "
253  << std::endl;
254  break;
255  }
256  }
257  }
258  else
259  {
261  << "ossimGeoidImage::offsetFromEllipsoid ERROR: Object not initialized!\n"
262  << std::endl;
263  }
264 
265  } // Matches: if ( m_enabledFlag )
266 
267  return offset;
268 }
ossimScalarType m_scalarType
64 bit floating point
ossimRefPtr< ossimImageData > m_cacheTile
bool valid() const
Definition: ossimRefPtr.h:75
float ossim_float32
virtual ossimString getEntryString(ossim_int32 entry_number) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
16 bit signed integer
32 bit floating point
ossimRefPtr< ossimImageGeometry > m_geom
double ossim_float64
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
signed short ossim_sint16
ossimRefPtr< ossimImageHandler > m_handler
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
double offsetFromEllipsoidTemplate(T dummy, const ossimGpt &gpt)

◆ offsetFromEllipsoidTemplate()

template<class T >
double ossimGeoidImage::offsetFromEllipsoidTemplate ( dummy,
const ossimGpt gpt 
)
protected

Definition at line 271 of file ossimGeoidImage.cpp.

References ossimGpt::changeDatum(), ossimImageData::getBuf(), ossimImageData::getNullPix(), ossimImageData::getOrigin(), ossimImageSource::getTile(), ossimImageData::getWidth(), ossimIrect::height(), ossimDatumFactory::instance(), m_cacheTile, m_geom, m_handler, m_imageRect, m_memoryMapFlag, ossim::nan(), ossimIrect::pointWithin(), ossimRefPtr< T >::valid(), ossimIrect::width(), ossimImageGeometry::worldToLocal(), ossimGpt::wrap(), ossimIpt::x, ossimDpt::x, ossimIpt::y, and ossimDpt::y.

Referenced by offsetFromEllipsoid().

273 {
274  double geoidOffset = ossim::nan();
275 
276  // Change the datum if needed:
277  ossimGpt copyGpt = gpt;
278  if(ossimDatumFactory::instance()->wgs84())
279  {
280  copyGpt.changeDatum(ossimDatumFactory::instance()->wgs84());
281  }
282 
283  // Fix wrap conditions:
284  copyGpt.wrap();
285 
286  // Get the local image point for the input ground point.
287  ossimDpt imgDpt;
288  m_geom->worldToLocal( copyGpt, imgDpt );
289 
290  if ( m_imageRect.pointWithin( ossimIpt( imgDpt ) ) )
291  {
292  ossim_int32 x0 = static_cast<ossim_int32>( imgDpt.x );
293  ossim_int32 y0 = static_cast<ossim_int32>( imgDpt.y );
294 
295  ossim_int32 IW = static_cast<ossim_int32>(m_imageRect.width());
296  ossim_int32 IH = static_cast<ossim_int32>(m_imageRect.height());
297 
298  if ( x0 == (IW-1) )
299  {
300  --x0; // Move over one point.
301  }
302  if ( y0 == (IH-1) )
303  {
304  --y0; // Move over one point.
305  }
306 
307  if ( !m_memoryMapFlag )
308  {
309  // Get the four points from the image handler.
310  ossimIrect tileRect(ossimIpt(x0, y0), ossimIpt(x0+1, y0+1));
311  m_cacheTile = m_handler->getTile( tileRect, 0 );
312  }
313 
314  if ( m_cacheTile.valid() )
315  {
316  // Get a pointer to the buffer.
317  const T* buf = static_cast<const T*>(m_cacheTile->getBuf());
318 
319  if ( buf )
320  {
321  const ossim_float64 NP = m_cacheTile->getNullPix(0);
322  const ossim_int64 TW = static_cast<ossim_int64>(m_cacheTile->getWidth());
323  ossim_int64 offset = (y0 - m_cacheTile->getOrigin().y) * TW +
324  (x0 - m_cacheTile->getOrigin().x);
325  ossim_int64 offset2 = offset + TW;
326 
327  double p00 = buf[offset];
328  double p01 = buf[offset+1];
329  double p10 = buf[offset2];
330  double p11 = buf[offset2+1];
331 
332  double xt0 = imgDpt.x - x0;
333  double yt0 = imgDpt.y - y0;
334  double xt1 = 1-xt0;
335  double yt1 = 1-yt0;
336 
337  double w00 = xt1*yt1;
338  double w01 = xt0*yt1;
339  double w10 = xt1*yt0;
340  double w11 = xt0*yt0;
341 
342  //---
343  // Test for null posts and set the corresponding weights to 0:
344  //---
345  if (p00 == NP) w00 = 0.0;
346  if (p01 == NP) w01 = 0.0;
347  if (p10 == NP) w10 = 0.0;
348  if (p11 == NP) w11 = 0.0;
349 
350  double sum_weights = w00 + w01 + w10 + w11;
351  if (sum_weights)
352  {
353  geoidOffset = (p00*w00 + p01*w01 + p10*w10 + p11*w11) / sum_weights;
354  }
355  }
356 
357  } // Matches: if ( m_cacheTile.valid() )
358 
359  } // Matches: if ( m_imageRect.pointWithin( imgPt ) )
360 
361  return geoidOffset;
362 }
virtual ossim_uint32 getWidth() const
ossimRefPtr< ossimImageData > m_cacheTile
bool valid() const
Definition: ossimRefPtr.h:75
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
double y
Definition: ossimDpt.h:165
ossim_uint32 height() const
Definition: ossimIrect.h:487
void wrap()
Wrap method to maintain longitude between -180 and +180 and latitude between -90 and +90...
Definition: ossimGpt.h:305
ossimRefPtr< ossimImageGeometry > m_geom
void changeDatum(const ossimDatum *datum)
This will actually perform a shift.
Definition: ossimGpt.cpp:316
double ossim_float64
ossimIrect m_imageRect
ossimRefPtr< ossimImageHandler > m_handler
virtual const ossim_float64 * getNullPix() const
static ossimDatumFactory * instance()
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossim_int32 y
Definition: ossimIpt.h:142
virtual const void * getBuf() const
double x
Definition: ossimDpt.h:164
long long ossim_int64
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
virtual const ossimIpt & getOrigin() const
int ossim_int32
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
bool pointWithin(const ossimIpt &pt) const
Definition: ossimIrect.h:729

◆ open()

bool ossimGeoidImage::open ( const ossimFilename file,
ossimByteOrder  byteOrder = OSSIM_BIG_ENDIAN 
)
virtual

open method

Parameters
fileThis can be any image that ossim can open and get geometry info for.
byteOrderNot used by this object.
Returns
true on success, false on erro.

Implements ossimGeoid.

Definition at line 46 of file ossimGeoidImage.cpp.

References ossimImageHandler::close(), ossimImageHandler::getImageGeometry(), ossimImageHandler::getImageRectangle(), ossimImageSource::getOutputScalarType(), ossimImageGeometry::getProjection(), ossimImageSource::getTile(), ossimImageHandlerRegistry::instance(), m_cacheTile, m_geom, m_handler, m_imageRect, m_memoryMapFlag, m_scalarType, ossimImageHandlerRegistry::open(), ossimNotify(), ossimNotifyLevel_WARN, ossimRefPtr< T >::valid(), and ossimException::what().

Referenced by loadState().

47 {
48  static const char MODULE[] = "ossimGeoidImage::open";
49 
50  m_geom = 0;
51  m_cacheTile = 0;
52  if ( m_handler.valid() )
53  {
54  m_handler->close();
55  }
56 
57  m_handler =
59  true, // try suffix 1st
60  false); // open overview
61  if ( m_handler.valid() )
62  {
63  // Store the bounding rectangle:
65 
66  // Scalar type:
68 
69  // Get the geometry info. Need this to compute grid indexes.
71 
72  if ( m_geom.valid() )
73  {
74  // Verify the geometry object has a good projection.
75  if ( m_geom->getProjection() )
76  {
77  if ( m_memoryMapFlag )
78  {
79  try
80  {
82 
83  if ( m_cacheTile.valid() )
84  {
85  // Close the image handler:
86  m_handler->close();
87  m_handler = 0;
88  }
89  }
90  catch ( const ossimException& e )
91  {
92  m_memoryMapFlag = false;
93  m_cacheTile = 0;
94 
96  << MODULE << " ERROR: Caught Exception!"
97  << "\n" << e.what()
98  << "\nMemory mapping entire grid into memory has been disabled..."
99  << std::endl;
100  }
101  }
102  }
103  else
104  {
105  m_handler = 0;
106  m_geom = 0;
108  << MODULE << " ERROR:"
109  << "\nGeometry object has null projection!"
110  << std::endl;
111  }
112  }
113 
114  else
115  {
116  m_handler = 0;
118  << MODULE << " ERROR:"
119  << "\nCould not get geometry info!"
120  << std::endl;
121  }
122  }
123 
124  return ( m_geom.valid() && (m_handler.valid() || (m_memoryMapFlag && m_cacheTile.valid()) ));
125 }
ossimScalarType m_scalarType
ossimRefPtr< ossimImageData > m_cacheTile
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimImageGeometry > m_geom
ossimIrect m_imageRect
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
virtual const char * what() const
Returns the error message.
ossimRefPtr< ossimImageHandler > m_handler
virtual void close()
Deletes the overview and clears the valid image vertices.
virtual ossimIrect getImageRectangle(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
static ossimImageHandlerRegistry * instance()
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)

◆ saveState()

bool ossimGeoidImage::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const
virtual

Method to save the state of the object to a keyword list.

Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 147 of file ossimGeoidImage.cpp.

References ossimKeywordlist::addPair(), ossimKeywordNames::ENABLED_KW, m_connectionString, m_enabledFlag, m_geoidTypeName, m_memoryMapFlag, ossimString::string(), true, and ossimKeywordNames::TYPE_KW.

149 {
150  std::string myPrefix = ( prefix ? prefix : "" );
151 
152  // Save the connection string:
153  std::string key = "connection_string";
154  kwl.addPair( myPrefix, key, m_connectionString, true );
155 
156  // Save the geoid type name:
157  key = "geoid.type";
158  kwl.addPair( myPrefix, key, m_geoidTypeName.string(), true );
159 
160  // Save the memory map flag:
161  key = "memory_map";
162  std::string value = (m_memoryMapFlag ? "true" : "false");
163  kwl.addPair( myPrefix, key, value, true );
164 
165  // Save the enabledFlag:
167  value = m_enabledFlag ? "true" : "false";
168  kwl.addPair( myPrefix, key, value, true );
169 
170  // Save the type:
172  value = "geoid_image";
173  kwl.addPair( myPrefix, key, value, true );
174 
175  return true;
176 }
ossimString m_geoidTypeName
std::string m_connectionString
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
static const char * TYPE_KW
static const char * ENABLED_KW
const std::string & string() const
Definition: ossimString.h:414

◆ setEnableFlag()

void ossimGeoidImage::setEnableFlag ( bool  flag)

◆ setMemoryMapFlag()

void ossimGeoidImage::setMemoryMapFlag ( bool  flag)

Set the memory map flag.

Definition at line 142 of file ossimGeoidImage.cpp.

References m_memoryMapFlag.

143 {
144  m_memoryMapFlag = flag;
145 }

◆ setShortName()

void ossimGeoidImage::setShortName ( const std::string &  geoidTypeName)

Sets the geoid type name string.

Definition at line 132 of file ossimGeoidImage.cpp.

References m_geoidTypeName.

133 {
134  m_geoidTypeName = geoidTypeName;
135 }
ossimString m_geoidTypeName

Member Data Documentation

◆ m_cacheTile

ossimRefPtr<ossimImageData> ossimGeoidImage::m_cacheTile
protected

◆ m_connectionString

std::string ossimGeoidImage::m_connectionString
protected

Definition at line 108 of file ossimGeoidImage.h.

Referenced by loadState(), and saveState().

◆ m_enabledFlag

bool ossimGeoidImage::m_enabledFlag
protected

Definition at line 111 of file ossimGeoidImage.h.

Referenced by loadState(), offsetFromEllipsoid(), and saveState().

◆ m_geoidTypeName

ossimString ossimGeoidImage::m_geoidTypeName
protected

Definition at line 109 of file ossimGeoidImage.h.

Referenced by getShortName(), loadState(), saveState(), and setShortName().

◆ m_geom

ossimRefPtr<ossimImageGeometry> ossimGeoidImage::m_geom
protected

◆ m_handler

ossimRefPtr<ossimImageHandler> ossimGeoidImage::m_handler
protected

◆ m_imageRect

ossimIrect ossimGeoidImage::m_imageRect
protected

Definition at line 112 of file ossimGeoidImage.h.

Referenced by offsetFromEllipsoidTemplate(), and open().

◆ m_memoryMapFlag

bool ossimGeoidImage::m_memoryMapFlag
protected

◆ m_scalarType

ossimScalarType ossimGeoidImage::m_scalarType
protected

Definition at line 113 of file ossimGeoidImage.h.

Referenced by offsetFromEllipsoid(), and open().


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