1
0
Fork 0

Adapt to the removal of Point3D from simgear.

This commit is contained in:
Ralf Gerlich 2010-07-31 19:21:59 +02:00
parent f68f25e0c5
commit 4e9a529b1f
50 changed files with 668 additions and 126 deletions

View file

@ -36,7 +36,7 @@
#include <newmat/newmatap.h> // need matrix applications
#include <newmat/newmatio.h> // need matrix output routines
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
/***

View file

@ -29,6 +29,7 @@
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/SGGeometry.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/structure/exception.hxx>
@ -460,9 +461,6 @@ void build_airport( string airport_id, float alt_m,
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());
Point3D center_geod( b.get_center_lon() * SGD_DEGREES_TO_RADIANS,
b.get_center_lat() * SGD_DEGREES_TO_RADIANS, 0 );
Point3D gbs_center = sgGeodToCart( center_geod );
point_list beacons; beacons.clear();
for ( i = 0; i < (int)beacons_raw.size(); ++i ) {
@ -903,7 +901,6 @@ void build_airport( string airport_id, float alt_m,
group_list strips_tc; strips_tc.clear();
string_list strip_materials; strip_materials.clear();
Point3D tc;
int index;
int_list pt_v, tri_v, strip_v;
int_list pt_n, tri_n, strip_n;
@ -946,7 +943,7 @@ void build_airport( string airport_id, float alt_m,
index = normals.unique_add( vn );
tri_n.push_back( index );
tc = tri_txs.get_pt( i, j );
Point3D tc = tri_txs.get_pt( i, j );
index = texcoords.unique_add( tc );
tri_tc.push_back( index );
}
@ -958,7 +955,7 @@ void build_airport( string airport_id, float alt_m,
}
// add base points
point_list base_txs;
std::vector< SGVec2f > base_txs;
int_list base_tc;
for ( i = 0; i < base_tris.contours(); ++i ) {
tri_v.clear();
@ -976,14 +973,19 @@ void build_airport( string airport_id, float alt_m,
tris_n.push_back( tri_n );
tri_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, nodes.get_node_list(), tri_v );
base_txs = sgCalcTexCoords( b, geodNodes, tri_v );
base_tc.clear();
for ( j = 0; j < (int)base_txs.size(); ++j ) {
tc = base_txs[j];
SGVec2f tc = base_txs[j];
// SG_LOG(SG_GENERAL, SG_DEBUG, "base_tc = " << tc);
index = texcoords.simple_add( tc );
index = texcoords.simple_add( Point3D( tc.x(), tc.y(), 0 ) );
base_tc.push_back( index );
}
tris_tc.push_back( base_tc );
@ -1163,14 +1165,19 @@ void build_airport( string airport_id, float alt_m,
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, nodes.get_node_list(), strip_v );
base_txs = sgCalcTexCoords( b, geodNodes, strip_v );
base_tc.clear();
for ( j = 0; j < (int)base_txs.size(); ++j ) {
tc = base_txs[j];
SGVec2f tc = base_txs[j];
// SG_LOG(SG_GENERAL, SG_DEBUG, "base_tc = " << tc);
index = texcoords.simple_add( tc );
index = texcoords.simple_add( Point3D( tc.x(), tc.y(), 0 ) );
base_tc.push_back( index );
}
strips_tc.push_back( base_tc );
@ -1273,17 +1280,22 @@ void build_airport( string airport_id, float alt_m,
}
// calculate wgs84 mapping of nodes
point_list wgs84_nodes;
std::vector< SGVec3d > wgs84_nodes;
for ( i = 0; i < (int)geod_nodes.size(); ++i ) {
p.setx( geod_nodes[i].x() * SGD_DEGREES_TO_RADIANS );
p.sety( geod_nodes[i].y() * SGD_DEGREES_TO_RADIANS );
p.setz( geod_nodes[i].z() );
SG_LOG(SG_GENERAL, SG_DEBUG, "geod pt = " << geod_nodes[i] );
Point3D cart = sgGeodToCart( p );
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 );
}
float gbs_radius = sgCalcBoundingRadius( gbs_center, wgs84_nodes );
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 );
@ -1296,14 +1308,26 @@ void build_airport( string airport_id, float alt_m,
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.get_node_list() );
obj.set_texcoords( texcoords.get_node_list() );
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 );

View file

@ -35,6 +35,7 @@
using std::cout;
using std::endl;
using std::string;
// calculate the runway light direction vector. We take the center of

View file

@ -27,7 +27,7 @@
#include <simgear/math/sg_types.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
// convert a point from cartesian to polar coordinates

View file

@ -26,7 +26,7 @@
#define _POLY_EXTRA_HXX
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <Geometry/trinodes.hxx>
#include <Polygon/polygon.hxx>

View file

@ -29,13 +29,13 @@
#include <string>
#include <vector>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <Polygon/polygon.hxx>
struct TGRunway {
string rwy_no;
std::string rwy_no;
double lon;
double lat;
@ -47,9 +47,9 @@ struct TGRunway {
double stopway1;
double stopway2;
string lighting_flags;
std::string lighting_flags;
int surface_code;
string shoulder_code;
std::string shoulder_code;
int marking_code;
double smoothness;
bool dist_remaining;
@ -69,7 +69,7 @@ struct TGRunway {
};
typedef vector < TGRunway > runway_list;
typedef std::vector < TGRunway > runway_list;
typedef runway_list::iterator runway_list_iterator;
typedef runway_list::const_iterator const_runway_list_iterator;

View file

@ -29,6 +29,8 @@
#include "poly_extra.hxx"
#include "rwy_common.hxx"
using std::string;
void gen_number_block( const TGRunway& rwy_info,
const string& material,

View file

@ -34,7 +34,7 @@
void gen_number_block( const TGRunway& rwy_info,
const string& material,
const std::string& material,
TGPolygon poly, double heading, int num,
double start_pct, double end_pct,
superpoly_list *rwy_polys,
@ -45,7 +45,7 @@ void gen_number_block( const TGRunway& rwy_info,
void gen_runway_stopway( const TGRunway& rwy_info,
const TGPolygon& runway_a,
const TGPolygon& runway_b,
const string& prefix,
const std::string& prefix,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon* accum );
@ -57,8 +57,8 @@ void gen_runway_section( const TGRunway& rwy_info,
double startw_pct, double endw_pct,
double minu, double maxu, double minv, double maxv,
double heading,
const string& prefix,
const string& material,
const std::string& prefix,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -28,6 +28,8 @@
#include "rwy_common.hxx"
#include "rwy_nonprec.hxx"
using std::string;
// generate a non-precision approach runway. The routine modifies
// rwy_polys, texparams, and accum. For specific details and

View file

@ -40,7 +40,7 @@
void gen_non_precision_rwy( const TGRunway& rwy_info,
double alt_m,
const string& material,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -28,6 +28,8 @@
#include "rwy_common.hxx"
#include "rwy_nonprec.hxx"
using std::string;
// generate a precision approach runway. The routine modifies
// rwy_polys, texparams, and accum. For specific details and

View file

@ -40,7 +40,7 @@
void gen_precision_rwy( const TGRunway& rwy_info,
double alt_m,
const string& material,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -31,6 +31,8 @@
#include "texparams.hxx"
#include "rwy_nonprec.hxx"
using std::string;
// generate a simple runway. The routine modifies rwy_polys,
// texparams, and accum

View file

@ -37,7 +37,7 @@
// texparams, and accum
void gen_simple_rwy( const TGRunway& rwy_info,
double alt_m,
const string& material,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -29,6 +29,8 @@
#include "rwy_common.hxx"
#include "rwy_visual.hxx"
using std::string;
// generate a visual approach runway. The routine modifies rwy_polys,
// texparams, and accum. For specific details and dimensions of

View file

@ -40,7 +40,7 @@
void gen_visual_rwy( const TGRunway& rwy_info,
double alt_m,
const string& material,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -31,6 +31,8 @@
#include "texparams.hxx"
#include "taxiway.hxx"
using std::string;
// generate a taxiway. The routine modifies rwy_polys, texparams, and
// accum

View file

@ -37,7 +37,7 @@
// accum
void gen_taxiway( const TGRunway& rwy_info,
double alt_m,
const string& material,
const std::string& material,
superpoly_list *rwy_polys,
texparams_list *texparams,
TGPolygon *accum );

View file

@ -41,6 +41,7 @@
using std::cout;
using std::endl;
using std::string;
#define MASK_CLIP 1

View file

@ -29,6 +29,7 @@
using std::cout;
using std::endl;
using std::string;
int main( int argc, char **argv ) {

View file

@ -26,6 +26,7 @@
#include <simgear/compiler.h>
#include <simgear/io/sg_binobj.hxx>
#include <simgear/math/SGGeometry.hxx>
#include <simgear/misc/texcoord.hxx>
#include <Output/output.hxx>
@ -38,33 +39,20 @@
using std::cout;
using std::endl;
using std::string;
// calculate the global bounding sphere. Center is the center of the
// tile and zero elevation
void TGGenOutput::calc_gbs( TGConstruct& c ) {
double dist_squared;
double radius_squared = 0;
SGBucket b = c.get_bucket();
Point3D p( b.get_center_lon() * SGD_DEGREES_TO_RADIANS,
b.get_center_lat() * SGD_DEGREES_TO_RADIANS,
0 );
gbs_center = sgGeodToCart(p);
point_list wgs84_nodes = c.get_wgs84_nodes();
const_point_list_iterator current = wgs84_nodes.begin();
const_point_list_iterator last = wgs84_nodes.end();
for ( ; current != last; ++current ) {
dist_squared = gbs_center.distance3Dsquared(*current);
if ( dist_squared > radius_squared ) {
radius_squared = dist_squared;
}
SGSphered d;
for ( int i = 0; i < wgs84_nodes.size(); ++i ) {
d.expandBy(wgs84_nodes[ i ].toSGVec3d());
}
gbs_radius = sqrt(radius_squared);
gbs_center = d.getCenter();
gbs_radius = d.getRadius();
}
@ -203,27 +191,38 @@ int TGGenOutput::build( TGConstruct& c ) {
// cout << fans[i][j].size() << " === "
// << t_list.size() << endl;
SGBucket b = c.get_bucket();
point_list tp_list;
Point3D ourPosition;
ourPosition.setlon(b.get_chunk_lon());
ourPosition.setlat(b.get_chunk_lat());
int_list ti_list;
ti_list.clear();
//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)) ) {
point_list tp_list;
tp_list = UK_calc_tex_coords( b, geod_nodes, fans[i][j], 1.0 );
for ( int k = 0; k < (int)tp_list.size(); ++k ) {
// cout << " tc = " << tp_list[k] << endl;
int index = tex_coords.simple_add( tp_list[k] );
ti_list.push_back( index );
}
} else {
tp_list = sgCalcTexCoords( b, geod_nodes, fans[i][j] );
std::vector < SGGeod > convGeodNodes;
for ( j = 0; j < geod_nodes.size(); j++ ) {
Point3D node = geod_nodes[j];
convGeodNodes.push_back( SGGeod::fromDegM( node.x(), node.y(), node.z() ) );
}
std::vector< SGVec2f > tp_list = sgCalcTexCoords( b, convGeodNodes, fans[i][j] );
for ( j = 0; j < (int)tp_list.size(); ++j ) {
SGVec2f tc = tp_list[j];
// SG_LOG(SG_GENERAL, SG_DEBUG, "base_tc = " << tc);
int index = tex_coords.simple_add( Point3D( tc.x(), tc.y(), 0 ) );
ti_list.push_back( index );
}
}
int_list ti_list;
ti_list.clear();
for ( int k = 0; k < (int)tp_list.size(); ++k ) {
// cout << " tc = " << tp_list[k] << endl;
int index = tex_coords.simple_add( tp_list[k] );
ti_list.push_back( index );
}
textures[i].push_back( ti_list );
}
}
@ -455,14 +454,26 @@ int TGGenOutput::write( TGConstruct &c ) {
string name = b.gen_index_str();
name += ".btg";
point_list wgs84_nodes = c.get_wgs84_nodes();
point_list normals = c.get_point_normals();
std::vector< SGVec3d > wgs84_nodes;
for ( i = 0; i < c.get_wgs84_nodes().size(); i++ ) {
Point3D node = c.get_wgs84_nodes()[i];
wgs84_nodes.push_back( node.toSGVec3d() );
}
std::vector< SGVec3f > normals;
for ( i = 0; i < c.get_point_normals().size(); i++ ) {
Point3D node = c.get_point_normals()[i];
normals.push_back( node.toSGVec3f() );
}
cout << "dumping normals = " << normals.size() << endl;
/* for ( i = 0; i < (int)normals.size(); ++i ) {
Point3D p = normals[i];
printf("vn %.5f %.5f %.5f\n", p.x(), p.y(), p.z());
} */
point_list texcoords = tex_coords.get_node_list();
std::vector< SGVec2f > texcoords;
for ( i = 0; i < tex_coords.get_node_list().size(); i++ ) {
Point3D node = tex_coords.get_node_list()[i];
texcoords.push_back( node.toSGVec2f() );
}
// allocate and initialize triangle group structures
group_list tris_v; group_list tris_tc; string_list tri_materials;

