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

FFTCompressor Class Reference

This class manages a lossy compression and decompression of a stream of floating-point numbers to a datagram, based a fourier transform algorithm (similar in principle to JPEG compression). More...

#include <fftCompressor.h>

List of all members.

Public Member Functions

 FFTCompressor ()
 Constructs a new compressor object with default parameters.

void set_quality (int quality)
 Sets the quality factor for the compression.

int get_quality () const
 Returns the quality number that was previously set via set_quality().

void set_transpose_quats (bool flag)
 Sets the transpose_quats flag.

bool get_transpose_quats () const
 Returns the transpose_quats flag.

void write_header (Datagram &datagram)
 Writes the compression parameters to the indicated datagram.

void write_reals (Datagram &datagram, const float *array, int length)
 Writes an array of floating-point numbers to the indicated datagram.

void write_hprs (Datagram &datagram, const LVecBase3f *array, int length)
 Writes an array of HPR angles to the indicated datagram.

bool read_header (DatagramIterator &di)
 Reads the compression header that was written previously.

bool read_reals (DatagramIterator &di, vector_float &array)
 Reads an array of floating-point numbers.

bool read_hprs (DatagramIterator &di, vector_LVecBase3f &array)
 Reads an array of HPR angles.


Static Public Member Functions

bool is_compression_available ()
 Returns true if the FFTW library is compiled in, so that this class is actually capable of doing useful compression/decompression work.

void free_storage ()
 Frees memory that has been allocated during past runs of the FFTCompressor.


Private Types

enum  RunWidth {
  RW_width_mask = 0xc0, RW_length_mask = 0x3f, RW_0 = 0x00, RW_8 = 0x40,
  RW_16 = 0x80, RW_32 = 0xc0, RW_double = 0xff, RW_invalid = 0x01
}

Private Member Functions

int write_run (Datagram &datagram, RunWidth run_width, const vector_double &run)
 Writes a sequence of integers that all require the same number of bits.

int read_run (DatagramIterator &di, vector_double &run)
 Reads a sequence of integers that all require the same number of bits.

double get_scale_factor (int i, int length) const
 Returns the appropriate scaling for the given position within the halfcomplex array.


Static Private Member Functions

double interpolate (double t, double a, double b)
 Returns a number between a and b, inclusive, according to the value of t between 0 and 1, inclusive.


Private Attributes

int _quality
double _fft_offset
double _fft_factor
double _fft_exponent
bool _transpose_quats


Detailed Description

This class manages a lossy compression and decompression of a stream of floating-point numbers to a datagram, based a fourier transform algorithm (similar in principle to JPEG compression).

Actually, it doesn't do any real compression on its own; it just outputs a stream of integers that should compress much tighter via gzip than the original stream of floats would have.

This class depends on the external FFTW library; without it, it will fall back on lossless output of the original data.

Definition at line 66 of file fftCompressor.h.


Member Enumeration Documentation

enum FFTCompressor::RunWidth [private]
 

Enumeration values:
RW_width_mask 
RW_length_mask 
RW_0 
RW_8 
RW_16 
RW_32 
RW_double 
RW_invalid 

Definition at line 89 of file fftCompressor.h.

Referenced by write_header().


Constructor & Destructor Documentation

FFTCompressor::FFTCompressor  ) 
 

Constructs a new compressor object with default parameters.

Definition at line 56 of file fftCompressor.cxx.


Member Function Documentation

void FFTCompressor::free_storage  )  [static]
 

Frees memory that has been allocated during past runs of the FFTCompressor.

This is an optional call, but it may be made from time to time to empty the global cache that the compressor objects keep to facilitate fast compression/decompression.

Definition at line 814 of file fftCompressor.cxx.

int FFTCompressor::get_quality  )  const
 

Returns the quality number that was previously set via set_quality().

Definition at line 201 of file fftCompressor.cxx.

double FFTCompressor::get_scale_factor int  i,
int  length
const [private]
 

Returns the appropriate scaling for the given position within the halfcomplex array.

Definition at line 1013 of file fftCompressor.cxx.

Referenced by write_header().

bool FFTCompressor::get_transpose_quats  )  const
 

Returns the transpose_quats flag.

See set_transpose_quats().

Definition at line 235 of file fftCompressor.cxx.

References Datagram::add_float32(), and length.

double FFTCompressor::interpolate double  t,
double  a,
double  b
[static, private]
 

Returns a number between a and b, inclusive, according to the value of t between 0 and 1, inclusive.

Definition at line 1035 of file fftCompressor.cxx.

Referenced by is_compression_available().

bool FFTCompressor::is_compression_available  )  [static]
 

Returns true if the FFTW library is compiled in, so that this class is actually capable of doing useful compression/decompression work.

