Point Cloud Library (PCL) 1.13.0
octree_pointcloud_compression.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2009-2012, Willow Garage, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of Willow Garage, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38#pragma once
39
40#include <pcl/octree/octree2buf_base.h>
41#include <pcl/octree/octree_pointcloud.h>
42#include "entropy_range_coder.h"
43#include "color_coding.h"
44#include "point_coding.h"
45
46#include "compression_profiles.h"
47
48#include <iostream>
49#include <vector>
50
51using namespace pcl::octree;
52
53namespace pcl
54{
55 namespace io
56 {
57 /** \brief @b Octree pointcloud compression class
58 * \note This class enables compression and decompression of point cloud data based on octree data structures.
59 * \note
60 * \note typename: PointT: type of point used in pointcloud
61 * \author Julius Kammerl (julius@kammerl.de)
62 */
63 template<typename PointT, typename LeafT = OctreeContainerPointIndices,
64 typename BranchT = OctreeContainerEmpty,
65 typename OctreeT = Octree2BufBase<LeafT, BranchT> >
66 class OctreePointCloudCompression : public OctreePointCloud<PointT, LeafT,
67 BranchT, OctreeT>
68 {
69 public:
70 // public typedefs
74
75 // Boost shared pointers
76 using Ptr = shared_ptr<OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeT> >;
77 using ConstPtr = shared_ptr<const OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeT> >;
78
79 using LeafNode = typename OctreeT::LeafNode;
81
84
85
86 /** \brief Constructor
87 * \param compressionProfile_arg: define compression profile
88 * \param octreeResolution_arg: octree resolution at lowest octree level
89 * \param pointResolution_arg: precision of point coordinates
90 * \param doVoxelGridDownDownSampling_arg: voxel grid filtering
91 * \param iFrameRate_arg: i-frame encoding rate
92 * \param doColorEncoding_arg: enable/disable color coding
93 * \param colorBitResolution_arg: color bit depth
94 * \param showStatistics_arg: output compression statistics
95 */
97 bool showStatistics_arg = false,
98 const double pointResolution_arg = 0.001,
99 const double octreeResolution_arg = 0.01,
100 bool doVoxelGridDownDownSampling_arg = false,
101 const unsigned int iFrameRate_arg = 30,
102 bool doColorEncoding_arg = true,
103 const unsigned char colorBitResolution_arg = 6) :
104 OctreePointCloud<PointT, LeafT, BranchT, OctreeT> (octreeResolution_arg),
106 color_coder_ (),
107 point_coder_ (),
108 do_voxel_grid_enDecoding_ (doVoxelGridDownDownSampling_arg), i_frame_rate_ (iFrameRate_arg),
109 i_frame_counter_ (0), frame_ID_ (0), point_count_ (0), i_frame_ (true),
110 do_color_encoding_ (doColorEncoding_arg), cloud_with_color_ (false), data_with_color_ (false),
111 point_color_offset_ (0), b_show_statistics_ (showStatistics_arg),
113 point_resolution_(pointResolution_arg), octree_resolution_(octreeResolution_arg),
114 color_bit_resolution_(colorBitResolution_arg),
116 {
118 }
119
120 /** \brief Empty deconstructor. */
121
122 ~OctreePointCloudCompression () override = default;
123
124 /** \brief Initialize globals */
127 {
128 // apply selected compression profile
129
130 // retrieve profile settings
132
133 // apply profile settings
134 i_frame_rate_ = selectedProfile.iFrameRate;
136 this->setResolution (selectedProfile.octreeResolution);
137 point_coder_.setPrecision (static_cast<float> (selectedProfile.pointResolution));
138 do_color_encoding_ = selectedProfile.doColorEncoding;
139 color_coder_.setBitDepth (selectedProfile.colorBitResolution);
140
141 }
142 else
143 {
144 // configure point & color coder
145 point_coder_.setPrecision (static_cast<float> (point_resolution_));
147 }
148
149 if (point_coder_.getPrecision () == this->getResolution ())
150 //disable differential point colding
152
153 }
154
155 /** \brief Add point at index from input pointcloud dataset to octree
156 * \param[in] pointIdx_arg the index representing the point in the dataset given by \a setInputCloud to be added
157 */
158 void
159 addPointIdx (const uindex_t pointIdx_arg) override
160 {
163 }
164
165 /** \brief Provide a pointer to the output data set.
166 * \param cloud_arg: the boost shared pointer to a PointCloud message
167 */
168 inline void
169 setOutputCloud (const PointCloudPtr &cloud_arg)
170 {
171 if (output_ != cloud_arg)
172 {
173 output_ = cloud_arg;
174 }
175 }
176
177 /** \brief Get a pointer to the output point cloud dataset.
178 * \return pointer to pointcloud output class.
179 */
180 inline PointCloudPtr
182 {
183 return (output_);
184 }
185
186 /** \brief Encode point cloud to output stream
187 * \param cloud_arg: point cloud to be compressed
188 * \param compressed_tree_data_out_arg: binary output stream containing compressed data
189 */
190 void
191 encodePointCloud (const PointCloudConstPtr &cloud_arg, std::ostream& compressed_tree_data_out_arg);
192
193 /** \brief Decode point cloud from input stream
194 * \param compressed_tree_data_in_arg: binary input stream containing compressed data
195 * \param cloud_arg: reference to decoded point cloud
196 * \warning This function is blocking until there is data available from the input stream. If the stream never contains any data, this will hang forever!
197 */
198 void
199 decodePointCloud (std::istream& compressed_tree_data_in_arg, PointCloudPtr &cloud_arg);
200
201 protected:
202
203 /** \brief Write frame information to output stream
204 * \param compressed_tree_data_out_arg: binary output stream
205 */
206 void
207 writeFrameHeader (std::ostream& compressed_tree_data_out_arg);
208
209 /** \brief Read frame information to output stream
210 * \param compressed_tree_data_in_arg: binary input stream
211 */
212 void
213 readFrameHeader (std::istream& compressed_tree_data_in_arg);
214
215 /** \brief Synchronize to frame header
216 * \param compressed_tree_data_in_arg: binary input stream
217 */
218 void
219 syncToHeader (std::istream& compressed_tree_data_in_arg);
220
221 /** \brief Apply entropy encoding to encoded information and output to binary stream
222 * \param compressed_tree_data_out_arg: binary output stream
223 */
224 void
225 entropyEncoding (std::ostream& compressed_tree_data_out_arg);
226
227 /** \brief Entropy decoding of input binary stream and output to information vectors
228 * \param compressed_tree_data_in_arg: binary input stream
229 */
230 void
231 entropyDecoding (std::istream& compressed_tree_data_in_arg);
232
233 /** \brief Encode leaf node information during serialization
234 * \param leaf_arg: reference to new leaf node
235 * \param key_arg: octree key of new leaf node
236 */
237 void
238 serializeTreeCallback (LeafT &leaf_arg, const OctreeKey& key_arg) override;
239
240 /** \brief Decode leaf nodes information during deserialization
241 * \param key_arg octree key of new leaf node
242 */
243 // param leaf_arg reference to new leaf node
244 void
245 deserializeTreeCallback (LeafT&, const OctreeKey& key_arg) override;
246
247
248 /** \brief Pointer to output point cloud dataset. */
250
251 /** \brief Vector for storing binary tree structure */
252 std::vector<char> binary_tree_data_vector_;
253
254 /** \brief Vector for storing points per voxel information */
255 std::vector<unsigned int> point_count_data_vector_;
256
257 /** \brief Iterator on points per voxel vector */
258 std::vector<unsigned int>::const_iterator point_count_data_vector_iterator_;
259
260 /** \brief Color coding instance */
262
263 /** \brief Point coding instance */
265
266 /** \brief Static range coder instance */
268
270 std::uint32_t i_frame_rate_;
271 std::uint32_t i_frame_counter_;
272 std::uint32_t frame_ID_;
273 std::uint64_t point_count_;
275
279 unsigned char point_color_offset_;
280
281 //bool activating statistics
285
286 // frame header identifier
287 static const char* frame_header_identifier_;
288
290 const double point_resolution_;
291 const double octree_resolution_;
292 const unsigned char color_bit_resolution_;
293
294 std::size_t object_count_;
295
296 };
297
298 // define frame identifier
299 template<typename PointT, typename LeafT, typename BranchT, typename OctreeT>
301 }
302
303}
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
StaticRangeCoder compression class
Octree pointcloud compression class
void encodePointCloud(const PointCloudConstPtr &cloud_arg, std::ostream &compressed_tree_data_out_arg)
Encode point cloud to output stream.
void entropyEncoding(std::ostream &compressed_tree_data_out_arg)
Apply entropy encoding to encoded information and output to binary stream.
shared_ptr< OctreePointCloudCompression< PointT, LeafT, BranchT, OctreeT > > Ptr
void syncToHeader(std::istream &compressed_tree_data_in_arg)
Synchronize to frame header.
ColorCoding< PointT > color_coder_
Color coding instance.
void readFrameHeader(std::istream &compressed_tree_data_in_arg)
Read frame information to output stream.
~OctreePointCloudCompression() override=default
Empty deconstructor.
std::vector< unsignedint >::const_iterator point_count_data_vector_iterator_
Iterator on points per voxel vector.
void writeFrameHeader(std::ostream &compressed_tree_data_out_arg)
Write frame information to output stream.
PointCoding< PointT > point_coder_
Point coding instance.
void addPointIdx(const uindex_t pointIdx_arg) override
Add point at index from input pointcloud dataset to octree.
typename OctreePointCloud< PointT, LeafT, BranchT, OctreeT >::PointCloud PointCloud
StaticRangeCoder entropy_coder_
Static range coder instance.
typename OctreePointCloud< PointT, LeafT, BranchT, OctreeT >::PointCloudConstPtr PointCloudConstPtr
void setOutputCloud(const PointCloudPtr &cloud_arg)
Provide a pointer to the output data set.
void entropyDecoding(std::istream &compressed_tree_data_in_arg)
Entropy decoding of input binary stream and output to information vectors.
void decodePointCloud(std::istream &compressed_tree_data_in_arg, PointCloudPtr &cloud_arg)
Decode point cloud from input stream.
void deserializeTreeCallback(LeafT &, const OctreeKey &key_arg) override
Decode leaf nodes information during deserialization.
PointCloudPtr getOutputCloud() const
Get a pointer to the output point cloud dataset.
OctreePointCloudCompression(compression_Profiles_e compressionProfile_arg=MED_RES_ONLINE_COMPRESSION_WITH_COLOR, bool showStatistics_arg=false, const double pointResolution_arg=0.001, const double octreeResolution_arg=0.01, bool doVoxelGridDownDownSampling_arg=false, const unsigned int iFrameRate_arg=30, bool doColorEncoding_arg=true, const unsigned char colorBitResolution_arg=6)
Constructor.
std::vector< char > binary_tree_data_vector_
Vector for storing binary tree structure.
shared_ptr< const OctreePointCloudCompression< PointT, LeafT, BranchT, OctreeT > > ConstPtr
PointCloudPtr output_
Pointer to output point cloud dataset.
std::vector< unsigned int > point_count_data_vector_
Vector for storing points per voxel information
void serializeTreeCallback(LeafT &leaf_arg, const OctreeKey &key_arg) override
Encode leaf node information during serialization.
typename OctreePointCloud< PointT, LeafT, BranchT, OctreeT >::PointCloudPtr PointCloudPtr
ColorCoding class
Definition: color_coding.h:57
Octree double buffer class
Octree container class that does not store any information.
Octree container class that does store a vector of point indices.
Octree key class
Definition: octree_key.h:54
Octree pointcloud class
typename PointCloud::Ptr PointCloudPtr
typename PointCloud::ConstPtr PointCloudConstPtr
PointCoding class
Definition: point_coding.h:55
const struct configurationProfile_t compressionProfiles_[COMPRESSION_PROFILE_COUNT]
@ MED_RES_ONLINE_COMPRESSION_WITH_COLOR
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition: types.h:120
A point structure representing Euclidean xyz coordinates, and the RGB color.