View file

@ -34,7 +34,7 @@
#include <simgear/compiler.h>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/sg_types.hxx>
@ -66,7 +66,7 @@ private:
tex_list textures[TG_MAX_AREA_TYPES];
// global bounding sphere
Point3D gbs_center;
SGVec3d gbs_center;
double gbs_radius;
// calculate the global bounding sphere. Center is the average of

View file

@ -44,7 +44,6 @@
#include <simgear/constants.h>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/polar3d.hxx>
#include <Geometry/poly_support.hxx>
#include <Array/array.hxx>
@ -444,6 +443,14 @@ static double distance2D( const Point3D p1, const Point3D p2 ) {
return sqrt( dx*dx + dy*dy );
}
inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
double *course, double *dist )
{
SGGeoc gs = start.toSGGeoc();
SGGeoc gd = dest.toSGGeoc();
*course = SGGeoc::courseRad(gs, gd);
*dist = SGGeoc::distanceM(gs, gd);
}
// calculate spherical distance between two points (lon, lat specified
// in degrees, result returned in meters)

View file

@ -26,7 +26,7 @@
#endif
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>

View file

@ -89,7 +89,7 @@ public:
void load_missing_shared( TGConstruct& c );
// scan the specified share file for the specified information
void scan_share_file( const string& dir, const SGBucket& b,
void scan_share_file( const std::string& dir, const SGBucket& b,
neighbor_type search, neighbor_type dest );
// try to find info for the specified shared component

View file

@ -19,7 +19,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
//*******************************************************************
//

View file

@ -3,7 +3,7 @@
#include <simgear/bucket/newbucket.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_types.hxx>

View file

@ -1,5 +1,5 @@
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <iostream>

View file

@ -18,7 +18,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
//Returns true if a point is within the mainland UK, excluding
//Northern Ireland. Requires lat and lon to be passed in degrees.

View file

@ -30,6 +30,7 @@
using std::cout;
using std::endl;
using std::string;
// Constructor

View file

@ -31,7 +31,7 @@
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <Array/array.hxx>
#include <Main/construct.hxx>

View file

@ -12,4 +12,4 @@ testarray_LDADD = \
-lsgbucket -lsgmath -lsgmisc -lsgdebug -lsgxml \
$(support_LIBS) -lz
INCLUDES = -I$(top_srcdir)/src
INCLUDES = -I$(top_srcdir)/src/Lib

View file

@ -36,7 +36,7 @@
#include <simgear/compiler.h>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_types.hxx>
#include <simgear/misc/sgstream.hxx>
@ -74,13 +74,13 @@ public:
// Constructor
TGArray( void );
TGArray( const string& file );
TGArray( const std::string& file );
// Destructor
~TGArray( void );
// open an Array file (use "-" if input is coming from stdin)
bool open ( const string& file_base );
bool open ( const std::string& file_base );
// return if array was successfully opened or not
inline bool is_open() {
@ -98,7 +98,7 @@ public:
bool parse( SGBucket& b );
// write an Array file
bool write( const string root_dir, SGBucket& b );
bool write( const std::string root_dir, SGBucket& b );
// do our best to remove voids by picking data from the nearest
// neighbor.

View file

@ -13,6 +13,7 @@
using std::cout;
using std::endl;
using std::string;
#ifdef _MSC_VER
#define M_ISDIR _S_IFDIR

View file

@ -12,7 +12,7 @@
#endif
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <vector>

View file

@ -0,0 +1,460 @@
/**
* \file point3d.hxx
* A 3d point class (depricated). This class is depricated and we are
* in the process of removing all usage of it in favor of plib's "sg"
* library of point, vector, and math routines. Plib's sg lib is less
* object oriented, but integrates more seamlessly with opengl.
*
* Adapted from algebra3 by Jean-Francois Doue, started October 1998.
*/
// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#ifndef _POINT3D_HXX
#define _POINT3D_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <simgear/compiler.h>
#include <cassert>
#include <cmath>
#include <istream>
#include <ostream>
#include <vector>
#include <simgear/math/SGMath.hxx>
const double fgPoint3_Epsilon = 0.0000001;
enum {PX, PY, PZ}; // axes
// Kludge for msvc++ 6.0 - requires forward decls of friend functions.
class Point3D;
std::istream& operator>> ( std::istream&, Point3D& );
std::ostream& operator<< ( std::ostream&, const Point3D& );
Point3D operator- (const Point3D& p); // -p1
bool operator== (const Point3D& a, const Point3D& b); // p1 == p2?
/**
* 3D Point class.
*/
class Point3D {
protected:
double n[3];
public:
/** Default constructor */
Point3D();
Point3D(const double x, const double y, const double z);
explicit Point3D(const double d);
Point3D(const Point3D &p);
static Point3D fromSGGeod(const SGGeod& geod);
static Point3D fromSGGeoc(const SGGeoc& geoc);
static Point3D fromSGVec3(const SGVec3<double>& cart);
static Point3D fromSGVec3(const SGVec3<float>& cart);
static Point3D fromSGVec2(const SGVec2<double>& cart);
// Assignment operators
Point3D& operator = ( const Point3D& p ); // assignment of a Point3D
Point3D& operator += ( const Point3D& p ); // incrementation by a Point3D
Point3D& operator -= ( const Point3D& p ); // decrementation by a Point3D
Point3D& operator *= ( const double d ); // multiplication by a constant
Point3D& operator /= ( const double d ); // division by a constant
void setx(const double x);
void sety(const double y);
void setz(const double z);
void setlon(const double x);
void setlat(const double y);
void setradius(const double z);
void setelev(const double z);
// Queries
double& operator [] ( int i); // indexing
double operator[] (int i) const; // read-only indexing
inline const double *get_n() const { return n; };
double x() const; // cartesian x
double y() const; // cartesian y
double z() const; // cartesian z
double lon() const; // polar longitude
double lat() const; // polar latitude
double radius() const; // polar radius
double elev() const; // geodetic elevation (if specifying a surface point)
SGGeod toSGGeod(void) const;
SGGeoc toSGGeoc(void) const;
SGVec3d toSGVec3d(void) const;
SGVec3f toSGVec3f(void) const;
SGVec2f toSGVec2f(void) const;
// friends
friend Point3D operator - (const Point3D& p); // -p1
friend bool operator == (const Point3D& a, const Point3D& b); // p1 == p2?
friend std::istream& operator>> ( std::istream&, Point3D& );
friend std::ostream& operator<< ( std::ostream&, const Point3D& );
// Special functions
double distance3D(const Point3D& a) const; // distance between
double distance3Dsquared(const Point3D& a) const; // distance between ^ 2
};
// input from stream
inline std::istream&
operator >> ( std::istream& in, Point3D& p)
{
char c;
in >> p.n[PX];
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> p.n[PY];
// read past optional comma
while ( in.get(c) ) {
if ( (c != ' ') && (c != ',') ) {
// push back on the stream
in.putback(c);
break;
}
}
in >> p.n[PZ];
return in;
}
inline std::ostream&
operator<< ( std::ostream& out, const Point3D& p )
{
return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ];
}
///////////////////////////
//
// Point3D Member functions
//
///////////////////////////
// CONSTRUCTORS
inline Point3D::Point3D()
{
n[PX] = n[PY] = 0.0;
n[PZ] = -9999.0;
}
inline Point3D::Point3D(const double x, const double y, const double z)
{
n[PX] = x; n[PY] = y; n[PZ] = z;
}
inline Point3D::Point3D(const double d)
{
n[PX] = n[PY] = n[PZ] = d;
}
inline Point3D::Point3D(const Point3D& p)
{
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ];
}
inline Point3D Point3D::fromSGGeod(const SGGeod& geod)
{
Point3D pt;
pt.setlon(geod.getLongitudeRad());
pt.setlat(geod.getLatitudeRad());
pt.setelev(geod.getElevationM());
return pt;
}
inline Point3D Point3D::fromSGGeoc(const SGGeoc& geoc)
{
Point3D pt;
pt.setlon(geoc.getLongitudeRad());
pt.setlat(geoc.getLatitudeRad());
pt.setradius(geoc.getRadiusM());
return pt;
}
inline Point3D Point3D::fromSGVec3(const SGVec3<double>& cart)
{
Point3D pt;
pt.setx(cart.x());
pt.sety(cart.y());
pt.setz(cart.z());
return pt;
}
inline Point3D Point3D::fromSGVec3(const SGVec3<float>& cart)
{
Point3D pt;
pt.setx(cart.x());
pt.sety(cart.y());
pt.setz(cart.z());
return pt;
}
inline Point3D Point3D::fromSGVec2(const SGVec2<double>& cart)
{
Point3D pt;
pt.setx(cart.x());
pt.sety(cart.y());
pt.setz(0);
return pt;
}
// ASSIGNMENT OPERATORS
inline Point3D& Point3D::operator = (const Point3D& p)
{
n[PX] = p.n[PX]; n[PY] = p.n[PY]; n[PZ] = p.n[PZ]; return *this;
}
inline Point3D& Point3D::operator += ( const Point3D& p )
{
n[PX] += p.n[PX]; n[PY] += p.n[PY]; n[PZ] += p.n[PZ]; return *this;
}
inline Point3D& Point3D::operator -= ( const Point3D& p )
{
n[PX] -= p.n[PX]; n[PY] -= p.n[PY]; n[PZ] -= p.n[PZ]; return *this;
}
inline Point3D& Point3D::operator *= ( const double d )
{
n[PX] *= d; n[PY] *= d; n[PZ] *= d; return *this;
}
inline Point3D& Point3D::operator /= ( const double d )
{
double d_inv = 1./d; n[PX] *= d_inv; n[PY] *= d_inv; n[PZ] *= d_inv;
return *this;
}
inline void Point3D::setx(const double x) {
n[PX] = x;
}
inline void Point3D::sety(const double y) {
n[PY] = y;
}
inline void Point3D::setz(const double z) {
n[PZ] = z;
}
inline void Point3D::setlon(const double x) {
n[PX] = x;
}
inline void Point3D::setlat(const double y) {
n[PY] = y;
}
inline void Point3D::setradius(const double z) {
n[PZ] = z;
}
inline void Point3D::setelev(const double z) {
n[PZ] = z;
}
// QUERIES
inline double& Point3D::operator [] ( int i)
{
assert(! (i < PX || i > PZ));
return n[i];
}
inline double Point3D::operator [] ( int i) const {
assert(! (i < PX || i > PZ));
return n[i];
}
inline double Point3D::x() const { return n[PX]; }
inline double Point3D::y() const { return n[PY]; }
inline double Point3D::z() const { return n[PZ]; }
inline double Point3D::lon() const { return n[PX]; }
inline double Point3D::lat() const { return n[PY]; }
inline double Point3D::radius() const { return n[PZ]; }
inline double Point3D::elev() const { return n[PZ]; }
inline SGGeod Point3D::toSGGeod(void) const
{
SGGeod geod;
geod.setLongitudeRad(lon());
geod.setLatitudeRad(lat());
geod.setElevationM(elev());
return geod;
}
inline SGGeoc Point3D::toSGGeoc(void) const
{
SGGeoc geoc;
geoc.setLongitudeRad(lon());
geoc.setLatitudeRad(lat());
geoc.setRadiusM(radius());
return geoc;
}
inline SGVec3d Point3D::toSGVec3d(void) const
{
return SGVec3d(x(), y(), z());
}
inline SGVec3f Point3D::toSGVec3f(void) const
{
return SGVec3f(x(), y(), z());
}
inline SGVec2f Point3D::toSGVec2f(void) const
{
return SGVec2f(x(), y());
}
// FRIENDS
inline Point3D operator - (const Point3D& a)
{
return Point3D(-a.n[PX],-a.n[PY],-a.n[PZ]);
}
inline Point3D operator + (const Point3D& a, const Point3D& b)
{
return Point3D(a) += b;
}
inline Point3D operator - (const Point3D& a, const Point3D& b)
{
return Point3D(a) -= b;
}
inline Point3D operator * (const Point3D& a, const double d)
{
return Point3D(a) *= d;
}
inline Point3D operator * (const double d, const Point3D& a)
{
return a*d;
}
inline Point3D operator / (const Point3D& a, const double d)
{
return Point3D(a) *= (1.0 / d );
}
inline bool operator == (const Point3D& a, const Point3D& b)
{
return
fabs(a.n[PX] - b.n[PX]) < fgPoint3_Epsilon &&
fabs(a.n[PY] - b.n[PY]) < fgPoint3_Epsilon &&
fabs(a.n[PZ] - b.n[PZ]) < fgPoint3_Epsilon;
}
inline bool operator != (const Point3D& a, const Point3D& b)
{
return !(a == b);
}
// Special functions
inline double
Point3D::distance3D(const Point3D& a ) const
{
double x, y, z;
x = n[PX] - a.n[PX];
y = n[PY] - a.n[PY];
z = n[PZ] - a.n[PZ];
return sqrt(x*x + y*y + z*z);
}
inline double
Point3D::distance3Dsquared(const Point3D& a ) const
{
double x, y, z;
x = n[PX] - a.n[PX];
y = n[PY] - a.n[PY];
z = n[PZ] - a.n[PZ];
return(x*x + y*y + z*z);
}
typedef std::vector< Point3D > point_list;
typedef point_list::iterator point_list_iterator;
typedef point_list::const_iterator const_point_list_iterator;
inline Point3D sgCartToGeod( const Point3D& p )
{
SGGeod geod;
SGGeodesy::SGCartToGeod(SGVec3d(p.x(), p.y(), p.z()), geod);
return Point3D::fromSGGeod(geod);
}
inline Point3D sgGeodToCart(const Point3D& geod)
{
SGVec3<double> cart;
SGGeodesy::SGGeodToCart(SGGeod::fromRadM(geod.lon(), geod.lat(), geod.elev()), cart);
return Point3D::fromSGVec3(cart);
}
#endif // _POINT3D_HXX

