00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "lwoDiscontinuousVertexMap.h"
00020 #include "lwoInputFile.h"
00021
00022 #include "dcast.h"
00023 #include "indent.h"
00024
00025 #include <algorithm>
00026
00027 TypeHandle LwoDiscontinuousVertexMap::_type_handle;
00028
00029
00030
00031
00032
00033
00034
00035
00036 bool LwoDiscontinuousVertexMap::
00037 has_value(int polygon_index, int vertex_index) const {
00038 VMad::const_iterator di;
00039 di = _vmad.find(polygon_index);
00040 if (di != _vmad.end()) {
00041 const VMap &vmap = (*di).second;
00042 return (vmap.count(vertex_index) != 0);
00043 }
00044
00045 return false;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055 PTA_float LwoDiscontinuousVertexMap::
00056 get_value(int polygon_index, int vertex_index) const {
00057 VMad::const_iterator di;
00058 di = _vmad.find(polygon_index);
00059 if (di != _vmad.end()) {
00060 const VMap &vmap = (*di).second;
00061 VMap::const_iterator vi;
00062 vi = vmap.find(vertex_index);
00063 if (vi != vmap.end()) {
00064 return (*vi).second;
00065 }
00066 }
00067
00068 return PTA_float();
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 bool LwoDiscontinuousVertexMap::
00082 read_iff(IffInputFile *in, size_t stop_at) {
00083 LwoInputFile *lin = DCAST(LwoInputFile, in);
00084
00085 _map_type = lin->get_id();
00086 _dimension = lin->get_be_uint16();
00087 _name = lin->get_string();
00088
00089 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00090 int vertex_index = lin->get_vx();
00091 int polygon_index = lin->get_vx();
00092
00093 PTA_float value;
00094 for (int i = 0; i < _dimension; i++) {
00095 value.push_back(lin->get_be_float32());
00096 }
00097
00098 VMap &vmap = _vmad[polygon_index];
00099 pair<VMap::iterator, bool> ir =
00100 vmap.insert(VMap::value_type(vertex_index, value));
00101 if (!ir.second) {
00102
00103
00104 PTA_float orig_value = (*ir.first).second;
00105
00106 if (value.v() != orig_value.v()) {
00107 nout << "Multiple UV values for vertex " << vertex_index
00108 << " of polygon " << polygon_index
00109 << " specified by discontinuous vertex map.\n"
00110 << "Original value = ";
00111
00112 PTA_float::const_iterator vi;
00113 for (vi = orig_value.begin(); vi != orig_value.end(); ++vi) {
00114 nout << (*vi) << " ";
00115 }
00116 nout << " new value = ";
00117 for (vi = value.begin(); vi != value.end(); ++vi) {
00118 nout << (*vi) << " ";
00119 }
00120 nout << "\n";
00121 }
00122 }
00123 }
00124
00125 return (lin->get_bytes_read() == stop_at);
00126 }
00127
00128
00129
00130
00131
00132
00133 void LwoDiscontinuousVertexMap::
00134 write(ostream &out, int indent_level) const {
00135 indent(out, indent_level)
00136 << get_id() << " { map_type = " << _map_type
00137 << ", dimension = " << _dimension
00138 << ", name = \"" << _name << "\", "
00139 << _vmad.size() << " polygons }\n";
00140 }