Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
point_coding.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2011-2012, 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 */
37
38#pragma once
39
40#include <algorithm>
41#include <iostream>
42#include <vector>
43
44namespace pcl
45{
46namespace octree
47{
48/** \brief @b PointCoding class
49 * \note This class encodes 8-bit differential point information for octree-based point cloud compression.
50 * \note typename: PointT: type of point used in pointcloud
51 * \author Julius Kammerl (julius@kammerl.de)
52 */
53template<typename PointT>
55{
56 // public typedefs
57 using PointCloud = pcl::PointCloud<PointT>;
58 using PointCloudPtr = typename PointCloud::Ptr;
59 using PointCloudConstPtr = typename PointCloud::ConstPtr;
60
61 public:
62 /** \brief Constructor. */
64 output_ (),
65 pointCompressionResolution_ (0.001f) // 1mm
66 {
67 }
68
69 /** \brief Empty class constructor. */
70 virtual
71 ~PointCoding () = default;
72
73 /** \brief Define precision of point information
74 * \param precision_arg: precision
75 */
76 inline void
77 setPrecision (float precision_arg)
78 {
79 pointCompressionResolution_ = precision_arg;
80 }
81
82 /** \brief Retrieve precision of point information
83 * \return precision
84 */
85 inline float
87 {
89 }
90
91 /** \brief Set amount of points within point cloud to be encoded and reserve memory
92 * \param pointCount_arg: amounts of points within point cloud
93 */
94 inline void
95 setPointCount (unsigned int pointCount_arg)
96 {
97 pointDiffDataVector_.reserve (pointCount_arg * 3);
98 }
99
100 /** \brief Initialize encoding of differential point */
101 void
103 {
104 pointDiffDataVector_.clear ();
105 }
106
107 /** \brief Initialize decoding of differential point */
108 void
113
114 /** \brief Get reference to vector containing differential color data */
115 std::vector<char>&
120
121 /** \brief Encode differential point information for a subset of points from point cloud
122 * \param indexVector_arg indices defining a subset of points from points cloud
123 * \param referencePoint_arg coordinates of reference point
124 * \param inputCloud_arg input point cloud
125 */
126 void
127 encodePoints (const Indices& indexVector_arg, const double* referencePoint_arg,
128 PointCloudConstPtr inputCloud_arg)
129 {
130 // iterate over points within current voxel
131 for (const auto& idx: indexVector_arg)
132 {
133 unsigned char diffX, diffY, diffZ;
134
135 // retrieve point from cloud
136 const PointT& idxPoint = (*inputCloud_arg)[idx];
137
138 // differentially encode point coordinates and truncate overflow
139 diffX = static_cast<unsigned char> (std::max (-127, std::min<int>(127, static_cast<int> ((idxPoint.x - referencePoint_arg[0]) / pointCompressionResolution_))));
140 diffY = static_cast<unsigned char> (std::max (-127, std::min<int>(127, static_cast<int> ((idxPoint.y - referencePoint_arg[1]) / pointCompressionResolution_))));
141 diffZ = static_cast<unsigned char> (std::max (-127, std::min<int>(127, static_cast<int> ((idxPoint.z - referencePoint_arg[2]) / pointCompressionResolution_))));
142
143 // store information in differential point vector
144 pointDiffDataVector_.push_back (diffX);
145 pointDiffDataVector_.push_back (diffY);
146 pointDiffDataVector_.push_back (diffZ);
147 }
148 }
149
150 /** \brief Decode differential point information
151 * \param outputCloud_arg output point cloud
152 * \param referencePoint_arg coordinates of reference point
153 * \param beginIdx_arg index indicating first point to be assigned with color information
154 * \param endIdx_arg index indicating last point to be assigned with color information
155 */
156 void
157 decodePoints (PointCloudPtr outputCloud_arg, const double* referencePoint_arg, uindex_t beginIdx_arg,
158 uindex_t endIdx_arg)
159 {
160 assert (beginIdx_arg <= endIdx_arg);
161
162 const uindex_t pointCount = endIdx_arg - beginIdx_arg;
163
164 // iterate over points within current voxel
165 for (uindex_t i = 0; i < pointCount; i++)
166 {
167 // retrieve differential point information
168 const unsigned char& diffX = static_cast<unsigned char> (*(pointDiffDataVectorIterator_++));
169 const unsigned char& diffY = static_cast<unsigned char> (*(pointDiffDataVectorIterator_++));
170 const unsigned char& diffZ = static_cast<unsigned char> (*(pointDiffDataVectorIterator_++));
171
172 // retrieve point from point cloud
173 PointT& point = (*outputCloud_arg)[beginIdx_arg + i];
174
175 // decode point position
176 point.x = static_cast<float> (referencePoint_arg[0] + diffX * pointCompressionResolution_);
177 point.y = static_cast<float> (referencePoint_arg[1] + diffY * pointCompressionResolution_);
178 point.z = static_cast<float> (referencePoint_arg[2] + diffZ * pointCompressionResolution_);
179 }
180 }
181
182 protected:
183 /** \brief Pointer to output point cloud dataset. */
184 PointCloudPtr output_;
185
186 /** \brief Vector for storing differential point information */
187 std::vector<char> pointDiffDataVector_;
188
189 /** \brief Iterator on differential point information vector */
190 std::vector<char>::const_iterator pointDiffDataVectorIterator_;
191
192 /** \brief Precision of point coding*/
194};
195
196} // namespace octree
197} // namespace pcl
198
199#define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>;
200
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
PointCoding class
PointCoding()
Constructor.
void encodePoints(const Indices &indexVector_arg, const double *referencePoint_arg, PointCloudConstPtr inputCloud_arg)
Encode differential point information for a subset of points from point cloud.
void initializeEncoding()
Initialize encoding of differential point.
std::vector< char > pointDiffDataVector_
Vector for storing differential point information
float pointCompressionResolution_
Precision of point coding.
void initializeDecoding()
Initialize decoding of differential point.
void decodePoints(PointCloudPtr outputCloud_arg, const double *referencePoint_arg, uindex_t beginIdx_arg, uindex_t endIdx_arg)
Decode differential point information.
float getPrecision()
Retrieve precision of point information.
std::vector< char > & getDifferentialDataVector()
Get reference to vector containing differential color data.
virtual ~PointCoding()=default
Empty class constructor.
void setPointCount(unsigned int pointCount_arg)
Set amount of points within point cloud to be encoded and reserve memory.
std::vector< char >::const_iterator pointDiffDataVectorIterator_
Iterator on differential point information vector.
PointCloudPtr output_
Pointer to output point cloud dataset.
void setPrecision(float precision_arg)
Define precision of point information.
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition types.h:120
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.