Point Cloud Library (PCL)
1.12.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
compression
entropy_range_coder.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Copyright (c) 2011, Willow Garage, Inc.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* * Neither the name of Willow Garage, Inc. nor the names of its
18
* contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*
34
*
35
* Range Coder based on Dmitry Subbotin's carry-less implementation (http://www.compression.ru/ds/)
36
* Added optimized symbol lookup and added implementation for static range coding (uses fixed precomputed frequency table)
37
*
38
* Author: Julius Kammerl (julius@kammerl.de)
39
*/
40
41
#pragma once
42
43
#include <iostream>
44
#include <vector>
45
#include <cmath>
46
#include <cstdint>
47
48
#include <
pcl/pcl_macros.h
>
49
50
namespace
pcl
51
{
52
53
using
std::uint8_t;
54
using
std::uint32_t;
55
using
std::uint64_t;
56
57
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
/** \brief @b AdaptiveRangeCoder compression class
59
* \note This class provides adaptive range coding functionality.
60
* \note Its symbol probability/frequency table is adaptively updated during encoding
61
* \note
62
* \author Julius Kammerl (julius@kammerl.de)
63
*/
64
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65
class
AdaptiveRangeCoder
66
{
67
68
public
:
69
70
/** \brief Empty constructor. */
71
AdaptiveRangeCoder
()
72
{
73
}
74
75
/** \brief Empty deconstructor. */
76
virtual
77
~AdaptiveRangeCoder
()
78
{
79
}
80
81
/** \brief Encode char vector to output stream
82
* \param inputByteVector_arg input vector
83
* \param outputByteStream_arg output stream containing compressed data
84
* \return amount of bytes written to output stream
85
*/
86
unsigned
long
87
encodeCharVectorToStream
(
const
std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
88
89
/** \brief Decode char stream to output vector
90
* \param inputByteStream_arg input stream of compressed data
91
* \param outputByteVector_arg decompressed output vector
92
* \return amount of bytes read from input stream
93
*/
94
unsigned
long
95
decodeStreamToCharVector
(std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
96
97
protected
:
98
using
DWord
= std::uint32_t;
// 4 bytes
99
100
private
:
101
/** vector containing compressed data
102
*/
103
std::vector<char> outputCharVector_;
104
105
};
106
107
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108
/** \brief @b StaticRangeCoder compression class
109
* \note This class provides static range coding functionality.
110
* \note Its symbol probability/frequency table is precomputed and encoded to the output stream
111
* \note
112
* \author Julius Kammerl (julius@kammerl.de)
113
*/
114
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115
class
StaticRangeCoder
116
{
117
public
:
118
/** \brief Constructor. */
119
StaticRangeCoder
() :
120
cFreqTable_ (65537)
121
{
122
}
123
124
/** \brief Empty deconstructor. */
125
virtual
126
~StaticRangeCoder
()
127
{
128
}
129
130
/** \brief Encode integer vector to output stream
131
* \param[in] inputIntVector_arg input vector
132
* \param[out] outputByterStream_arg output stream containing compressed data
133
* \return amount of bytes written to output stream
134
*/
135
unsigned
long
136
encodeIntVectorToStream
(std::vector<unsigned int>& inputIntVector_arg, std::ostream& outputByterStream_arg);
137
138
/** \brief Decode stream to output integer vector
139
* \param inputByteStream_arg input stream of compressed data
140
* \param outputIntVector_arg decompressed output vector
141
* \return amount of bytes read from input stream
142
*/
143
unsigned
long
144
decodeStreamToIntVector
(std::istream& inputByteStream_arg, std::vector<unsigned int>& outputIntVector_arg);
145
146
/** \brief Encode char vector to output stream
147
* \param inputByteVector_arg input vector
148
* \param outputByteStream_arg output stream containing compressed data
149
* \return amount of bytes written to output stream
150
*/
151
unsigned
long
152
encodeCharVectorToStream
(
const
std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
153
154
/** \brief Decode char stream to output vector
155
* \param inputByteStream_arg input stream of compressed data
156
* \param outputByteVector_arg decompressed output vector
157
* \return amount of bytes read from input stream
158
*/
159
unsigned
long
160
decodeStreamToCharVector
(std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
161
162
protected
:
163
using
DWord
= std::uint32_t;
// 4 bytes
164
165
private
:
166
/** \brief Vector containing cumulative symbol frequency table. */
167
std::vector<std::uint64_t> cFreqTable_;
168
169
/** \brief Vector containing compressed data. */
170
std::vector<char> outputCharVector_;
171
172
};
173
}
174
175
176
//#include "impl/entropy_range_coder.hpp"
pcl::AdaptiveRangeCoder::DWord
std::uint32_t DWord
Definition
entropy_range_coder.h:98
pcl::AdaptiveRangeCoder::decodeStreamToCharVector
unsigned long decodeStreamToCharVector(std::istream &inputByteStream_arg, std::vector< char > &outputByteVector_arg)
Decode char stream to output vector.
Definition
entropy_range_coder.hpp:131
pcl::AdaptiveRangeCoder::encodeCharVectorToStream
unsigned long encodeCharVectorToStream(const std::vector< char > &inputByteVector_arg, std::ostream &outputByteStream_arg)
Encode char vector to output stream.
Definition
entropy_range_coder.hpp:53
pcl::AdaptiveRangeCoder::AdaptiveRangeCoder
AdaptiveRangeCoder()
Empty constructor.
Definition
entropy_range_coder.h:71
pcl::AdaptiveRangeCoder::~AdaptiveRangeCoder
virtual ~AdaptiveRangeCoder()
Empty deconstructor.
Definition
entropy_range_coder.h:77
pcl::StaticRangeCoder::DWord
std::uint32_t DWord
Definition
entropy_range_coder.h:163
pcl::StaticRangeCoder::decodeStreamToIntVector
unsigned long decodeStreamToIntVector(std::istream &inputByteStream_arg, std::vector< unsigned int > &outputIntVector_arg)
Decode stream to output integer vector.
Definition
entropy_range_coder.hpp:354
pcl::StaticRangeCoder::encodeCharVectorToStream
unsigned long encodeCharVectorToStream(const std::vector< char > &inputByteVector_arg, std::ostream &outputByteStream_arg)
Encode char vector to output stream.
Definition
entropy_range_coder.hpp:444
pcl::StaticRangeCoder::StaticRangeCoder
StaticRangeCoder()
Constructor.
Definition
entropy_range_coder.h:119
pcl::StaticRangeCoder::decodeStreamToCharVector
unsigned long decodeStreamToCharVector(std::istream &inputByteStream_arg, std::vector< char > &outputByteVector_arg)
Decode char stream to output vector.
Definition
entropy_range_coder.hpp:543
pcl::StaticRangeCoder::encodeIntVectorToStream
unsigned long encodeIntVectorToStream(std::vector< unsigned int > &inputIntVector_arg, std::ostream &outputByterStream_arg)
Encode integer vector to output stream.
Definition
entropy_range_coder.hpp:223
pcl::StaticRangeCoder::~StaticRangeCoder
virtual ~StaticRangeCoder()
Empty deconstructor.
Definition
entropy_range_coder.h:126
pcl
Definition
convolution.h:46
pcl_macros.h
Defines all the PCL and non-PCL macros used.