00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00026
00027
00028
00029
00030 bool LwoVertexMap::
00031 has_value(int index) const {
00032 return (_vmap.count(index) != 0);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042 PTA_float 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_float();
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
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_float 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
00090
00091
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 }