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

pandatool/src/lwo/lwoVertexMap.cxx

Go to the documentation of this file.
00001 // Filename: lwoVertexMap.cxx
00002 // Created by:  drose (24Apr01)
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 "lwoVertexMap.h"
00020 #include "lwoInputFile.h"
00021 
00022 #include "dcast.h"
00023 #include "indent.h"
00024 
00025 TypeHandle LwoVertexMap::_type_handle;
00026 
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: LwoVertexMap::has_value
00030 //       Access: Public
00031 //  Description: Returns true if the map has a value associated with
00032 //               the given index, false otherwise.
00033 ////////////////////////////////////////////////////////////////////
00034 bool LwoVertexMap::
00035 has_value(int index) const {
00036   return (_vmap.count(index) != 0);
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: LwoVertexMap::get_value
00041 //       Access: Public
00042 //  Description: Returns the mapping value associated with the given
00043 //               index, or an empty PTA_float if there is no mapping
00044 //               value associated.
00045 ////////////////////////////////////////////////////////////////////
00046 PTA_float LwoVertexMap::
00047 get_value(int index) const {
00048   VMap::const_iterator vi;
00049   vi = _vmap.find(index);
00050   if (vi != _vmap.end()) {
00051     return (*vi).second;
00052   }
00053 
00054   return PTA_float();
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: LwoVertexMap::read_iff
00059 //       Access: Public, Virtual
00060 //  Description: Reads the data of the chunk in from the given input
00061 //               file, if possible.  The ID and length of the chunk
00062 //               have already been read.  stop_at is the byte position
00063 //               of the file to stop at (based on the current position
00064 //               at in->get_bytes_read()).  Returns true on success,
00065 //               false otherwise.
00066 ////////////////////////////////////////////////////////////////////
00067 bool LwoVertexMap::
00068 read_iff(IffInputFile *in, size_t stop_at) {
00069   LwoInputFile *lin = DCAST(LwoInputFile, in);
00070 
00071   _map_type = lin->get_id();
00072   _dimension = lin->get_be_uint16();
00073   _name = lin->get_string();
00074 
00075   while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00076     int index = lin->get_vx();
00077 
00078     PTA_float value;
00079     for (int i = 0; i < _dimension; i++) {
00080       value.push_back(lin->get_be_float32());
00081     }
00082 
00083     bool inserted = _vmap.insert(VMap::value_type(index, value)).second;
00084     if (!inserted) {
00085       nout << "Duplicate index " << index << " in map.\n";
00086     }
00087   }
00088 
00089   return (lin->get_bytes_read() == stop_at);
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: LwoVertexMap::write
00094 //       Access: Public, Virtual
00095 //  Description:
00096 ////////////////////////////////////////////////////////////////////
00097 void LwoVertexMap::
00098 write(ostream &out, int indent_level) const {
00099   indent(out, indent_level)
00100     << get_id() << " { map_type = " << _map_type
00101     << ", dimension = " << _dimension
00102     << ", name = \"" << _name << "\", "
00103     << _vmap.size() << " values }\n";
00104 }

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