1
0
Fork 0

More changes to split up tiles, munge in the previously existing shared

pieces, and reassemble, so we are ready to retriangulate.
This commit is contained in:
curt 1999-05-04 04:12:07 +00:00
parent 869e47fca4
commit bab8b9cadf
3 changed files with 299 additions and 105 deletions

View file

@ -405,6 +405,9 @@ void construct_tile( FGConstruct& c ) {
m.load_neighbor_shared( c );
m.split_tile( c );
m.write_shared( c );
m.assemble_tile( c );
// now we must retriangulate the pasted together tile points
// generate the output
FGGenOutput output;
@ -431,10 +434,10 @@ main(int argc, char **argv) {
c.set_min_nodes( 50 );
c.set_max_nodes( (int)(FG_MAX_NODES * 0.8) );
lon = -146.248360; lat = 61.133950; // PAVD (Valdez, AK)
// lon = -146.248360; lat = 61.133950; // PAVD (Valdez, AK)
// lon = -110.664244; lat = 33.352890; // P13
// lon = -93.211389; lat = 45.145000; // KANE
// lon = -92.486188; lat = 44.590190; // KRGK
lon = -92.486188; lat = 44.590190; // KRGK
// lon = -89.7446823; lat= 29.314495;
// lon = -122.488090; lat = 42.743183; // 64S
// lon = -114.861097; lat = 35.947480; // 61B
@ -455,14 +458,14 @@ main(int argc, char **argv) {
FGBucket b_max( lon + 3, lat + 1 );
FGBucket b_start(566777L);
bool do_tile = false;
bool do_tile = true;
// FGBucket b_omit(-1L);
// FGBucket b(1122504L);
FGBucket b(-146.248360, 61.133950);
c.set_bucket( b );
construct_tile( c );
exit(0);
// FGBucket b(-146.248360, 61.133950);
// c.set_bucket( b );
// construct_tile( c );
// exit(0);
if ( b_min == b_max ) {
c.set_bucket( b_min );

View file

@ -25,6 +25,7 @@
# include <config.h>
#endif
#include <Math/point3d.hxx>
#include <Misc/fgstream.hxx>
#include "match.hxx"
@ -41,9 +42,9 @@ FGMatch::~FGMatch( void ) {
// scan the specified share file for the specified information
void FGMatch::scan_share_file( const string& dir, const FGBucket& b,
neighbor_type n )
neighbor_type search, neighbor_type dest )
{
string file = dir + "/" + b.gen_index_str();
string file = dir + "/" + b.gen_base_path() + "/" + b.gen_index_str();
cout << "reading shared data from " << file << endl;
fg_gzifstream in( file );
@ -53,14 +54,22 @@ void FGMatch::scan_share_file( const string& dir, const FGBucket& b,
}
string target;
if ( n == SW_Corner ) {
if ( search == SW_Corner ) {
target = "sw_node";
} else if ( n == SE_Corner ) {
} else if ( search == SE_Corner ) {
target = "se_node";
} else if ( n == NE_Corner ) {
} else if ( search == NE_Corner ) {
target = "ne_node";
} else if ( n == NW_Corner ) {
} else if ( search == NW_Corner ) {
target = "nw_node";
} else if ( search == NORTH ) {
target = "n_node";
} else if ( search == SOUTH ) {
target = "s_node";
} else if ( search == EAST ) {
target = "e_node";
} else if ( search == WEST ) {
target = "w_node";
}
string key;
@ -73,39 +82,47 @@ void FGMatch::scan_share_file( const string& dir, const FGBucket& b,
in >> key;
in >> normal;
if ( n == SW_Corner ) {
if ( dest == SW_Corner ) {
sw_node = node;
sw_normal = normal;
sw_flag = true;
} else if ( n == SE_Corner ) {
} else if ( dest == SE_Corner ) {
se_node = node;
se_normal = normal;
se_flag = true;
} else if ( n == NE_Corner ) {
} else if ( dest == NE_Corner ) {
ne_node = node;
ne_normal = normal;
ne_flag = true;
} else if ( n == NW_Corner ) {
} else if ( dest == NW_Corner ) {
nw_node = node;
nw_normal = normal;
nw_flag = true;
} else if ( n == NORTH ) {
} else if ( dest == NORTH ) {
north_nodes.push_back(node);
north_normals.push_back(normal);
north_flat = true;
} else if ( n == SOUTH ) {
north_flag = true;
} else if ( dest == SOUTH ) {
south_nodes.push_back(node);
south_normals.push_back(normal);
south_flat = true;
} else if ( n == EAST ) {
south_flag = true;
} else if ( dest == EAST ) {
east_nodes.push_back(node);
east_normals.push_back(normal);
east_flat = true;
} else if ( n == WEST ) {
east_flag = true;
} else if ( dest == WEST ) {
west_nodes.push_back(node);
west_normals.push_back(normal);
west_flat = true;
west_flag = true;
}
} else if ( (target == "n_node") && (key == "n_null") ) {
south_flag = true;
} else if ( (target == "s_node") && (key == "s_null") ) {
north_flag = true;
} else if ( (target == "e_node") && (key == "e_null") ) {
west_flag = true;
} else if ( (target == "w_node") && (key == "w_null") ) {
east_flag = true;
}
}
}
@ -118,61 +135,60 @@ void FGMatch::load_shared( const FGConstruct& c, neighbor_type n ) {
double clon = b.get_center_lon();
double clat = b.get_center_lat();
string base = c.get_work_base() + ".shared/Scenery/" + b.gen_base_path();
string base = c.get_work_base() + ".shared/Scenery/";
FGBucket cb;
// test
scan_share_file( base, b, SE_Corner );
if ( n == SW_Corner ) {
cb = fgBucketOffset(clon, clat, -1, 0);
scan_share_file( base, cb, SE_Corner );
scan_share_file( base, cb, SE_Corner, n );
cb = fgBucketOffset(clon, clat, -1, -1);
scan_share_file( base, cb, NE_Corner );
scan_share_file( base, cb, NE_Corner, n );
cb = fgBucketOffset(clon, clat, 0, -1);
scan_share_file( base, cb, NW_Corner );
scan_share_file( base, cb, NW_Corner, n );
} else if ( n == SE_Corner ) {
cb = fgBucketOffset(clon, clat, 0, -1);
scan_share_file( base, cb, NE_Corner );
scan_share_file( base, cb, NE_Corner, n );
cb = fgBucketOffset(clon, clat, 1, -1);
scan_share_file( base, cb, NW_Corner );
scan_share_file( base, cb, NW_Corner, n );
cb = fgBucketOffset(clon, clat, 1, 0);
scan_share_file( base, cb, SW_Corner );
scan_share_file( base, cb, SW_Corner, n );
} else if ( n == NE_Corner ) {
cb = fgBucketOffset(clon, clat, 1, 0);
scan_share_file( base, cb, NW_Corner );
scan_share_file( base, cb, NW_Corner, n );
cb = fgBucketOffset(clon, clat, 1, 1);
scan_share_file( base, cb, SW_Corner );
scan_share_file( base, cb, SW_Corner, n );
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, SE_Corner );
scan_share_file( base, cb, SE_Corner, n );
} else if ( n == NW_Corner ) {
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, SW_Corner );
scan_share_file( base, cb, SW_Corner, n );
cb = fgBucketOffset(clon, clat, -1, 1);
scan_share_file( base, cb, SE_Corner );
scan_share_file( base, cb, SE_Corner, n );
cb = fgBucketOffset(clon, clat, -1, 0);
scan_share_file( base, cb, NE_Corner );
scan_share_file( base, cb, NE_Corner, n );
} else if ( n == NORTH ) {
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, SOUTH );
scan_share_file( base, cb, SOUTH, n );
} else if ( n == SOUTH ) {
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, NORTH );
cb = fgBucketOffset(clon, clat, 0, -1);
scan_share_file( base, cb, NORTH, n );
} else if ( n == EAST ) {
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, WEST );
cb = fgBucketOffset(clon, clat, 1, 0);
scan_share_file( base, cb, WEST, n );
} else if ( n == WEST ) {
cb = fgBucketOffset(clon, clat, 0, 1);
scan_share_file( base, cb, EAST );
cb = fgBucketOffset(clon, clat, -1, 0);
scan_share_file( base, cb, EAST, n );
}
}
// load any previously existing shared data from all neighbors
// load any previously existing shared data from all neighbors (if
// shared data for a component exists set that components flag to true
void FGMatch::load_neighbor_shared( FGConstruct& c ) {
cout << "Loading existing shared data from neighbor tiles" << endl;
// start with all flags false
sw_flag = se_flag = ne_flag = nw_flag = false;
north_flag = south_flag = east_flag = west_flag = false;
@ -244,17 +260,25 @@ void FGMatch::split_tile( FGConstruct& c ) {
nw_normal = normal;
}
} else if ( fabs(node.x() - min.x) < FG_EPSILON ) {
west_nodes.push_back( node );
west_normals.push_back( normal );
if ( ! west_flag ) {
west_nodes.push_back( node );
west_normals.push_back( normal );
}
} else if ( fabs(node.x() - max.x) < FG_EPSILON ) {
east_nodes.push_back( node );
east_normals.push_back( normal );
if ( ! east_flag ) {
east_nodes.push_back( node );
east_normals.push_back( normal );
}
} else if ( fabs(node.y() - min.y) < FG_EPSILON ) {
south_nodes.push_back( node );
south_normals.push_back( normal );
if ( ! south_flag ) {
south_nodes.push_back( node );
south_normals.push_back( normal );
}
} else if ( fabs(node.y() - max.y) < FG_EPSILON ) {
north_nodes.push_back( node );
north_normals.push_back( normal );
if ( ! north_flag ) {
north_nodes.push_back( node );
north_normals.push_back( normal );
}
} else {
body_nodes.push_back( node );
body_normals.push_back( normal );
@ -300,7 +324,8 @@ void FGMatch::split_tile( FGConstruct& c ) {
}
// write the shared edge points, normals, and segments for this tile
// write the new shared edge points, normals, and segments for this
// tile
void FGMatch::write_shared( FGConstruct& c ) {
string base = c.get_work_base();
FGBucket b = c.get_bucket();
@ -312,62 +337,109 @@ void FGMatch::write_shared( FGConstruct& c ) {
system(command.c_str());
cout << "FLAGS" << endl;
cout << "=====" << endl;
cout << "sw_flag = " << sw_flag << endl;
cout << "se_flag = " << se_flag << endl;
cout << "ne_flag = " << ne_flag << endl;
cout << "nw_flag = " << nw_flag << endl;
cout << "north_flag = " << north_flag << endl;
cout << "south_flag = " << south_flag << endl;
cout << "east_flag = " << east_flag << endl;
cout << "west_flag = " << west_flag << endl;
FILE *fp;
if ( (fp = fopen( file.c_str(), "w" )) == NULL ) {
cout << "ERROR: opening " << file << " for writing!" << endl;
exit(-1);
}
fprintf( fp, "sw_node %.6f %.6f %.6f\n",
sw_node.x(), sw_node.y(), sw_node.z() );
fprintf( fp, "sw_normal %.6f %.6f %.6f\n",
sw_normal.x(), sw_normal.y(), sw_normal.z() );
fprintf( fp, "se_node %.6f %.6f %.6f\n",
se_node.x(), se_node.y(), se_node.z() );
fprintf( fp, "se_normal %.6f %.6f %.6f\n",
se_normal.x(), se_normal.y(), se_normal.z() );
fprintf( fp, "nw_node %.6f %.6f %.6f\n",
nw_node.x(), nw_node.y(), nw_node.z() );
fprintf( fp, "nw_normal %.6f %.6f %.6f\n",
nw_normal.x(), nw_normal.y(), nw_normal.z() );
fprintf( fp, "ne_node %.6f %.6f %.6f\n",
ne_node.x(), ne_node.y(), ne_node.z() );
fprintf( fp, "ne_normal %.6f %.6f %.6f\n",
ne_normal.x(), ne_normal.y(), ne_normal.z() );
for ( int i = 0; i < (int)north_nodes.size(); ++i ) {
fprintf( fp, "n_node %.6f %.6f %.6f\n",
north_nodes[i].x(), north_nodes[i].y(), north_nodes[i].z() );
fprintf( fp, "n_normal %.6f %.6f %.6f\n",
north_normals[i].x(), north_normals[i].y(),
north_normals[i].z() );
if ( ! sw_flag ) {
fprintf( fp, "sw_node %.6f %.6f %.6f\n",
sw_node.x(), sw_node.y(), sw_node.z() );
fprintf( fp, "sw_normal %.6f %.6f %.6f\n",
sw_normal.x(), sw_normal.y(), sw_normal.z() );
}
for ( int i = 0; i < (int)south_nodes.size(); ++i ) {
fprintf( fp, "s_node %.6f %.6f %.6f\n",
south_nodes[i].x(), south_nodes[i].y(), south_nodes[i].z() );
fprintf( fp, "s_normal %.6f %.6f %.6f\n",
south_normals[i].x(), south_normals[i].y(),
south_normals[i].z() );
if ( ! se_flag ) {
fprintf( fp, "se_node %.6f %.6f %.6f\n",
se_node.x(), se_node.y(), se_node.z() );
fprintf( fp, "se_normal %.6f %.6f %.6f\n",
se_normal.x(), se_normal.y(), se_normal.z() );
}
for ( int i = 0; i < (int)east_nodes.size(); ++i ) {
fprintf( fp, "e_node %.6f %.6f %.6f\n",
east_nodes[i].x(), east_nodes[i].y(), east_nodes[i].z() );
fprintf( fp, "e_normal %.6f %.6f %.6f\n",
east_normals[i].x(), east_normals[i].y(),
east_normals[i].z() );
if ( ! nw_flag ) {
fprintf( fp, "nw_node %.6f %.6f %.6f\n",
nw_node.x(), nw_node.y(), nw_node.z() );
fprintf( fp, "nw_normal %.6f %.6f %.6f\n",
nw_normal.x(), nw_normal.y(), nw_normal.z() );
}
for ( int i = 0; i < (int)west_nodes.size(); ++i ) {
fprintf( fp, "w_node %.6f %.6f %.6f\n",
west_nodes[i].x(), west_nodes[i].y(), west_nodes[i].z() );
fprintf( fp, "w_normal %.6f %.6f %.6f\n",
west_normals[i].x(), west_normals[i].y(),
west_normals[i].z() );
if ( ! ne_flag ) {
fprintf( fp, "ne_node %.6f %.6f %.6f\n",
ne_node.x(), ne_node.y(), ne_node.z() );
fprintf( fp, "ne_normal %.6f %.6f %.6f\n",
ne_normal.x(), ne_normal.y(), ne_normal.z() );
}
if ( ! north_flag ) {
if ( (int)north_nodes.size() == 0 ) {
fprintf( fp, "n_null -999.0 -999.0 -999.0\n" );
} else {
for ( int i = 0; i < (int)north_nodes.size(); ++i ) {
fprintf( fp, "n_node %.6f %.6f %.6f\n",
north_nodes[i].x(), north_nodes[i].y(),
north_nodes[i].z() );
fprintf( fp, "n_normal %.6f %.6f %.6f\n",
north_normals[i].x(), north_normals[i].y(),
north_normals[i].z() );
}
}
}
if ( ! south_flag ) {
if ( (int)south_nodes.size() == 0 ) {
fprintf( fp, "s_null -999.0 -999.0 -999.0\n" );
} else {
for ( int i = 0; i < (int)south_nodes.size(); ++i ) {
fprintf( fp, "s_node %.6f %.6f %.6f\n",
south_nodes[i].x(), south_nodes[i].y(),
south_nodes[i].z() );
fprintf( fp, "s_normal %.6f %.6f %.6f\n",
south_normals[i].x(), south_normals[i].y(),
south_normals[i].z() );
}
}
}
if ( ! east_flag ) {
if ( (int)east_nodes.size() == 0 ) {
fprintf( fp, "e_null -999.0 -999.0 -999.0\n" );
} else {
for ( int i = 0; i < (int)east_nodes.size(); ++i ) {
fprintf( fp, "e_node %.6f %.6f %.6f\n",
east_nodes[i].x(), east_nodes[i].y(),
east_nodes[i].z() );
fprintf( fp, "e_normal %.6f %.6f %.6f\n",
east_normals[i].x(), east_normals[i].y(),
east_normals[i].z() );
}
}
}
if ( ! west_flag ) {
if ( (int)west_nodes.size() == 0 ) {
fprintf( fp, "w_null -999.0 -999.0 -999.0\n" );
} else {
for ( int i = 0; i < (int)west_nodes.size(); ++i ) {
fprintf( fp, "w_node %.6f %.6f %.6f\n",
west_nodes[i].x(), west_nodes[i].y(),
west_nodes[i].z() );
fprintf( fp, "w_normal %.6f %.6f %.6f\n",
west_normals[i].x(), west_normals[i].y(),
west_normals[i].z() );
}
}
}
#if 0 // not needed
@ -408,3 +480,115 @@ void FGMatch::write_shared( FGConstruct& c ) {
command = "gzip --force --best " + file;
system(command.c_str());
}
// insert normal into vector, extending it first if needed
void insert_normal( point_list& normals, Point3D n, int i ) {
Point3D empty( 0.0 );
// extend vector if needed
while ( i >= (int)normals.size() ) {
normals.push_back( empty );
}
normals[i] = n;
}
// reassemble the tile pieces (combining the shared data and our own
// data)
void FGMatch::assemble_tile( FGConstruct& c ) {
FGTriNodes new_nodes;
new_nodes.clear();
point_list new_normals;
new_normals.clear();
FGTriSegments new_segs;
new_segs.clear();
// add the corner points
int sw_index = new_nodes.unique_add( sw_node );
insert_normal( new_normals, sw_normal, sw_index );
int se_index = new_nodes.unique_add( se_node );
insert_normal( new_normals, se_normal, se_index );
int ne_index = new_nodes.unique_add( ne_node );
insert_normal( new_normals, ne_normal, ne_index );
int nw_index = new_nodes.unique_add( nw_node );
insert_normal( new_normals, nw_normal, nw_index );
// add the edge points
int index;
for ( int i = 0; i < (int)north_nodes.size(); ++i ) {
index = new_nodes.unique_add( north_nodes[i] );
insert_normal( new_normals, north_normals[i], index );
}
for ( int i = 0; i < (int)south_nodes.size(); ++i ) {
index = new_nodes.unique_add( south_nodes[i] );
insert_normal( new_normals, south_normals[i], index );
}
for ( int i = 0; i < (int)east_nodes.size(); ++i ) {
index = new_nodes.unique_add( east_nodes[i] );
insert_normal( new_normals, east_normals[i], index );
}
for ( int i = 0; i < (int)west_nodes.size(); ++i ) {
index = new_nodes.unique_add( west_nodes[i] );
insert_normal( new_normals, west_normals[i], index );
}
// add the body points
for ( int i = 0; i < (int)body_nodes.size(); ++i ) {
index = new_nodes.unique_add( body_nodes[i] );
insert_normal( new_normals, body_normals[i], index );
}
// add the edge segments
new_segs.unique_divide_and_add( new_nodes.get_node_list(),
FGTriSeg(sw_index, se_index) );
new_segs.unique_divide_and_add( new_nodes.get_node_list(),
FGTriSeg(se_index, ne_index) );
new_segs.unique_divide_and_add( new_nodes.get_node_list(),
FGTriSeg(ne_index, nw_index) );
new_segs.unique_divide_and_add( new_nodes.get_node_list(),
FGTriSeg(nw_index, sw_index) );
// add the body segments
point_list geod_nodes = c.get_geod_nodes();
FGTriSeg seg;
Point3D p1, p2;
int n1, n2;
triseg_list_iterator current = body_segs.begin();
triseg_list_iterator last = body_segs.end();
for ( ; current != last; ++current ) {
seg = *current;
// get the original points (x,y,z)
p1 = geod_nodes[ seg.get_n1() ];
p2 = geod_nodes[ seg.get_n2() ];
// make sure these points are in the new node list (and get
// their new index)
n1 = new_nodes.unique_add( p1 );
n2 = new_nodes.unique_add( p2 );
// add the segment using the new indices
new_segs.unique_divide_and_add( new_nodes.get_node_list(),
FGTriSeg(n1, n2) );
}
c.set_tri_nodes( new_nodes );
c.set_point_normals( new_normals );
c.set_tri_segs( new_segs );
}

View file

@ -79,12 +79,14 @@ public:
// Destructor
~FGMatch( void );
// load any previously existing shared data from all neighbors
// load any previously existing shared data from all neighbors (if
// shared data for a component exists set that components flag to
// true
void load_neighbor_shared( FGConstruct& c );
// scan the specified share file for the specified information
void scan_share_file( const string& dir, const FGBucket& b,
neighbor_type n );
neighbor_type search, neighbor_type dest );
// try to find info for the specified shared component
void load_shared( const FGConstruct& c, neighbor_type n );
@ -95,8 +97,13 @@ public:
// current tile that already exists from a neighbor.
void split_tile( FGConstruct& c );
// write the shared edge points, normals, and segments for this tile
// write the new shared edge points, normals, and segments for
// this tile
void write_shared( FGConstruct& c );
// reassemble the tile pieces (combining the shared data and our
// own data)
void assemble_tile( FGConstruct& c );
};