00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2009-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 */ 00037 00038 #ifndef OCTREE_COMPRESSION_H 00039 #define OCTREE_COMPRESSION_H 00040 00041 #include <pcl/common/common.h> 00042 #include <pcl/common/io.h> 00043 #include <pcl/octree/octree2buf_base.h> 00044 #include <pcl/octree/octree_pointcloud.h> 00045 #include "entropy_range_coder.h" 00046 #include "color_coding.h" 00047 #include "point_coding.h" 00048 00049 #include "compression_profiles.h" 00050 00051 #include <iterator> 00052 #include <iostream> 00053 #include <vector> 00054 #include <string.h> 00055 #include <iostream> 00056 #include <stdio.h> 00057 #include <string.h> 00058 00059 using namespace pcl::octree; 00060 00061 namespace pcl 00062 { 00063 namespace io 00064 { 00065 /** \brief @b Octree pointcloud compression class 00066 * \note This class enables compression and decompression of point cloud data based on octree data structures. 00067 * \note 00068 * \note typename: PointT: type of point used in pointcloud 00069 * \author Julius Kammerl (julius@kammerl.de) 00070 */ 00071 template<typename PointT, typename LeafT = OctreeContainerPointIndices, 00072 typename BranchT = OctreeContainerEmpty, 00073 typename OctreeT = Octree2BufBase<LeafT, BranchT> > 00074 class OctreePointCloudCompression : public OctreePointCloud<PointT, LeafT, 00075 BranchT, OctreeT> 00076 { 00077 public: 00078 // public typedefs 00079 typedef typename OctreePointCloud<PointT, LeafT, BranchT, OctreeT>::PointCloud PointCloud; 00080 typedef typename OctreePointCloud<PointT, LeafT, BranchT, OctreeT>::PointCloudPtr PointCloudPtr; 00081 typedef typename OctreePointCloud<PointT, LeafT, BranchT, OctreeT>::PointCloudConstPtr PointCloudConstPtr; 00082 00083 // Boost shared pointers 00084 typedef boost::shared_ptr<OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeT> > Ptr; 00085 typedef boost::shared_ptr<const OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeT> > ConstPtr; 00086 00087 typedef typename OctreeT::LeafNode LeafNode; 00088 typedef typename OctreeT::BranchNode BranchNode; 00089 00090 typedef OctreePointCloudCompression<PointT, LeafT, BranchT, Octree2BufBase<LeafT, BranchT> > RealTimeStreamCompression; 00091 typedef OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeBase<LeafT, BranchT> > SinglePointCloudCompressionLowMemory; 00092 00093 00094 /** \brief Constructor 00095 * \param compressionProfile_arg: define compression profile 00096 * \param octreeResolution_arg: octree resolution at lowest octree level 00097 * \param pointResolution_arg: precision of point coordinates 00098 * \param doVoxelGridDownDownSampling_arg: voxel grid filtering 00099 * \param iFrameRate_arg: i-frame encoding rate 00100 * \param doColorEncoding_arg: enable/disable color coding 00101 * \param colorBitResolution_arg: color bit depth 00102 * \param showStatistics_arg: output compression statistics 00103 */ 00104 OctreePointCloudCompression (compression_Profiles_e compressionProfile_arg = MED_RES_ONLINE_COMPRESSION_WITH_COLOR, 00105 bool showStatistics_arg = false, 00106 const double pointResolution_arg = 0.001, 00107 const double octreeResolution_arg = 0.01, 00108 bool doVoxelGridDownDownSampling_arg = false, 00109 const unsigned int iFrameRate_arg = 30, 00110 bool doColorEncoding_arg = true, 00111 const unsigned char colorBitResolution_arg = 6) : 00112 OctreePointCloud<PointT, LeafT, BranchT, OctreeT> (octreeResolution_arg), 00113 output_ (PointCloudPtr ()), 00114 binary_tree_data_vector_ (), 00115 binary_color_tree_vector_ (), 00116 point_count_data_vector_ (), 00117 point_count_data_vector_iterator_ (), 00118 color_coder_ (), 00119 point_coder_ (), 00120 entropy_coder_ (), 00121 do_voxel_grid_enDecoding_ (doVoxelGridDownDownSampling_arg), i_frame_rate_ (iFrameRate_arg), 00122 i_frame_counter_ (0), frame_ID_ (0), point_count_ (0), i_frame_ (true), 00123 do_color_encoding_ (doColorEncoding_arg), cloud_with_color_ (false), data_with_color_ (false), 00124 point_color_offset_ (0), b_show_statistics_ (showStatistics_arg), 00125 compressed_point_data_len_ (), compressed_color_data_len_ (), selected_profile_(compressionProfile_arg), 00126 point_resolution_(pointResolution_arg), octree_resolution_(octreeResolution_arg), 00127 color_bit_resolution_(colorBitResolution_arg), 00128 object_count_(0) 00129 { 00130 initialization(); 00131 } 00132 00133 /** \brief Empty deconstructor. */ 00134 virtual 00135 ~OctreePointCloudCompression () 00136 { 00137 } 00138 00139 /** \brief Initialize globals */ 00140 void initialization () { 00141 if (selected_profile_ != MANUAL_CONFIGURATION) 00142 { 00143 // apply selected compression profile 00144 00145 // retrieve profile settings 00146 const configurationProfile_t selectedProfile = compressionProfiles_[selected_profile_]; 00147 00148 // apply profile settings 00149 i_frame_rate_ = selectedProfile.iFrameRate; 00150 do_voxel_grid_enDecoding_ = selectedProfile.doVoxelGridDownSampling; 00151 this->setResolution (selectedProfile.octreeResolution); 00152 point_coder_.setPrecision (static_cast<float> (selectedProfile.pointResolution)); 00153 do_color_encoding_ = selectedProfile.doColorEncoding; 00154 color_coder_.setBitDepth (selectedProfile.colorBitResolution); 00155 00156 } 00157 else 00158 { 00159 // configure point & color coder 00160 point_coder_.setPrecision (static_cast<float> (point_resolution_)); 00161 color_coder_.setBitDepth (color_bit_resolution_); 00162 } 00163 00164 if (point_coder_.getPrecision () == this->getResolution ()) 00165 //disable differential point colding 00166 do_voxel_grid_enDecoding_ = true; 00167 00168 } 00169 00170 /** \brief Add point at index from input pointcloud dataset to octree 00171 * \param[in] pointIdx_arg the index representing the point in the dataset given by \a setInputCloud to be added 00172 */ 00173 virtual void 00174 addPointIdx (const int pointIdx_arg) 00175 { 00176 ++object_count_; 00177 OctreePointCloud<PointT, LeafT, BranchT, OctreeT>::addPointIdx(pointIdx_arg); 00178 } 00179 00180 /** \brief Provide a pointer to the output data set. 00181 * \param cloud_arg: the boost shared pointer to a PointCloud message 00182 */ 00183 inline void 00184 setOutputCloud (const PointCloudPtr &cloud_arg) 00185 { 00186 if (output_ != cloud_arg) 00187 { 00188 output_ = cloud_arg; 00189 } 00190 } 00191 00192 /** \brief Get a pointer to the output point cloud dataset. 00193 * \return pointer to pointcloud output class. 00194 */ 00195 inline PointCloudPtr 00196 getOutputCloud () const 00197 { 00198 return (output_); 00199 } 00200 00201 /** \brief Encode point cloud to output stream 00202 * \param cloud_arg: point cloud to be compressed 00203 * \param compressed_tree_data_out_arg: binary output stream containing compressed data 00204 */ 00205 void 00206 encodePointCloud (const PointCloudConstPtr &cloud_arg, std::ostream& compressed_tree_data_out_arg); 00207 00208 /** \brief Decode point cloud from input stream 00209 * \param compressed_tree_data_in_arg: binary input stream containing compressed data 00210 * \param cloud_arg: reference to decoded point cloud 00211 */ 00212 void 00213 decodePointCloud (std::istream& compressed_tree_data_in_arg, PointCloudPtr &cloud_arg); 00214 00215 protected: 00216 00217 /** \brief Write frame information to output stream 00218 * \param compressed_tree_data_out_arg: binary output stream 00219 */ 00220 void 00221 writeFrameHeader (std::ostream& compressed_tree_data_out_arg); 00222 00223 /** \brief Read frame information to output stream 00224 * \param compressed_tree_data_in_arg: binary input stream 00225 */ 00226 void 00227 readFrameHeader (std::istream& compressed_tree_data_in_arg); 00228 00229 /** \brief Synchronize to frame header 00230 * \param compressed_tree_data_in_arg: binary input stream 00231 */ 00232 void 00233 syncToHeader (std::istream& compressed_tree_data_in_arg); 00234 00235 /** \brief Apply entropy encoding to encoded information and output to binary stream 00236 * \param compressed_tree_data_out_arg: binary output stream 00237 */ 00238 void 00239 entropyEncoding (std::ostream& compressed_tree_data_out_arg); 00240 00241 /** \brief Entropy decoding of input binary stream and output to information vectors 00242 * \param compressed_tree_data_in_arg: binary input stream 00243 */ 00244 void 00245 entropyDecoding (std::istream& compressed_tree_data_in_arg); 00246 00247 /** \brief Encode leaf node information during serialization 00248 * \param leaf_arg: reference to new leaf node 00249 * \param key_arg: octree key of new leaf node 00250 */ 00251 virtual void 00252 serializeTreeCallback (LeafT &leaf_arg, const OctreeKey& key_arg); 00253 00254 /** \brief Decode leaf nodes information during deserialization 00255 * \param leaf_arg: reference to new leaf node 00256 * \param key_arg: octree key of new leaf node 00257 */ 00258 virtual void 00259 deserializeTreeCallback (LeafT&, const OctreeKey& key_arg); 00260 00261 00262 /** \brief Pointer to output point cloud dataset. */ 00263 PointCloudPtr output_; 00264 00265 /** \brief Vector for storing binary tree structure */ 00266 std::vector<char> binary_tree_data_vector_; 00267 00268 /** \brief Interator on binary tree structure vector */ 00269 std::vector<char> binary_color_tree_vector_; 00270 00271 /** \brief Vector for storing points per voxel information */ 00272 std::vector<unsigned int> point_count_data_vector_; 00273 00274 /** \brief Interator on points per voxel vector */ 00275 std::vector<unsigned int>::const_iterator point_count_data_vector_iterator_; 00276 00277 /** \brief Color coding instance */ 00278 ColorCoding<PointT> color_coder_; 00279 00280 /** \brief Point coding instance */ 00281 PointCoding<PointT> point_coder_; 00282 00283 /** \brief Static range coder instance */ 00284 StaticRangeCoder entropy_coder_; 00285 00286 bool do_voxel_grid_enDecoding_; 00287 uint32_t i_frame_rate_; 00288 uint32_t i_frame_counter_; 00289 uint32_t frame_ID_; 00290 uint64_t point_count_; 00291 bool i_frame_; 00292 00293 bool do_color_encoding_; 00294 bool cloud_with_color_; 00295 bool data_with_color_; 00296 unsigned char point_color_offset_; 00297 00298 //bool activating statistics 00299 bool b_show_statistics_; 00300 uint64_t compressed_point_data_len_; 00301 uint64_t compressed_color_data_len_; 00302 00303 // frame header identifier 00304 static const char* frame_header_identifier_; 00305 00306 const compression_Profiles_e selected_profile_; 00307 const double point_resolution_; 00308 const double octree_resolution_; 00309 const unsigned char color_bit_resolution_; 00310 00311 std::size_t object_count_; 00312 00313 }; 00314 00315 // define frame identifier 00316 template<typename PointT, typename LeafT, typename BranchT, typename OctreeT> 00317 const char* OctreePointCloudCompression<PointT, LeafT, BranchT, OctreeT>::frame_header_identifier_ = "<PCL-OCT-COMPRESSED>"; 00318 } 00319 00320 } 00321 00322 00323 #endif 00324
Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
Pages generated on Wed Mar 25 00:24:29 2015