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