Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
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
123 {
124 }
125
126 /** \brief Initialize globals */
129 {
130 // apply selected compression profile
131
132 // retrieve profile settings
134
135 // apply profile settings
136 i_frame_rate_ = selectedProfile.iFrameRate;
138 this->setResolution (selectedProfile.octreeResolution);
139 point_coder_.setPrecision (static_cast<float> (selectedProfile.pointResolution));
140 do_color_encoding_ = selectedProfile.doColorEncoding;
141 color_coder_.setBitDepth (selectedProfile.colorBitResolution);
142
143 }
144 else
145 {
146 // configure point & color coder
147 point_coder_.setPrecision (static_cast<float> (point_resolution_));
149 }
150
151 if (point_coder_.getPrecision () == this->getResolution ())
152 //disable differential point colding
154
155 }
156
157 /** \brief Add point at index from input pointcloud dataset to octree
158 * \param[in] pointIdx_arg the index representing the point in the dataset given by \a setInputCloud to be added
159 */
160 void
161 addPointIdx (const uindex_t pointIdx_arg) override
162 {
165 }
166
167 /** \brief Provide a pointer to the output data set.
168 * \param cloud_arg: the boost shared pointer to a PointCloud message
169 */
170 inline void
171 setOutputCloud (const PointCloudPtr &cloud_arg)
172 {
173 if (output_ != cloud_arg)
174 {
175 output_ = cloud_arg;
176 }
177 }
178
179 /** \brief Get a pointer to the output point cloud dataset.
180 * \return pointer to pointcloud output class.
181 */
182 inline PointCloudPtr
184 {
185 return (output_);
186 }
187
188 /** \brief Encode point cloud to output stream
189 * \param cloud_arg: point cloud to be compressed
190 * \param compressed_tree_data_out_arg: binary output stream containing compressed data
191 */
192 void
193 encodePointCloud (const PointCloudConstPtr &cloud_arg, std::ostream& compressed_tree_data_out_arg);
194
195 /** \brief Decode point cloud from input stream
196 * \param compressed_tree_data_in_arg: binary input stream containing compressed data
197 * \param cloud_arg: reference to decoded point cloud
198 */
199 void
200 decodePointCloud (std::istream& compressed_tree_data_in_arg, PointCloudPtr &cloud_arg);
201
202 protected:
203
204 /** \brief Write frame information to output stream
205 * \param compressed_tree_data_out_arg: binary output stream
206 */
207 void
208 writeFrameHeader (std::ostream& compressed_tree_data_out_arg);
209
210 /** \brief Read frame information to output stream
211 * \param compressed_tree_data_in_arg: binary input stream
212 */
213 void
214 readFrameHeader (std::istream& compressed_tree_data_in_arg);
215
216 /** \brief Synchronize to frame header
217 * \param compressed_tree_data_in_arg: binary input stream
218 */
219 void
220 syncToHeader (std::istream& compressed_tree_data_in_arg);
221
222 /** \brief Apply entropy encoding to encoded information and output to binary stream
223 * \param compressed_tree_data_out_arg: binary output stream
224 */
225 void
226 entropyEncoding (std::ostream& compressed_tree_data_out_arg);
227
228 /** \brief Entropy decoding of input binary stream and output to information vectors
229 * \param compressed_tree_data_in_arg: binary input stream
230 */
231 void
232 entropyDecoding (std::istream& compressed_tree_data_in_arg);
233
234 /** \brief Encode leaf node information during serialization
235 * \param leaf_arg: reference to new leaf node
236 * \param key_arg: octree key of new leaf node
237 */
238 void
239 serializeTreeCallback (LeafT &leaf_arg, const OctreeKey& key_arg) override;
240
241 /** \brief Decode leaf nodes information during deserialization
242 * \param key_arg octree key of new leaf node
243 */
244 // param leaf_arg reference to new leaf node
245 void
246 deserializeTreeCallback (LeafT&, const OctreeKey& key_arg) override;
247
248
249 /** \brief Pointer to output point cloud dataset. */
251
252 /** \brief Vector for storing binary tree structure */
253 std::vector<char> binary_tree_data_vector_;
254
255 /** \brief Vector for storing points per voxel information */
256 std::vector<unsigned int> point_count_data_vector_;
257
258 /** \brief Iterator on points per voxel vector */
259 std::vector<unsigned int>::const_iterator point_count_data_vector_iterator_;
260
261 /** \brief Color coding instance */
263
264 /** \brief Point coding instance */
266
267 /** \brief Static range coder instance */
269
271 std::uint32_t i_frame_rate_;
272 std::uint32_t i_frame_counter_;
273 std::uint32_t frame_ID_;
274 std::uint64_t point_count_;
276
280 unsigned char point_color_offset_;
281
282 //bool activating statistics
286
287 // frame header identifier
288 static const char* frame_header_identifier_;
289
291 const double point_resolution_;
292 const double octree_resolution_;
293 const unsigned char color_bit_resolution_;
294
295 std::size_t object_count_;
296
297 };
298
299 // define frame identifier
300 template<typename PointT, typename LeafT, typename BranchT, typename OctreeT>
302 }
303
304}
PointCloud represents the base class in PCL for storing collections of 3D points.
StaticRangeCoder 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.
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
Octree double buffer class
OctreeBranchNode< BranchContainerT > BranchNode
Definition octree_base.h:66
OctreeLeafNode< LeafContainerT > LeafNode
Definition octree_base.h:67
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:52
Octree pointcloud class
typename PointCloud::Ptr PointCloudPtr
typename PointCloud::ConstPtr PointCloudConstPtr
virtual void addPointIdx(uindex_t point_idx_arg)
Add point at index from input pointcloud dataset to octree.
void setResolution(double resolution_arg)
Set/change the octree voxel resolution.
PointCoding class
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.