From ae6ad2094080c3e5214b6f9b11a7563d52603cf5 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sat, 4 May 2019 15:26:25 -0500 Subject: [PATCH] [SGDemSession] fix uninitialized members. --- simgear/scene/dem/SGDemSession.cxx | 83 +++++++++++++----------- simgear/scene/dem/SGDemSession.hxx | 101 ++++++++++++++++++----------- 2 files changed, 108 insertions(+), 76 deletions(-) diff --git a/simgear/scene/dem/SGDemSession.cxx b/simgear/scene/dem/SGDemSession.cxx index fb95caec..391b8c6f 100644 --- a/simgear/scene/dem/SGDemSession.cxx +++ b/simgear/scene/dem/SGDemSession.cxx @@ -1,79 +1,86 @@ #include #include -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& 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& 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)); } } } diff --git a/simgear/scene/dem/SGDemSession.hxx b/simgear/scene/dem/SGDemSession.hxx index f0813556..3d5cddc6 100644 --- a/simgear/scene/dem/SGDemSession.hxx +++ b/simgear/scene/dem/SGDemSession.hxx @@ -3,58 +3,83 @@ #include -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& getTiles( void ) const { + const std::vector& 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& 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& 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 tileRefs; };