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

panda/src/mathutil/fftCompressor.h

Go to the documentation of this file.
00001 // Filename: fftCompressor.h
00002 // Created by:  drose (11Dec00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef FFTCOMPRESSOR_H
00020 #define FFTCOMPRESSOR_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include <pointerToArray.h>
00025 #include <vector_float.h>
00026 #include <vector_double.h>
00027 #include <vector_LVecBase3f.h>
00028 
00029 class Datagram;
00030 class DatagramIterator;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : FFTCompressor
00034 // Description : This class manages a lossy compression and
00035 //               decompression of a stream of floating-point numbers
00036 //               to a datagram, based a fourier transform algorithm
00037 //               (similar in principle to JPEG compression).
00038 //
00039 //               Actually, it doesn't do any real compression on its
00040 //               own; it just outputs a stream of integers that should
00041 //               compress much tighter via gzip than the original
00042 //               stream of floats would have.
00043 //
00044 //               This class depends on the external FFTW library;
00045 //               without it, it will fall back on lossless output of
00046 //               the original data.
00047 ////////////////////////////////////////////////////////////////////
00048 class EXPCL_PANDA FFTCompressor {
00049 public:
00050   FFTCompressor();
00051 
00052   static bool is_compression_available();
00053 
00054   void set_quality(int quality);
00055   int get_quality() 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 float *array, int length);
00062   void write_hprs(Datagram &datagram, const LVecBase3f *array, int length);
00063 
00064   bool read_header(DatagramIterator &di);
00065   bool read_reals(DatagramIterator &di, vector_float &array);
00066   bool read_hprs(DatagramIterator &di, vector_LVecBase3f &array);
00067 
00068   static void free_storage();
00069 
00070 private:
00071   enum RunWidth {
00072     // We write a byte to the datagram at the beginning of each run to
00073     // encode the width and length of the run.  The width is indicated
00074     // by the top two bits, while the length fits in the lower six,
00075     // except RW_double, which is a special case.
00076     RW_width_mask  = 0xc0,
00077     RW_length_mask = 0x3f,
00078     RW_0           = 0x00,
00079     RW_8           = 0x40,
00080     RW_16          = 0x80,
00081     RW_32          = 0xc0,
00082     RW_double      = 0xff,
00083     RW_invalid     = 0x01
00084   };
00085 
00086   int write_run(Datagram &datagram, RunWidth run_width,
00087                 const vector_double &run);
00088   int read_run(DatagramIterator &di, vector_double &run);
00089   double get_scale_factor(int i, int length) const;
00090   static double interpolate(double t, double a, double b);
00091 
00092   int _quality;
00093   double _fft_offset;
00094   double _fft_factor;
00095   double _fft_exponent;
00096   bool _transpose_quats;
00097 };
00098 
00099 #endif
00100 

Generated on Fri May 2 00:40:26 2003 for Panda by doxygen1.3