16 #include "animChannelScalarTable.h"
17 #include "animBundle.h"
18 #include "config_chan.h"
22 #include "datagramIterator.h"
23 #include "bamReader.h"
24 #include "bamWriter.h"
25 #include "fftCompressor.h"
27 TypeHandle AnimChannelScalarTable::_type_handle;
34 AnimChannelScalarTable::
35 AnimChannelScalarTable() : _table(get_class_type()) {
46 AnimChannelScalarTable::
58 AnimChannelScalarTable::
59 AnimChannelScalarTable(
AnimGroup *parent,
const string &name) :
61 _table(get_class_type())
75 int this_frame,
double this_frac) {
76 if (_table.size() > 1) {
77 if (last_frame != this_frame) {
78 if (_table[last_frame % _table.size()] !=
79 _table[this_frame % _table.size()]) {
83 if (last_frac != this_frac) {
86 if (_table[last_frame % _table.size()] !=
87 _table[(this_frame + 1) % _table.size()]) {
103 if (_table.empty()) {
106 value = _table[frame % _table.size()];
118 int num_frames = _root->get_num_frames();
120 if (table.size() > 1 && (int)table.size() < num_frames) {
137 write(ostream &out,
int indent_level)
const {
138 indent(out, indent_level)
139 << get_type() <<
" " << get_name() <<
" " << _table.size();
141 if (!_children.empty()) {
143 write_descendants(out, indent_level + 2);
144 indent(out, indent_level) <<
"}";
175 <<
"Compression is not available; writing uncompressed channels.\n";
176 compress_channels =
false;
180 if (!compress_channels) {
183 for(
int i = 0; i < (int)_table.size(); i++) {
195 static const int max_values = 16;
196 static const PN_stdfloat scale = 1000.0f;
201 i < (int)_table.size() && (int)index.size() <= max_values;
203 int value = (int)cfloor(_table[i] * scale + 0.5f);
206 int index_length = index.size();
207 if (index_length <= max_values) {
213 if (index_length > 0) {
216 vector_stdfloat reverse_index(index_length);
218 for (mi = index.begin(); mi != index.end(); ++mi) {
219 PN_stdfloat f = (PN_stdfloat)(*mi).first / scale;
220 int i = (*mi).second;
221 nassertv(i >= 0 && i < (
int)reverse_index.size());
222 reverse_index[i] = f;
225 for (i = 0; i < index_length; i++) {
231 int table_length = _table.size();
234 if (index_length == 1) {
239 for (i = 0; i < table_length - 1; i+= 2) {
240 int value1 = (int)cfloor(_table[i] * scale + 0.5f);
241 int value2 = (int)cfloor(_table[i + 1] * scale + 0.5f);
242 int i1 = index[value1];
243 int i2 = index[value2];
249 if (i < table_length) {
250 int value1 = (int)cfloor(_table[i] * scale + 0.5f);
251 int i1 = index[value1];
281 void AnimChannelScalarTable::
283 AnimChannelScalar::fillin(scan, manager);
285 bool wrote_compressed = scan.
get_bool();
287 PTA_stdfloat temp_table = PTA_stdfloat::empty_array(0, get_class_type());
289 if (!wrote_compressed) {
292 for(
int i = 0; i < size; i++) {
301 if (index_length < 0xff) {
303 if (index_length > 0) {
304 PN_stdfloat *index = (PN_stdfloat *)alloca(index_length *
sizeof(PN_stdfloat));
307 for (i = 0; i < index_length; i++) {
313 if (index_length == 1) {
315 for (i = 0; i < table_length; i++) {
316 temp_table.push_back(index[0]);
320 for (i = 0; i < table_length - 1; i+= 2) {
322 int i1 = (num >> 4) & 0xf;
324 temp_table.push_back(index[i1]);
325 temp_table.push_back(index[i2]);
328 if (i < table_length) {
330 int i1 = (num >> 4) & 0xf;
331 temp_table.push_back(index[i1]);
357 parse_params(params, scan, manager);
358 me->fillin(scan, manager);
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
bool read_reals(DatagramIterator &di, vector_stdfloat &array)
Reads an array of floating-point numbers.
void set_quality(int quality)
Sets the quality factor for the compression.
bool get_bool()
Extracts a boolean value.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
virtual void write(ostream &out, int indent_level) const
Writes a brief description of the table and all of its descendants.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool read_header(DatagramIterator &di, int bam_minor_version)
Reads the compression header that was written previously.
An animation channel that issues a scalar each frame, read from a table such as might have been read ...
Base class for objects that can be written to and read from Bam files.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
static void register_with_read_factory()
Factory method to generate a AnimChannelScalarTable object.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
This class manages a lossy compression and decompression of a stream of floating-point numbers to a d...
This template class is the parent class for all kinds of AnimChannels that return different values...
void set_table(const CPTA_stdfloat &table)
Assigns the data table.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_bool(bool value)
Adds a boolean value to the datagram.
This is the base class for AnimChannel and AnimBundle.
void write_header(Datagram &datagram)
Writes the compression parameters to the indicated datagram.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
void write_reals(Datagram &datagram, const PN_stdfloat *array, int length)
Writes an array of floating-point numbers to the indicated datagram.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac)
Returns true if the value has changed since the last call to has_changed().
static TypedWritable * make_AnimChannelScalarTable(const FactoryParams ¶ms)
Factory method to generate a AnimChannelScalarTable object.
A class to retrieve the individual data elements previously stored in a Datagram. ...
void set_use_error_threshold(bool use_error_threshold)
Enables or disables the use of the error threshold measurement to put a cap on the amount of damage d...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual void get_value(int frame, PN_stdfloat &value)
Gets the value of the channel at the indicated frame.
static bool is_compression_available()
Returns true if the FFTW library is compiled in, so that this class is actually capable of doing usef...
Similar to PointerToArray, except that its contents may not be modified.