Panda3D

Loading...
Searching...
No Matches
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:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FFTCompressor::free_storage
static void free_storage()
Frees memory that has been allocated during past runs of the FFTCompressor.
Definition fftCompressor.cxx:820
FFTCompressor::read_reals
bool read_reals(DatagramIterator &di, vector_stdfloat &array)
Reads an array of floating-point numbers.
Definition fftCompressor.cxx:576
FFTCompressor::set_use_error_threshold
void set_use_error_threshold(bool use_error_threshold)
Enables or disables the use of the error threshold measurement to put a cap on the amount of damage d...
Definition fftCompressor.cxx:152
FFTCompressor::set_transpose_quats
void set_transpose_quats(bool flag)
Sets the transpose_quats flag.
Definition fftCompressor.cxx:171
FFTCompressor::FFTCompressor
FFTCompressor()
Constructs a new compressor object with default parameters.
Definition fftCompressor.cxx:49
FFTCompressor::read_hprs
bool read_hprs(DatagramIterator &di, pvector< LVecBase3 > &array, bool new_hpr)
Reads an array of HPR angles.
Definition fftCompressor.cxx:681
FFTCompressor::get_use_error_threshold
bool get_use_error_threshold() const
Returns whether the error threshold measurement is enabled.
Definition fftCompressor.cxx:161
FFTCompressor::set_quality
void set_quality(int quality)
Sets the quality factor for the compression.
Definition fftCompressor.cxx:89
FFTCompressor::read_header
bool read_header(DatagramIterator &di, int bam_minor_version)
Reads the compression header that was written previously.
Definition fftCompressor.cxx:541
FFTCompressor::get_quality
int get_quality() const
Returns the quality number that was previously set via set_quality().
Definition fftCompressor.cxx:139
FFTCompressor::is_compression_available
static bool is_compression_available()
Returns true if the FFTW library is compiled in, so that this class is actually capable of doing usef...
Definition fftCompressor.cxx:64
FFTCompressor::write_header
void write_header(Datagram &datagram)
Writes the compression parameters to the indicated datagram.
Definition fftCompressor.cxx:189
FFTCompressor::write_reals
void write_reals(Datagram &datagram, const PN_stdfloat *array, int length)
Writes an array of floating-point numbers to the indicated datagram.
Definition fftCompressor.cxx:202
FFTCompressor::write_hprs
void write_hprs(Datagram &datagram, const LVecBase3 *array, int length)
Writes an array of HPR angles to the indicated datagram.
Definition fftCompressor.cxx:371
FFTCompressor::get_transpose_quats
bool get_transpose_quats() const
Returns the transpose_quats flag.
Definition fftCompressor.cxx:179
array
STL class.
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.