[SGDemSession] fix uninitialized members.

This commit is contained in:
Scott Giese
2019-05-04 15:26:25 -05:00
parent dd38e399ca
commit ae6ad20940
2 changed files with 108 additions and 76 deletions

View File

@@ -1,79 +1,86 @@
#include <simgear/scene/dem/SGDem.hxx>
#include <simgear/scene/dem/SGDemSession.hxx>
SGDemSession::SGDemSession( int mnLon, int mnLat, int mxLon, int mxLat, int idx, int lvlW, int lvlH, SGDemRoot* root )
SGDemSession::SGDemSession(int mnLon, int mnLat, int mxLon, int mxLat, int idx, int lvlW, int lvlH, SGDemRoot* root)
{
setOffsets( SGDem::longitudeDegToOffset((double)mnLon),
SGDem::latitudeDegToOffset((double)mnLat),
SGDem::longitudeDegToOffset((double)mxLon),
SGDem::latitudeDegToOffset((double)mxLat) );
setOffsets(SGDem::longitudeDegToOffset((double)mnLon),
SGDem::latitudeDegToOffset((double)mnLat),
SGDem::longitudeDegToOffset((double)mxLon),
SGDem::latitudeDegToOffset((double)mxLat));
pDemRoot = root;
lvlIndex = idx;
lvlWidth = lvlW;
pDemRoot = root;
lvlIndex = idx;
lvlWidth = lvlW;
lvlHeight = lvlH;
}
SGDemSession::SGDemSession( int mnLon, int mnLat, int mxLon, int mxLat, SGDemRoot* root ) {
setOffsets( SGDem::longitudeDegToOffset((double)mnLon),
SGDem::latitudeDegToOffset((double)mnLat),
SGDem::longitudeDegToOffset((double)mxLon),
SGDem::latitudeDegToOffset((double)mxLat) );
SGDemSession::SGDemSession(int mnLon, int mnLat, int mxLon, int mxLat, SGDemRoot* root)
{
setOffsets(SGDem::longitudeDegToOffset((double)mnLon),
SGDem::latitudeDegToOffset((double)mnLat),
SGDem::longitudeDegToOffset((double)mxLon),
SGDem::latitudeDegToOffset((double)mxLat));
pDemRoot = root;
lvlIndex = -1; // no level - session is raw input dir
pDemRoot = root;
lvlIndex = -1; // no level - session is raw input dir
}
void SGDemSession::close( void )
void SGDemSession::close(void)
{
if ( tileRefs.size() ) {
if (tileRefs.size()) {
tileRefs.clear();
if ( lvlIndex >= 0 ) {
pDemRoot->flushCaches( lvlIndex );
if (lvlIndex >= 0) {
pDemRoot->flushCaches(lvlIndex);
}
}
}
void SGDemSession::getGeods( unsigned wo, unsigned so, unsigned eo, unsigned no, int resx, int resy, int incx, int incy, ::std::vector<SGGeod>& geods, bool Debug1, bool Debug2 )
void SGDemSession::getGeods(unsigned wo, unsigned so, unsigned eo, unsigned no, int resx, int resy, int incx, int incy, ::std::vector<SGGeod>& geods, bool Debug1, bool Debug2)
{
// todo - store this info in deminfo
unsigned span; // smallest tile width/height in level ( in offsets )
switch( lvlIndex ) {
case 0: span = 1; break; // 1/8 deg
case 1: span = 16; break; // 2 degrees
case 2: span = 480; break; // 60 degrees
default:
fprintf( stderr, "invalid lvlIndex %d\n", lvlIndex );
exit(0);
switch (lvlIndex) {
case 0:
span = 1;
break; // 1/8 deg
case 1:
span = 16;
break; // 2 degrees
case 2:
span = 480;
break; // 60 degrees
default:
fprintf(stderr, "invalid lvlIndex %d\n", lvlIndex);
exit(0);
}
if ( lvlIndex >= 0 ) {
if (lvlIndex >= 0) {
unsigned tileLon, tileLat;
unsigned meshLon, meshLat;
int subx, suby;
int subx, suby;
meshLon = wo;
tileLon = SGDem::roundDown( meshLon, lvlWidth);
tileLon = SGDem::roundDown(meshLon, lvlWidth);
subx = (meshLon - tileLon) / span;
// fprintf(stderr, "getGeods: lon is %lf : meshLon is %u, tileLon is %u, subx is %d\n", SGDem::offsetToLongitudeDeg(wo), meshLon, tileLon, subx );
meshLat = so;
tileLat = SGDem::roundDown( meshLat, lvlHeight );
tileLat = SGDem::roundDown(meshLat, lvlHeight);
suby = (meshLat - tileLat) / span;
// fprintf(stderr, "getGeods: lat is %lf : meshLat is %u, tileLat is %u, suby is %d\n", SGDem::offsetToLatitudeDeg(so), meshLat, tileLat, suby );
// get the tle from the tile cache
unsigned long key = tileLon << 16 | tileLat;
SGDemTileRef tile = pDemRoot->getTile( lvlIndex, key );
if ( tile ) {
SGDemTileRef tile = pDemRoot->getTile(lvlIndex, key);
if (tile) {
tile->getGeods(wo, so, eo, no, resx, resy, subx, suby, incx, incy, geods, Debug1, Debug2);
} else {
fprintf(stderr, " *** ERROR: tile %d,%d not in session @ (%lf,%lf) - (%lf,%lf)\n",
fprintf(stderr, " *** ERROR: tile %u,%u not in session @ (%lf,%lf) - (%lf,%lf)\n",
tileLon, tileLat,
SGDem::offsetToLongitudeDeg( west_off ),
SGDem::offsetToLatitudeDeg( south_off ),
SGDem::offsetToLongitudeDeg( east_off ),
SGDem::offsetToLatitudeDeg( north_off ) );
SGDem::offsetToLongitudeDeg(west_off),
SGDem::offsetToLatitudeDeg(south_off),
SGDem::offsetToLongitudeDeg(east_off),
SGDem::offsetToLatitudeDeg(north_off));
}
}
}

View File

@@ -3,58 +3,83 @@
#include <simgear/scene/dem/SGDemRoot.hxx>
class SGDemSession
{
class SGDemSession {
public:
SGDemSession() {
lvlIndex = -1;
SGDemSession()
: west_off(0)
, south_off(0)
, east_off(0)
, north_off(0)
, maxLon(0)
, maxLat(0)
, pDemRoot(NULL)
, lvlIndex(-1)
, lvlWidth(0)
, lvlHeight(0)
{
}
SGDemSession( int mnLon, int mnLat, int mxLon, int mxLat, int idx, int lvlW, int lvlH, SGDemRoot* root );
SGDemSession( int mnLon, int mnLat, int mxLon, int mxLat, SGDemRoot* root );
SGDemSession(int mnLon, int mnLat, int mxLon, int mxLat, int idx, int lvlW, int lvlH, SGDemRoot* root);
SGDemSession(int mnLon, int mnLat, int mxLon, int mxLat, SGDemRoot* root);
SGDemSession( unsigned wo, unsigned so, unsigned eo, unsigned no, int idx, unsigned lvlW, unsigned lvlH, SGDemRoot* root ) {
setOffsets( wo, so, eo, no );
pDemRoot = root;
lvlIndex = idx;
lvlWidth = lvlW;
lvlHeight = lvlH;
SGDemSession(unsigned wo, unsigned so, unsigned eo, unsigned no, int idx, unsigned lvlW, unsigned lvlH, SGDemRoot* root)
: west_off(wo)
, south_off(so)
, east_off(eo)
, north_off(no)
, maxLon(0)
, maxLat(0)
, pDemRoot(root)
, lvlIndex(idx)
, lvlWidth(lvlW)
, lvlHeight(lvlH)
{
}
SGDemSession( unsigned wo, unsigned so, unsigned eo, unsigned no, SGDemRoot* root ) {
setOffsets( wo, so, eo, no );
pDemRoot = root;
lvlIndex = -1; // no level - session is raw input dir
SGDemSession(unsigned wo, unsigned so, unsigned eo, unsigned no, SGDemRoot* root)
: west_off(wo)
, south_off(so)
, east_off(eo)
, north_off(no)
, maxLon(0)
, maxLat(0)
, pDemRoot(root)
, lvlIndex(-1) // no level - session is raw input dir
, lvlWidth(0)
, lvlHeight(0)
{
}
~SGDemSession() {
~SGDemSession()
{
close();
}
void addTile(SGDemTileRef pTile) {
tileRefs.push_back( pTile );
void addTile(SGDemTileRef pTile)
{
tileRefs.push_back(pTile);
}
const std::vector<SGDemTileRef>& getTiles( void ) const {
const std::vector<SGDemTileRef>& getTiles(void) const
{
return tileRefs;
}
unsigned int size( void ) const {
unsigned int size(void) const
{
return tileRefs.size();
}
void getGeods( unsigned wp, unsigned so, unsigned eo, unsigned no,
int resx, int resy, int incx, int incy,
::std::vector<SGGeod>& geods,
bool Debug1, bool Debug2
);
void getGeods(unsigned wp, unsigned so, unsigned eo, unsigned no,
int resx, int resy, int incx, int incy,
::std::vector<SGGeod>& geods,
bool Debug1, bool Debug2);
void close( void );
void close(void);
int getLvlIndex( void ) const {
return lvlIndex;
int getLvlIndex(void) const
{
return lvlIndex;
};
private:
@@ -64,13 +89,13 @@ private:
east_off = eo;
north_off = no;
}
unsigned west_off, south_off;
unsigned east_off, north_off;
int maxLon, maxLat;
SGDemRoot* pDemRoot;
int lvlIndex;
unsigned lvlWidth, lvlHeight;
unsigned west_off, south_off;
unsigned east_off, north_off;
int maxLon, maxLat;
SGDemRoot* pDemRoot;
int lvlIndex;
unsigned lvlWidth, lvlHeight;
std::vector<SGDemTileRef> tileRefs;
};