TGArray: Speed up the construction and destruction
This commit is contained in:
parent
7ed3965933
commit
1b53799d51
2 changed files with 89 additions and 101 deletions
|
@ -17,25 +17,19 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
|
||||||
// $Id: array.cxx,v 1.24 2005-11-10 16:26:59 curt Exp $
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
|
||||||
#include <simgear/misc/sgstream.hxx>
|
#include <simgear/misc/sgstream.hxx>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/misc/strutils.hxx>
|
#include <simgear/misc/strutils.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/math/leastsqs.hxx>
|
|
||||||
|
|
||||||
#include "array.hxx"
|
#include "array.hxx"
|
||||||
|
|
||||||
|
@ -47,10 +41,7 @@ TGArray::TGArray( void ):
|
||||||
fitted_in(NULL)
|
fitted_in(NULL)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "class TGArray CONstructor called." );
|
SG_LOG(SG_GENERAL, SG_DEBUG, "class TGArray CONstructor called." );
|
||||||
in_data = new int*[ARRAY_SIZE_1];
|
in_data = new int[ARRAY_SIZE_1 * ARRAY_SIZE_1];
|
||||||
for (int i = 0; i < ARRAY_SIZE_1; i++) {
|
|
||||||
in_data[i] = new int[ARRAY_SIZE_1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,9 +50,7 @@ TGArray::TGArray( const string &file ):
|
||||||
fitted_in(NULL)
|
fitted_in(NULL)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "class TGArray CONstructor called." );
|
SG_LOG(SG_GENERAL, SG_DEBUG, "class TGArray CONstructor called." );
|
||||||
in_data = new int* [ARRAY_SIZE_1];
|
in_data = new int[ARRAY_SIZE_1 * ARRAY_SIZE_1];
|
||||||
for (int i = 0; i < ARRAY_SIZE_1; i++)
|
|
||||||
in_data[i] = new int[ARRAY_SIZE_1];
|
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "ps TGArray CONstructor called." );
|
SG_LOG(SG_GENERAL, SG_ALERT, "ps TGArray CONstructor called." );
|
||||||
|
|
||||||
|
@ -137,7 +126,7 @@ TGArray::parse( SGBucket& b ) {
|
||||||
|
|
||||||
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++ ) {
|
||||||
*array_in >> in_data[i][j];
|
*array_in >> in_data[(i * ARRAY_SIZE_1) + j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,12 +149,7 @@ 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 );
|
||||||
|
|
||||||
for ( int i = 0; i < cols; i++ ) {
|
memset(in_data, 0, sizeof(int) * ARRAY_SIZE_1 * ARRAY_SIZE_1);
|
||||||
for ( int j = 0; j < rows; j++ ) {
|
|
||||||
in_data[i][j] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +193,7 @@ bool TGArray::write( const string root_dir, SGBucket& b ) {
|
||||||
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 ", (int)in_data[i][j] );
|
gzprintf( fp, "%d ", get_array_elev(i, j) );
|
||||||
}
|
}
|
||||||
gzprintf( fp, "\n" );
|
gzprintf( fp, "\n" );
|
||||||
}
|
}
|
||||||
|
@ -234,10 +218,10 @@ void TGArray::remove_voids( ) {
|
||||||
last_elev = -32768;
|
last_elev = -32768;
|
||||||
have_void = false;
|
have_void = false;
|
||||||
for ( j = 0; j < rows; j++ ) {
|
for ( j = 0; j < rows; j++ ) {
|
||||||
if ( in_data[i][j] > -9000 ) {
|
if ( get_array_elev(i,j) > -9000 ) {
|
||||||
last_elev = in_data[i][j];
|
last_elev = get_array_elev(i,j) ;
|
||||||
} else if ( last_elev > -9000 ) {
|
} else if ( last_elev > -9000 ) {
|
||||||
in_data[i][j] = last_elev;
|
set_array_elev(i, j, last_elev);
|
||||||
} else {
|
} else {
|
||||||
have_void = true;
|
have_void = true;
|
||||||
}
|
}
|
||||||
|
@ -246,10 +230,10 @@ void TGArray::remove_voids( ) {
|
||||||
last_elev = -32768;
|
last_elev = -32768;
|
||||||
have_void = false;
|
have_void = false;
|
||||||
for ( j = rows - 1; j >= 0; j-- ) {
|
for ( j = rows - 1; j >= 0; j-- ) {
|
||||||
if ( in_data[i][j] > -9000 ) {
|
if ( get_array_elev(i,j) > -9000 ) {
|
||||||
last_elev = in_data[i][j];
|
last_elev = get_array_elev(i,j);
|
||||||
} else if ( last_elev > -9000 ) {
|
} else if ( last_elev > -9000 ) {
|
||||||
in_data[i][j] = last_elev;
|
set_array_elev(i, j, last_elev);
|
||||||
} else {
|
} else {
|
||||||
have_void = true;
|
have_void = true;
|
||||||
}
|
}
|
||||||
|
@ -264,10 +248,10 @@ void TGArray::remove_voids( ) {
|
||||||
last_elev = -32768;
|
last_elev = -32768;
|
||||||
have_void = false;
|
have_void = false;
|
||||||
for ( i = 0; i < cols; i++ ) {
|
for ( i = 0; i < cols; i++ ) {
|
||||||
if ( in_data[i][j] > -9999 ) {
|
if ( get_array_elev(i,j) > -9999 ) {
|
||||||
last_elev = in_data[i][j];
|
last_elev = get_array_elev(i,j);
|
||||||
} else if ( last_elev > -9999 ) {
|
} else if ( last_elev > -9999 ) {
|
||||||
in_data[i][j] = last_elev;
|
set_array_elev(i, j, last_elev);
|
||||||
} else {
|
} else {
|
||||||
have_void = true;
|
have_void = true;
|
||||||
}
|
}
|
||||||
|
@ -277,10 +261,10 @@ void TGArray::remove_voids( ) {
|
||||||
last_elev = -32768;
|
last_elev = -32768;
|
||||||
have_void = false;
|
have_void = false;
|
||||||
for ( i = cols - 1; i >= 0; i-- ) {
|
for ( i = cols - 1; i >= 0; i-- ) {
|
||||||
if ( in_data[i][j] > -9999 ) {
|
if ( get_array_elev(i,j) > -9999 ) {
|
||||||
last_elev = in_data[i][j];
|
last_elev = get_array_elev(i,j);
|
||||||
} else if ( last_elev > -9999 ) {
|
} else if ( last_elev > -9999 ) {
|
||||||
in_data[i][j] = last_elev;
|
set_array_elev(i, j, last_elev);
|
||||||
} else {
|
} else {
|
||||||
have_void = true;
|
have_void = true;
|
||||||
}
|
}
|
||||||
|
@ -294,8 +278,8 @@ void TGArray::remove_voids( ) {
|
||||||
// as a panic fall back.
|
// as a panic fall back.
|
||||||
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++ ) {
|
||||||
if ( in_data[i][j] <= -9999 ) {
|
if ( get_array_elev(i,j) <= -9999 ) {
|
||||||
in_data[i][j] = 0;
|
set_array_elev(i, j, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,7 +483,7 @@ double TGArray::closest_nonvoid_elev( double lon, double lat ) const {
|
||||||
for ( int col = 0; col < cols; col++ ) {
|
for ( int col = 0; col < cols; col++ ) {
|
||||||
Point3D p1(originx + col * col_step, originy + row * row_step, 0.0);
|
Point3D p1(originx + col * col_step, originy + row * row_step, 0.0);
|
||||||
double dist = p0.distance3D( p1 );
|
double dist = p0.distance3D( p1 );
|
||||||
double elev = in_data[col][row];
|
double elev = get_array_elev(col, row);
|
||||||
if ( dist < mindist && elev > -9000 ) {
|
if ( dist < mindist && elev > -9000 ) {
|
||||||
mindist = dist;
|
mindist = dist;
|
||||||
minelev = elev;
|
minelev = elev;
|
||||||
|
@ -568,15 +552,15 @@ double TGArray::altitude_from_grid( double lon, double lat ) const {
|
||||||
|
|
||||||
x1 = xindex;
|
x1 = xindex;
|
||||||
y1 = yindex;
|
y1 = yindex;
|
||||||
z1 = in_data[x1][y1];
|
z1 = get_array_elev(x1, y1);
|
||||||
|
|
||||||
x2 = xindex + 1;
|
x2 = xindex + 1;
|
||||||
y2 = yindex;
|
y2 = yindex;
|
||||||
z2 = in_data[x2][y2];
|
z2 = get_array_elev(x2, y2);
|
||||||
|
|
||||||
x3 = xindex + 1;
|
x3 = xindex + 1;
|
||||||
y3 = yindex + 1;
|
y3 = yindex + 1;
|
||||||
z3 = in_data[x3][y3];
|
z3 = get_array_elev(x3, y3);
|
||||||
|
|
||||||
if ( z1 < -9000 || z2 < -9000 || z3 < -9000 ) {
|
if ( z1 < -9000 || z2 < -9000 || z3 < -9000 ) {
|
||||||
// don't interpolate off a void
|
// don't interpolate off a void
|
||||||
|
@ -596,15 +580,15 @@ double TGArray::altitude_from_grid( double lon, double lat ) const {
|
||||||
|
|
||||||
x1 = xindex;
|
x1 = xindex;
|
||||||
y1 = yindex;
|
y1 = yindex;
|
||||||
z1 = in_data[x1][y1];
|
z1 = get_array_elev(x1, y1);
|
||||||
|
|
||||||
x2 = xindex;
|
x2 = xindex;
|
||||||
y2 = yindex + 1;
|
y2 = yindex + 1;
|
||||||
z2 = in_data[x2][y2];
|
z2 = get_array_elev(x2, y2);
|
||||||
|
|
||||||
x3 = xindex + 1;
|
x3 = xindex + 1;
|
||||||
y3 = yindex + 1;
|
y3 = yindex + 1;
|
||||||
z3 = in_data[x3][y3];
|
z3 = get_array_elev(x3, y3);
|
||||||
|
|
||||||
if ( z1 < -9000 || z2 < -9000 || z3 < -9000 ) {
|
if ( z1 < -9000 || z2 < -9000 || z3 < -9000 ) {
|
||||||
// don't interpolate off a void
|
// don't interpolate off a void
|
||||||
|
@ -744,10 +728,17 @@ void TGArray::outputmesh_output_nodes( const string& fg_root, SGBucket& p )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
TGArray::~TGArray( void ) {
|
TGArray::~TGArray( void )
|
||||||
for (int i = 0; i < ARRAY_SIZE_1; i++)
|
{
|
||||||
delete [] in_data[i];
|
delete in_data;
|
||||||
delete [] in_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TGArray::get_array_elev( int col, int row ) const
|
||||||
|
{
|
||||||
|
return in_data[(col * ARRAY_SIZE_1) + row];
|
||||||
|
}
|
||||||
|
|
||||||
|
void TGArray::set_array_elev( int col, int row, int val )
|
||||||
|
{
|
||||||
|
in_data[(col * ARRAY_SIZE_1) + row] = val;
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
//
|
||||||
// $Id: array.hxx,v 1.18 2005-11-10 16:26:59 curt Exp $
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _ARRAY_HXX
|
#ifndef _ARRAY_HXX
|
||||||
|
@ -63,7 +62,7 @@ private:
|
||||||
double col_step, row_step;
|
double col_step, row_step;
|
||||||
|
|
||||||
// pointers to the actual grid data allocated here
|
// pointers to the actual grid data allocated here
|
||||||
int **in_data;
|
int *in_data;
|
||||||
// float (*out_data)[ARRAY_SIZE_1];
|
// float (*out_data)[ARRAY_SIZE_1];
|
||||||
|
|
||||||
// output nodes
|
// output nodes
|
||||||
|
@ -129,12 +128,10 @@ public:
|
||||||
inline point_list get_corner_list() const { return corner_list; }
|
inline point_list get_corner_list() const { return corner_list; }
|
||||||
inline point_list get_fitted_list() const { return fitted_list; }
|
inline point_list get_fitted_list() const { return fitted_list; }
|
||||||
|
|
||||||
inline int get_array_elev( int col, int row ) {
|
int get_array_elev( int col, int row ) const;
|
||||||
return in_data[col][row];
|
void set_array_elev( int col, int row, int val );
|
||||||
}
|
|
||||||
inline void set_array_elev( int col, int row, int val ) {
|
|
||||||
in_data[col][row] = val;
|
|
||||||
}
|
|
||||||
inline Point3D get_fitted_pt( int i ) {
|
inline Point3D get_fitted_pt( int i ) {
|
||||||
return fitted_list[i];
|
return fitted_list[i];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue