Panda3D

sceneGraphAnalyzer.h

00001 // Filename: sceneGraphAnalyzer.h
00002 // Created by:  drose (02Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SCENEGRAPHANALYZER_H
00016 #define SCENEGRAPHANALYZER_H
00017 
00018 #include "pandabase.h"
00019 #include "typedObject.h"
00020 #include "luse.h"
00021 #include "pmap.h"
00022 #include "pset.h"
00023 #include "bitArray.h"
00024 #include "indirectCompareTo.h"
00025 
00026 class PandaNode;
00027 class GeomNode;
00028 class Geom;
00029 class GeomVertexData;
00030 class GeomVertexFormat;
00031 class GeomVertexArrayData;
00032 class Texture;
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //       Class : SceneGraphAnalyzer
00036 // Description : A handy class that can scrub over a scene graph and
00037 //               collect interesting statistics on it.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_PGRAPHNODES SceneGraphAnalyzer {
00040 PUBLISHED:
00041   SceneGraphAnalyzer();
00042   ~SceneGraphAnalyzer();
00043 
00044   enum LodMode {
00045     LM_lowest,
00046     LM_highest,
00047     LM_all,
00048     LM_none,
00049   };
00050 
00051   INLINE void set_lod_mode(LodMode lod_mode);
00052   INLINE LodMode get_lod_mode(LodMode lod_mode) const;
00053 
00054   void clear();
00055   void add_node(PandaNode *node);
00056 
00057   void write(ostream &out, int indent_level = 0) const;
00058 
00059   INLINE int get_num_nodes() const;
00060   INLINE int get_num_instances() const;
00061   INLINE int get_num_transforms() const;
00062   INLINE int get_num_nodes_with_attribs() const;
00063   INLINE int get_num_lod_nodes() const;
00064   INLINE int get_num_geom_nodes() const;
00065   INLINE int get_num_geoms() const;
00066   INLINE int get_num_geom_vertex_datas() const;
00067   INLINE int get_num_geom_vertex_formats() const;
00068   INLINE int get_vertex_data_size() const;
00069 
00070   INLINE int get_num_vertices() const;
00071   INLINE int get_num_normals() const;
00072   INLINE int get_num_colors() const;
00073   INLINE int get_num_texcoords() const;
00074   INLINE int get_num_tris() const;
00075   INLINE int get_num_lines() const;
00076   INLINE int get_num_points() const;
00077 
00078   INLINE int get_num_individual_tris() const;
00079   INLINE int get_num_tristrips() const;
00080   INLINE int get_num_triangles_in_strips() const;
00081   INLINE int get_num_trifans() const;
00082   INLINE int get_num_triangles_in_fans() const;
00083 
00084   INLINE int get_texture_bytes() const;
00085 
00086   INLINE int get_num_long_normals() const;
00087   INLINE int get_num_short_normals() const;
00088   INLINE PN_stdfloat get_total_normal_length() const;
00089 
00090 private:
00091   void collect_statistics(PandaNode *node, bool under_instance);
00092   void collect_statistics(GeomNode *geom_node);
00093   void collect_statistics(const Geom *geom);
00094   void collect_statistics(Texture *texture);
00095   void collect_statistics(const GeomVertexArrayData *vadata);
00096   void collect_prim_statistics(const GeomVertexArrayData *vadata);
00097 
00098   class VDataTracker {
00099   public:
00100     BitArray _referenced_vertices;
00101   };
00102 
00103   typedef pmap<PandaNode *, int> Nodes;
00104   typedef pmap<CPT(GeomVertexData), VDataTracker> VDatas;
00105   typedef pset<CPT(GeomVertexFormat) > VFormats;
00106   typedef pset<CPT(GeomVertexArrayData) > VADatas;
00107   typedef pmap<const GeomVertexData *, int, IndirectCompareTo<GeomVertexData> > UniqueVDatas;
00108   typedef pmap<const GeomVertexArrayData *, int, IndirectCompareTo<GeomVertexArrayData> > UniqueVADatas;
00109   typedef pmap<Texture *, int> Textures;
00110 
00111   LodMode _lod_mode;
00112 
00113   Nodes _nodes;
00114   VDatas _vdatas;
00115   VFormats _vformats;
00116   VADatas _vadatas;
00117   VADatas _prim_vadatas;
00118   UniqueVDatas _unique_vdatas;
00119   UniqueVADatas _unique_vadatas;
00120   UniqueVADatas _unique_prim_vadatas;
00121   Textures _textures;
00122 
00123 private:
00124   int _num_nodes;
00125   int _num_instances;
00126   int _num_transforms;
00127   int _num_nodes_with_attribs;
00128   int _num_lod_nodes;
00129   int _num_geom_nodes;
00130   int _num_geoms;
00131   int _num_geom_vertex_datas;
00132   int _num_geom_vertex_formats;
00133   size_t _vertex_data_size;
00134   size_t _prim_data_size;
00135 
00136   int _num_vertices;
00137   int _num_vertices_64;
00138   int _num_normals;
00139   int _num_colors;
00140   int _num_texcoords;
00141   int _num_tris;
00142   int _num_lines;
00143   int _num_points;
00144 
00145   int _num_individual_tris;
00146   int _num_tristrips;
00147   int _num_triangles_in_strips;
00148   int _num_trifans;
00149   int _num_triangles_in_fans;
00150 
00151   int _texture_bytes;
00152 
00153   int _num_long_normals;
00154   int _num_short_normals;
00155   PN_stdfloat _total_normal_length;
00156 };
00157 
00158 #include "sceneGraphAnalyzer.I"
00159 
00160 #endif
 All Classes Functions Variables Enumerations