View file

@ -27,7 +27,7 @@
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_types.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
@ -49,11 +49,12 @@ extern "C" {
#include "trinodes.hxx"
#include "trisegs.hxx"
using std::copy;
using std::cout;
using std::endl;
using std::sort;
using std::copy;
using std::ostream_iterator;
using std::sort;
using std::vector;
// Given a line segment specified by two endpoints p1 and p2, return
// the slope of the line.
@ -429,6 +430,13 @@ static void write_tree_element( TGContourNode *node, TGPolygon& p, int hole=0) {
}
}
class Point3DYOrdering {
public:
bool operator()(const Point3D& a, const Point3D& b) const {
return a.y()<b.y();
}
};
// recurse the contour tree and build up the point inside list for
// each contour/hole
static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
@ -471,7 +479,7 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
throw sg_exception("Polygon must have at least 2 contour points");
}
sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY));
sort(allpoints.begin(), allpoints.end(), Point3DYOrdering());
point_list::iterator point_it;

View file

@ -12,7 +12,7 @@
#endif
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <Polygon/polygon.hxx>

View file

@ -31,7 +31,7 @@
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_types.hxx>

View file

@ -22,7 +22,7 @@
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <iostream>

View file

@ -12,6 +12,8 @@
#include <Polygon/polygon.hxx>
using std::vector;
namespace tg {

View file

@ -12,7 +12,7 @@
#endif
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <string>

View file

@ -44,18 +44,18 @@
#include <Polygon/polygon.hxx>
void write_polygon( const TGPolygon& poly, const string& base );
void write_polygon( const TGPolygon& poly, const std::string& base );
// update index file (list of objects to be included in final scenery build)
void write_index( const string& base, const SGBucket& b, const string& name );
void write_index( const std::string& base, const SGBucket& b, const std::string& name );
// update index file (list of shared objects to be included in final
// scenery build)
void write_index_shared( const string &base, const SGBucket &b,
const Point3D &p, const string& name,
void write_index_shared( const std::string &base, const SGBucket &b,
const Point3D &p, const std::string& name,
const double &heading );
void write_boundary( const string& base, const SGBucket& b,
void write_boundary( const std::string& base, const SGBucket& b,
const TGPolygon& bounds, long int p_index );
#endif // _TG_OUTPUT_HXX

View file

@ -27,12 +27,14 @@
#define _TG_CHOP_HXX
#include <string>
#include "polygon.hxx"
// process polygon shape (chop up along tile boundaries and write each
// polygon piece to a file)
void tgChopNormalPolygon( const string& path, const string& poly_type,
void tgChopNormalPolygon( const std::string& path, const std::string& poly_type,
const TGPolygon& shape, bool preserve3d );
@ -40,7 +42,7 @@ void tgChopNormalPolygon( const string& path, const string& poly_type,
// polygon piece to a file) This has a front end to a crude clipper
// that doesn't handle holes so beware. This routine is appropriate
// for breaking down really huge structures if needed.
void tgChopBigSimplePolygon( const string& path, const string& poly_type,
void tgChopBigSimplePolygon( const std::string& path, const std::string& poly_type,
const TGPolygon& shape, bool preserve3d );
#endif // _TG_CHOP_HXX

View file

@ -31,7 +31,7 @@ extern "C" {
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/structure/exception.hxx>

View file

@ -32,7 +32,7 @@
#include <simgear/compiler.h>
#include <simgear/math/sg_types.hxx>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <iostream>
#include <string>

View file

@ -24,6 +24,7 @@
#ifndef _GSHHS_SPLIT_HXX
#define _GSHHS_SPLIT_HXX
#include <string>
#include <Polygon/polygon.hxx>
@ -31,13 +32,13 @@
// process shape front end ... split shape into lon = -180 ... 180,
// -360 ... -180, and 180 ... 360 ... shift the offset sections and
// process each separately
void split_and_shift_chunk( const string& path, const string& poly_type,
void split_and_shift_chunk( const std::string& path, const std::string& poly_type,
const TGPolygon& shape );
// process a large shape through my crude polygon splitter to reduce
// the polygon sizes before handing off to gpc
void gshhs_split_polygon( const string& path, const string& poly_type, TGPolygon& shape,
void gshhs_split_polygon( const std::string& path, const std::string& poly_type, TGPolygon& shape,
const double min, const double max );

View file

@ -35,7 +35,9 @@
#include <simgear/bucket/newbucket.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/io/sg_binobj.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/SGGeodesy.hxx>
#include <simgear/math/SGGeometry.hxx>
#include <simgear/math/SGMath.hxx>
#include <Array/array.hxx>
#include <Geometry/trinodes.hxx>
@ -237,31 +239,37 @@ int main( int argc, char **argv ) {
}
// wgs84 cartesian nodes
point_list wgs84_nodes; wgs84_nodes.clear();
std::vector< SGVec3d > wgs84_nodes; wgs84_nodes.clear();
for ( i = 0; i < (int)geod_nodes.size(); ++i ) {
Point3D p = Point3D( geod_nodes[i].x() * SGD_DEGREES_TO_RADIANS,
geod_nodes[i].y() * SGD_DEGREES_TO_RADIANS,
geod_nodes[i].z() );
cout << sgGeodToCart( p ) << endl;
wgs84_nodes.push_back( sgGeodToCart( p ) );
SGGeod geod;
geod = SGGeod::fromDegM( geod_nodes[i].x(), geod_nodes[i].y(), geod_nodes[i].z() );
SGVec3d cart = SGVec3d::fromGeod(geod);
cout << cart << endl;
wgs84_nodes.push_back( cart );
}
// bounding sphere
SGBucket b( (x0 + x2) / 2, (y0 + y2) / 2 );
Point3D center_geod( b.get_center_lon() * SGD_DEGREES_TO_RADIANS,
b.get_center_lat() * SGD_DEGREES_TO_RADIANS, 0 );
Point3D gbs_center = sgGeodToCart( center_geod );
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;
float gbs_radius = sgCalcBoundingRadius( gbs_center, wgs84_nodes );
// normals
point_list normals = wgs84_nodes;
sgdVec3 vn;
for ( i = 0; i < (int)normals.size(); ++i ) {
sgdSetVec3( vn, normals[i].x(), normals[i].y(), normals[i].z() );
sgdNormalizeVec3( vn );
normals[i] = Point3D( vn[0], vn[1], vn[2] );
// cout << normals[i] << endl;
std::vector< SGVec3f > normals;
for ( i = 0; i < (int)wgs84_nodes.size(); ++i ) {
normals.push_back(toVec3f(normalize( wgs84_nodes[i] )));
}
const point_list &tc_nodes = texcoords.get_node_list();
std::vector< SGVec2f > texcoords_vec;
for ( i = 0; i < (int)tc_nodes.size(); ++i )
{
texcoords_vec.push_back( SGVec2f( tc_nodes[i].x(), tc_nodes[i].y() ) );
}
// build the object
@ -281,7 +289,7 @@ int main( int argc, char **argv ) {
obj.set_gbs_radius( gbs_radius );
obj.set_wgs84_nodes( wgs84_nodes );
obj.set_normals( normals );
obj.set_texcoords( texcoords.get_node_list() );
obj.set_texcoords( texcoords_vec );
obj.set_tris_v( tris_v );
obj.set_tris_tc( tris_tc );
obj.set_tri_materials( tri_materials );

View file

@ -3,7 +3,7 @@
#endif
#include <simgear/compiler.h>
#include <simgear/math/point3d.hxx>
#include <Geometry/point3d.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/exception.hxx>

View file

@ -45,6 +45,8 @@
#include <ogrsf_frmts.h>
using std::string;
typedef std::map<std::string,OGRLayer*> LayerMap;
const char* format_name="ESRI Shapefile";
@ -265,7 +267,7 @@ void process_scenery_file(const std::string& path) {
return;
}
Point3D gbs_center = binObject.get_gbs_center();
SGVec3d gbs_center = binObject.get_gbs_center();
const std::vector<SGVec3d>& wgs84_nodes = binObject.get_wgs84_nodes();
std::vector<Point3D> geod_nodes;
const size_t node_count = wgs84_nodes.size();