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

pandatool/src/bam/bamInfo.cxx

Go to the documentation of this file.
00001 // Filename: bamInfo.cxx
00002 // Created by:  drose (02Jul00)
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 #include "bamInfo.h"
00020 
00021 #include "bamFile.h"
00022 #include "pandaNode.h"
00023 #include "geomNode.h"
00024 #include "dcast.h"
00025 #include "pvector.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: BamInfo::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 BamInfo::
00033 BamInfo() {
00034   set_program_description
00035     ("This program scans one or more Bam files--Panda's Binary Animation "
00036      "and Models native binary format--and describes their contents.");
00037 
00038   clear_runlines();
00039   add_runline("[opts] input.bam [input.bam ... ]");
00040 
00041   add_option
00042     ("ls", "", 0,
00043      "List the scene graph hierarchy in the bam file.",
00044      &BamInfo::dispatch_none, &_ls);
00045 
00046   add_option
00047     ("t", "", 0,
00048      "List explicitly each transition in the hierarchy.",
00049      &BamInfo::dispatch_none, &_verbose_transitions);
00050 
00051   add_option
00052     ("g", "", 0,
00053      "Output verbose information about the each Geom in the Bam file.",
00054      &BamInfo::dispatch_none, &_verbose_geoms);
00055 
00056   _num_scene_graphs = 0;
00057 }
00058 
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: BamInfo::run
00062 //       Access: Public
00063 //  Description:
00064 ////////////////////////////////////////////////////////////////////
00065 void BamInfo::
00066 run() {
00067   bool okflag = true;
00068 
00069   Filenames::const_iterator fi;
00070   for (fi = _filenames.begin(); fi != _filenames.end(); ++fi) {
00071     if (!get_info(*fi)) {
00072       okflag = false;
00073     }
00074   }
00075 
00076   if (_num_scene_graphs > 0) {
00077     nout << "\nScene graph statistics:\n";
00078     _analyzer.write(nout, 2);
00079   }
00080   nout << "\n";
00081 
00082   if (!okflag) {
00083     // Exit with an error if any of the files was unreadable.
00084     exit(1);
00085   }
00086 }
00087 
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: BamInfo::handle_args
00091 //       Access: Protected, Virtual
00092 //  Description:
00093 ////////////////////////////////////////////////////////////////////
00094 bool BamInfo::
00095 handle_args(ProgramBase::Args &args) {
00096   if (args.empty()) {
00097     nout << "You must specify the Bam file(s) to read on the command line.\n";
00098     return false;
00099   }
00100 
00101   ProgramBase::Args::const_iterator ai;
00102   for (ai = args.begin(); ai != args.end(); ++ai) {
00103     _filenames.push_back(*ai);
00104   }
00105 
00106   return true;
00107 }
00108 
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: BamInfo::get_info
00112 //       Access: Private
00113 //  Description: Reads a single Bam file and displays its contents.
00114 //               Returns true if successful, false on error.
00115 ////////////////////////////////////////////////////////////////////
00116 bool BamInfo::
00117 get_info(const Filename &filename) {
00118   BamFile bam_file;
00119 
00120   if (!bam_file.open_read(filename)) {
00121     nout << "Unable to read.\n";
00122     return false;
00123   }
00124 
00125   nout << filename << " : Bam version " << bam_file.get_file_major_ver()
00126        << "." << bam_file.get_file_minor_ver() << "\n";
00127 
00128   typedef pvector<TypedWritable *> Objects;
00129   Objects objects;
00130   TypedWritable *object = bam_file.read_object();
00131   while (object != (TypedWritable *)NULL || !bam_file.is_eof()) {
00132     if (object != (TypedWritable *)NULL) {
00133       objects.push_back(object);
00134     }
00135     object = bam_file.read_object();
00136   }
00137   bam_file.resolve();
00138   bam_file.close();
00139 
00140   if (objects.size() == 1 && 
00141       objects[0]->is_of_type(PandaNode::get_class_type())) {
00142     describe_scene_graph(DCAST(PandaNode, objects[0]));
00143 
00144   } else {
00145     for (int i = 0; i < (int)objects.size(); i++) {
00146       describe_general_object(objects[i]);
00147     }
00148   }
00149 
00150   return true;
00151 }
00152 
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: BamInfo::describe_scene_graph
00156 //       Access: Private
00157 //  Description: Called for Bam files that contain a single scene
00158 //               graph and no other objects.  This should describe
00159 //               that scene graph in some meaningful way.
00160 ////////////////////////////////////////////////////////////////////
00161 void BamInfo::
00162 describe_scene_graph(PandaNode *node) {
00163   // Parent the node to our own scene graph root, so we can (a)
00164   // guarantee it won't accidentally be deleted before we're done, (b)
00165   // easily determine the bounding volume of the scene, and (c) report
00166   // statistics on all the bam file's scene graphs together when we've
00167   // finished.
00168 
00169   PT(PandaNode) root = new PandaNode("root");
00170   root->add_child(node);
00171   _num_scene_graphs++;
00172 
00173   int num_nodes = _analyzer._num_nodes;
00174   _analyzer.add_node(node);
00175   num_nodes = _analyzer._num_nodes - num_nodes;
00176 
00177   nout << "  " << num_nodes << " nodes, bounding volume is "
00178        << root->get_bound() << "\n";
00179 
00180   if (_ls || _verbose_geoms || _verbose_transitions) {
00181     list_hierarchy(node, 0);
00182   }
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: BamInfo::describe_general_object
00187 //       Access: Private
00188 //  Description: Called for Bam files that contain multiple objects
00189 //               which may or may not be scene graph nodes.  This
00190 //               should describe each object in some meaningful way.
00191 ////////////////////////////////////////////////////////////////////
00192 void BamInfo::
00193 describe_general_object(TypedWritable *object) {
00194   nout << "  " << object->get_type() << "\n";
00195 }
00196 
00197 ////////////////////////////////////////////////////////////////////
00198 //     Function: BamInfo::list_hierarchy
00199 //       Access: Private
00200 //  Description: Outputs the hierarchy and all of the verbose GeomNode
00201 //               information.
00202 ////////////////////////////////////////////////////////////////////
00203 void BamInfo::
00204 list_hierarchy(PandaNode *node, int indent_level) {
00205   indent(nout, indent_level) << *node;
00206 
00207   if (_verbose_transitions) {
00208     nout << "\n";
00209     if (!node->get_transform()->is_identity()) {
00210       node->get_transform()->write(nout, indent_level);
00211     }
00212     if (!node->get_state()->is_empty()) {
00213       node->get_state()->write(nout, indent_level);
00214     }
00215     if (!node->get_effects()->is_empty()) {
00216       node->get_effects()->write(nout, indent_level);
00217     }
00218 
00219   } else {
00220     if (!node->get_transform()->is_identity()) {
00221       nout << " " << *node->get_transform();
00222     }
00223     if (!node->get_state()->is_empty()) {
00224       nout << " " << *node->get_state();
00225     }
00226     if (!node->get_effects()->is_empty()) {
00227       nout << " " << *node->get_effects();
00228     }
00229     nout << "\n";
00230   }
00231 
00232   if (_verbose_geoms && node->is_geom_node()) {
00233     GeomNode *geom_node;
00234     DCAST_INTO_V(geom_node, node);
00235     geom_node->write_verbose(nout, indent_level);
00236   }
00237 
00238   int num_children = node->get_num_children();
00239   for (int i = 0; i < num_children; i++) {
00240     PandaNode *child = node->get_child(i);
00241     list_hierarchy(child, indent_level + 2);
00242   }
00243 }
00244 
00245 int main(int argc, char *argv[]) {
00246   BamInfo prog;
00247   prog.parse_command_line(argc, argv);
00248   prog.run();
00249   return 0;
00250 }

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