Panda3D

fftCompressor.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file fftCompressor.h
10 * @author drose
11 * @date 2000-12-11
12 */
13
14 #ifndef FFTCOMPRESSOR_H
15 #define FFTCOMPRESSOR_H
16
17 #include "pandabase.h"
18
19 #include "pvector.h"
20 #include "pointerToArray.h"
21 #include "vector_stdfloat.h"
22 #include "vector_double.h"
23 #include "luse.h"
24
25 class Datagram;
26 class DatagramIterator;
27
28 /**
29 * This class manages a lossy compression and decompression of a stream of
30 * floating-point numbers to a datagram, based a fourier transform algorithm
31 * (similar in principle to JPEG compression).
32 *
33 * Actually, it doesn't do any real compression on its own; it just outputs a
34 * stream of integers that should compress much tighter via gzip than the
35 * original stream of floats would have.
36 *
37 * This class depends on the external FFTW library; without it, it will fall
38 * back on lossless output of the original data.
39 */
40 class EXPCL_PANDA_MATHUTIL FFTCompressor {
41 public:
42 FFTCompressor();
43
44 static bool is_compression_available();
45
46 void set_quality(int quality);
47 int get_quality() const;
48
49 void set_use_error_threshold(bool use_error_threshold);
50 bool get_use_error_threshold() const;
51
52 void set_transpose_quats(bool flag);
53 bool get_transpose_quats() const;
54
55 void write_header(Datagram &datagram);
56 void write_reals(Datagram &datagram, const PN_stdfloat *array, int length);
57 void write_hprs(Datagram &datagram, const LVecBase3 *array, int length);
58
59 bool read_header(DatagramIterator &di, int bam_minor_version);
60 bool read_reals(DatagramIterator &di, vector_stdfloat &array);
61 bool read_hprs(DatagramIterator &di, pvector<LVecBase3> &array,
62 bool new_hpr);
63 bool read_hprs(DatagramIterator &di, pvector<LVecBase3> &array);
64
65 static void free_storage();
66
67 private:
68 enum RunWidth {
69 // We write a byte to the datagram at the beginning of each run to encode
70 // the width and length of the run. The width is indicated by the top two
71 // bits, while the length fits in the lower six, except RW_double, which
72 // is a special case.
73 RW_width_mask = 0xc0,
74 RW_length_mask = 0x3f,
75 RW_0 = 0x00,
76 RW_8 = 0x40,
77 RW_16 = 0x80,
78 RW_32 = 0xc0,
79 RW_double = 0xff,
80 RW_invalid = 0x01
81 };
82
83 int write_run(Datagram &datagram, RunWidth run_width,
84 const vector_double &run);
85 int read_run(DatagramIterator &di, vector_double &run);
86 double get_scale_factor(int i, int length) const;
87 static double interpolate(double t, double a, double b);
88
89 PN_stdfloat get_compressability(const PN_stdfloat *data, int length) const;
90
91 int _bam_minor_version;
92 int _quality;
93 bool _use_error_threshold;
94 double _fft_offset;
95 double _fft_factor;
96 double _fft_exponent;
97 bool _transpose_quats;
98 };
99
100 #endif
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
FFTCompressor
This class manages a lossy compression and decompression of a stream of floating-point numbers to a d...
Definition: fftCompressor.h:40
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerToArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_double.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_stdfloat.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.