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