Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltHeader.h

Go to the documentation of this file.
00001 // Filename: fltHeader.h
00002 // Created by:  drose (24Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef FLTHEADER_H
00020 #define FLTHEADER_H
00021 
00022 #include "pandatoolbase.h"
00023 
00024 #include "fltBeadID.h"
00025 #include "fltVertex.h"
00026 #include "fltMaterial.h"
00027 #include "fltTexture.h"
00028 #include "fltLightSourceDefinition.h"
00029 #include "fltEyepoint.h"
00030 #include "fltTrackplane.h"
00031 #include "fltInstanceDefinition.h"
00032 
00033 #include "pathReplace.h"
00034 #include "pointerTo.h"
00035 #include "filename.h"
00036 #include "dSearchPath.h"
00037 #include "distanceUnit.h"
00038 #include "pvector.h"
00039 #include "pset.h"
00040 #include "pmap.h"
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //       Class : FltHeader
00044 // Description : This is the first bead in the file, the top of the
00045 //               bead hierarchy, and the primary interface to reading
00046 //               and writing a Flt file.  You always read a Flt file
00047 //               by creating a header and calling read_flt(), which
00048 //               fills in its children beads automatically; you write
00049 //               a Flt file by creating a header, adding its children,
00050 //               and calling write_flt().
00051 ////////////////////////////////////////////////////////////////////
00052 class FltHeader : public FltBeadID {
00053 public:
00054   FltHeader(PathReplace *path_replace);
00055 
00056   virtual void apply_converted_filenames();
00057 
00058   void set_path_replace(PathReplace *path_replace);
00059   PathReplace *get_path_replace();
00060   const PathReplace *get_path_replace() const;
00061   Filename convert_path(const Filename &orig_filename,
00062             const DSearchPath &additional_path = DSearchPath());
00063 
00064   void set_flt_filename(const Filename &flt_filename);
00065   const Filename &get_flt_filename() const;
00066 
00067   FltError read_flt(Filename filename);
00068   FltError read_flt(istream &in);
00069   FltError write_flt(Filename filename);
00070   FltError write_flt(ostream &out);
00071 
00072   enum AttrUpdate {
00073     AU_none,
00074     AU_if_missing,
00075     AU_always
00076   };
00077 
00078   void set_auto_attr_update(AttrUpdate attr);
00079   AttrUpdate get_auto_attr_update() const;
00080 
00081   enum Units {
00082     U_meters               = 0,
00083     U_kilometers           = 1,
00084     U_feet                 = 4,
00085     U_inches               = 5,
00086     U_nautical_miles       = 8
00087   };
00088 
00089   enum Flags {
00090     F_save_vertex_normals  = 0x80000000
00091   };
00092 
00093   enum ProjectionType {
00094     PT_flat_earth          = 0,
00095     PT_trapezoidal         = 1,
00096     PT_round_earth         = 2,
00097     PT_lambert             = 3,
00098     PT_utm                 = 4
00099   };
00100 
00101   enum VertexStorageType {
00102     VTS_double             = 1
00103   };
00104 
00105   enum DatabaseOrigin {
00106     DO_open_flight         = 100,
00107     DO_dig                 = 200,
00108     DO_es_ct6              = 300,
00109     DO_psp                 = 400,
00110     DO_ge_civ              = 600,
00111     DO_es_gdf              = 700,
00112   };
00113 
00114   enum EarthModel {
00115     EM_wgs84               = 0,
00116     EM_wgs72               = 1,
00117     EM_bessel              = 2,
00118     EM_clarke_1866         = 3,
00119     EM_nad27               = 4
00120   };
00121 
00122   int _format_revision_level;
00123   int _edit_revision_level;
00124   string _last_revision;
00125   int _next_group_id;
00126   int _next_lod_id;
00127   int _next_object_id;
00128   int _next_face_id;
00129   int _unit_multiplier;
00130   Units _vertex_units;
00131   bool _texwhite_new;
00132   unsigned int _flags;
00133   ProjectionType _projection_type;
00134   int _next_dof_id;
00135   VertexStorageType _vertex_storage_type;
00136   DatabaseOrigin _database_origin;
00137   double _sw_x, _sw_y;
00138   double _delta_x, _delta_y;
00139   int _next_sound_id;
00140   int _next_path_id;
00141   int _next_clip_id;
00142   int _next_text_id;
00143   int _next_bsp_id;
00144   int _next_switch_id;
00145   double _sw_lat, _sw_long;
00146   double _ne_lat, _ne_long;
00147   double _origin_lat, _origin_long;
00148   double _lambert_upper_lat, _lambert_lower_lat;
00149   int _next_light_id;
00150   int _next_road_id;
00151   int _next_cat_id;
00152   EarthModel _earth_model;
00153   int _next_adaptive_id;
00154   int _next_curve_id;
00155   double _delta_z;
00156   double _radius;
00157   int _next_mesh_id;
00158 
00159 public:
00160   int get_flt_version() const;
00161   void set_flt_version(int version);
00162   static int min_flt_version();
00163   static int max_flt_version();
00164   bool check_version() const;
00165 
00166   DistanceUnit get_units() const;
00167 
00168   // Accessors into the instance pool.
00169   bool has_instance(int instance_index) const;
00170   FltInstanceDefinition *get_instance(int instance_index) const;
00171   void clear_instances();
00172   void add_instance(FltInstanceDefinition *instance);
00173   void remove_instance(int instance_index);
00174 
00175 
00176   // Accessors into the vertex palette.
00177   int get_num_vertices() const;
00178   FltVertex *get_vertex(int n) const;
00179   void clear_vertices();
00180   void add_vertex(FltVertex *vertex);
00181 
00182   FltVertex *get_vertex_by_offset(int offset);
00183   int get_offset_by_vertex(FltVertex *vertex);
00184 
00185 
00186   // Accessors into the color palette.  This is read-only; why would
00187   // you want to mess with building a new color palette?
00188   int get_num_colors() const;
00189   Colorf get_color(int color_index) const;
00190   RGBColorf get_rgb(int color_index) const;
00191   bool has_color_name(int color_index) const;
00192   string get_color_name(int color_index) const;
00193 
00194   int get_closest_color(Colorf color) const;
00195   int get_closest_rgb(RGBColorf color) const;
00196 
00197   int get_num_color_entries() const;
00198   int get_num_color_shades() const;
00199 
00200   // These functions are mainly used behind-the-scenes to decode the
00201   // strange forest of color options defined for faces and vertices.
00202   Colorf get_color(int color_index, bool use_packed_color,
00203                    const FltPackedColor &packed_color,
00204                    int transparency);
00205   RGBColorf get_rgb(int color_index, bool use_packed_color,
00206                     const FltPackedColor &packed_color);
00207 
00208   // Accessors into the material palette.
00209   bool has_material(int material_index) const;
00210   FltMaterial *get_material(int material_index) const;
00211   void clear_materials();
00212   void add_material(FltMaterial *material);
00213   void remove_material(int material_index);
00214 
00215 
00216   // Accessors into the texture palette.
00217   bool has_texture(int texture_index) const;
00218   FltTexture *get_texture(int texture_index) const;
00219   void clear_textures();
00220   void add_texture(FltTexture *texture);
00221   void remove_texture(int texture_index);
00222 
00223 
00224   // Accessors into the light source palette.
00225   bool has_light_source(int light_index) const;
00226   FltLightSourceDefinition *get_light_source(int light_index) const;
00227   void clear_light_sources();
00228   void add_light_source(FltLightSourceDefinition *light_source);
00229   void remove_light_source(int light_index);
00230 
00231 
00232   // Accessors into the eyepoint/trackplane palette.
00233   bool got_eyepoint_trackplane_palette() const;
00234   void set_eyepoint_trackplane_palette(bool flag);
00235 
00236   int get_num_eyepoints() const;
00237   FltEyepoint *get_eyepoint(int n);
00238   int get_num_trackplanes() const;
00239   FltTrackplane *get_trackplane(int n);
00240 
00241 private:
00242   // Instance subtrees.  These are standalone subtrees, which may be
00243   // referenced by various points in the hierarchy, stored by instance
00244   // ID number.
00245   typedef pmap<int, PT(FltInstanceDefinition)> Instances;
00246   Instances _instances;
00247 
00248 
00249   // Support for the vertex palette.
00250   int update_vertex_lookups();
00251 
00252   typedef pvector<PT(FltVertex)> Vertices;
00253   typedef pset<FltVertex *> UniqueVertices;
00254 
00255   typedef pmap<int, FltVertex *> VerticesByOffset;
00256   typedef pmap<FltVertex *, int> OffsetsByVertex;
00257 
00258   Vertices _vertices;
00259   UniqueVertices _unique_vertices;
00260   VerticesByOffset _vertices_by_offset;
00261   OffsetsByVertex _offsets_by_vertex;
00262 
00263   bool _vertex_lookups_stale;
00264 
00265   // This is maintained while the header is being read, to map the
00266   // vertices to their corresponding offsets in the vertex palette.
00267   int _current_vertex_offset;
00268 
00269 
00270   // Support for the color palette.
00271   bool _got_color_palette;
00272   typedef pvector<FltPackedColor> Colors;
00273   typedef pmap<int, string> ColorNames;
00274   Colors _colors;
00275   ColorNames _color_names;
00276 
00277 
00278   // Support for the material palette.
00279   bool _got_14_material_palette;
00280   typedef pmap<int, PT(FltMaterial)> Materials;
00281   Materials _materials;
00282 
00283 
00284   // Support for the texture palette.
00285   AttrUpdate _auto_attr_update;
00286   typedef pmap<int, PT(FltTexture)> Textures;
00287   Textures _textures;
00288 
00289 
00290   // Support for the light source palette.
00291   typedef pmap<int, PT(FltLightSourceDefinition)> LightSources;
00292   LightSources _light_sources;
00293 
00294 
00295   // Support for the eyepoint/trackplane palette.
00296   bool _got_eyepoint_trackplane_palette;
00297   FltEyepoint _eyepoints[10];
00298   FltTrackplane _trackplanes[10];
00299 
00300   // This pointer is used to resolve references in the flt file.
00301   PT(PathReplace) _path_replace;
00302   Filename _flt_filename;
00303 
00304 protected:
00305   virtual bool extract_record(FltRecordReader &reader);
00306   virtual bool extract_ancillary(FltRecordReader &reader);
00307 
00308   virtual bool build_record(FltRecordWriter &writer) const;
00309   virtual FltError write_ancillary(FltRecordWriter &writer) const;
00310 
00311 private:
00312   bool extract_vertex(FltRecordReader &reader);
00313   bool extract_color_palette(FltRecordReader &reader);
00314   bool extract_material(FltRecordReader &reader);
00315   bool extract_14_material_palette(FltRecordReader &reader);
00316   bool extract_texture(FltRecordReader &reader);
00317   bool extract_texture_map(FltRecordReader &reader);
00318   bool extract_light_source(FltRecordReader &reader);
00319   bool extract_eyepoint_palette(FltRecordReader &reader);
00320 
00321   FltError write_vertex_palette(FltRecordWriter &writer) const;
00322   FltError write_color_palette(FltRecordWriter &writer) const;
00323   FltError write_material_palette(FltRecordWriter &writer) const;
00324   FltError write_texture_palette(FltRecordWriter &writer) const;
00325   FltError write_light_source_palette(FltRecordWriter &writer) const;
00326   FltError write_eyepoint_palette(FltRecordWriter &writer) const;
00327 
00328 public:
00329   virtual TypeHandle get_type() const {
00330     return get_class_type();
00331   }
00332   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00333   static TypeHandle get_class_type() {
00334     return _type_handle;
00335   }
00336   static void init_type() {
00337     FltBeadID::init_type();
00338     register_type(_type_handle, "FltHeader",
00339                   FltBeadID::get_class_type());
00340   }
00341 
00342 private:
00343   static TypeHandle _type_handle;
00344 };
00345 
00346 #endif
00347 
00348 

Generated on Fri May 2 03:19:18 2003 for Panda-Tool by doxygen1.3