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