00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _SG_BINOBJ_HXX
00028 #define _SG_BINOBJ_HXX
00029
00030
00031 #include <plib/sg.h>
00032
00033 #include <simgear/compiler.h>
00034 #include <simgear/constants.h>
00035 #include <simgear/math/sg_types.hxx>
00036 #include <simgear/math/point3d.hxx>
00037 #include <simgear/bucket/newbucket.hxx>
00038
00039 #include <stdio.h>
00040 #include <time.h>
00041
00042 #include <list>
00043 #include <string>
00044
00045
00046
00048 typedef vector < int_list > group_list;
00049 typedef group_list::iterator group_list_iterator;
00050 typedef group_list::const_iterator const_group_list_iterator;
00051
00052
00054 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
00055
00056
00090 class SGBinObject {
00091 unsigned short version;
00092
00093 SGVec3d gbs_center;
00094 float gbs_radius;
00095
00096 std::vector<SGVec3d> wgs84_nodes;
00097 std::vector<SGVec4f> colors;
00098 std::vector<SGVec3f> normals;
00099 std::vector<SGVec2f> texcoords;
00100
00101 group_list pts_v;
00102 group_list pts_n;
00103 group_list pts_c;
00104 group_list pts_tc;
00105 string_list pt_materials;
00106
00107 group_list tris_v;
00108 group_list tris_n;
00109 group_list tris_c;
00110 group_list tris_tc;
00111 string_list tri_materials;
00112
00113 group_list strips_v;
00114 group_list strips_n;
00115 group_list strips_c;
00116 group_list strips_tc;
00117 string_list strip_materials;
00118
00119 group_list fans_v;
00120 group_list fans_n;
00121 group_list fans_c;
00122 group_list fans_tc;
00123 string_list fan_materials;
00124
00125 public:
00126
00127 inline unsigned short get_version() const { return version; }
00128
00129 inline Point3D get_gbs_center() const { return Point3D::fromSGVec3(gbs_center); }
00130 inline void set_gbs_center( const Point3D& p ) { gbs_center = p.toSGVec3d(); }
00131 inline const SGVec3d& get_gbs_center2() const { return gbs_center; }
00132 inline void set_gbs_center( const SGVec3d& p ) { gbs_center = p; }
00133
00134 inline float get_gbs_radius() const { return gbs_radius; }
00135 inline void set_gbs_radius( float r ) { gbs_radius = r; }
00136
00137 inline const std::vector<SGVec3d>& get_wgs84_nodes() const
00138 { return wgs84_nodes; }
00139 inline void set_wgs84_nodes( const std::vector<SGVec3d>& n )
00140 { wgs84_nodes = n; }
00141 inline void set_wgs84_nodes( const point_list& n )
00142 {
00143 wgs84_nodes.resize(n.size());
00144 for (unsigned i = 0; i < wgs84_nodes.size(); ++i)
00145 wgs84_nodes[i] = n[i].toSGVec3d();
00146 }
00147
00148 inline const std::vector<SGVec4f>& get_colors() const { return colors; }
00149 inline void set_colors( const std::vector<SGVec4f>& c ) { colors = c; }
00150 inline void set_colors( const point_list& c )
00151 {
00152 colors.resize(c.size());
00153 for (unsigned i = 0; i < colors.size(); ++i)
00154 colors[i] = SGVec4f(c[i].toSGVec3f(), 1);
00155 }
00156
00157 inline const std::vector<SGVec3f>& get_normals() const { return normals; }
00158 inline void set_normals( const std::vector<SGVec3f>& n ) { normals = n; }
00159 inline void set_normals( const point_list& n )
00160 {
00161 normals.resize(n.size());
00162 for (unsigned i = 0; i < normals.size(); ++i)
00163 normals[i] = n[i].toSGVec3f();
00164 }
00165
00166 inline const std::vector<SGVec2f>& get_texcoords() const { return texcoords; }
00167 inline void set_texcoords( const std::vector<SGVec2f>& t ) { texcoords = t; }
00168 inline void set_texcoords( const point_list& t )
00169 {
00170 texcoords.resize(t.size());
00171 for (unsigned i = 0; i < texcoords.size(); ++i)
00172 texcoords[i] = t[i].toSGVec2f();
00173 }
00174
00175 inline const group_list& get_pts_v() const { return pts_v; }
00176 inline void set_pts_v( const group_list& g ) { pts_v = g; }
00177 inline const group_list& get_pts_n() const { return pts_n; }
00178 inline void set_pts_n( const group_list& g ) { pts_n = g; }
00179 inline const group_list& get_pts_c() const { return pts_c; }
00180 inline void set_pts_c( const group_list& g ) { pts_c = g; }
00181 inline const group_list& get_pts_tc() const { return pts_tc; }
00182 inline void set_pts_tc( const group_list& g ) { pts_tc = g; }
00183 inline const string_list& get_pt_materials() const { return pt_materials; }
00184 inline void set_pt_materials( const string_list& s ) { pt_materials = s; }
00185
00186 inline const group_list& get_tris_v() const { return tris_v; }
00187 inline void set_tris_v( const group_list& g ) { tris_v = g; }
00188 inline const group_list& get_tris_n() const { return tris_n; }
00189 inline void set_tris_n( const group_list& g ) { tris_n = g; }
00190 inline const group_list& get_tris_c() const { return tris_c; }
00191 inline void set_tris_c( const group_list& g ) { tris_c = g; }
00192 inline const group_list& get_tris_tc() const { return tris_tc; }
00193 inline void set_tris_tc( const group_list& g ) { tris_tc = g; }
00194 inline const string_list& get_tri_materials() const { return tri_materials; }
00195 inline void set_tri_materials( const string_list& s ) { tri_materials = s; }
00196
00197 inline const group_list& get_strips_v() const { return strips_v; }
00198 inline void set_strips_v( const group_list& g ) { strips_v = g; }
00199 inline const group_list& get_strips_n() const { return strips_n; }
00200 inline void set_strips_n( const group_list& g ) { strips_n = g; }
00201 inline const group_list& get_strips_c() const { return strips_c; }
00202 inline void set_strips_c( const group_list& g ) { strips_c = g; }
00203
00204 inline const group_list& get_strips_tc() const { return strips_tc; }
00205 inline void set_strips_tc( const group_list& g ) { strips_tc = g; }
00206 inline const string_list& get_strip_materials() const { return strip_materials; }
00207 inline void set_strip_materials( const string_list& s ) { strip_materials = s; }
00208
00209 inline const group_list& get_fans_v() const { return fans_v; }
00210 inline void set_fans_v( const group_list& g ) { fans_v = g; }
00211 inline const group_list& get_fans_n() const { return fans_n; }
00212 inline void set_fans_n( const group_list& g ) { fans_n = g; }
00213 inline const group_list& get_fans_c() const { return fans_c; }
00214 inline void set_fans_c( const group_list& g ) { fans_c = g; }
00215
00216 inline const group_list& get_fans_tc() const { return fans_tc; }
00217 inline void set_fans_tc( const group_list& g ) { fans_tc = g; }
00218 inline const string_list& get_fan_materials() const { return fan_materials; }
00219 inline void set_fan_materials( const string_list& s ) { fan_materials = s; }
00220
00226 bool read_bin( const string& file );
00227
00237 bool write_bin( const string& base, const string& name, const SGBucket& b );
00238
00248 bool write_ascii( const string& base, const string& name,
00249 const SGBucket& b );
00250 };
00251
00252
00260 Point3D sgCalcCenter( point_list& wgs84_nodes );
00261
00262
00271 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
00272
00273
00274 #endif // _SG_BINOBJ_HXX