Point Cloud Library (PCL)
1.12.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
compression
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
44
namespace
pcl
45
{
46
namespace
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
*/
53
template
<
typename
Po
int
T>
54
class
PointCoding
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. */
63
PointCoding
() :
64
output_
(),
65
pointCompressionResolution_
(0.001f)
// 1mm
66
{
67
}
68
69
/** \brief Empty class constructor. */
70
virtual
71
~PointCoding
()
72
{
73
}
74
75
/** \brief Define precision of point information
76
* \param precision_arg: precision
77
*/
78
inline
void
79
setPrecision
(
float
precision_arg)
80
{
81
pointCompressionResolution_
= precision_arg;
82
}
83
84
/** \brief Retrieve precision of point information
85
* \return precision
86
*/
87
inline
float
88
getPrecision
()
89
{
90
return
(
pointCompressionResolution_
);
91
}
92
93
/** \brief Set amount of points within point cloud to be encoded and reserve memory
94
* \param pointCount_arg: amounts of points within point cloud
95
*/
96
inline
void
97
setPointCount
(
unsigned
int
pointCount_arg)
98
{
99
pointDiffDataVector_
.reserve (pointCount_arg * 3);
100
}
101
102
/** \brief Initialize encoding of differential point */
103
void
104
initializeEncoding
()
105
{
106
pointDiffDataVector_
.clear ();
107
}
108
109
/** \brief Initialize decoding of differential point */
110
void
111
initializeDecoding
()
112
{
113
pointDiffDataVectorIterator_
=
pointDiffDataVector_
.begin ();
114
}
115
116
/** \brief Get reference to vector containing differential color data */
117
std::vector<char>&
118
getDifferentialDataVector
()
119
{
120
return
(
pointDiffDataVector_
);
121
}
122
123
/** \brief Encode differential point information for a subset of points from point cloud
124
* \param indexVector_arg indices defining a subset of points from points cloud
125
* \param referencePoint_arg coordinates of reference point
126
* \param inputCloud_arg input point cloud
127
*/
128
void
129
encodePoints
(
const
Indices
& indexVector_arg,
const
double
* referencePoint_arg,
130
PointCloudConstPtr inputCloud_arg)
131
{
132
// iterate over points within current voxel
133
for
(
const
auto
& idx: indexVector_arg)
134
{
135
unsigned
char
diffX, diffY, diffZ;
136
137
// retrieve point from cloud
138
const
PointT& idxPoint = (*inputCloud_arg)[idx];
139
140
// differentially encode point coordinates and truncate overflow
141
diffX =
static_cast<
unsigned
char
>
(std::max (-127, std::min<int>(127,
static_cast<
int
>
((idxPoint.x - referencePoint_arg[0]) /
pointCompressionResolution_
))));
142
diffY =
static_cast<
unsigned
char
>
(std::max (-127, std::min<int>(127,
static_cast<
int
>
((idxPoint.y - referencePoint_arg[1]) /
pointCompressionResolution_
))));
143
diffZ =
static_cast<
unsigned
char
>
(std::max (-127, std::min<int>(127,
static_cast<
int
>
((idxPoint.z - referencePoint_arg[2]) /
pointCompressionResolution_
))));
144
145
// store information in differential point vector
146
pointDiffDataVector_
.push_back (diffX);
147
pointDiffDataVector_
.push_back (diffY);
148
pointDiffDataVector_
.push_back (diffZ);
149
}
150
}
151
152
/** \brief Decode differential point information
153
* \param outputCloud_arg output point cloud
154
* \param referencePoint_arg coordinates of reference point
155
* \param beginIdx_arg index indicating first point to be assigned with color information
156
* \param endIdx_arg index indicating last point to be assigned with color information
157
*/
158
void
159
decodePoints
(PointCloudPtr outputCloud_arg,
const
double
* referencePoint_arg,
uindex_t
beginIdx_arg,
160
uindex_t
endIdx_arg)
161
{
162
assert (beginIdx_arg <= endIdx_arg);
163
164
const
uindex_t
pointCount = endIdx_arg - beginIdx_arg;
165
166
// iterate over points within current voxel
167
for
(
uindex_t
i = 0; i < pointCount; i++)
168
{
169
// retrieve differential point information
170
const
unsigned
char
& diffX =
static_cast<
unsigned
char
>
(*(
pointDiffDataVectorIterator_
++));
171
const
unsigned
char
& diffY =
static_cast<
unsigned
char
>
(*(
pointDiffDataVectorIterator_
++));
172
const
unsigned
char
& diffZ =
static_cast<
unsigned
char
>
(*(
pointDiffDataVectorIterator_
++));
173
174
// retrieve point from point cloud
175
PointT& point = (*outputCloud_arg)[beginIdx_arg + i];
176
177
// decode point position
178
point.x =
static_cast<
float
>
(referencePoint_arg[0] + diffX *
pointCompressionResolution_
);
179
point.y =
static_cast<
float
>
(referencePoint_arg[1] + diffY *
pointCompressionResolution_
);
180
point.z =
static_cast<
float
>
(referencePoint_arg[2] + diffZ *
pointCompressionResolution_
);
181
}
182
}
183
184
protected
:
185
/** \brief Pointer to output point cloud dataset. */
186
PointCloudPtr
output_
;
187
188
/** \brief Vector for storing differential point information */
189
std::vector<char>
pointDiffDataVector_
;
190
191
/** \brief Iterator on differential point information vector */
192
std::vector<char>::const_iterator
pointDiffDataVectorIterator_
;
193
194
/** \brief Precision of point coding*/
195
float
pointCompressionResolution_
;
196
};
197
198
}
// namespace octree
199
}
// namespace pcl
200
201
#define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>;
202
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition
point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition
point_cloud.h:414
pcl::octree::PointCoding::PointCoding
PointCoding()
Constructor.
Definition
point_coding.h:63
pcl::octree::PointCoding::encodePoints
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.
Definition
point_coding.h:129
pcl::octree::PointCoding::initializeEncoding
void initializeEncoding()
Initialize encoding of differential point.
Definition
point_coding.h:104
pcl::octree::PointCoding::pointDiffDataVector_
std::vector< char > pointDiffDataVector_
Vector for storing differential point information.
Definition
point_coding.h:189
pcl::octree::PointCoding::pointCompressionResolution_
float pointCompressionResolution_
Precision of point coding.
Definition
point_coding.h:195
pcl::octree::PointCoding::initializeDecoding
void initializeDecoding()
Initialize decoding of differential point.
Definition
point_coding.h:111
pcl::octree::PointCoding::decodePoints
void decodePoints(PointCloudPtr outputCloud_arg, const double *referencePoint_arg, uindex_t beginIdx_arg, uindex_t endIdx_arg)
Decode differential point information.
Definition
point_coding.h:159
pcl::octree::PointCoding::getPrecision
float getPrecision()
Retrieve precision of point information.
Definition
point_coding.h:88
pcl::octree::PointCoding::~PointCoding
virtual ~PointCoding()
Empty class constructor.
Definition
point_coding.h:71
pcl::octree::PointCoding::getDifferentialDataVector
std::vector< char > & getDifferentialDataVector()
Get reference to vector containing differential color data.
Definition
point_coding.h:118
pcl::octree::PointCoding::setPointCount
void setPointCount(unsigned int pointCount_arg)
Set amount of points within point cloud to be encoded and reserve memory.
Definition
point_coding.h:97
pcl::octree::PointCoding::pointDiffDataVectorIterator_
std::vector< char >::const_iterator pointDiffDataVectorIterator_
Iterator on differential point information vector.
Definition
point_coding.h:192
pcl::octree::PointCoding::output_
PointCloudPtr output_
Pointer to output point cloud dataset.
Definition
point_coding.h:186
pcl::octree::PointCoding::setPrecision
void setPrecision(float precision_arg)
Define precision of point information.
Definition
point_coding.h:79
pcl::octree
Definition
color_coding.h:47
pcl
Definition
convolution.h:46
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition
types.h:133
pcl::uindex_t
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition
types.h:120