Returns false otherwise, in which case any attempt to write a compressed stream will actually write an uncompressed stream, and any attempt to read a compressed stream will fail.

Definition at line 82 of file fftCompressor.cxx.

References _fft_exponent, _fft_factor, _fft_offset, _quality, fft_exponent, fft_factor, fft_offset, interpolate(), and t.

bool FFTCompressor::read_header DatagramIterator di  ) 
 

Reads the compression header that was written previously.

This fills in the compression parameters necessary to correctly decompress the following data.

Returns true if the header is read successfully, false otherwise.

Definition at line 553 of file fftCompressor.cxx.

bool FFTCompressor::read_hprs DatagramIterator di,
vector_LVecBase3f &  array
 

Reads an array of HPR angles.

The result is pushed onto the end of the indicated vector, which is not cleared first; it is the user's responsibility to ensure that the array is initially empty.

Definition at line 674 of file fftCompressor.cxx.

References _quality.

bool FFTCompressor::read_reals DatagramIterator di,
vector_float &  array
 

Reads an array of floating-point numbers.

The result is pushed onto the end of the indicated vector, which is not cleared first; it is the user's responsibility to ensure that the array is initially empty. Returns true if the data is read correctly, false if there is an error.

Definition at line 599 of file fftCompressor.cxx.

Referenced by AnimChannelMatrixXfmTable::fillin().

int FFTCompressor::read_run DatagramIterator di,
vector_double &  run
[private]
 

Reads a sequence of integers that all require the same number of bits.

Returns the number of integers read. It is the responsibility of the user to clear the vector before calling this function, or the numbers read will be appended to the end.

Definition at line 938 of file fftCompressor.cxx.

void FFTCompressor::set_quality int  quality  ) 
 

Sets the quality factor for the compression.

This is an integer in the range 0 - 100 that roughly controls how aggressively the reals are compressed; lower numbers mean smaller output, and more data loss.

There are a few special cases. Quality -1 means to use whatever individual parameters are set in the user's Configrc file, rather than the single quality dial. Quality 101 or higher means to generate lossless output (this is the default if libfftw is not available).

Quality 102 writes all four components of quaternions to the output file, rather than just three, quality 103 converts hpr to matrix (instead of quat) and writes a 9-component matrix, and quality 104 just writes out hpr directly. Quality levels 102 and greater are strictly for debugging purposes, and are only available if NDEBUG is not defined.

Definition at line 135 of file fftCompressor.cxx.

References _fft_exponent, _fft_factor, and _fft_offset.

void FFTCompressor::set_transpose_quats bool  flag  ) 
 

Sets the transpose_quats flag.

This is provided mainly for backward compatibility with old bam files that were written out with the quaternions inadvertently transposed.

Definition at line 220 of file fftCompressor.cxx.

void FFTCompressor::write_header Datagram datagram  ) 
 

Writes the compression parameters to the indicated datagram.

It is necessary to call this before writing anything else to the datagram, since these parameters will be necessary to correctly decompress the data later.

Definition at line 256 of file fftCompressor.cxx.

References cfloor(), get_scale_factor(), length, RunWidth, RW_0, RW_invalid, and scale_factor.

void FFTCompressor::write_hprs Datagram datagram,
const LVecBase3f *  array,
int  length
 

Writes an array of HPR angles to the indicated datagram.

Definition at line 386 of file fftCompressor.cxx.

References length.

void FFTCompressor::write_reals Datagram datagram,
const float *  array,
int  length
 

Writes an array of floating-point numbers to the indicated datagram.

Definition at line 276 of file fftCompressor.cxx.

Referenced by AnimChannelMatrixXfmTable::write_datagram().

int FFTCompressor::write_run Datagram datagram,
FFTCompressor::RunWidth  run_width,
const vector_double &  run
[private]
 

Writes a sequence of integers that all require the same number of bits.

Returns the number of integers written, i.e. run.size().

Definition at line 846 of file fftCompressor.cxx.

References DatagramIterator::get_uint16(), and length.


Member Data Documentation

double FFTCompressor::_fft_exponent [private]
 

Definition at line 113 of file fftCompressor.h.

Referenced by is_compression_available(), and set_quality().

double FFTCompressor::_fft_factor [private]
 

Definition at line 112 of file fftCompressor.h.

Referenced by is_compression_available(), and set_quality().

double FFTCompressor::_fft_offset [private]
 

Definition at line 111 of file fftCompressor.h.

Referenced by is_compression_available(), and set_quality().

int FFTCompressor::_quality [private]
 

Definition at line 110 of file fftCompressor.h.

Referenced by is_compression_available(), and read_hprs().

bool FFTCompressor::_transpose_quats [private]
 

Definition at line 114 of file fftCompressor.h.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:50:36 2003 for Panda by doxygen1.3