00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00029
00030
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
00062
00063
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
00084 exit(1);
00085 }
00086 }
00087
00088
00089
00090
00091
00092
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
00112
00113
00114
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
00156
00157
00158
00159
00160
00161 void BamInfo::
00162 describe_scene_graph(PandaNode *node) {
00163
00164
00165
00166
00167
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
00187
00188
00189
00190
00191
00192 void BamInfo::
00193 describe_general_object(TypedWritable *object) {
00194 nout << " " << object->get_type() << "\n";
00195 }
00196
00197
00198
00199
00200
00201
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 }