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