From 39ea6404996cb1096605910226cecb41dc58fe59 Mon Sep 17 00:00:00 2001 From: PSadrozinski Date: Tue, 4 Oct 2011 18:38:43 -0400 Subject: [PATCH] cleanup airport.cxx and simple fix in linear features --- src/Airports/GenAirports850/airport.cxx | 1143 +---------------- src/Airports/GenAirports850/linearfeature.cxx | 1 + 2 files changed, 46 insertions(+), 1098 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 46bfb5c4..03b91108 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -44,6 +44,7 @@ Airport::Airport( int c, char* def) description = d; } +// TODO: fix OSG - it was nice, but unnecesary... void Airport::BuildOsg( osg::Group* airport ) { // draw for OSG @@ -71,7 +72,7 @@ void Airport::BuildOsg( osg::Group* airport ) } -// TODO: Add to object +// TODO: Add to runway object // calculate texture coordinates for runway section using the provided // texturing parameters. Returns a mirror polygon to the runway, // except each point is the texture coordinate of the corresponding @@ -81,8 +82,6 @@ static TGPolygon rwy_section_tex_coords( const TGPolygon& in_poly, const TGTexPa int i, j; TGPolygon result; result.erase(); - // double length = rwy.length * SG_FEET_TO_METER; - // double width = rwy.width * SG_FEET_TO_METER; Point3D ref = tp.get_ref(); double width = tp.get_width(); @@ -100,79 +99,77 @@ static TGPolygon rwy_section_tex_coords( const TGPolygon& in_poly, const TGTexPa double x, y, tx, ty; for ( i = 0; i < in_poly.contours(); ++i ) { - for ( j = 0; j < in_poly.contour_size( i ); ++j ) { - p = in_poly.get_pt( i, j ); - SG_LOG(SG_GENERAL, SG_DEBUG, "point = " << p); + for ( j = 0; j < in_poly.contour_size( i ); ++j ) { + p = in_poly.get_pt( i, j ); + SG_LOG(SG_GENERAL, SG_DEBUG, "point = " << p); - // - // 1. Calculate distance and bearing from the center of - // the runway - // + // + // 1. Calculate distance and bearing from the center of + // the runway + // - // given alt, lat1, lon1, lat2, lon2, calculate starting - // and ending az1, az2 and distance (s). Lat, lon, and - // azimuth are in degrees. distance in meters - double az1, az2, dist; - geo_inverse_wgs_84( 0, ref.y(), ref.x(), p.y(), p.x(), - &az1, &az2, &dist ); - SG_LOG(SG_GENERAL, SG_DEBUG, "basic course = " << az2); + // given alt, lat1, lon1, lat2, lon2, calculate starting + // and ending az1, az2 and distance (s). Lat, lon, and + // azimuth are in degrees. distance in meters + double az1, az2, dist; + geo_inverse_wgs_84( 0, ref.y(), ref.x(), p.y(), p.x(), + &az1, &az2, &dist ); + SG_LOG(SG_GENERAL, SG_DEBUG, "basic course = " << az2); - // - // 2. Rotate this back into a coordinate system where Y - // runs the length of the runway and X runs crossways. - // + // + // 2. Rotate this back into a coordinate system where Y + // runs the length of the runway and X runs crossways. + // - double course = az2 - heading; - while ( course < -360 ) { course += 360; } - while ( course > 360 ) { course -= 360; } - SG_LOG( SG_GENERAL, SG_DEBUG, + double course = az2 - heading; + while ( course < -360 ) { course += 360; } + while ( course > 360 ) { course -= 360; } + SG_LOG( SG_GENERAL, SG_DEBUG, " course = " << course << " dist = " << dist ); - // - // 3. Convert from polar to cartesian coordinates - // + // + // 3. Convert from polar to cartesian coordinates + // + + x = sin( course * SGD_DEGREES_TO_RADIANS ) * dist; + y = cos( course * SGD_DEGREES_TO_RADIANS ) * dist; + SG_LOG(SG_GENERAL, SG_DEBUG, " x = " << x << " y = " << y); - x = sin( course * SGD_DEGREES_TO_RADIANS ) * dist; - y = cos( course * SGD_DEGREES_TO_RADIANS ) * dist; - SG_LOG(SG_GENERAL, SG_DEBUG, " x = " << x << " y = " << y); - - // - // 4. Map x, y point into texture coordinates - // - double tmp; + // + // 4. Map x, y point into texture coordinates + // + double tmp; tmp = x / width; tx = tmp * (maxu - minu) + minu; - // tx = ((int)(tx * 100)) / 100.0; - SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ")"); + SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ")"); if ( clip_result) { if ( tx < 0.0 ) { tx = 0.0; } if ( tx > 1.0 ) { tx = 1.0; } } - // ty = (y - min.y()) / (max.y() - min.y()); - ty = y / length; + ty = y / length; tmp = y / length; ty = tmp * (maxv - minv) + minv; - // ty = ((int)(ty * 100)) / 100.0; - SG_LOG(SG_GENERAL, SG_DEBUG, " (" << ty << ")"); + SG_LOG(SG_GENERAL, SG_DEBUG, " (" << ty << ")"); if ( clip_result ) { if ( ty < 0.0 ) { ty = 0.0; } if ( ty > 1.0 ) { ty = 1.0; } } - t = Point3D( tx, ty, 0 ); - SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ", " << ty << ")"); + t = Point3D( tx, ty, 0 ); + SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ", " << ty << ")"); - result.add_node( i, t ); - } + result.add_node( i, t ); + } } return result; } +// TODO: add to linear feature class static TGPolygon linear_feature_tex_coords( const TGPolygon& in_poly, const TGTexParams& tp ) { int i, j; @@ -250,11 +247,6 @@ static TGPolygon linear_feature_tex_coords( const TGPolygon& in_poly, const TGTe SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ")"); -/* - ty = y / length; - tmp = y / length; - ty = tmp + minv; -*/ ty = (y/length) + minv; SG_LOG(SG_GENERAL, SG_DEBUG, " (" << ty << ")"); @@ -915,8 +907,6 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src ) } } - // need newmat.... - // Extend the area a bit so we don't have wierd things on the edges double dlon = max_deg.lon() - min_deg.lon(); double dlat = max_deg.lat() - min_deg.lat(); @@ -941,7 +931,7 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src ) SG_LOG(SG_GENERAL, SG_DEBUG, "Done with base calc_elevations()"); -#if 0 +#if 0 // TODO : along with taxiway sign elevations SG_LOG(SG_GENERAL, SG_INFO, "Computing beacon node elevations"); point_list beacon_nodes = calc_elevations( apt_surf, beacons, 0.0 ); SG_LOG(SG_GENERAL, SG_INFO, "Computing tower node elevations"); @@ -1225,7 +1215,7 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src ) // write out airport object reference write_index( objpath, b, name ); -#if 0 +#if 0 // TODO : along with taxiway signs // write out beacon references for ( i = 0; i < (int)beacon_nodes.size(); ++i ) { @@ -1266,1046 +1256,3 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src ) tgChopNormalPolygon( holepath, "Hole", divided_base, true ); tgChopNormalPolygon( holepath, "Airport", apt_clearing, false ); } - - -#if 0 // RFERENCE from GenApts.... - -// build 3d airport -void build_airport( string airport_id, float alt_m, - string_list& runways_raw, - string_list& beacons_raw, - string_list& towers_raw, - string_list& windsocks_raw, - const string& root, - const string_list& elev_src ) -{ - int i, j, k; - - superpoly_list rwy_polys; - texparams_list texparams; - - // poly_list rwy_tris, rwy_txs; - TGPolygon runway, runway_a, runway_b, clipped_a, clipped_b; - TGPolygon split_a, split_b; - TGPolygon apt_base; - TGPolygon apt_clearing; - Point3D p; - - TGPolygon accum; - accum.erase(); - - // parse main airport information - double apt_lon = 0.0, apt_lat = 0.0; - int rwy_count = 0; - - SG_LOG( SG_GENERAL, SG_INFO, "Building " << airport_id ); - - // parse runways/taxiways and generate the vertex list - runway_list runways; runways.clear(); - runway_list taxiways; taxiways.clear(); - - for ( i = 0; i < (int)runways_raw.size(); ++i ) { - ++rwy_count; - - string rwy_str = runways_raw[i]; - vector token = simgear::strutils::split( rwy_str ); - - TGRunway rwy; - - SG_LOG(SG_GENERAL, SG_DEBUG, rwy_str); - rwy.rwy_no = token[3]; - rwy.really_taxiway = (rwy.rwy_no == "xxx"); - rwy.generated = false; - - rwy.lat = atof( token[1].c_str() ); - apt_lat += rwy.lat; - - rwy.lon = atof( token[2].c_str() ); - apt_lon += rwy.lon; - - rwy.heading = atof( token[4].c_str() ); - - rwy.length = atoi( token[5].c_str() ); - rwy.width = atoi( token[8].c_str() ); - - - string rwy_displ_threshold = token[6]; - vector displ - = simgear::strutils::split( rwy_displ_threshold, "." ); - rwy.disp_thresh1 = atoi( displ[0].c_str() ); - rwy.disp_thresh2 = atoi( displ[1].c_str() ); - - string rwy_stopway = token[7]; - vector stop - = simgear::strutils::split( rwy_stopway, "." ); - rwy.stopway1 = atoi( stop[0].c_str() ); - rwy.stopway2 = atoi( stop[1].c_str() ); - - rwy.lighting_flags = token[9]; - rwy.surface_code = atoi( token[10].c_str() ); - rwy.shoulder_code = token[11]; - rwy.marking_code = atoi( token[12].c_str() ); - rwy.smoothness = atof( token[13].c_str() ); - rwy.dist_remaining = (atoi( token[14].c_str() ) == 1 ); - - if (token.size()>15) { - string vasi_angles = token[15]; - vector vasis = simgear::strutils::split( vasi_angles, "." ); - rwy.gs_angle1 = atof( vasis[0].c_str() ) * 0.01; - rwy.gs_angle2 = atof( vasis[1].c_str() ) * 0.01; - } else { - rwy.gs_angle1 = rwy.gs_angle2 = 3.0; - } - - SG_LOG( SG_GENERAL, SG_DEBUG, " no = " << rwy.rwy_no); - SG_LOG( SG_GENERAL, SG_DEBUG, " lat = " << rwy.lat); - SG_LOG( SG_GENERAL, SG_DEBUG, " lon = " << rwy.lon); - SG_LOG( SG_GENERAL, SG_DEBUG, " hdg = " << rwy.heading); - SG_LOG( SG_GENERAL, SG_DEBUG, " len = " << rwy.length); - SG_LOG( SG_GENERAL, SG_DEBUG, " width = " << rwy.width); - SG_LOG( SG_GENERAL, SG_DEBUG, " lighting = " << rwy.lighting_flags); - SG_LOG( SG_GENERAL, SG_DEBUG, " sfc = " << rwy.surface_code); - SG_LOG( SG_GENERAL, SG_DEBUG, " mrkgs = " << rwy.marking_code); - SG_LOG( SG_GENERAL, SG_DEBUG, " dspth1= " << rwy.disp_thresh1); - SG_LOG( SG_GENERAL, SG_DEBUG, " stop1 = " << rwy.stopway1); - SG_LOG( SG_GENERAL, SG_DEBUG, " dspth2= " << rwy.disp_thresh2); - SG_LOG( SG_GENERAL, SG_DEBUG, " stop2 = " << rwy.stopway2); - - if ( rwy.really_taxiway ) { - taxiways.push_back( rwy ); - } else { - runways.push_back( rwy ); - } - } - SG_LOG(SG_GENERAL, SG_INFO, "Runway count = " << runways.size() ); - SG_LOG(SG_GENERAL, SG_INFO, "Taxiway count = " << taxiways.size() ); - - - SGBucket b( apt_lon / (double)rwy_count, apt_lat / (double)rwy_count ); - SG_LOG(SG_GENERAL, SG_INFO, b.gen_base_path() << "/" << b.gen_index_str()); - - point_list beacons; beacons.clear(); - for ( i = 0; i < (int)beacons_raw.size(); ++i ) { - string beacon_str = beacons_raw[i]; - vector token = simgear::strutils::split( beacon_str ); - - Point3D beacon; - - SG_LOG(SG_GENERAL, SG_INFO, beacon_str); - - beacon.setlat( atof( token[1].c_str() ) ); - beacon.setlon( atof( token[2].c_str() ) ); - - SG_LOG( SG_GENERAL, SG_DEBUG, " beacon = " << beacon ); - - beacons.push_back( beacon ); - } - - point_list towers; towers.clear(); - for ( i = 0; i < (int)towers_raw.size(); ++i ) { - string tower_str = towers_raw[i]; - vector token = simgear::strutils::split( tower_str ); - - Point3D tower; - - SG_LOG(SG_GENERAL, SG_INFO, tower_str); - - tower.setlat( atof( token[1].c_str() ) ); - tower.setlon( atof( token[2].c_str() ) ); - - if (!atoi(token[4].c_str())) { - // Ralf Gerlich: Skip towers that shall not be drawn - continue; - } - - SG_LOG( SG_GENERAL, SG_DEBUG, " tower = " << tower ); - - towers.push_back( tower ); - } - - point_list windsocks; windsocks.clear(); - int_list windsock_types; windsock_types.clear(); - for ( i = 0; i < (int)windsocks_raw.size(); ++i ) { - string windsock_str = windsocks_raw[i]; - vector token = simgear::strutils::split( windsock_str ); - - Point3D windsock; - - SG_LOG(SG_GENERAL, SG_INFO, windsock_str); - - windsock.setlat( atof( token[1].c_str() ) ); - windsock.setlon( atof( token[2].c_str() ) ); - - string windsock_type = token[3]; - - SG_LOG( SG_GENERAL, SG_DEBUG, " windsock = " << windsock ); - - windsocks.push_back( windsock ); - if ( windsock_type == "0" ) { - windsock_types.push_back( 0 ); - } else { - windsock_types.push_back( 1 ); - } - } - - TGSuperPoly sp; - TGTexParams tp; - - - // First pass: generate the precision runways since these have - // precidence - for ( i = 0; i < (int)runways.size(); ++i ) { - if ( runways[i].marking_code == 3 /* Precision */ ) { - build_runway( runways[i], alt_m, - &rwy_polys, &texparams, &accum, - &apt_base, &apt_clearing ); - } - } - - // 2nd pass: generate the non-precision and visual runways - for ( i = 0; i < (int)runways.size(); ++i ) { - if ( runways[i].marking_code == 2 /* Non-precision */ - || runways[i].marking_code == 1 /* Visual */ ) - { - if ( runways[i].surface_code != 13 /* Water */ ) { - // only build non-water runways - build_runway( runways[i], alt_m, - &rwy_polys, &texparams, &accum, - &apt_base, &apt_clearing ); - } - } - } - - // 3rd pass: generate all remaining runways not covered in the first pass - for ( i = 0; i < (int)runways.size(); ++i ) { - if ( runways[i].marking_code != 3 /* Precision */ - && runways[i].marking_code != 2 /* Non-precision */ - && runways[i].marking_code != 1 /* Visual */ ) - { - if ( runways[i].surface_code != 6 /* Asphalt Helipad */ && - runways[i].surface_code != 7 /* Concrete Helipad */ && - runways[i].surface_code != 8 /* Turf Helipad */ && - runways[i].surface_code != 9 /* Dirt Helipad */ && - runways[i].surface_code != 13 /* Water/buoy runway */ ) - { - // only build non-water and non-heliport runways - build_runway( runways[i], alt_m, - &rwy_polys, &texparams, &accum, - &apt_base, &apt_clearing ); - } - } - } - - // 4th pass: generate all taxiways - -#if 0 - // we want to generate in order of largest size first so this will - // look a little weird, but that's all I'm doing, otherwise a - // simple list traversal would work fine. - bool done = false; - while ( !done ) { - // find the largest taxiway - int largest_idx = -1; - double max_size = 0; - for ( i = 0; i < (int)taxiways.size(); ++i ) { - SG_LOG( SG_GENERAL, SG_DEBUG, "taxiway i = " << i ); - double size = taxiways[i].length * taxiways[i].width; - if ( size > max_size && !taxiways[i].generated ) { - SG_LOG( SG_GENERAL, SG_DEBUG, "taxiway max i = " << i ); - max_size = size; - largest_idx = i; - } - } - - if ( largest_idx >= 0 ) { - SG_LOG( SG_GENERAL, SG_DEBUG, "generating " << largest_idx ); - build_runway( taxiways[largest_idx], alt_m, - &rwy_polys, &texparams, &accum, - &apt_base, &apt_clearing ); - taxiways[largest_idx].generated = true; - } else { - SG_LOG( SG_GENERAL, SG_DEBUG, "done with taxiways." ); - done = true; - } - } -#else - /* Ralf Gerlich: Generate Taxiways in specified order from bottom to top */ - for ( i=0; i geodNodes; - for ( j = 0; j < nodes.get_node_list().size(); j++ ) - { - Point3D node = nodes.get_node_list()[j]; - geodNodes.push_back( SGGeod::fromDegM( node.x(), node.y(), node.z() ) ); - } - base_txs.clear(); - base_txs = sgCalcTexCoords( b, geodNodes, tri_v ); - - base_tc.clear(); - for ( j = 0; j < (int)base_txs.size(); ++j ) - { - SGVec2f tc = base_txs[j]; - // SG_LOG(SG_GENERAL, SG_DEBUG, "base_tc = " << tc); - index = texcoords.simple_add( Point3D( tc.x(), tc.y(), 0 ) ); - base_tc.push_back( index ); - } - tris_tc.push_back( base_tc ); - } - - // on rare occasion, one or more of the divided base points can be - // missed. Make sure they are all in the node list so we can - // build a proper skirt. - - for ( i = 0; i < divided_base.contours(); ++i ) - { - for ( j = 0; j < divided_base.contour_size( i ); ++j ) - { - nodes.unique_add( divided_base.get_pt(i, j) ); - } - } - - // Now that we have assembled all the airport geometry nodes into - // a list, calculate an "average" airport elevation based on all - // the actual airport node points. This is more useful than - // calculating an average over the entire airport surface because - // it avoids biases introduced from the surrounding area if the - // airport is located in a bowl or on a hill. - - double average = tgAverageElevation( root, elev_src, nodes.get_node_list() ); - // cout << "average airport elevation = " << average << endl; - - // Now build the fitted airport surface ... - - // calculation min/max coordinates of airport area - Point3D min_deg(9999.0, 9999.0, 0), max_deg(-9999.0, -9999.0, 0); - for ( j = 0; j < (int)nodes.get_node_list().size(); ++j ) - { - Point3D p = nodes.get_node_list()[j]; - if ( p.lon() < min_deg.lon() ) - { - min_deg.setlon( p.lon() ); - } - if ( p.lon() > max_deg.lon() ) - { - max_deg.setlon( p.lon() ); - } - if ( p.lat() < min_deg.lat() ) - { - min_deg.setlat( p.lat() ); - } - if ( p.lat() > max_deg.lat() ) - { - max_deg.setlat( p.lat() ); - } - } - - // extend the min/max coordinates of airport area to cover all - // lights as well - for ( i = 0; i < (int)rwy_lights.size(); ++i ) - { - for ( j = 0; - j < (int)rwy_lights[i].get_poly().get_contour(0).size(); - ++j ) - { - Point3D p = rwy_lights[i].get_poly().get_contour(0)[j]; - if ( p.lon() < min_deg.lon() ) - { - min_deg.setlon( p.lon() ); - } - if ( p.lon() > max_deg.lon() ) - { - max_deg.setlon( p.lon() ); - } - if ( p.lat() < min_deg.lat() ) - { - min_deg.setlat( p.lat() ); - } - if ( p.lat() > max_deg.lat() ) - { - max_deg.setlat( p.lat() ); - } - } - } - - // Extend the area a bit so we don't have wierd things on the edges - double dlon = max_deg.lon() - min_deg.lon(); - double dlat = max_deg.lat() - min_deg.lat(); - min_deg.setlon( min_deg.lon() - 0.01 * dlon ); - max_deg.setlon( max_deg.lon() + 0.01 * dlon ); - min_deg.setlat( min_deg.lat() - 0.01 * dlat ); - max_deg.setlat( max_deg.lat() + 0.01 * dlat ); - cout << "min = " << min_deg << " max = " << max_deg << endl; - - TGAptSurface apt_surf( root, elev_src, min_deg, max_deg, average ); - SG_LOG(SG_GENERAL, SG_INFO, "Airport surface created"); - - // calculate node elevations - SG_LOG(SG_GENERAL, SG_INFO, "Computing airport node elevations"); - point_list geod_nodes = calc_elevations( apt_surf, - nodes.get_node_list(), - 0.0 ); - divided_base = calc_elevations( apt_surf, divided_base, 0.0 ); - SG_LOG(SG_GENERAL, SG_DEBUG, "DIVIDED"); - SG_LOG(SG_GENERAL, SG_DEBUG, divided_base); - - SG_LOG(SG_GENERAL, SG_DEBUG, "Done with base calc_elevations()"); - - SG_LOG(SG_GENERAL, SG_INFO, "Computing beacon node elevations"); - point_list beacon_nodes = calc_elevations( apt_surf, beacons, 0.0 ); - SG_LOG(SG_GENERAL, SG_INFO, "Computing tower node elevations"); - point_list tower_nodes = calc_elevations( apt_surf, towers, 0.0 ); - SG_LOG(SG_GENERAL, SG_INFO, "Computing windsock node elevations"); - point_list windsock_nodes = calc_elevations( apt_surf, windsocks, 0.0 ); - - // add base skirt (to hide potential cracks) - // - // this has to happen after we've calculated the node elevations - // but before we convert to wgs84 coordinates - int uindex, lindex; - - for ( i = 0; i < divided_base.contours(); ++i ) - { - strip_v.clear(); - strip_n.clear(); - strip_tc.clear(); - - // prime the pump ... - p = divided_base.get_pt( i, 0 ); - uindex = nodes.find( p ); - if ( uindex >= 0 ) - { - Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20); - SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower); - lindex = nodes.simple_add( lower ); - geod_nodes.push_back( lower ); - strip_v.push_back( lindex ); - strip_v.push_back( uindex ); - - // use 'the' normal. We are pushing on two nodes so we - // need to push on two normals. - index = normals.unique_add( vn ); - strip_n.push_back( index ); - strip_n.push_back( index ); - } - else - { - string message = "Ooops missing node when building skirt (in init)"; - SG_LOG( SG_GENERAL, SG_INFO, message << " " << p ); - throw sg_exception( message ); - } - - // loop through the list - for ( j = 1; j < divided_base.contour_size(i); ++j ) - { - p = divided_base.get_pt( i, j ); - uindex = nodes.find( p ); - if ( uindex >= 0 ) - { - Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20); - SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower); - lindex = nodes.simple_add( lower ); - geod_nodes.push_back( lower ); - strip_v.push_back( lindex ); - strip_v.push_back( uindex ); - - index = normals.unique_add( vn ); - strip_n.push_back( index ); - strip_n.push_back( index ); - } - else - { - string message = "Ooops missing node when building skirt (in loop)"; - SG_LOG( SG_GENERAL, SG_INFO, message << " " << p ); - throw sg_exception( message ); - } - } - - // close off the loop - p = divided_base.get_pt( i, 0 ); - uindex = nodes.find( p ); - if ( uindex >= 0 ) - { - Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20); - SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower); - lindex = nodes.simple_add( lower ); - geod_nodes.push_back( lower ); - strip_v.push_back( lindex ); - strip_v.push_back( uindex ); - - index = normals.unique_add( vn ); - strip_n.push_back( index ); - strip_n.push_back( index ); - } - else - { - string message = "Ooops missing node when building skirt (at end)"; - SG_LOG( SG_GENERAL, SG_INFO, message << " " << p ); - throw sg_exception( message ); - } - - strips_v.push_back( strip_v ); - strips_n.push_back( strip_n ); - strip_materials.push_back( "Grass" ); - - std::vector < SGGeod > geodNodes; - for ( j = 0; j < nodes.get_node_list().size(); j++ ) - { - Point3D node = nodes.get_node_list()[j]; - geodNodes.push_back( SGGeod::fromDegM( node.x(), node.y(), node.z() ) ); - } - base_txs.clear(); - base_txs = sgCalcTexCoords( b, geodNodes, strip_v ); - - base_tc.clear(); - for ( j = 0; j < (int)base_txs.size(); ++j ) - { - SGVec2f tc = base_txs[j]; - // SG_LOG(SG_GENERAL, SG_DEBUG, "base_tc = " << tc); - index = texcoords.simple_add( Point3D( tc.x(), tc.y(), 0 ) ); - base_tc.push_back( index ); - } - strips_tc.push_back( base_tc ); - } - -#if 0 - // add light points - - superpoly_list tmp_light_list; tmp_light_list.clear(); - typedef map < string, double, less > elev_map_type; - typedef elev_map_type::const_iterator const_elev_map_iterator; - elev_map_type elevation_map; - - SG_LOG(SG_GENERAL, SG_INFO, "Computing runway/approach lighting elevations"); - - // pass one, calculate raw elevations from Array - - for ( i = 0; i < (int)rwy_lights.size(); ++i ) - { - TGTriNodes light_nodes; - light_nodes.clear(); - point_list lights_v = rwy_lights[i].get_poly().get_contour(0); - for ( j = 0; j < (int)lights_v.size(); ++j ) - { - p = lights_v[j]; - index = light_nodes.simple_add( p ); - } - - // calculate light node elevations - - point_list geod_light_nodes = calc_elevations( apt_surf, light_nodes.get_node_list(), 0.5 ); - TGPolygon p; - p.add_contour( geod_light_nodes, 0 ); - TGSuperPoly s; - s.set_poly( p ); - tmp_light_list.push_back( s ); - - string flag = rwy_lights[i].get_flag(); - if ( flag != (string)"" ) - { - double max = -9999; - const_elev_map_iterator it = elevation_map.find( flag ); - if ( it != elevation_map.end() ) - { - max = elevation_map[flag]; - } - for ( j = 0; j < (int)geod_light_nodes.size(); ++j ) - { - if ( geod_light_nodes[j].z() > max ) - { - max = geod_light_nodes[j].z(); - } - } - elevation_map[flag] = max; - SG_LOG( SG_GENERAL, SG_DEBUG, flag << " max = " << max ); - } - } - - SG_LOG(SG_GENERAL, SG_INFO, "Done with lighting calc_elevations()"); - - // pass two, for each light group check if we need to lift (based - // on flag) and do so, then output next structures. - for ( i = 0; i < (int)rwy_lights.size(); ++i ) - { - // tmp_light_list is a parallel structure to rwy_lights - point_list geod_light_nodes = tmp_light_list[i].get_poly().get_contour(0); - - // this is a little round about, but what we want to calculate the - // light node elevations as ground + an offset so we do them - // seperately, then we add them back into nodes to get the index - // out, but also add them to geod_nodes to maintain consistancy - // between these two lists. - point_list light_normals = rwy_lights[i].get_normals().get_contour(0); - pt_v.clear(); - pt_n.clear(); - for ( j = 0; j < (int)geod_light_nodes.size(); ++j ) - { - p = geod_light_nodes[j]; - index = nodes.simple_add( p ); - pt_v.push_back( index ); - geod_nodes.push_back( p ); - - index = normals.unique_add( light_normals[j] ); - pt_n.push_back( index ); - } - pts_v.push_back( pt_v ); - pts_n.push_back( pt_n ); - pt_materials.push_back( rwy_lights[i].get_material() ); - } -#endif - - // calculate wgs84 mapping of nodes - std::vector< SGVec3d > wgs84_nodes; - for ( i = 0; i < (int)geod_nodes.size(); ++i ) - { - SGGeod geod = SGGeod::fromDegM( geod_nodes[i].x(), geod_nodes[i].y(), geod_nodes[i].z() ); - SG_LOG(SG_GENERAL, SG_DEBUG, "geod pt = " << geod_nodes[i] ); - SGVec3d cart = SGVec3d::fromGeod(geod); - SG_LOG(SG_GENERAL, SG_DEBUG, " cart pt = " << cart ); - wgs84_nodes.push_back( cart ); - } - SGSphered d; - for ( i = 0; i < wgs84_nodes.size(); ++i ) - { - d.expandBy(wgs84_nodes[ i ]); - } - - SGVec3d gbs_center = d.getCenter(); - double gbs_radius = d.getRadius(); - cout << "gbs center = " << gbs_center << endl; - SG_LOG(SG_GENERAL, SG_DEBUG, "Done with wgs84 node mapping"); - SG_LOG(SG_GENERAL, SG_DEBUG, " center = " << gbs_center << " radius = " << gbs_radius ); - - // null structures - group_list fans_v; fans_v.clear(); - group_list fans_n; fans_n.clear(); - group_list fans_tc; fans_tc.clear(); - string_list fan_materials; fan_materials.clear(); - - string objpath = root + "/AirportObj"; - string name = airport_id + ".btg"; - - std::vector< SGVec3f > normals_3f; - for ( i=0; i < normals.get_node_list().size(); i++ ) - { - Point3D node = normals.get_node_list()[i]; - normals_3f.push_back( node.toSGVec3f() ); - } - - std::vector< SGVec2f > texcoords_2f; - for ( i=0; i < texcoords.get_node_list().size(); i++ ) - { - Point3D node = texcoords.get_node_list()[i]; - texcoords_2f.push_back( node.toSGVec2f() ); - } - - SGBinObject obj; - - obj.set_gbs_center( gbs_center ); - obj.set_gbs_radius( gbs_radius ); - obj.set_wgs84_nodes( wgs84_nodes ); - obj.set_normals( normals_3f ); - obj.set_texcoords( texcoords_2f ); - obj.set_pts_v( pts_v ); - obj.set_pts_n( pts_n ); - obj.set_pt_materials( pt_materials ); - obj.set_tris_v( tris_v ); - obj.set_tris_n( tris_n ); - obj.set_tris_tc( tris_tc ); - obj.set_tri_materials( tri_materials ); - obj.set_strips_v( strips_v ); - obj.set_strips_n( strips_n ); - obj.set_strips_tc( strips_tc ); - obj.set_strip_materials( strip_materials ); - obj.set_fans_v( fans_v ); - obj.set_fans_n( fans_n ); - obj.set_fans_tc( fans_tc ); - obj.set_fan_materials( fan_materials ); - - bool result; - result = obj.write_bin( objpath, name, b ); - if ( !result ) - { - throw sg_exception("error writing file. :-("); - } - - // write out airport object reference - write_index( objpath, b, name ); - - // write out beacon references - for ( i = 0; i < (int)beacon_nodes.size(); ++i ) - { - write_index_shared( objpath, b, beacon_nodes[i], - "Models/Airport/beacon.xml", - 0.0 ); - } - - // write out tower references - for ( i = 0; i < (int)tower_nodes.size(); ++i ) - { - write_index_shared( objpath, b, tower_nodes[i], - "Models/Airport/tower.xml", - 0.0 ); - } - - // write out windsock references - for ( i = 0; i < (int)windsock_nodes.size(); ++i ) - { - if ( windsock_types[i] == 0 ) - { - write_index_shared( objpath, b, windsock_nodes[i], - "Models/Airport/windsock.xml", - 0.0 ); - } - else - { - write_index_shared( objpath, b, windsock_nodes[i], - "Models/Airport/windsock_lit.xml", - 0.0 ); - } - } - - string holepath = root + "/AirportArea"; - // long int poly_index = poly_index_next(); - // write_boundary( holepath, b, hull, poly_index ); - tgChopNormalPolygon( holepath, "Hole", divided_base, true ); - tgChopNormalPolygon( holepath, "Airport", apt_clearing, false ); -} -#endif - - diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index f03c67ca..94fd606b 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -451,6 +451,7 @@ int LinearFeature::Finish() int i, j; string material; int mat_idx = 0; + double cur_light_dist = 0.0f; // create the inner and outer boundaries to generate polys