Panda3D
lwoPolygonTags.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file lwoPolygonTags.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoPolygonTags.h"
15 #include "lwoInputFile.h"
16 
17 #include "dcast.h"
18 #include "indent.h"
19 
20 TypeHandle LwoPolygonTags::_type_handle;
21 
22 
23 /**
24  * Returns true if the map has a tag associated with the given polygon index,
25  * false otherwise.
26  */
28 has_tag(int polygon_index) const {
29  return (_tmap.count(polygon_index) != 0);
30 }
31 
32 /**
33  * Returns the tag associated with the given polygon index, or -1 if there is
34  * no tag associated.
35  */
37 get_tag(int polygon_index) const {
38  TMap::const_iterator ti;
39  ti = _tmap.find(polygon_index);
40  if (ti != _tmap.end()) {
41  return (*ti).second;
42  }
43 
44  return -1;
45 }
46 
47 /**
48  * Reads the data of the chunk in from the given input file, if possible. The
49  * ID and length of the chunk have already been read. stop_at is the byte
50  * position of the file to stop at (based on the current position at
51  * in->get_bytes_read()). Returns true on success, false otherwise.
52  */
54 read_iff(IffInputFile *in, size_t stop_at) {
55  LwoInputFile *lin = DCAST(LwoInputFile, in);
56 
57  _tag_type = lin->get_id();
58 
59  while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
60  int polygon_index = lin->get_vx();
61  int tag = lin->get_be_int16();
62 
63  bool inserted = _tmap.insert(TMap::value_type(polygon_index, tag)).second;
64  if (!inserted) {
65  nout << "Duplicate index " << polygon_index << " in map.\n";
66  }
67  }
68 
69  return (lin->get_bytes_read() == stop_at);
70 }
71 
72 /**
73  *
74  */
75 void LwoPolygonTags::
76 write(std::ostream &out, int indent_level) const {
77  indent(out, indent_level)
78  << get_id() << " { tag_type = " << _tag_type << ", "
79  << _tmap.size() << " values }\n";
80 }
int get_vx()
Reads a Lightwave variable-length index.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:44
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_tag(int polygon_index) const
Returns the tag associated with the given polygon index, or -1 if there is no tag associated.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:36
bool has_tag(int polygon_index) const
Returns true if the map has a tag associated with the given polygon index, false otherwise.
IffId get_id()
Extracts a 4-character IFF ID.