1
0
Fork 0

TGArray: remove old code

This commit is contained in:
Christian Schmitt 2012-11-23 18:35:31 +01:00
parent 1b53799d51
commit f7bb81c370

View file

@ -307,172 +307,6 @@ void TGArray::add_fit_node( int i, int j, double val ) {
}
#if 0
// Use least squares to fit a simpler data set to dem data. Return
// the number of fitted nodes. This is a horrible approach that
// doesn't really work, but it's better than nothing if you've got
// nothing. Using src/Prep/ArrayFit to create .fit files from the
// .arr files is a *much* better approach, but it is slower which is
// why it needs to be done "offline".
int TGArray::fit( double error ) {
if ( ! fit_on_the_fly ) {
return fitted_list.size();
}
double x[ARRAY_SIZE_1], y[ARRAY_SIZE_1];
double m, b, max_error, error_sq;
double x1, y1;
// double ave_error;
double cury, lasty;
int n, row, start, end;
int colmin, colmax, rowmin, rowmax;
bool good_fit;
// FILE *dem, *fit, *fit1;
error_sq = error * error;
cout << " Initializing fitted node list" << endl;
corner_list.clear();
fitted_list.clear();
// determine dimensions
colmin = 0;
colmax = cols;
rowmin = 0;
rowmax = rows;
cout << " Fitting region = " << colmin << "," << rowmin << " to "
<< colmax << "," << rowmax << endl;;
// generate corners list
add_corner_node( colmin, rowmin, in_data[colmin][rowmin] );
add_corner_node( colmin, rowmax-1, in_data[colmin][rowmax] );
add_corner_node( colmax-1, rowmin, in_data[colmax][rowmin] );
add_corner_node( colmax-1, rowmax-1, in_data[colmax][rowmax] );
cout << " Beginning best fit procedure" << endl;
lasty = 0;
for ( row = rowmin; row < rowmax; row++ ) {
// fit = fopen("fit.dat", "w");
// fit1 = fopen("fit1.dat", "w");
start = colmin;
// cout << " fitting row = " << row << endl;
while ( start < colmax - 1 ) {
end = start + 1;
good_fit = true;
x[0] = start * col_step;
y[0] = in_data[start][row];
x[1] = end * col_step;
y[1] = in_data[end][row];
n = 2;
// cout << "Least square of first 2 points" << endl;
least_squares(x, y, n, &m, &b);
end++;
while ( (end < colmax) && good_fit ) {
++n;
// cout << "Least square of first " << n << " points" << endl;
x[n-1] = x1 = end * col_step;
y[n-1] = y1 = in_data[end][row];
least_squares_update(x1, y1, &m, &b);
// ave_error = least_squares_error(x, y, n, m, b);
max_error = least_squares_max_error(x, y, n, m, b);
/*
printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n",
start, end, ave_error, max_error, m, b);
f = fopen("gnuplot.dat", "w");
for ( j = 0; j <= end; j++) {
fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ),
in_data[row][j]);
}
for ( j = start; j <= end; j++) {
fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ),
in_data[row][j]);
}
fclose(f);
printf("Please hit return: "); gets(junk);
*/
if ( max_error > error_sq ) {
good_fit = false;
}
end++;
}
if ( !good_fit ) {
// error exceeded the threshold, back up
end -= 2; // back "end" up to the last good enough fit
n--; // back "n" up appropriately too
} else {
// we popped out of the above loop while still within
// the error threshold, so we must be at the end of
// the data set
end--;
}
least_squares(x, y, n, &m, &b);
// ave_error = least_squares_error(x, y, n, m, b);
max_error = least_squares_max_error(x, y, n, m, b);
/*
printf("\n");
printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n",
start, end, ave_error, max_error, m, b);
printf("\n");
fprintf(fit1, "%.2f %.2f\n", x[0], m * x[0] + b);
fprintf(fit1, "%.2f %.2f\n", x[end-start], m * x[end-start] + b);
*/
if ( start > colmin ) {
// skip this for the first line segment
cury = m * x[0] + b;
add_fit_node( start, row, (lasty + cury) / 2 );
// fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2);
}
lasty = m * x[end-start] + b;
start = end;
}
/*
fclose(fit);
fclose(fit1);
dem = fopen("gnuplot.dat", "w");
for ( j = 0; j < ARRAY_SIZE_1; j++) {
fprintf(dem, "%.2f %.2f\n", 0.0 + ( j * col_step ),
in_data[j][row]);
}
fclose(dem);
*/
// NOTICE, this is for testing only. This instance of
// output_nodes should be removed. It should be called only
// once at the end once all the nodes have been generated.
// newmesh_output_nodes(&nm, "mesh.node");
// printf("Please hit return: "); gets(junk);
}
// outputmesh_output_nodes(fg_root, p);
// return fit nodes + 4 corners
return fitted_list.size() + 4;
}
#endif
// Return the elevation of the closest non-void grid point to lon, lat
double TGArray::closest_nonvoid_elev( double lon, double lat ) const {
double mindist = 99999999999.9;
@ -609,125 +443,6 @@ double TGArray::altitude_from_grid( double lon, double lat ) const {
}
#if 0
// Write out a node file that can be used by the "triangle" program.
// Check for an optional "index.node.ex" file in case there is a .poly
// file to go along with this node file. Include these nodes first
// since they are referenced by position from the .poly file.
void TGArray::outputmesh_output_nodes( const string& fg_root, SGBucket& p )
{
double exnodes[MAX_EX_NODES][3];
struct stat stat_buf;
string dir, file;
char exfile[256];
#ifdef WIN32
char tmp_path[256];
#endif
string command;
FILE *fd;
int colmin, colmax, rowmin, rowmax;
int i, j, count, excount, result;
// determine dimensions
colmin = p.get_x() * ( (cols - 1) / 8);
colmax = colmin + ( (cols - 1) / 8);
rowmin = p.get_y() * ( (rows - 1) / 8);
rowmax = rowmin + ( (rows - 1) / 8);
cout << " dumping region = " << colmin << "," << rowmin << " to " <<
colmax << "," << rowmax << "\n";
// generate the base directory
string base_path = p.gen_base_path();
cout << " fg_root = " << fg_root << " Base Path = " << base_path << endl;
dir = fg_root + "/" + base_path;
cout << " Dir = " << dir << endl;
// stat() directory and create if needed
errno = 0;
result = stat(dir.c_str(), &stat_buf);
if ( result != 0 && errno == ENOENT ) {
cout << " Creating directory\n";
#ifdef _MSC_VER
fg_mkdir( dir.cstr() );
#else
command = "mkdir -p " + dir + "\n";
system( command.c_str() );
#endif
} else {
// assume directory exists
}
// get index and generate output file name
file = dir + "/" + p.gen_index_str() + ".node";
// get (optional) extra node file name (in case there is matching
// .poly file.
exfile = file + ".ex";
// load extra nodes if they exist
excount = 0;
if ( (fd = fopen(exfile, "r")) != NULL ) {
int junki;
fscanf(fd, "%d %d %d %d", &excount, &junki, &junki, &junki);
if ( excount > MAX_EX_NODES - 1 ) {
printf("Error, too many 'extra' nodes, increase array size\n");
exit(-1);
} else {
printf(" Expecting %d 'extra' nodes\n", excount);
}
for ( i = 1; i <= excount; i++ ) {
fscanf(fd, "%d %lf %lf %lf\n", &junki,
&exnodes[i][0], &exnodes[i][1], &exnodes[i][2]);
printf("(extra) %d %.2f %.2f %.2f\n",
i, exnodes[i][0], exnodes[i][1], exnodes[i][2]);
}
fclose(fd);
}
printf("Creating node file: %s\n", file);
fd = fopen(file, "w");
// first count regular nodes to generate header
count = 0;
for ( j = rowmin; j <= rowmax; j++ ) {
for ( i = colmin; i <= colmax; i++ ) {
if ( out_data[i][j] > -9000.0 ) {
count++;
}
}
// printf(" count = %d\n", count);
}
fprintf(fd, "%d 2 1 0\n", count + excount);
// now write out extra node data
for ( i = 1; i <= excount; i++ ) {
fprintf(fd, "%d %.2f %.2f %.2f\n",
i, exnodes[i][0], exnodes[i][1], exnodes[i][2]);
}
// write out actual node data
count = excount + 1;
for ( j = rowmin; j <= rowmax; j++ ) {
for ( i = colmin; i <= colmax; i++ ) {
if ( out_data[i][j] > -9000.0 ) {
fprintf(fd, "%d %.2f %.2f %.2f\n",
count++,
originx + (double)i * col_step,
originy + (double)j * row_step,
out_data[i][j]);
}
}
// printf(" count = %d\n", count);
}
fclose(fd);
}
#endif
TGArray::~TGArray( void )
{
delete in_data;