Point Cloud Library (PCL)  1.7.0
organized_pointcloud_compression.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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  * $Id$
37  */
38 
39 #ifndef PCL_ORGANIZED_POINT_COMPRESSION_H_
40 #define PCL_ORGANIZED_POINT_COMPRESSION_H_
41 
42 #include <pcl/pcl_macros.h>
43 #include <pcl/point_cloud.h>
44 
45 #include <pcl/common/boost.h>
46 #include <pcl/common/eigen.h>
47 #include <pcl/common/common.h>
48 #include <pcl/common/io.h>
49 
50 #include <pcl/io/openni_camera/openni_shift_to_depth_conversion.h>
51 
52 #include <vector>
53 
54 namespace pcl
55 {
56  namespace io
57  {
58  /** \author Julius Kammerl (julius@kammerl.de)
59  */
60  template<typename PointT>
62  {
63  public:
65  typedef boost::shared_ptr<PointCloud> PointCloudPtr;
66  typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
67 
68  /** \brief Empty Constructor. */
70  {
71  }
72 
73  /** \brief Empty deconstructor. */
75  {
76  }
77 
78  /** \brief Encode point cloud to output stream
79  * \param[in] cloud_arg: point cloud to be compressed
80  * \param[out] compressedDataOut_arg: binary output stream containing compressed data
81  * \param[in] doColorEncoding: encode color information (if available)
82  * \param[in] convertToMono: convert rgb to mono
83  * \param[in] pngLevel_arg: png compression level (default compression: -1)
84  * \param[in] bShowStatistics_arg: show statistics
85  */
86  void encodePointCloud (const PointCloudConstPtr &cloud_arg,
87  std::ostream& compressedDataOut_arg,
88  bool doColorEncoding = false,
89  bool convertToMono = false,
90  bool bShowStatistics_arg = true,
91  int pngLevel_arg = -1);
92 
93  /** \brief Encode raw disparity map and color image.
94  * \note Default values are configured according to the kinect/asus device specifications
95  * \param[in] disparityMap_arg: pointer to raw 16-bit disparity map
96  * \param[in] disparityMap_arg: pointer to raw 8-bit rgb color image
97  * \param[in] width_arg: width of disparity map/color image
98  * \param[in] height_arg: height of disparity map/color image
99  * \param[out] compressedDataOut_arg: binary output stream containing compressed data
100  * \param[in] doColorEncoding: encode color information (if available)
101  * \param[in] convertToMono: convert rgb to mono
102  * \param[in] pngLevel_arg: png compression level (default compression: -1)
103  * \param[in] bShowStatistics_arg: show statistics
104  * \param[in] focalLength_arg focal length
105  * \param[in] disparityShift_arg disparity shift
106  * \param[in] disparityScale_arg disparity scaling
107  */
108  void encodeRawDisparityMapWithColorImage ( std::vector<uint16_t>& disparityMap_arg,
109  std::vector<uint8_t>& colorImage_arg,
110  uint32_t width_arg,
111  uint32_t height_arg,
112  std::ostream& compressedDataOut_arg,
113  bool doColorEncoding = false,
114  bool convertToMono = false,
115  bool bShowStatistics_arg = true,
116  int pngLevel_arg = -1,
117  float focalLength_arg = 525.0f,
118  float disparityShift_arg = 174.825f,
119  float disparityScale_arg = -0.161175f);
120 
121  /** \brief Decode point cloud from input stream
122  * \param[in] compressedDataIn_arg: binary input stream containing compressed data
123  * \param[out] cloud_arg: reference to decoded point cloud
124  * \param[in] bShowStatistics_arg: show compression statistics during decoding
125  * \return false if an I/O error occured.
126  */
127  bool decodePointCloud (std::istream& compressedDataIn_arg,
128  PointCloudPtr &cloud_arg,
129  bool bShowStatistics_arg = true);
130 
131  protected:
132  /** \brief Analyze input point cloud and calculate the maximum depth and focal length
133  * \param[in] cloud_arg: input point cloud
134  * \param[out] maxDepth_arg: calculated maximum depth
135  * \param[out] focalLength_arg: estimated focal length
136  */
137  void analyzeOrganizedCloud (PointCloudConstPtr cloud_arg,
138  float& maxDepth_arg,
139  float& focalLength_arg) const;
140 
141  private:
142  // frame header identifier
143  static const char* frameHeaderIdentifier_;
144 
145  //
147  };
148 
149  // define frame identifier
150  template<typename PointT>
151  const char* OrganizedPointCloudCompression<PointT>::frameHeaderIdentifier_ = "<PCL-ORG-COMPRESSED>";
152  }
153 }
154 
155 #endif
void encodeRawDisparityMapWithColorImage(std::vector< uint16_t > &disparityMap_arg, std::vector< uint8_t > &colorImage_arg, uint32_t width_arg, uint32_t height_arg, std::ostream &compressedDataOut_arg, bool doColorEncoding=false, bool convertToMono=false, bool bShowStatistics_arg=true, int pngLevel_arg=-1, float focalLength_arg=525.0f, float disparityShift_arg=174.825f, float disparityScale_arg=-0.161175f)
Encode raw disparity map and color image.
boost::shared_ptr< const PointCloud > PointCloudConstPtr
bool decodePointCloud(std::istream &compressedDataIn_arg, PointCloudPtr &cloud_arg, bool bShowStatistics_arg=true)
Decode point cloud from input stream.
void encodePointCloud(const PointCloudConstPtr &cloud_arg, std::ostream &compressedDataOut_arg, bool doColorEncoding=false, bool convertToMono=false, bool bShowStatistics_arg=true, int pngLevel_arg=-1)
Encode point cloud to output stream.
virtual ~OrganizedPointCloudCompression()
Empty deconstructor.
This class provides conversion of the openni 11-bit shift data to depth;.
void analyzeOrganizedCloud(PointCloudConstPtr cloud_arg, float &maxDepth_arg, float &focalLength_arg) const
Analyze input point cloud and calculate the maximum depth and focal length.