Panda3D
Loading...
Searching...
No Matches
lwoVertexMap.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 lwoVertexMap.cxx
10 * @author drose
11 * @date 2001-04-24
12 */
13
14#include "lwoVertexMap.h"
15#include "lwoInputFile.h"
16
17#include "dcast.h"
18#include "indent.h"
19
20TypeHandle LwoVertexMap::_type_handle;
21
22
23/**
24 * Returns true if the map has a value associated with the given index, false
25 * otherwise.
26 */
28has_value(int index) const {
29 return (_vmap.count(index) != 0);
30}
31
32/**
33 * Returns the mapping value associated with the given index, or an empty
34 * PTA_stdfloat if there is no mapping value associated.
35 */
36PTA_stdfloat LwoVertexMap::
37get_value(int index) const {
38 VMap::const_iterator vi;
39 vi = _vmap.find(index);
40 if (vi != _vmap.end()) {
41 return (*vi).second;
42 }
43
44 return PTA_stdfloat();
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 */
54read_iff(IffInputFile *in, size_t stop_at) {
55 LwoInputFile *lin = DCAST(LwoInputFile, in);
56
57 _map_type = lin->get_id();
58 _dimension = lin->get_be_uint16();
59 _name = lin->get_string();
60
61 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
62 int index = lin->get_vx();
63
64 PTA_stdfloat value;
65 for (int i = 0; i < _dimension; i++) {
66 value.push_back(lin->get_be_float32());
67 }
68
69 bool inserted = _vmap.insert(VMap::value_type(index, value)).second;
70 if (!inserted) {
71 nout << "Duplicate index " << index << " in map.\n";
72 }
73 }
74
75 return (lin->get_bytes_read() == stop_at);
76}
77
78/**
79 *
80 */
81void LwoVertexMap::
82write(std::ostream &out, int indent_level) const {
83 indent(out, indent_level)
84 << get_id() << " { map_type = " << _map_type
85 << ", dimension = " << _dimension
86 << ", name = \"" << _name << "\", "
87 << _vmap.size() << " values }\n";
88}
IffId get_id() const
Returns the ID associated with this chunk.
Definition iffChunk.I:25
A wrapper around an istream used for reading an IFF file.
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
IffId get_id()
Extracts a 4-character IFF ID.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
std::string get_string()
Extracts a null-terminated string.
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
A specialization of IffInputFile to handle reading a Lightwave Object file.
int get_vx()
Reads a Lightwave variable-length index.
PTA_stdfloat get_value(int index) const
Returns the mapping value associated with the given index, or an empty PTA_stdfloat if there is no ma...
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
bool has_value(int index) const
Returns true if the map has a value associated with the given index, false otherwise.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.