From 1b2915aa2a73317e9c53af968bad8c3c53f33bbb Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 26 Jul 2010 11:24:16 +0100 Subject: [PATCH] WIP - removing remaining users of Point3D. --- simgear/io/sg_binobj.cxx | 91 +++++++---------------------- simgear/io/sg_binobj.hxx | 58 ++---------------- simgear/math/sg_types.hxx | 16 +---- simgear/misc/texcoord.cxx | 67 ++++++++++----------- simgear/misc/texcoord.hxx | 7 ++- simgear/scene/material/mat.cxx | 10 ++-- simgear/scene/material/matmodel.cxx | 4 +- simgear/scene/tgdb/SGOceanTile.cxx | 22 ++++--- simgear/scene/tgdb/TileEntry.hxx | 7 --- simgear/scene/tgdb/obj.cxx | 2 +- 10 files changed, 89 insertions(+), 195 deletions(-) diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 3c321308..faed1e68 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -38,6 +38,7 @@ #include #include +#include #include "lowlevel.hxx" #include "sg_binobj.hxx" @@ -115,51 +116,6 @@ public: } }; - -// calculate the center of a list of points, by taking the halfway -// point between the min and max points. -Point3D sgCalcCenter( point_list& wgs84_nodes ) { - Point3D p, min, max; - - if ( wgs84_nodes.size() ) { - min = max = wgs84_nodes[0]; - } else { - min = max = Point3D( 0 ); - } - - for ( int i = 0; i < (int)wgs84_nodes.size(); ++i ) { - p = wgs84_nodes[i]; - - if ( p.x() < min.x() ) { min.setx( p.x() ); } - if ( p.y() < min.y() ) { min.sety( p.y() ); } - if ( p.z() < min.z() ) { min.setz( p.z() ); } - - if ( p.x() > max.x() ) { max.setx( p.x() ); } - if ( p.y() > max.y() ) { max.sety( p.y() ); } - if ( p.z() > max.z() ) { max.setz( p.z() ); } - } - - return ( min + max ) / 2.0; -} - -// calculate the bounding sphere. Center is the center of the -// tile and zero elevation -double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ) { - double dist_squared; - double radius_squared = 0; - - for ( int i = 0; i < (int)wgs84_nodes.size(); ++i ) { - dist_squared = center.distance3Dsquared( wgs84_nodes[i] ); - if ( dist_squared > radius_squared ) { - radius_squared = dist_squared; - } - } - - return sqrt(radius_squared); -} - - - // read object properties static void read_object( gzFile fp, int obj_type, @@ -1128,19 +1084,16 @@ bool SGBinObject::write_ascii( const string& base, const string& name, } // cout << "group = " << start << " to " << end - 1 << endl; - // make a list of points for the group - point_list group_nodes; - group_nodes.clear(); - SGVec3d bs_center; - double bs_radius = 0; - for ( i = start; i < end; ++i ) { - for ( j = 0; j < (int)tris_v[i].size(); ++j ) { - group_nodes.push_back( Point3D::fromSGVec3(wgs84_nodes[ tris_v[i][j] ]) ); - bs_center = sgCalcCenter( group_nodes ).toSGVec3d(); - bs_radius = sgCalcBoundingRadius( Point3D::fromSGVec3(bs_center), group_nodes ); - } - } - + SGSphered d; + for ( i = start; i < end; ++i ) { + for ( j = 0; j < (int)tris_v[i].size(); ++j ) { + d.expandBy(wgs84_nodes[ tris_v[i][j] ]); + } + } + + SGVec3d bs_center = d.getCenter(); + double bs_radius = d.getRadius(); + // write group headers fprintf(fp, "\n"); fprintf(fp, "# usemtl %s\n", material.c_str()); @@ -1179,18 +1132,16 @@ bool SGBinObject::write_ascii( const string& base, const string& name, } // cout << "group = " << start << " to " << end - 1 << endl; - // make a list of points for the group - point_list group_nodes; - group_nodes.clear(); - SGVec3d bs_center; - double bs_radius = 0; - for ( i = start; i < end; ++i ) { - for ( j = 0; j < (int)strips_v[i].size(); ++j ) { - group_nodes.push_back( Point3D::fromSGVec3(wgs84_nodes[ strips_v[i][j] ]) ); - bs_center = sgCalcCenter( group_nodes ).toSGVec3d(); - bs_radius = sgCalcBoundingRadius( Point3D::fromSGVec3(bs_center), group_nodes ); - } - } + + SGSphered d; + for ( i = start; i < end; ++i ) { + for ( j = 0; j < (int)tris_v[i].size(); ++j ) { + d.expandBy(wgs84_nodes[ tris_v[i][j] ]); + } + } + + SGVec3d bs_center = d.getCenter(); + double bs_radius = d.getRadius(); // write group headers fprintf(fp, "\n"); diff --git a/simgear/io/sg_binobj.hxx b/simgear/io/sg_binobj.hxx index be77d586..b4069491 100644 --- a/simgear/io/sg_binobj.hxx +++ b/simgear/io/sg_binobj.hxx @@ -45,7 +45,7 @@ /** STL Structure used to store object information */ -typedef vector < int_list > group_list; +typedef std::vector < int_list > group_list; typedef group_list::iterator group_list_iterator; typedef group_list::const_iterator const_group_list_iterator; @@ -126,9 +126,7 @@ public: inline unsigned short get_version() const { return version; } - inline Point3D get_gbs_center() const { return Point3D::fromSGVec3(gbs_center); } - inline void set_gbs_center( const Point3D& p ) { gbs_center = p.toSGVec3d(); } - inline const SGVec3d& get_gbs_center2() const { return gbs_center; } + inline const SGVec3d& get_gbs_center() const { return gbs_center; } inline void set_gbs_center( const SGVec3d& p ) { gbs_center = p; } inline float get_gbs_radius() const { return gbs_radius; } @@ -138,40 +136,16 @@ public: { return wgs84_nodes; } inline void set_wgs84_nodes( const std::vector& n ) { wgs84_nodes = n; } - inline void set_wgs84_nodes( const point_list& n ) - { - wgs84_nodes.resize(n.size()); - for (unsigned i = 0; i < wgs84_nodes.size(); ++i) - wgs84_nodes[i] = n[i].toSGVec3d(); - } inline const std::vector& get_colors() const { return colors; } inline void set_colors( const std::vector& c ) { colors = c; } - inline void set_colors( const point_list& c ) - { - colors.resize(c.size()); - for (unsigned i = 0; i < colors.size(); ++i) - colors[i] = SGVec4f(c[i].toSGVec3f(), 1); - } - + inline const std::vector& get_normals() const { return normals; } inline void set_normals( const std::vector& n ) { normals = n; } - inline void set_normals( const point_list& n ) - { - normals.resize(n.size()); - for (unsigned i = 0; i < normals.size(); ++i) - normals[i] = n[i].toSGVec3f(); - } - + inline const std::vector& get_texcoords() const { return texcoords; } inline void set_texcoords( const std::vector& t ) { texcoords = t; } - inline void set_texcoords( const point_list& t ) - { - texcoords.resize(t.size()); - for (unsigned i = 0; i < texcoords.size(); ++i) - texcoords[i] = t[i].toSGVec2f(); - } - + inline const group_list& get_pts_v() const { return pts_v; } inline void set_pts_v( const group_list& g ) { pts_v = g; } inline const group_list& get_pts_n() const { return pts_n; } @@ -249,26 +223,4 @@ public: const SGBucket& b ); }; - -/** - * \relates SGBinObject - * Calculate the center of a list of points, by taking the halfway - * point between the min and max points. - * @param wgs84_nodes list of points in wgs84 coordinates - * @return center point - */ -Point3D sgCalcCenter( point_list& wgs84_nodes ); - - -/** - * \relates SGBinObject - * Calculate the bounding sphere of a set of nodes. - * Center is the center of the tile and zero elevation. - * @param center center of our bounding radius - * @param wgs84_nodes list of points in wgs84 coordinates - * @return radius - */ -double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes ); - - #endif // _SG_BINOBJ_HXX diff --git a/simgear/math/sg_types.hxx b/simgear/math/sg_types.hxx index f413c26b..36a2a35a 100644 --- a/simgear/math/sg_types.hxx +++ b/simgear/math/sg_types.hxx @@ -38,28 +38,18 @@ #include #include -class Point3D; - -using std::vector; -using std::string; - /** STL vector list of ints */ -typedef vector < int > int_list; +typedef std::vector < int > int_list; typedef int_list::iterator int_list_iterator; typedef int_list::const_iterator const_int_list_iterator; /** STL vector list of doubles */ -typedef vector < double > double_list; +typedef std::vector < double > double_list; typedef double_list::iterator double_list_iterator; typedef double_list::const_iterator const_double_list_iterator; -/** STL vector list of Point3D */ -typedef vector < Point3D > point_list; -typedef point_list::iterator point_list_iterator; -typedef point_list::const_iterator const_point_list_iterator; - /** STL vector list of strings */ -typedef vector < string > string_list; +typedef std::vector < std::string > string_list; typedef string_list::iterator string_list_iterator; typedef string_list::const_iterator const_string_list_iterator; diff --git a/simgear/misc/texcoord.cxx b/simgear/misc/texcoord.cxx index 30af6eff..9246ad54 100644 --- a/simgear/misc/texcoord.cxx +++ b/simgear/misc/texcoord.cxx @@ -160,28 +160,28 @@ enter this in the official comments in case I forget again. :-) // return the basic unshifted/unmoded texture coordinate for a lat/lon -static inline Point3D basic_tex_coord( const Point3D& p, +static inline SGVec2f basic_tex_coord( const SGGeod& p, double degree_width, double degree_height, double scale ) { - return Point3D( p.x() * ( degree_width * scale / + return SGVec2f( p.getLongitudeDeg() * ( degree_width * scale / FG_STANDARD_TEXTURE_DIMENSION ), - p.y() * ( degree_height * scale / - FG_STANDARD_TEXTURE_DIMENSION ), - 0.0 ); + p.getLatitudeDeg() * ( degree_height * scale / + FG_STANDARD_TEXTURE_DIMENSION ) + ); } // traverse the specified fan/strip/list of vertices and attempt to // calculate "none stretching" texture coordinates -point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, +std::vector sgCalcTexCoords( const SGBucket& b, const std::vector& geod_nodes, const int_list& fan, double scale ) { return sgCalcTexCoords(b.get_center_lat(), geod_nodes, fan, scale); } -point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, +std::vector sgCalcTexCoords( double centerLat, const std::vector& geod_nodes, const int_list& fan, double scale ) { // cout << "calculating texture coordinates for a specific fan of size = " @@ -214,16 +214,16 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, // cout << "degree_height = " << degree_height << endl; // find min/max of fan - Point3D tmin, tmax, p, t; + SGVec2f tmin, tmax; bool first = true; int i; for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; + SGGeod p = geod_nodes[ fan[i] ]; // cout << "point p = " << p << endl; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "basic_tex_coord = " << t << endl; if ( first ) { @@ -231,16 +231,16 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, first = false; } else { if ( t.x() < tmin.x() ) { - tmin.setx( t.x() ); + tmin.x() = t.x(); } if ( t.y() < tmin.y() ) { - tmin.sety( t.y() ); + tmin.y() = t.y(); } if ( t.x() > tmax.x() ) { - tmax.setx( t.x() ); + tmax.x() = t.x(); } if ( t.y() > tmax.y() ) { - tmax.sety( t.y() ); + tmax.y() = t.y(); } } } @@ -256,30 +256,31 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, // but is the best we can do. // cout << "SHIFTING" << endl; if ( tmin.x() < 0 ) { - tmin.setx( (double)( (int)tmin.x() - 1 ) ); + tmin.x() = (double)( (int)tmin.x() - 1 ) ; } else { - tmin.setx( (int)tmin.x() ); + tmin.x() = (int)tmin.x(); } + if ( tmin.y() < 0 ) { - tmin.sety( (double)( (int)tmin.y() - 1 ) ); + tmin.y() = (double)( (int)tmin.y() - 1 ); } else { - tmin.sety( (int)tmin.y() ); + tmin.y() = (int)tmin.y(); } // cout << "found tmin = " << tmin << endl; } else { if ( tmin.x() < 0 ) { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } if ( tmin.y() < 0 ) { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } #if 0 // structure is small enough ... we can mod it so we can @@ -319,12 +320,12 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, } // generate tex_list - Point3D adjusted_t; - point_list tex; + SGVec2f adjusted_t; + std::vector tex; tex.clear(); for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGGeod p = geod_nodes[ fan[i] ]; + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "second t = " << t << endl; adjusted_t = t - tmin; @@ -342,12 +343,12 @@ point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, } #endif if ( adjusted_t.x() < SG_EPSILON ) { - adjusted_t.setx( 0.0 ); + adjusted_t.x() = 0.0; } if ( adjusted_t.y() < SG_EPSILON ) { - adjusted_t.sety( 0.0 ); + adjusted_t.y() = 0.0; } - adjusted_t.setz( 0.0 ); + // cout << "adjusted_t = " << adjusted_t << endl; tex.push_back( adjusted_t ); diff --git a/simgear/misc/texcoord.hxx b/simgear/misc/texcoord.hxx index a5d49bd4..20537922 100644 --- a/simgear/misc/texcoord.hxx +++ b/simgear/misc/texcoord.hxx @@ -36,6 +36,9 @@ #include #include +#include +#include +#include /** * Traverse the specified fan/strip/list of vertices and attempt to @@ -46,10 +49,10 @@ * @param scale (default = 1.0) scaling factor * @return list of texture coordinates */ -point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, +std::vector sgCalcTexCoords( const SGBucket& b, const std::vector& geod_nodes, const int_list& fan, double scale = 1.0 ); -point_list sgCalcTexCoords( double centerLat, const point_list& geod_nodes, +std::vector sgCalcTexCoords( double centerLat, const std::vector& geod_nodes, const int_list& fan, double scale = 1.0 ); diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 83b1a9fa..cc2d178a 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -119,7 +119,7 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, const SGPropertyNode *props) { // Gather the path(s) to the texture(s) - vector textures = props->getChildren("texture"); + std::vector textures = props->getChildren("texture"); for (unsigned int i = 0; i < textures.size(); i++) { string tname = textures[i]->getStringValue(); @@ -141,11 +141,11 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, } } - vector texturesets = props->getChildren("texture-set"); + std::vector texturesets = props->getChildren("texture-set"); for (unsigned int i = 0; i < texturesets.size(); i++) { _internal_state st( NULL, false, options ); - vector textures = texturesets[i]->getChildren("texture"); + std::vector textures = texturesets[i]->getChildren("texture"); for (unsigned int j = 0; j < textures.size(); j++) { string tname = textures[j]->getStringValue(); @@ -229,13 +229,13 @@ SGMaterial::read_properties(const SGReaderWriterXMLOptions* options, if (props->hasChild("effect")) effect = props->getStringValue("effect"); - vector object_group_nodes = + std::vector object_group_nodes = ((SGPropertyNode *)props)->getChildren("object-group"); for (unsigned int i = 0; i < object_group_nodes.size(); i++) object_groups.push_back(new SGMatModelGroup(object_group_nodes[i])); // read glyph table for taxi-/runway-signs - vector glyph_nodes = props->getChildren("glyph"); + std::vector glyph_nodes = props->getChildren("glyph"); for (unsigned int i = 0; i < glyph_nodes.size(); i++) { const char *name = glyph_nodes[i]->getStringValue("name"); if (name) diff --git a/simgear/scene/material/matmodel.cxx b/simgear/scene/material/matmodel.cxx index 93cbd494..0ac77543 100644 --- a/simgear/scene/material/matmodel.cxx +++ b/simgear/scene/material/matmodel.cxx @@ -65,7 +65,7 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m) } // Note all the model paths - vector path_nodes = node->getChildren("path"); + std::vector path_nodes = node->getChildren("path"); for (unsigned int i = 0; i < path_nodes.size(); i++) _paths.push_back(path_nodes[i]->getStringValue()); @@ -182,7 +182,7 @@ SGMatModelGroup::SGMatModelGroup (SGPropertyNode * node) : _range_m(node->getDoubleValue("range-m", 2000)) { // Load the object subnodes - vector object_nodes = + std::vector object_nodes = ((SGPropertyNode *)node)->getChildren("object"); for (unsigned int i = 0; i < object_nodes.size(); i++) { const SGPropertyNode * object_node = object_nodes[i]; diff --git a/simgear/scene/tgdb/SGOceanTile.cxx b/simgear/scene/tgdb/SGOceanTile.cxx index 337a3103..7e7b590c 100644 --- a/simgear/scene/tgdb/SGOceanTile.cxx +++ b/simgear/scene/tgdb/SGOceanTile.cxx @@ -81,7 +81,7 @@ public: SGVec3f normals[latPoints][lonPoints]; SGVec3d rel[latPoints][lonPoints]; - point_list geod_nodes; + std::vector geod_nodes; osg::Vec3Array* vl; osg::Vec3Array* nl; @@ -122,27 +122,31 @@ void OceanMesh::calcMesh(const SGVec3d& cartCenter, const SGQuatd& orient, } // Calculate texture coordinates - point_list geod_nodes(latPoints * lonPoints); - VectorArrayAdapter geodNodesArray(geod_nodes, lonPoints); + typedef std::vector GeodVector; + + GeodVector geod_nodes(latPoints * lonPoints); + VectorArrayAdapter geodNodesArray(geod_nodes, lonPoints); int_list rectangle(latPoints * lonPoints); VectorArrayAdapter rectArray(rectangle, lonPoints); for (int j = 0; j < latPoints; j++) { for (int i = 0; i < lonPoints; i++) { - geodNodesArray(j, i) = Point3D(geod[j][i].getLongitudeDeg(), - geod[j][i].getLatitudeDeg(), - geod[j][i].getElevationM()); + geodNodesArray(j, i) = geod[j][i]; rectArray(j, i) = j * 5 + i; } } - point_list texs = sgCalcTexCoords( clat, geod_nodes, rectangle, + + typedef std::vector Vec2Array; + Vec2Array texs = sgCalcTexCoords( clat, geod_nodes, rectangle, 1000.0 / tex_width ); - VectorArrayAdapter texsArray(texs, lonPoints); + + + VectorArrayAdapter texsArray(texs, lonPoints); for (int j = 0; j < latPoints; j++) { for (int i = 0; i < lonPoints; ++i) { vlArray(j, i) = toOsg(rel[j][i]); nlArray(j, i) = toOsg(normals[j][i]); - tlArray(j, i) = toOsg(texsArray(j, i).toSGVec2f()); + tlArray(j, i) = toOsg(texsArray(j, i)); } } diff --git a/simgear/scene/tgdb/TileEntry.hxx b/simgear/scene/tgdb/TileEntry.hxx index 5fc69827..55c6e317 100644 --- a/simgear/scene/tgdb/TileEntry.hxx +++ b/simgear/scene/tgdb/TileEntry.hxx @@ -47,9 +47,6 @@ #include #endif -using std::string; -using std::vector; - namespace simgear { class ModelLoadHelper; @@ -64,10 +61,6 @@ public: SGBucket tile_bucket; std::string tileFileName; - typedef vector < Point3D > point_list; - typedef point_list::iterator point_list_iterator; - typedef point_list::const_iterator const_point_list_iterator; - private: // pointer to ssg range selector for this tile diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index fd6d42e2..4481b830 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -563,7 +563,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool if (!tile.read_bin(path)) return false; - SGVec3d center = tile.get_gbs_center2(); + SGVec3d center = tile.get_gbs_center(); SGGeod geodPos = SGGeod::fromCart(center); SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180); -- 2.39.5