Added support (contributed by David Luff) for UK OSBG36 coordinate systems as
it impacts texture coordinates.
This commit is contained in:
parent
522bff9911
commit
0283cdf05b
10 changed files with 221 additions and 40 deletions
|
@ -1,4 +1,4 @@
|
|||
EXTRA_DIST = README README.howto README.gpc acsite.m4 scenery_version.hxx \
|
||||
EXTRA_DIST = README README.howto README.gpc acsite.m4 \
|
||||
TerraGear.dsp TerraGear.dsw
|
||||
|
||||
SUBDIRS = src
|
||||
|
|
|
@ -301,6 +301,7 @@ AC_OUTPUT( \
|
|||
src/Construct/Match/Makefile \
|
||||
src/Construct/Triangulate/Makefile \
|
||||
src/Construct/Main/Makefile \
|
||||
src/Construct/Osgb36/Makefile \
|
||||
src/Construct/Parallel/Makefile \
|
||||
src/Lib/Makefile \
|
||||
src/Lib/Array/Makefile \
|
||||
|
|
|
@ -8,10 +8,11 @@ testclipper_SOURCES = testclipper.cxx
|
|||
|
||||
testclipper_LDADD = \
|
||||
$(top_builddir)/src/Construct/Clipper/libClipper.a \
|
||||
$(top_builddir)/src/Construct/Osgb36/libOsgb36.a \
|
||||
$(top_builddir)/src/Construct/Triangulate/libTriangulate.a \
|
||||
$(top_builddir)/src/Lib/Polygon/libPolygon.a \
|
||||
$(top_builddir)/src/Lib/landcover/liblandcover.a \
|
||||
$(top_builddir)/src/Lib/poly2tri/libpoly2tri.a \
|
||||
-lsgbucket -lsgdebug -lsgmisc -lz -lgpc
|
||||
|
||||
INCLUDES += -I$(top_srcdir)/src/Lib
|
||||
INCLUDES += -I$(top_srcdir)/src/Lib -I$(top_srcdir)/src/Construct
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <simgear/misc/sgstream.hxx>
|
||||
|
||||
#include <Polygon/names.hxx>
|
||||
#include <Osgb36/osgb36.hxx>
|
||||
|
||||
#include "clipper.hxx"
|
||||
|
||||
|
@ -142,6 +143,132 @@ bool FGClipper::load_polys(const string& path) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Load a polygon definition file containing osgb36 Eastings and Northings
|
||||
// and convert them to WGS84 Latitude and Longitude
|
||||
bool FGClipper::load_osgb36_polys(const string& path) {
|
||||
// cout << "Loading osgb36 poly\n";
|
||||
string poly_name;
|
||||
AreaType poly_type = DefaultArea;
|
||||
int contours, count, i, j;
|
||||
int hole_flag;
|
||||
double startx, starty, x, y, lastx, lasty;
|
||||
|
||||
SG_LOG( SG_CLIPPER, SG_INFO, "Loading " << path << " ..." );
|
||||
|
||||
sg_gzifstream in( path );
|
||||
|
||||
if ( !in ) {
|
||||
SG_LOG( SG_CLIPPER, SG_ALERT, "Cannot open file: " << path );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// gpc_polygon *poly = new gpc_polygon;
|
||||
// poly->num_contours = 0;
|
||||
// poly->contour = NULL;
|
||||
FGPolygon poly;
|
||||
|
||||
Point3D p;
|
||||
Point3D OSRef;
|
||||
Point3D OSLatLon;
|
||||
Point3D OSCartesian;
|
||||
Point3D WGS84Cartesian;
|
||||
in >> skipcomment;
|
||||
while ( !in.eof() ) {
|
||||
in >> poly_name;
|
||||
cout << "poly name = " << poly_name << endl;
|
||||
poly_type = get_area_type( poly_name );
|
||||
cout << "poly type (int) = " << (int)poly_type << endl;
|
||||
in >> contours;
|
||||
cout << "num contours = " << contours << endl;
|
||||
|
||||
poly.erase();
|
||||
|
||||
for ( i = 0; i < contours; ++i ) {
|
||||
in >> count;
|
||||
|
||||
if ( count < 3 ) {
|
||||
SG_LOG( SG_CLIPPER, SG_ALERT,
|
||||
"Polygon with less than 3 data points." );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
in >> hole_flag;
|
||||
|
||||
in >> startx;
|
||||
in >> starty;
|
||||
OSRef = Point3D(startx, starty, 0.0);
|
||||
|
||||
//Convert from OSGB36 Eastings/Northings to WGS84 Lat/Lon
|
||||
//Note that startx and starty themselves must not be altered since we compare them with unaltered lastx and lasty later
|
||||
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
||||
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
||||
WGS84Cartesian = ConvertOSGB36ToWGS84(OSCartesian);
|
||||
p = ConvertGRS80CartesianToPolar(WGS84Cartesian);
|
||||
|
||||
poly.add_node( i, p );
|
||||
SG_LOG( SG_CLIPPER, SG_BULK, "0 = "
|
||||
<< startx << ", " << starty );
|
||||
|
||||
for ( j = 1; j < count - 1; ++j ) {
|
||||
in >> x;
|
||||
in >> y;
|
||||
OSRef = Point3D( x, y, 0.0 );
|
||||
|
||||
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
||||
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
||||
WGS84Cartesian = ConvertOSGB36ToWGS84(OSCartesian);
|
||||
p = ConvertGRS80CartesianToPolar(WGS84Cartesian);
|
||||
|
||||
poly.add_node( i, p );
|
||||
SG_LOG( SG_CLIPPER, SG_BULK, j << " = " << x << ", " << y );
|
||||
}
|
||||
|
||||
in >> lastx;
|
||||
in >> lasty;
|
||||
|
||||
if ( (fabs(startx - lastx) < SG_EPSILON)
|
||||
&& (fabs(starty - lasty) < SG_EPSILON) ) {
|
||||
// last point same as first, discard
|
||||
} else {
|
||||
OSRef = Point3D( lastx, lasty, 0.0 );
|
||||
|
||||
OSLatLon = ConvertEastingsNorthingsToLatLon(OSRef);
|
||||
OSCartesian = ConvertAiry1830PolarToCartesian(OSLatLon);
|
||||
WGS84Cartesian = ConvertOSGB36ToWGS84(OSCartesian);
|
||||
p = ConvertGRS80CartesianToPolar(WGS84Cartesian);
|
||||
|
||||
poly.add_node( i, p );
|
||||
SG_LOG( SG_CLIPPER, SG_BULK, count - 1 << " = "
|
||||
<< lastx << ", " << lasty );
|
||||
}
|
||||
|
||||
// gpc_add_contour( poly, &v_list, hole_flag );
|
||||
}
|
||||
|
||||
in >> skipcomment;
|
||||
}
|
||||
|
||||
int area = (int)poly_type;
|
||||
|
||||
// if ( area == OceanArea ) {
|
||||
// TEST - Ignore
|
||||
// } else
|
||||
|
||||
if ( area < FG_MAX_AREA_TYPES ) {
|
||||
polys_in.polys[area].push_back(poly);
|
||||
} else {
|
||||
SG_LOG( SG_CLIPPER, SG_ALERT, "Polygon type out of range = "
|
||||
<< (int)poly_type);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// FILE *ofp= fopen("outfile", "w");
|
||||
// gpc_write_polygon(ofp, &polys.landuse);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add a polygon to the clipper.
|
||||
void FGClipper::add_poly( int area, const FGPolygon &poly )
|
||||
{
|
||||
|
|
|
@ -79,6 +79,9 @@ public:
|
|||
// Load a polygon definition file
|
||||
bool load_polys(const string& path);
|
||||
|
||||
// Load an Osgb36 polygon definition file
|
||||
bool load_osgb36_polys(const string& path);
|
||||
|
||||
// Add a polygon.
|
||||
void add_poly(int area, const FGPolygon &poly);
|
||||
|
||||
|
|
|
@ -24,14 +24,16 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <win32/mkdir.hpp>
|
||||
#endif
|
||||
|
||||
#include <simgear/io/sg_binobj.hxx>
|
||||
#include <simgear/misc/texcoord.hxx>
|
||||
|
||||
#include <Polygon/names.hxx>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <win32/mkdir.hpp>
|
||||
#endif
|
||||
#include <Osgb36/osgbtc.hxx>
|
||||
|
||||
#include "genobj.hxx"
|
||||
|
||||
|
@ -155,6 +157,16 @@ int_list FGGenOutput::calc_tex_coords( FGConstruct& c, point_list geod_nodes,
|
|||
#endif
|
||||
|
||||
|
||||
// This needs to get fixed!
|
||||
static int isInUK( Point3D p ) {
|
||||
cout << "Exited in isInUK() because the function was not defined!!!"
|
||||
<< endl;
|
||||
cout << "TerraGear/src/Construct/GenOutput/genobj.cxx: line # 164?"
|
||||
<< endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// build the necessary output structures based on the triangulation
|
||||
// data
|
||||
int FGGenOutput::build( FGConstruct& c ) {
|
||||
|
@ -199,8 +211,20 @@ int FGGenOutput::build( FGConstruct& c ) {
|
|||
// int_list t_list = calc_tex_coords( c, geod_nodes, fans[i][j] );
|
||||
// cout << fans[i][j].size() << " === "
|
||||
// << t_list.size() << endl;
|
||||
point_list tp_list = calc_tex_coords( c.get_bucket(),
|
||||
geod_nodes, fans[i][j] );
|
||||
SGBucket b = c.get_bucket();
|
||||
point_list tp_list;
|
||||
Point3D ourPosition;
|
||||
|
||||
ourPosition.setlon(b.get_lon());
|
||||
ourPosition.setlat(b.get_lat());
|
||||
|
||||
//dcl - here read the flag to check if we are building UK grid
|
||||
//If so - check if the bucket is within the UK lat & lon
|
||||
if( (c.get_useUKGrid()) && (isInUK(ourPosition)) )
|
||||
tp_list = UK_calc_tex_coords( b, geod_nodes, fans[i][j], 1.0 );
|
||||
else
|
||||
tp_list = calc_tex_coords( b, geod_nodes, fans[i][j] );
|
||||
|
||||
int_list ti_list;
|
||||
ti_list.clear();
|
||||
for ( int k = 0; k < (int)tp_list.size(); ++k ) {
|
||||
|
|
|
@ -8,6 +8,7 @@ fgfs_construct_LDADD = \
|
|||
$(top_builddir)/src/Construct/Clipper/libClipper.a \
|
||||
$(top_builddir)/src/Construct/GenOutput/libGenOutput.a \
|
||||
$(top_builddir)/src/Construct/Match/libMatch.a \
|
||||
$(top_builddir)/src/Construct/Osgb36/libOsgb36.a \
|
||||
$(top_builddir)/src/Construct/Triangulate/libTriangulate.a \
|
||||
$(top_builddir)/src/Lib/Array/libArray.a \
|
||||
$(top_builddir)/src/Lib/Geometry/libGeometry.a \
|
||||
|
|
|
@ -69,6 +69,10 @@ private:
|
|||
string work_base;
|
||||
string output_base;
|
||||
|
||||
// flag indicating whether to align texture coords within the UK
|
||||
// with the UK grid
|
||||
bool useUKGrid;
|
||||
|
||||
// detail level constraints
|
||||
int min_nodes;
|
||||
int max_nodes;
|
||||
|
@ -126,6 +130,10 @@ public:
|
|||
inline string get_output_base() const { return output_base; }
|
||||
inline void set_output_base( const string s ) { output_base = s; }
|
||||
|
||||
// UK grid flag
|
||||
inline bool get_useUKGrid() const { return useUKGrid; }
|
||||
inline void set_useUKGrid( const bool b ) { useUKGrid = b; }
|
||||
|
||||
// detail level constraints
|
||||
inline int get_min_nodes() const { return min_nodes; }
|
||||
inline void set_min_nodes( const int n ) { min_nodes = n; }
|
||||
|
|
|
@ -150,22 +150,26 @@ static int actual_load_polys( const string& dir,
|
|||
|
||||
// load all matching polygon files
|
||||
do {
|
||||
file = de.name;
|
||||
pos = file.find(".");
|
||||
f_index = file.substr(0, pos);
|
||||
file = de.name;
|
||||
pos = file.find(".");
|
||||
f_index = file.substr(0, pos);
|
||||
|
||||
if ( tile_str == f_index ) {
|
||||
ext = file.substr(pos + 1);
|
||||
cout << file << " " << f_index << " '" << ext << "'" << endl;
|
||||
full_path = dir + "/" + file;
|
||||
if ( (ext == "dem") || (ext == "dem.gz") ) {
|
||||
// skip
|
||||
} else {
|
||||
cout << "ext = '" << ext << "'" << endl;
|
||||
clipper.load_polys( full_path );
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
if ( tile_str == f_index ) {
|
||||
ext = file.substr(pos + 1);
|
||||
cout << file << " " << f_index << " '" << ext << "'" << endl;
|
||||
full_path = dir + "/" + file;
|
||||
if ( (ext == "dem") || (ext == "dem.gz") ) {
|
||||
// skip
|
||||
} else if (ext == "osgb36") {
|
||||
cout << "Loading osgb36 poly definition file\n";
|
||||
clipper.load_osgb36_polys( full_path );
|
||||
++counter;
|
||||
} else {
|
||||
cout << "ext = '" << ext << "'" << endl;
|
||||
clipper.load_polys( full_path );
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
} while ( _findnext( hfile, &de ) == 0 );
|
||||
|
||||
#else
|
||||
|
@ -180,22 +184,26 @@ static int actual_load_polys( const string& dir,
|
|||
|
||||
// load all matching polygon files
|
||||
while ( (de = readdir(d)) != NULL ) {
|
||||
file = de->d_name;
|
||||
pos = file.find(".");
|
||||
f_index = file.substr(0, pos);
|
||||
file = de->d_name;
|
||||
pos = file.find(".");
|
||||
f_index = file.substr(0, pos);
|
||||
|
||||
if ( tile_str == f_index ) {
|
||||
ext = file.substr(pos + 1);
|
||||
cout << file << " " << f_index << " '" << ext << "'" << endl;
|
||||
full_path = dir + "/" + file;
|
||||
if ( (ext == "dem") || (ext == "dem.gz") || (ext == "ind") ) {
|
||||
// skip
|
||||
} else {
|
||||
cout << "ext = '" << ext << "'" << endl;
|
||||
clipper.load_polys( full_path );
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
if ( tile_str == f_index ) {
|
||||
ext = file.substr(pos + 1);
|
||||
cout << file << " " << f_index << " '" << ext << "'" << endl;
|
||||
full_path = dir + "/" + file;
|
||||
if ( (ext == "dem") || (ext == "dem.gz") || (ext == "ind") ) {
|
||||
// skip
|
||||
} else if (ext == "osgb36") {
|
||||
cout << "Loading osgb36 poly definition file\n";
|
||||
clipper.load_osgb36_polys( full_path );
|
||||
++counter;
|
||||
} else {
|
||||
cout << "ext = '" << ext << "'" << endl;
|
||||
clipper.load_polys( full_path );
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
|
@ -970,7 +978,8 @@ static void usage( const string name ) {
|
|||
cout << " --lat=<degrees>" << endl;
|
||||
cout << " --xdist=<degrees>" << endl;
|
||||
cout << " --ydist=<degrees>" << endl;
|
||||
cout << "<load directory...>" << endl;
|
||||
cout << " --useUKgrid" << endl;
|
||||
cout << " ] <load directory...>" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -986,6 +995,10 @@ int main(int argc, char **argv) {
|
|||
double ydist = -1;
|
||||
long tile_id = -1;
|
||||
|
||||
// flag indicating whether UK grid should be used for in-UK
|
||||
// texture coordinate generation
|
||||
bool useUKgrid = false;
|
||||
|
||||
sglog().setLogLevels( SG_ALL, SG_DEBUG );
|
||||
|
||||
//
|
||||
|
@ -1013,6 +1026,8 @@ int main(int argc, char **argv) {
|
|||
ydist = atof(arg.substr(8).c_str());
|
||||
} else if (arg.find("--cover=") == 0) {
|
||||
cover = arg.substr(8);
|
||||
} else if (arg.find("--useUKgrid") == 0) {
|
||||
useUKgrid = true;
|
||||
} else if (arg.find("--") == 0) {
|
||||
usage(argv[0]);
|
||||
} else {
|
||||
|
@ -1069,14 +1084,14 @@ int main(int argc, char **argv) {
|
|||
c.set_cover( cover );
|
||||
c.set_work_base( work_dir );
|
||||
c.set_output_base( output_dir );
|
||||
c.set_useUKGrid( useUKgrid );
|
||||
|
||||
c.set_min_nodes( 50 );
|
||||
c.set_max_nodes( (int)(FG_MAX_NODES * 0.8) );
|
||||
|
||||
if (tile_id == -1) {
|
||||
if (xdist == -1 || ydist == -1) {
|
||||
// construct the tile around the
|
||||
// specified location
|
||||
// construct the tile around the specified location
|
||||
cout << "Building single tile at " << lat << ',' << lon << endl;
|
||||
SGBucket b( lon, lat );
|
||||
c.set_bucket( b );
|
||||
|
|
|
@ -3,6 +3,7 @@ SUBDIRS = \
|
|||
Clipper \
|
||||
GenOutput \
|
||||
Match \
|
||||
Osgb36 \
|
||||
Parallel \
|
||||
Main
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue