Panda3D

lwoPolygonTags.cxx

00001 // Filename: lwoPolygonTags.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 "lwoPolygonTags.h"
00016 #include "lwoInputFile.h"
00017 
00018 #include "dcast.h"
00019 #include "indent.h"
00020 
00021 TypeHandle LwoPolygonTags::_type_handle;
00022 
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: LwoPolygonTags::has_tag
00026 //       Access: Public
00027 //  Description: Returns true if the map has a tag associated with
00028 //               the given polygon index, false otherwise.
00029 ////////////////////////////////////////////////////////////////////
00030 bool LwoPolygonTags::
00031 has_tag(int polygon_index) const {
00032   return (_tmap.count(polygon_index) != 0);
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: LwoPolygonTags::get_tag
00037 //       Access: Public
00038 //  Description: Returns the tag associated with the given polygon
00039 //               index, or -1 if there is no tag associated.
00040 ////////////////////////////////////////////////////////////////////
00041 int LwoPolygonTags::
00042 get_tag(int polygon_index) const {
00043   TMap::const_iterator ti;
00044   ti = _tmap.find(polygon_index);
00045   if (ti != _tmap.end()) {
00046     return (*ti).second;
00047   }
00048 
00049   return -1;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: LwoPolygonTags::read_iff
00054 //       Access: Public, Virtual
00055 //  Description: Reads the data of the chunk in from the given input
00056 //               file, if possible.  The ID and length of the chunk
00057 //               have already been read.  stop_at is the byte position
00058 //               of the file to stop at (based on the current position
00059 //               at in->get_bytes_read()).  Returns true on success,
00060 //               false otherwise.
00061 ////////////////////////////////////////////////////////////////////
00062 bool LwoPolygonTags::
00063 read_iff(IffInputFile *in, size_t stop_at) {
00064   LwoInputFile *lin = DCAST(LwoInputFile, in);
00065 
00066   _tag_type = lin->get_id();
00067 
00068   while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00069     int polygon_index = lin->get_vx();
00070     int tag = lin->get_be_int16();
00071 
00072     bool inserted = _tmap.insert(TMap::value_type(polygon_index, tag)).second;
00073     if (!inserted) {
00074       nout << "Duplicate index " << polygon_index << " in map.\n";
00075     }
00076   }
00077 
00078   return (lin->get_bytes_read() == stop_at);
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: LwoPolygonTags::write
00083 //       Access: Public, Virtual
00084 //  Description:
00085 ////////////////////////////////////////////////////////////////////
00086 void LwoPolygonTags::
00087 write(ostream &out, int indent_level) const {
00088   indent(out, indent_level)
00089     << get_id() << " { tag_type = " << _tag_type << ", "
00090     << _tmap.size() << " values }\n";
00091 }
 All Classes Functions Variables Enumerations