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 ):
|
TGArray::TGArray( void ):
|
||||||
array_in(NULL),
|
array_in(NULL),
|
||||||
fitted_in(NULL),
|
fitted_in(NULL),
|
||||||
in_data(NULL)
|
in_data(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TGArray::TGArray( const string &file ):
|
TGArray::TGArray( const string &file ):
|
||||||
array_in(NULL),
|
array_in(NULL),
|
||||||
fitted_in(NULL),
|
fitted_in(NULL),
|
||||||
in_data(NULL)
|
in_data(NULL)
|
||||||
{
|
{
|
||||||
TGArray::open(file);
|
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, " cols = " << cols << " rows = " << rows );
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, " col_step = " << col_step << " row_step = " << row_step );
|
SG_LOG(SG_GENERAL, SG_DEBUG, " col_step = " << col_step << " row_step = " << row_step );
|
||||||
|
|
||||||
|
|
||||||
in_data = new short[cols * rows];
|
in_data = new short[cols * rows];
|
||||||
memset(in_data, 0, sizeof(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" );
|
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
|
// Write out an array. If rectified is true, the heights have been adjusted
|
||||||
// for discontinuities.
|
// 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
|
// generate output file name
|
||||||
string base = b.gen_base_path();
|
string base = b.gen_base_path();
|
||||||
string path = root_dir + "/" + base;
|
string path = root_dir + "/" + base;
|
||||||
string extension = ".arr.new.gz";
|
string extension = ".arr.new.gz";
|
||||||
if (rectified) extension = ".arr.rectified.gz";
|
if (rectified)
|
||||||
SGPath sgp( path );
|
extension = ".arr.rectified.gz";
|
||||||
sgp.append( "dummy" );
|
SGPath sgp( path );
|
||||||
sgp.create_dir( 0755 );
|
sgp.append( "dummy" );
|
||||||
|
sgp.create_dir( 0755 );
|
||||||
|
|
||||||
string array_file = path + "/" + b.gen_index_str() + extension;
|
string array_file = path + "/" + b.gen_index_str() + extension;
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file );
|
SG_LOG(SG_GENERAL, SG_DEBUG, "array_file = " << array_file );
|
||||||
|
|
||||||
// write the file
|
// write the file
|
||||||
gzFile fp;
|
gzFile fp;
|
||||||
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t header = 0x54474152; //'TGAR'
|
int32_t header = 0x54474152; //'TGAR'
|
||||||
sgWriteLong(fp,header);
|
sgWriteLong(fp,header);
|
||||||
sgWriteInt(fp,originx);
|
sgWriteInt(fp,originx);
|
||||||
sgWriteInt(fp,originy);
|
sgWriteInt(fp,originy);
|
||||||
sgWriteInt(fp,cols);
|
sgWriteInt(fp,cols);
|
||||||
sgWriteInt(fp,col_step);
|
sgWriteInt(fp,col_step);
|
||||||
sgWriteInt(fp,rows);
|
sgWriteInt(fp,rows);
|
||||||
sgWriteInt(fp,row_step);
|
sgWriteInt(fp,row_step);
|
||||||
sgWriteShort(fp, rows*cols, in_data);
|
sgWriteShort(fp, rows*cols, in_data);
|
||||||
gzclose(fp);
|
gzclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write an Array file
|
// write an Array file
|
||||||
|
@ -296,18 +296,18 @@ bool TGArray::write( const string root_dir, SGBucket& b ) {
|
||||||
// write the file
|
// write the file
|
||||||
gzFile fp;
|
gzFile fp;
|
||||||
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: cannot open " << array_file << " for writing!" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "origin = " << originx << ", " << originy );
|
SG_LOG(SG_GENERAL, SG_DEBUG, "origin = " << originx << ", " << originy );
|
||||||
gzprintf( fp, "%d %d\n", (int)originx, (int)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 );
|
gzprintf( fp, "%d %d %d %d\n", cols, (int)col_step, rows, (int)row_step );
|
||||||
for ( int i = 0; i < cols; ++i ) {
|
for ( int i = 0; i < cols; ++i ) {
|
||||||
for ( int j = 0; j < rows; ++j ) {
|
for ( int j = 0; j < rows; ++j ) {
|
||||||
gzprintf( fp, "%d ", get_array_elev(i, j) );
|
gzprintf( fp, "%d ", get_array_elev(i, j) );
|
||||||
}
|
}
|
||||||
gzprintf( fp, "\n" );
|
gzprintf( fp, "\n" );
|
||||||
}
|
}
|
||||||
gzclose(fp);
|
gzclose(fp);
|
||||||
|
|
||||||
|
@ -610,19 +610,19 @@ double TGArray::altitude_from_grid( double lon, double lat ) const {
|
||||||
yindex = (int)(ylocal);
|
yindex = (int)(ylocal);
|
||||||
|
|
||||||
if ( xindex + 1 == cols ) {
|
if ( xindex + 1 == cols ) {
|
||||||
xindex--;
|
xindex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( yindex + 1 == rows ) {
|
if ( yindex + 1 == rows ) {
|
||||||
yindex--;
|
yindex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (xindex < 0) || (xindex + 1 >= cols) ||
|
if ( (xindex < 0) || (xindex + 1 >= cols) ||
|
||||||
(yindex < 0) || (yindex + 1 >= rows) ) {
|
(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
|
// Now check if we are on the same side of any cliffs
|
||||||
|
@ -924,4 +924,3 @@ bool TGArray::is_open() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,9 @@ private:
|
||||||
// number of columns and rows
|
// number of columns and rows
|
||||||
int cols, rows;
|
int cols, rows;
|
||||||
|
|
||||||
// Whether or not the input data have been rectified
|
// Whether or not the input data have been rectified
|
||||||
bool rectified;
|
bool rectified;
|
||||||
|
|
||||||
// Distance between column and row data points (in arc seconds)
|
// Distance between column and row data points (in arc seconds)
|
||||||
double col_step, row_step;
|
double col_step, row_step;
|
||||||
|
|
||||||
|
@ -59,15 +60,17 @@ private:
|
||||||
std::vector<SGGeod> corner_list;
|
std::vector<SGGeod> corner_list;
|
||||||
std::vector<SGGeod> fitted_list;
|
std::vector<SGGeod> fitted_list;
|
||||||
|
|
||||||
// list of cliff contours
|
// list of cliff contours
|
||||||
tgcontour_list cliffs_list;
|
tgcontour_list cliffs_list;
|
||||||
|
|
||||||
void parse_bin();
|
void parse_bin();
|
||||||
|
|
||||||
// Routines for height rectification
|
// Routines for height rectification
|
||||||
std::vector<int> collect_bad_points(const double bad_zone);
|
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;
|
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;
|
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;
|
bool is_near_cliff(const double lon1,const double lon2, const double bad_zone) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -80,8 +83,8 @@ public:
|
||||||
// open an Array file (use "-" if input is coming from stdin)
|
// open an Array file (use "-" if input is coming from stdin)
|
||||||
bool open ( const std::string& file_base );
|
bool open ( const std::string& file_base );
|
||||||
|
|
||||||
// Load contours from polygon files delineating height discontinuities
|
// Load contours from polygon files delineating height discontinuities
|
||||||
void load_cliffs(const std::string & height_base);
|
void load_cliffs(const std::string & height_base);
|
||||||
|
|
||||||
// return if array was successfully opened or not
|
// return if array was successfully opened or not
|
||||||
bool is_open() const;
|
bool is_open() const;
|
||||||
|
@ -95,9 +98,9 @@ public:
|
||||||
// write an Array file
|
// 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,
|
// write an Array file in binary format. If ht_rect is true,
|
||||||
// the file will have extension 'arr.rectified.gz'
|
// 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
|
// do our best to remove voids by picking data from the nearest
|
||||||
// neighbor.
|
// neighbor.
|
||||||
|
@ -127,8 +130,9 @@ public:
|
||||||
int get_array_elev( int col, int row ) const;
|
int get_array_elev( int col, int row ) const;
|
||||||
void set_array_elev( int col, int row, int val );
|
void set_array_elev( int col, int row, int val );
|
||||||
|
|
||||||
// Check whether or not two points are on the same side of contour
|
// 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;
|
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
|
// reset Array to initial state - ready to load another elevation file
|
||||||
void unload( void );
|
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 )
|
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;
|
SGGeod new_geode;
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_BULK, " " << p0 << " <==> " << p1 );
|
SG_LOG(SG_GENERAL, SG_BULK, " " << p0 << " <==> " << p1 );
|
||||||
|
|
Loading…
Add table
Reference in a new issue