Panda3D
|
00001 // Filename: fftCompressor.h 00002 // Created by: drose (11Dec00) 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 #ifndef FFTCOMPRESSOR_H 00016 #define FFTCOMPRESSOR_H 00017 00018 #include "pandabase.h" 00019 00020 #include "pointerToArray.h" 00021 #include "vector_float.h" 00022 #include "vector_double.h" 00023 #include "vector_LVecBase3f.h" 00024 00025 class Datagram; 00026 class DatagramIterator; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Class : FFTCompressor 00030 // Description : This class manages a lossy compression and 00031 // decompression of a stream of floating-point numbers 00032 // to a datagram, based a fourier transform algorithm 00033 // (similar in principle to JPEG compression). 00034 // 00035 // Actually, it doesn't do any real compression on its 00036 // own; it just outputs a stream of integers that should 00037 // compress much tighter via gzip than the original 00038 // stream of floats would have. 00039 // 00040 // This class depends on the external FFTW library; 00041 // without it, it will fall back on lossless output of 00042 // the original data. 00043 //////////////////////////////////////////////////////////////////// 00044 class EXPCL_PANDA_MATHUTIL FFTCompressor { 00045 public: 00046 FFTCompressor(); 00047 00048 static bool is_compression_available(); 00049 00050 void set_quality(int quality); 00051 int get_quality() const; 00052 00053 void set_use_error_threshold(bool use_error_threshold); 00054 bool get_use_error_threshold() const; 00055 00056 void set_transpose_quats(bool flag); 00057 bool get_transpose_quats() const; 00058 00059 void write_header(Datagram &datagram); 00060 void write_reals(Datagram &datagram, const float *array, int length); 00061 void write_hprs(Datagram &datagram, const LVecBase3f *array, int length); 00062 00063 bool read_header(DatagramIterator &di, int bam_minor_version); 00064 bool read_reals(DatagramIterator &di, vector_float &array); 00065 bool read_hprs(DatagramIterator &di, vector_LVecBase3f &array, 00066 bool new_hpr); 00067 bool read_hprs(DatagramIterator &di, vector_LVecBase3f &array); 00068 00069 static void free_storage(); 00070 00071 private: 00072 enum RunWidth { 00073 // We write a byte to the datagram at the beginning of each run to 00074 // encode the width and length of the run. The width is indicated 00075 // by the top two bits, while the length fits in the lower six, 00076 // except RW_double, which is a special case. 00077 RW_width_mask = 0xc0, 00078 RW_length_mask = 0x3f, 00079 RW_0 = 0x00, 00080 RW_8 = 0x40, 00081 RW_16 = 0x80, 00082 RW_32 = 0xc0, 00083 RW_double = 0xff, 00084 RW_invalid = 0x01 00085 }; 00086 00087 int write_run(Datagram &datagram, RunWidth run_width, 00088 const vector_double &run); 00089 int read_run(DatagramIterator &di, vector_double &run); 00090 double get_scale_factor(int i, int length) const; 00091 static double interpolate(double t, double a, double b); 00092 00093 float get_compressability(const float *data, int length) const; 00094 00095 int _bam_minor_version; 00096 int _quality; 00097 bool _use_error_threshold; 00098 double _fft_offset; 00099 double _fft_factor; 00100 double _fft_exponent; 00101 bool _transpose_quats; 00102 }; 00103 00104 #endif 00105