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

pandatool/src/lwo/lwoDiscontinuousVertexMap.cxx

Go to the documentation of this file.
00001 // Filename: lwoDiscontinuousVertexMap.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 "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 //     Function: LwoDiscontinuousVertexMap::has_value
00032 //       Access: Public
00033 //  Description: Returns true if the map has a value associated with
00034 //               the given index, false otherwise.
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 //     Function: LwoDiscontinuousVertexMap::get_value
00050 //       Access: Public
00051 //  Description: Returns the mapping value associated with the given
00052 //               index, or an empty PTA_float if there is no mapping
00053 //               value associated.
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 //     Function: LwoDiscontinuousVertexMap::read_iff
00073 //       Access: Public, Virtual
00074 //  Description: Reads the data of the chunk in from the given input
00075 //               file, if possible.  The ID and length of the chunk
00076 //               have already been read.  stop_at is the byte position
00077 //               of the file to stop at (based on the current position
00078 //               at in->get_bytes_read()).  Returns true on success,
00079 //               false otherwise.
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       // This polygon/vertex pair was repeated in the vmad.  Is it
00103       // simply redundant, or is it contradictory?
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 //     Function: LwoDiscontinuousVertexMap::write
00130 //       Access: Public, Virtual
00131 //  Description:
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 }

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