1
0
Fork 0

[Lib, Prep, Utils] Reduce technical debt.

This commit is contained in:
Scott Giese 2019-01-28 00:11:44 -06:00
parent fb50bb4681
commit 4fa0606498
7 changed files with 41 additions and 38 deletions

View file

@ -38,19 +38,20 @@
using std::string;
TGArray::TGArray( void ):
TGArray::TGArray() :
array_in(NULL),
fitted_in(NULL),
originx(0.0), originy(0.0),
cols(0), rows(0),
rectified(false),
col_step(0.0), row_step(0.0),
in_data(NULL)
{
}
TGArray::TGArray( const string &file ):
array_in(NULL),
fitted_in(NULL),
in_data(NULL)
TGArray::TGArray( const string &file ) :
TGArray()
{
TGArray::open(file);
}
@ -248,7 +249,7 @@ void TGArray::parse_bin()
// Write out an array. If rectified is true, the heights have been adjusted
// for discontinuities.
void TGArray::write_bin(const string root_dir, bool rectified, SGBucket& b) {
void TGArray::write_bin(const string& root_dir, bool rectified, SGBucket& b) {
// generate output file name
string base = b.gen_base_path();
string path = root_dir + "/" + base;
@ -282,7 +283,7 @@ void TGArray::write_bin(const string root_dir, bool rectified, SGBucket& b) {
}
// write an Array file
bool TGArray::write( const string root_dir, SGBucket& b ) {
bool TGArray::write( const string& root_dir, SGBucket& b ) {
// generate output file name
string base = b.gen_base_path();
string path = root_dir + "/" + base;
@ -444,7 +445,7 @@ std::vector<int> TGArray::collect_bad_points(const double bad_zone) {
}
// Check to see if the specified grid point is bad
bool TGArray::is_bad_point(const int xgrid, const int ygrid, const std::vector<int> bad_points) const {
bool TGArray::is_bad_point(const int xgrid, const int ygrid, const std::vector<int>& bad_points) const {
int grididx;
grididx = xgrid+ygrid*cols;
auto result = std::find( std::begin(bad_points),std::end(bad_points),grididx );
@ -503,7 +504,7 @@ through the three known points.
TODO: Handle points on the boundaries. */
double TGArray::rectify_point(const int xgrid, const int ygrid, const std::vector<int> bad_points) const {
double TGArray::rectify_point(const int xgrid, const int ygrid, const std::vector<int>& bad_points) const {
//xgrid: grid units horizontally
//ygrid: grid units vertically
//Loop over corner points, if no points available, give up

View file

@ -67,15 +67,15 @@ private:
// Routines for height rectification
std::vector<int> collect_bad_points(const double bad_zone);
bool is_bad_point(const int xgrid, const int ygrid, const std::vector<int> bad_points) const;
double rectify_point(const int xgrid, const int ygrid, const std::vector<int> bad_points) const;
bool is_bad_point(const int xgrid, const int ygrid, const std::vector<int>& bad_points) const;
double rectify_point(const int xgrid, const int ygrid, const std::vector<int>& bad_points) const;
bool is_near_cliff(const double lon1,const double lon2, const double bad_zone) const;
public:
// Constructor
TGArray( void );
TGArray( const std::string& file );
explicit TGArray( const std::string& file );
// Destructor
~TGArray( void );
@ -96,11 +96,11 @@ public:
bool parse( SGBucket& b );
// write an Array file
bool write( const std::string root_dir, SGBucket& b );
bool write( const std::string& root_dir, SGBucket& b );
// write an Array file in binary format. If ht_rect is true,
// the file will have extension 'arr.rectified.gz'
void write_bin(const std::string root_dir, bool ht_rect, SGBucket& b);
void write_bin(const std::string& root_dir, bool ht_rect, SGBucket& b);
// do our best to remove voids by picking data from the nearest
// neighbor.

View file

@ -40,7 +40,7 @@ and if they have an associated cliff file, will adjust and then output
the heights. */
// display usage and exit
static void usage( const std::string name ) {
static void usage( const std::string& name ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << name);
SG_LOG(SG_GENERAL, SG_ALERT, " --work-dir=<directory>");
SG_LOG(SG_GENERAL, SG_ALERT, " --height-dir=<directory>");
@ -69,26 +69,26 @@ int main( int argc, char **argv) {
//
int arg_pos;
for (arg_pos = 1; arg_pos < argc; arg_pos++) {
std::string arg = argv[arg_pos];
std::string arg = argv[arg_pos];
if (arg.find("--work-dir=") == 0) {
if (arg.compare(0, 11, "--work-dir=") == 0) {
work_dir = arg.substr(11);
} else if (arg.find("--height-dir=") == 0) {
height_dir = arg.substr(13);
} else if (arg.find("--tile-id=") == 0) {
} else if (arg.compare(0, 13, "--height-dir=") == 0) {
height_dir = arg.substr(13);
} else if (arg.compare(0, 10, "--tile-id=") == 0) {
tile_id = atol(arg.substr(10).c_str());
} else if ( arg.find("--min-lon=") == 0 ) {
} else if ( arg.compare(0, 10, "--min-lon=") == 0 ) {
min.setLongitudeDeg(atof( arg.substr(10).c_str() ));
} else if ( arg.find("--max-lon=") == 0 ) {
} else if ( arg.compare(0, 10, "--max-lon=") == 0 ) {
max.setLongitudeDeg(atof( arg.substr(10).c_str() ));
} else if ( arg.find("--min-lat=") == 0 ) {
} else if ( arg.compare(0, 10, "--min-lat=") == 0 ) {
min.setLatitudeDeg(atof( arg.substr(10).c_str() ));
} else if ( arg.find("--max-lat=") == 0 ) {
} else if ( arg.compare(0, 10, "--max-lat=") == 0 ) {
max.setLatitudeDeg(atof( arg.substr(10).c_str() ));
} else if ( arg.find("--min-dist=") == 0) {
bad_zone = atof(arg.substr(11).c_str());
} else if (arg.find("--") == 0) {
usage(argv[0]);
} else if ( arg.compare(0, 11, "--min-dist=") == 0) {
bad_zone = atof(arg.substr(11).c_str());
} else if (arg.compare(0, 2, "--") == 0) {
usage(argv[0]);
} else {
break;
}

View file

@ -59,7 +59,7 @@ using std::ios;
#define MAX_HGT_SIZE 6001
class TGSrtmTiff : public TGSrtmBase {
public:
TGSrtmTiff( const SGPath &file );
explicit TGSrtmTiff( const SGPath &file );
~TGSrtmTiff();
bool open( const SGPath &f );
bool close();
@ -181,8 +181,7 @@ bool TGSrtmTiff::open( const SGPath &f ) {
}
bool TGSrtmTiff::load() {
int size;
cols = rows = size = 6000;
cols = rows = 6000;
col_step = row_step = 3;
uint32 w, h, d;

View file

@ -76,7 +76,7 @@ int SimpleRasterTransformer(void *pTransformerArg,
int bDstToSrc, int nPointCount,
double *x, double *y, double *z, int *panSuccess )
{
SimpleRasterTransformerInfo* info = (SimpleRasterTransformerInfo*)pTransformerArg;
SimpleRasterTransformerInfo* info = static_cast<SimpleRasterTransformerInfo*>(pTransformerArg);
int success;
if (bDstToSrc) {
@ -105,7 +105,7 @@ int SimpleRasterTransformer(void *pTransformerArg,
class ImageInfo {
public:
ImageInfo(GDALDataset *dataset);
explicit ImageInfo(GDALDataset *dataset);
void GetBounds(double &n, double &s, double &e, double &w) const {
n = north;

View file

@ -75,7 +75,7 @@ SGLockedQueue<SGPath> global_workQueue;
*/
class ArrayMap: public Terra::Map {
public:
ArrayMap(TGArray& array): array(array) {
explicit ArrayMap(TGArray& array): array(array) {
width=array.get_cols();
height=array.get_rows();
min=30000;

View file

@ -147,10 +147,12 @@ OGRLayer* get_layer_for_material(const std::string& material) {
OGRLinearRing* make_ring_from_fan(const int_list& fan, const std::vector<SGGeod>& nodes) {
OGRLinearRing* ring = new OGRLinearRing();
int_list::const_iterator vertex = fan.begin();
if (fan[1]==fan[fan.size()-1]) {
/* The fan is closed, so the first vertex is in the interior */
vertex++;
++vertex;
}
for (;vertex!=fan.end();++vertex) {
OGRPoint *point=new OGRPoint();
const SGGeod& node = nodes[*vertex];
@ -347,12 +349,13 @@ void process_polygon_file(const std::string& path) {
for (int pt=0;pt<count;pt++) {
OGRPoint *point=new OGRPoint();
double x,y,z;
double x, y;
in >> x >> y;
point->setX(x);
point->setY(y);
if (poly3d) {
double z;
in >> z;
point->setZ(z);
} else {