60 template<
typename Po
intT>
73 output_ (), colorBitReduction_ (0)
90 colorBitReduction_ =
static_cast<unsigned char> (8 - bitDepth_arg);
99 return (static_cast<unsigned char> (8 - colorBitReduction_));
108 pointAvgColorDataVector_.reserve (voxelCount_arg * 3);
118 pointDiffColorDataVector_.reserve (pointCount_arg * 3);
126 pointAvgColorDataVector_.clear ();
128 pointDiffColorDataVector_.clear ();
136 pointAvgColorDataVector_Iterator_ = pointAvgColorDataVector_.begin ();
138 pointDiffColorDataVector_Iterator_ = pointDiffColorDataVector_.begin ();
146 return pointAvgColorDataVector_;
154 return pointDiffColorDataVector_;
163 encodeAverageOfPoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
165 unsigned int avgRed = 0;
166 unsigned int avgGreen = 0;
167 unsigned int avgBlue = 0;
170 std::size_t len = indexVector_arg.size ();
171 for (std::size_t i = 0; i < len; i++)
174 const int& idx = indexVector_arg[i];
175 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
176 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
179 avgRed += (colorInt >> 0) & 0xFF;
180 avgGreen += (colorInt >> 8) & 0xFF;
181 avgBlue += (colorInt >> 16) & 0xFF;
188 avgRed /=
static_cast<unsigned int> (len);
189 avgGreen /=
static_cast<unsigned int> (len);
190 avgBlue /=
static_cast<unsigned int> (len);
194 avgRed >>= colorBitReduction_;
195 avgGreen >>= colorBitReduction_;
196 avgBlue >>= colorBitReduction_;
199 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
200 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
201 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
210 encodePoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
213 unsigned int avgGreen;
214 unsigned int avgBlue;
217 avgRed = avgGreen = avgBlue = 0;
220 std::size_t len = indexVector_arg.size ();
221 for (std::size_t i = 0; i < len; i++)
224 const int& idx = indexVector_arg[i];
225 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
226 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
229 avgRed += (colorInt >> 0) & 0xFF;
230 avgGreen += (colorInt >> 8) & 0xFF;
231 avgBlue += (colorInt >> 16) & 0xFF;
237 unsigned char diffRed;
238 unsigned char diffGreen;
239 unsigned char diffBlue;
242 avgRed /=
static_cast<unsigned int> (len);
243 avgGreen /=
static_cast<unsigned int> (len);
244 avgBlue /=
static_cast<unsigned int> (len);
247 for (std::size_t i = 0; i < len; i++)
249 const int& idx = indexVector_arg[i];
250 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
251 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
254 diffRed = (
static_cast<unsigned char> (avgRed)) ^
static_cast<unsigned char> (((colorInt >> 0) & 0xFF));
255 diffGreen = (
static_cast<unsigned char> (avgGreen)) ^
static_cast<unsigned char> (((colorInt >> 8) & 0xFF));
256 diffBlue = (
static_cast<unsigned char> (avgBlue)) ^
static_cast<unsigned char> (((colorInt >> 16) & 0xFF));
259 diffRed =
static_cast<unsigned char> (diffRed >> colorBitReduction_);
260 diffGreen =
static_cast<unsigned char> (diffGreen >> colorBitReduction_);
261 diffBlue =
static_cast<unsigned char> (diffBlue >> colorBitReduction_);
264 pointDiffColorDataVector_.push_back (static_cast<char> (diffRed));
265 pointDiffColorDataVector_.push_back (static_cast<char> (diffGreen));
266 pointDiffColorDataVector_.push_back (static_cast<char> (diffBlue));
271 avgRed >>= colorBitReduction_;
272 avgGreen >>= colorBitReduction_;
273 avgBlue >>= colorBitReduction_;
276 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
277 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
278 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
289 decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
291 assert (beginIdx_arg <= endIdx_arg);
294 unsigned int pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
297 unsigned char avgRed = *(pointAvgColorDataVector_Iterator_++);
298 unsigned char avgGreen = *(pointAvgColorDataVector_Iterator_++);
299 unsigned char avgBlue = *(pointAvgColorDataVector_Iterator_++);
302 avgRed =
static_cast<unsigned char> (avgRed << colorBitReduction_);
303 avgGreen =
static_cast<unsigned char> (avgGreen << colorBitReduction_);
304 avgBlue =
static_cast<unsigned char> (avgBlue << colorBitReduction_);
307 for (std::size_t i = 0; i < pointCount; i++)
309 unsigned int colorInt;
313 unsigned char diffRed =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
314 unsigned char diffGreen =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
315 unsigned char diffBlue =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
318 diffRed =
static_cast<unsigned char> (diffRed << colorBitReduction_);
319 diffGreen =
static_cast<unsigned char> (diffGreen << colorBitReduction_);
320 diffBlue =
static_cast<unsigned char> (diffBlue << colorBitReduction_);
323 colorInt = ((avgRed ^ diffRed) << 0) |
324 ((avgGreen ^ diffGreen) << 8) |
325 ((avgBlue ^ diffBlue) << 16);
330 colorInt = (avgRed << 0) | (avgGreen << 8) | (avgBlue << 16);
333 char* idxPointPtr =
reinterpret_cast<char*
> (&outputCloud_arg->points[beginIdx_arg + i]);
334 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
347 setDefaultColor (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
349 assert (beginIdx_arg <= endIdx_arg);
352 unsigned int pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
355 for (std::size_t i = 0; i < pointCount; i++)
357 char* idxPointPtr =
reinterpret_cast<char*
> (&outputCloud_arg->points[beginIdx_arg + i]);
358 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
360 pointColor = defaultColor_;
388 template<
typename Po
intT>
396 #define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>;
shared_ptr< PointCloud< PointT > > Ptr
std::vector< char >::const_iterator pointDiffColorDataVector_Iterator_
Iterator on differential color information vector.
std::vector< char > pointAvgColorDataVector_
Vector for storing average color information.
unsigned char colorBitReduction_
Amount of bits to be removed from color components before encoding.
static const int defaultColor_
void initializeDecoding()
Initialize decoding of color information.
PointCloudPtr output_
Pointer to output point cloud dataset.
void setVoxelCount(unsigned int voxelCount_arg)
Set amount of voxels containing point color information and reserve memory.
void setDefaultColor(PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg, unsigned char rgba_offset_arg)
Set default color to points.
std::vector< char > pointDiffColorDataVector_
Vector for storing differential color information.
std::vector< char >::const_iterator pointAvgColorDataVector_Iterator_
Iterator on average color information vector.
std::vector< char > & getAverageDataVector()
Get reference to vector containing averaged color data.
ColorCoding()
Constructor.
void encodeAverageOfPoints(const typename std::vector< int > &indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
Encode averaged color information for a subset of points from point cloud.
unsigned char getBitDepth()
Retrieve color bit depth of encoded color information.
void setBitDepth(unsigned char bitDepth_arg)
Define color bit depth of encoded color information.
virtual ~ColorCoding()
Empty class constructor.
std::vector< char > & getDifferentialDataVector()
Get reference to vector containing differential color data.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void decodePoints(PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg, unsigned char rgba_offset_arg)
Decode color information.
void initializeEncoding()
Initialize encoding of color information.
shared_ptr< const PointCloud< PointT > > ConstPtr
void encodePoints(const typename std::vector< int > &indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
Encode color information of a subset of points from point cloud.
void setPointCount(unsigned int pointCount_arg)
Set amount of points within point cloud to be encoded and reserve memory.