Minor clean up
This commit is contained in:
parent
e84b69efae
commit
de43172716
3 changed files with 67 additions and 64 deletions
|
@ -39,18 +39,18 @@ using std::string;
|
|||
|
||||
|
||||
TGArray::TGArray( void ):
|
||||
array_in(NULL),
|
||||
fitted_in(NULL),
|
||||
in_data(NULL)
|
||||
array_in(NULL),
|
||||
fitted_in(NULL),
|
||||
in_data(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
TGArray::TGArray( const string &file ):
|
||||
array_in(NULL),
|
||||
fitted_in(NULL),
|
||||
in_data(NULL)
|
||||
array_in(NULL),
|
||||
fitted_in(NULL),
|
||||
in_data(NULL)
|
||||
{
|
||||
TGArray::open(file);
|
||||
}
|
||||
|
@ -198,7 +198,6 @@ TGArray::parse( SGBucket& b ) {
|
|||
SG_LOG(SG_GENERAL, SG_DEBUG, " cols = " << cols << " rows = " << rows );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, " col_step = " << col_step << " row_step = " << row_step );
|
||||
|
||||
|
||||
in_data = new short[cols * rows];
|
||||
memset(in_data, 0, sizeof(short) * cols * rows);
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, " File not open, so using zero'd data" );
|
||||
|
@ -250,35 +249,36 @@ 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) {
|
||||
// generate output file name
|
||||
string base = b.gen_base_path();
|
||||
string path = root_dir + "/" + base;
|
||||
string extension = ".arr.new.gz";
|
||||
if (rectified) extension = ".arr.rectified.gz";
|
||||
SGPath sgp( path );
|
||||
sgp.append( "dummy" );
|
||||
sgp.create_dir( 0755 );
|
||||
// generate output file name
|
||||
string base = b.gen_base_path();
|
||||
string path = root_dir + "/" + base;
|
||||
string extension = ".arr.new.gz";
|
||||
if (rectified)
|
||||
extension = ".arr.rectified.gz";
|
||||
SGPath sgp( path );
|
||||
sgp.append( "dummy" );
|
||||
sgp.create_dir( 0755 );
|
||||
|
||||
string array_file = path + "/" + b.gen_index_str() + extension;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file );
|
||||
string array_file = path + "/" + b.gen_index_str() + extension;
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file );
|
||||
|
||||
// write the file
|
||||
gzFile fp;
|
||||
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||
return;
|
||||
}
|
||||
// write the file
|
||||
gzFile fp;
|
||||
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t header = 0x54474152; //'TGAR'
|
||||
sgWriteLong(fp,header);
|
||||
sgWriteInt(fp,originx);
|
||||
sgWriteInt(fp,originy);
|
||||
sgWriteInt(fp,cols);
|
||||
sgWriteInt(fp,col_step);
|
||||
sgWriteInt(fp,rows);
|
||||
sgWriteInt(fp,row_step);
|
||||
sgWriteShort(fp, rows*cols, in_data);
|
||||
gzclose(fp);
|
||||
int32_t header = 0x54474152; //'TGAR'
|
||||
sgWriteLong(fp,header);
|
||||
sgWriteInt(fp,originx);
|
||||
sgWriteInt(fp,originy);
|
||||
sgWriteInt(fp,cols);
|
||||
sgWriteInt(fp,col_step);
|
||||
sgWriteInt(fp,rows);
|
||||
sgWriteInt(fp,row_step);
|
||||
sgWriteShort(fp, rows*cols, in_data);
|
||||
gzclose(fp);
|
||||
}
|
||||
|
||||
// write an Array file
|
||||
|
@ -296,18 +296,18 @@ bool TGArray::write( const string root_dir, SGBucket& b ) {
|
|||
// write the file
|
||||
gzFile fp;
|
||||
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||
return false;
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||
return false;
|
||||
}
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "origin = " << originx << ", " << originy );
|
||||
gzprintf( fp, "%d %d\n", (int)originx, (int)originy );
|
||||
gzprintf( fp, "%d %d %d %d\n", cols, (int)col_step, rows, (int)row_step );
|
||||
for ( int i = 0; i < cols; ++i ) {
|
||||
for ( int j = 0; j < rows; ++j ) {
|
||||
gzprintf( fp, "%d ", get_array_elev(i, j) );
|
||||
}
|
||||
gzprintf( fp, "\n" );
|
||||
for ( int j = 0; j < rows; ++j ) {
|
||||
gzprintf( fp, "%d ", get_array_elev(i, j) );
|
||||
}
|
||||
gzprintf( fp, "\n" );
|
||||
}
|
||||
gzclose(fp);
|
||||
|
||||
|
@ -610,19 +610,19 @@ double TGArray::altitude_from_grid( double lon, double lat ) const {
|
|||
yindex = (int)(ylocal);
|
||||
|
||||
if ( xindex + 1 == cols ) {
|
||||
xindex--;
|
||||
xindex--;
|
||||
}
|
||||
|
||||
if ( yindex + 1 == rows ) {
|
||||
yindex--;
|
||||
yindex--;
|
||||
}
|
||||
|
||||
if ( (xindex < 0) || (xindex + 1 >= cols) ||
|
||||
(yindex < 0) || (yindex + 1 >= rows) ) {
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "WARNING: Attempt to interpolate value outside of array!!!" );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "WARNING: Attempt to interpolate value outside of array!!!" );
|
||||
|
||||
return -9999;
|
||||
return -9999;
|
||||
}
|
||||
|
||||
// Now check if we are on the same side of any cliffs
|
||||
|
@ -924,4 +924,3 @@ bool TGArray::is_open() const
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,9 @@ private:
|
|||
// number of columns and rows
|
||||
int cols, rows;
|
||||
|
||||
// Whether or not the input data have been rectified
|
||||
bool rectified;
|
||||
// Whether or not the input data have been rectified
|
||||
bool rectified;
|
||||
|
||||
// Distance between column and row data points (in arc seconds)
|
||||
double col_step, row_step;
|
||||
|
||||
|
@ -59,15 +60,17 @@ private:
|
|||
std::vector<SGGeod> corner_list;
|
||||
std::vector<SGGeod> fitted_list;
|
||||
|
||||
// list of cliff contours
|
||||
tgcontour_list cliffs_list;
|
||||
// list of cliff contours
|
||||
tgcontour_list cliffs_list;
|
||||
|
||||
void parse_bin();
|
||||
|
||||
// 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_near_cliff(const double lon1,const double lon2, const double bad_zone) const;
|
||||
// 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_near_cliff(const double lon1,const double lon2, const double bad_zone) const;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
|
@ -80,8 +83,8 @@ public:
|
|||
// open an Array file (use "-" if input is coming from stdin)
|
||||
bool open ( const std::string& file_base );
|
||||
|
||||
// Load contours from polygon files delineating height discontinuities
|
||||
void load_cliffs(const std::string & height_base);
|
||||
// Load contours from polygon files delineating height discontinuities
|
||||
void load_cliffs(const std::string & height_base);
|
||||
|
||||
// return if array was successfully opened or not
|
||||
bool is_open() const;
|
||||
|
@ -95,9 +98,9 @@ public:
|
|||
// write an Array file
|
||||
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);
|
||||
// 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);
|
||||
|
||||
// do our best to remove voids by picking data from the nearest
|
||||
// neighbor.
|
||||
|
@ -127,8 +130,9 @@ public:
|
|||
int get_array_elev( int col, int row ) const;
|
||||
void set_array_elev( int col, int row, int val );
|
||||
|
||||
// Check whether or not two points are on the same side of contour
|
||||
bool check_points (const double a,const double b, const double c, const double d) const;
|
||||
// Check whether or not two points are on the same side of contour
|
||||
bool check_points (const double a,const double b, const double c, const double d) const;
|
||||
|
||||
// reset Array to initial state - ready to load another elevation file
|
||||
void unload( void );
|
||||
};
|
||||
|
|
|
@ -812,7 +812,7 @@ extern SGGeod InterpolateElevation( const SGGeod& dst_node, const SGGeod& start,
|
|||
|
||||
static void AddIntermediateNodes( const SGGeod& p0, const SGGeod& p1, bool preserve3d, std::vector<TGNode*>& nodes, tgContour& result, double bbEpsilon, double errEpsilon )
|
||||
{
|
||||
TGNode* new_pt;
|
||||
TGNode* new_pt = nullptr;
|
||||
SGGeod new_geode;
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_BULK, " " << p0 << " <==> " << p1 );
|
||||
|
|
Loading…
Add table
Reference in a new issue