Point Cloud Library (PCL)  1.12.1-dev
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 #pragma once
40 
41 #include <pcl/pcl_macros.h>
42 #include <pcl/point_cloud.h>
43 
44 #include <pcl/io/openni_camera/openni_shift_to_depth_conversion.h>
45 
46 #include <vector>
47 
48 namespace pcl
49 {
50  namespace io
51  {
52  /** \author Julius Kammerl (julius@kammerl.de)
53  */
54  template<typename PointT>
56  {
57  public:
59  using PointCloudPtr = typename PointCloud::Ptr;
61 
62  /** \brief Empty Constructor. */
64 
65  /** \brief Empty deconstructor. */
66  virtual ~OrganizedPointCloudCompression () = default;
67 
68  /** \brief Encode point cloud to output stream
69  * \param[in] cloud_arg: point cloud to be compressed
70  * \param[out] compressedDataOut_arg: binary output stream containing compressed data
71  * \param[in] doColorEncoding: encode color information (if available)
72  * \param[in] convertToMono: convert rgb to mono
73  * \param[in] pngLevel_arg: png compression level (default compression: -1)
74  * \param[in] bShowStatistics_arg: show statistics
75  */
76  void encodePointCloud (const PointCloudConstPtr &cloud_arg,
77  std::ostream& compressedDataOut_arg,
78  bool doColorEncoding = false,
79  bool convertToMono = false,
80  bool bShowStatistics_arg = true,
81  int pngLevel_arg = -1);
82 
83  /** \brief Encode raw disparity map and color image.
84  * \note Default values are configured according to the kinect/asus device specifications
85  * \param[in] disparityMap_arg: pointer to raw 16-bit disparity map
86  * \param[in] colorImage_arg: pointer to raw 8-bit rgb color image
87  * \param[in] width_arg: width of disparity map/color image
88  * \param[in] height_arg: height of disparity map/color image
89  * \param[out] compressedDataOut_arg: binary output stream containing compressed data
90  * \param[in] doColorEncoding: encode color information (if available)
91  * \param[in] convertToMono: convert rgb to mono
92  * \param[in] pngLevel_arg: png compression level (default compression: -1)
93  * \param[in] bShowStatistics_arg: show statistics
94  * \param[in] focalLength_arg focal length
95  * \param[in] disparityShift_arg disparity shift
96  * \param[in] disparityScale_arg disparity scaling
97  */
98  void encodeRawDisparityMapWithColorImage ( std::vector<std::uint16_t>& disparityMap_arg,
99  std::vector<std::uint8_t>& colorImage_arg,
100  std::uint32_t width_arg,
101  std::uint32_t height_arg,
102  std::ostream& compressedDataOut_arg,
103  bool doColorEncoding = false,
104  bool convertToMono = false,
105  bool bShowStatistics_arg = true,
106  int pngLevel_arg = -1,
107  float focalLength_arg = 525.0f,
108  float disparityShift_arg = 174.825f,
109  float disparityScale_arg = -0.161175f);
110 
111  /** \brief Decode point cloud from input stream
112  * \param[in] compressedDataIn_arg: binary input stream containing compressed data
113  * \param[out] cloud_arg: reference to decoded point cloud
114  * \param[in] bShowStatistics_arg: show compression statistics during decoding
115  * \return false if an I/O error occurred.
116  */
117  bool decodePointCloud (std::istream& compressedDataIn_arg,
118  PointCloudPtr &cloud_arg,
119  bool bShowStatistics_arg = true);
120 
121  protected:
122  /** \brief Analyze input point cloud and calculate the maximum depth and focal length
123  * \param[in] cloud_arg: input point cloud
124  * \param[out] maxDepth_arg: calculated maximum depth
125  * \param[out] focalLength_arg: estimated focal length
126  */
128  float& maxDepth_arg,
129  float& focalLength_arg) const;
130 
131  private:
132  // frame header identifier
133  static const char* frameHeaderIdentifier_;
134 
135  //
137  };
138 
139  // define frame identifier
140  template<typename PointT>
141  const char* OrganizedPointCloudCompression<PointT>::frameHeaderIdentifier_ = "<PCL-ORG-COMPRESSED>";
142  }
143 }
This class provides conversion of the openni 11-bit shift data to depth;.
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
virtual ~OrganizedPointCloudCompression()=default
Empty deconstructor.
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.
OrganizedPointCloudCompression()=default
Empty Constructor.
bool decodePointCloud(std::istream &compressedDataIn_arg, PointCloudPtr &cloud_arg, bool bShowStatistics_arg=true)
Decode point cloud from input stream.
void analyzeOrganizedCloud(PointCloudConstPtr cloud_arg, float &maxDepth_arg, float &focalLength_arg) const
Analyze input point cloud and calculate the maximum depth and focal length.
void encodeRawDisparityMapWithColorImage(std::vector< std::uint16_t > &disparityMap_arg, std::vector< std::uint8_t > &colorImage_arg, std::uint32_t width_arg, std::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.
Defines all the PCL and non-PCL macros used.