38#ifndef OCTREE_COMPRESSION_HPP
39#define OCTREE_COMPRESSION_HPP
41#include <pcl/common/io.h>
42#include <pcl/compression/entropy_range_coder.h>
53 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void OctreePointCloudCompression<
59 static_cast<unsigned char> (this->getTreeDepth ());
65 this->addPointsFromInputCloud ();
68 if (this->leaf_count_>0) {
72 cloud_with_color_ =
false;
73 std::vector<pcl::PCLPointField> fields;
82 point_color_offset_ =
static_cast<unsigned char> (fields[
rgba_index].offset);
83 cloud_with_color_ =
true;
87 cloud_with_color_ &= do_color_encoding_;
94 if (i_frame_counter_++==i_frame_rate_)
104 if (!do_voxel_grid_enDecoding_)
106 point_count_data_vector_.clear ();
111 color_coder_.initializeEncoding ();
112 color_coder_.setPointCount (
static_cast<unsigned int> (
cloud_arg->
size ()));
113 color_coder_.setVoxelCount (
static_cast<unsigned int> (this->leaf_count_));
116 point_coder_.initializeEncoding ();
117 point_coder_.setPointCount (
static_cast<unsigned int> (
cloud_arg->
size ()));
122 this->serializeTree (binary_tree_data_vector_,
false);
125 this->serializeTree (binary_tree_data_vector_,
true);
135 this->switchBuffers ();
140 if (b_show_statistics_)
142 float bytes_per_XYZ =
static_cast<float> (compressed_point_data_len_) /
static_cast<float> (point_count_);
143 float bytes_per_color =
static_cast<float> (compressed_color_data_len_) /
static_cast<float> (point_count_);
145 PCL_INFO (
"*** POINTCLOUD ENCODING ***\n");
146 PCL_INFO (
"Frame ID: %d\n", frame_ID_);
148 PCL_INFO (
"Encoding Frame: Intra frame\n");
150 PCL_INFO (
"Encoding Frame: Prediction frame\n");
151 PCL_INFO (
"Number of encoded points: %ld\n", point_count_);
152 PCL_INFO (
"XYZ compression percentage: %f%%\n",
bytes_per_XYZ / (3.0f *
sizeof (
float)) * 100.0f);
154 PCL_INFO (
"Color compression percentage: %f%%\n",
bytes_per_color / (
sizeof (
int)) * 100.0f);
156 PCL_INFO (
"Size of uncompressed point cloud: %f kBytes\n",
static_cast<float> (point_count_) * (
sizeof (
int) + 3.0f *
sizeof (
float)) / 1024.0f);
157 PCL_INFO (
"Size of compressed point cloud: %f kBytes\n",
static_cast<float> (compressed_point_data_len_ + compressed_color_data_len_) / 1024.0f);
160 PCL_INFO (
"Compression ratio: %f\n\n",
static_cast<float> (
sizeof (
int) + 3.0f *
sizeof (
float)) /
static_cast<float> (
bytes_per_XYZ +
bytes_per_color));
165 if (b_show_statistics_)
166 PCL_INFO (
"Info: Dropping empty point cloud\n");
168 i_frame_counter_ = 0;
174 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
184 this->switchBuffers ();
188 cloud_with_color_ =
false;
189 std::vector<pcl::PCLPointField> fields;
196 point_color_offset_ =
static_cast<unsigned char> (fields[
rgba_index].offset);
197 cloud_with_color_ =
true;
207 color_coder_.initializeDecoding ();
208 point_coder_.initializeDecoding ();
211 output_->points.clear ();
212 output_->points.reserve (
static_cast<std::size_t
> (point_count_));
216 this->deserializeTree (binary_tree_data_vector_,
false);
219 this->deserializeTree (binary_tree_data_vector_,
true);
224 output_->is_dense =
false;
226 if (b_show_statistics_)
228 float bytes_per_XYZ =
static_cast<float> (compressed_point_data_len_) /
static_cast<float> (point_count_);
229 float bytes_per_color =
static_cast<float> (compressed_color_data_len_) /
static_cast<float> (point_count_);
231 PCL_INFO (
"*** POINTCLOUD DECODING ***\n");
232 PCL_INFO (
"Frame ID: %d\n", frame_ID_);
234 PCL_INFO (
"Decoding Frame: Intra frame\n");
236 PCL_INFO (
"Decoding Frame: Prediction frame\n");
237 PCL_INFO (
"Number of decoded points: %ld\n", point_count_);
238 PCL_INFO (
"XYZ compression percentage: %f%%\n",
bytes_per_XYZ / (3.0f *
sizeof (
float)) * 100.0f);
240 PCL_INFO (
"Color compression percentage: %f%%\n",
bytes_per_color / (
sizeof (
int)) * 100.0f);
242 PCL_INFO (
"Size of uncompressed point cloud: %f kBytes\n",
static_cast<float> (point_count_) * (
sizeof (
int) + 3.0f *
sizeof (
float)) / 1024.0f);
243 PCL_INFO (
"Size of compressed point cloud: %f kBytes\n",
static_cast<float> (compressed_point_data_len_ + compressed_color_data_len_) / 1024.0f);
246 PCL_INFO (
"Compression ratio: %f\n\n",
static_cast<float> (
sizeof (
int) + 3.0f *
sizeof (
float)) /
static_cast<float> (
bytes_per_XYZ +
bytes_per_color));
251 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
257 compressed_point_data_len_ = 0;
258 compressed_color_data_len_ = 0;
263 compressed_point_data_len_ += entropy_coder_.encodeCharVectorToStream (binary_tree_data_vector_,
266 if (cloud_with_color_)
277 if (!do_voxel_grid_enDecoding_)
286 compressed_point_data_len_ += entropy_coder_.encodeIntVectorToStream (point_count_data_vector_,
295 if (cloud_with_color_)
311 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
317 compressed_point_data_len_ = 0;
318 compressed_color_data_len_ = 0;
324 binary_tree_data_vector_);
326 if (data_with_color_)
336 if (!do_voxel_grid_enDecoding_)
346 point_count_data_vector_iterator_ = point_count_data_vector_.begin ();
355 if (data_with_color_)
368 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
391 if (do_voxel_grid_enDecoding_)
392 point_count_ = this->leaf_count_;
394 point_count_ = this->object_count_;
415 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
430 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
471 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
478 if (!do_voxel_grid_enDecoding_)
483 point_count_data_vector_.push_back (
static_cast<int> (
leafIdx.
size ()));
493 if (cloud_with_color_)
495 color_coder_.encodePoints (
leafIdx, point_color_offset_, this->input_);
499 if (cloud_with_color_)
501 color_coder_.encodeAverageOfPoints (
leafIdx, point_color_offset_, this->input_);
506 template<
typename Po
intT,
typename LeafT,
typename BranchT,
typename OctreeT>
void
514 if (!do_voxel_grid_enDecoding_)
520 pointCount = *point_count_data_vector_iterator_;
521 point_count_data_vector_iterator_++;
525 output_->points.push_back (
newPoint);
539 newPoint.x =
static_cast<float> ((
static_cast<double> (
key_arg.x) + 0.5) * this->resolution_ + this->min_x_);
540 newPoint.y =
static_cast<float> ((
static_cast<double> (
key_arg.y) + 0.5) * this->resolution_ + this->min_y_);
541 newPoint.z =
static_cast<float> ((
static_cast<double> (
key_arg.z) + 0.5) * this->resolution_ + this->min_z_);
544 output_->points.push_back (
newPoint);
547 if (cloud_with_color_)
549 if (data_with_color_)
551 color_coder_.decodePoints (output_, output_->size () -
pointCount,
552 output_->
size (), point_color_offset_);
555 color_coder_.setDefaultColor (output_, output_->size () -
pointCount,
556 output_->
size (), point_color_offset_);
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
void entropyEncoding(std::ostream &compressed_tree_data_out_arg)
Apply entropy encoding to encoded information and output to binary stream.
void syncToHeader(std::istream &compressed_tree_data_in_arg)
Synchronize to frame header.
void readFrameHeader(std::istream &compressed_tree_data_in_arg)
Read frame information to output stream.
void writeFrameHeader(std::ostream &compressed_tree_data_out_arg)
Write frame information to output stream.
typename OctreePointCloud< PointT, LeafT, BranchT, OctreeT >::PointCloudConstPtr PointCloudConstPtr
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.
void serializeTreeCallback(LeafT &leaf_arg, const OctreeKey &key_arg) override
Encode leaf node information during serialization.
typename OctreePointCloud< PointT, LeafT, BranchT, OctreeT >::PointCloudPtr PointCloudPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.