38 #ifndef COLOR_COMPRESSION_H
39 #define COLOR_COMPRESSION_H
63 template<
typename Po
intT>
78 output_ (), pointAvgColorDataVector_ (), pointAvgColorDataVector_Iterator_ (),
79 pointDiffColorDataVector_ (), pointDiffColorDataVector_Iterator_ (), colorBitReduction_ (0)
94 setBitDepth (
unsigned char bitDepth_arg)
96 assert (bitDepth_arg <= bitDepth_arg);
97 colorBitReduction_ =
static_cast<unsigned char> (8 - bitDepth_arg);
106 return (static_cast<unsigned char> (8 - colorBitReduction_));
113 setVoxelCount (
unsigned int voxelCount_arg)
115 pointAvgColorDataVector_.reserve (voxelCount_arg * 3);
123 setPointCount (
unsigned int pointCount_arg)
125 pointDiffColorDataVector_.reserve (pointCount_arg * 3);
131 initializeEncoding ()
133 pointAvgColorDataVector_.clear ();
135 pointDiffColorDataVector_.clear ();
141 initializeDecoding ()
143 pointAvgColorDataVector_Iterator_ = pointAvgColorDataVector_.begin ();
145 pointDiffColorDataVector_Iterator_ = pointDiffColorDataVector_.begin ();
151 getAverageDataVector ()
153 return pointAvgColorDataVector_;
159 getDifferentialDataVector ()
161 return pointDiffColorDataVector_;
170 encodeAverageOfPoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
175 unsigned int avgGreen;
176 unsigned int avgBlue;
179 avgRed = avgGreen = avgBlue = 0;
182 len = indexVector_arg.size ();
183 for (i = 0; i < len; i++)
186 const int& idx = indexVector_arg[i];
187 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
188 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
191 avgRed += (colorInt >> 0) & 0xFF;
192 avgGreen += (colorInt >> 8) & 0xFF;
193 avgBlue += (colorInt >> 16) & 0xFF;
200 avgRed /=
static_cast<unsigned int> (len);
201 avgGreen /=
static_cast<unsigned int> (len);
202 avgBlue /=
static_cast<unsigned int> (len);
206 avgRed >>= colorBitReduction_;
207 avgGreen >>= colorBitReduction_;
208 avgBlue >>= colorBitReduction_;
211 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
212 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
213 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
222 encodePoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
227 unsigned int avgGreen;
228 unsigned int avgBlue;
231 avgRed = avgGreen = avgBlue = 0;
234 len = indexVector_arg.size ();
235 for (i = 0; i < len; i++)
238 const int& idx = indexVector_arg[i];
239 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
240 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
243 avgRed += (colorInt >> 0) & 0xFF;
244 avgGreen += (colorInt >> 8) & 0xFF;
245 avgBlue += (colorInt >> 16) & 0xFF;
251 unsigned char diffRed;
252 unsigned char diffGreen;
253 unsigned char diffBlue;
256 avgRed /=
static_cast<unsigned int> (len);
257 avgGreen /=
static_cast<unsigned int> (len);
258 avgBlue /=
static_cast<unsigned int> (len);
261 for (i = 0; i < len; i++)
263 const int& idx = indexVector_arg[i];
264 const char* idxPointPtr =
reinterpret_cast<const char*
> (&inputCloud_arg->points[idx]);
265 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
268 diffRed = (
static_cast<unsigned char> (avgRed)) ^
static_cast<unsigned char> (((colorInt >> 0) & 0xFF));
269 diffGreen = (
static_cast<unsigned char> (avgGreen)) ^
static_cast<unsigned char> (((colorInt >> 8) & 0xFF));
270 diffBlue = (
static_cast<unsigned char> (avgBlue)) ^
static_cast<unsigned char> (((colorInt >> 16) & 0xFF));
273 diffRed =
static_cast<unsigned char> (diffRed >> colorBitReduction_);
274 diffGreen =
static_cast<unsigned char> (diffGreen >> colorBitReduction_);
275 diffBlue =
static_cast<unsigned char> (diffBlue >> colorBitReduction_);
278 pointDiffColorDataVector_.push_back (static_cast<char> (diffRed));
279 pointDiffColorDataVector_.push_back (static_cast<char> (diffGreen));
280 pointDiffColorDataVector_.push_back (static_cast<char> (diffBlue));
285 avgRed >>= colorBitReduction_;
286 avgGreen >>= colorBitReduction_;
287 avgBlue >>= colorBitReduction_;
290 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
291 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
292 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
303 decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
306 unsigned int pointCount;
307 unsigned int colorInt;
309 assert (beginIdx_arg <= endIdx_arg);
312 pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
315 unsigned char avgRed = *(pointAvgColorDataVector_Iterator_++);
316 unsigned char avgGreen = *(pointAvgColorDataVector_Iterator_++);
317 unsigned char avgBlue = *(pointAvgColorDataVector_Iterator_++);
320 avgRed =
static_cast<unsigned char> (avgRed << colorBitReduction_);
321 avgGreen =
static_cast<unsigned char> (avgGreen << colorBitReduction_);
322 avgBlue =
static_cast<unsigned char> (avgBlue << colorBitReduction_);
325 for (i = 0; i < pointCount; i++)
330 unsigned char diffRed =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
331 unsigned char diffGreen =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
332 unsigned char diffBlue =
static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
335 diffRed =
static_cast<unsigned char> (diffRed << colorBitReduction_);
336 diffGreen =
static_cast<unsigned char> (diffGreen << colorBitReduction_);
337 diffBlue =
static_cast<unsigned char> (diffBlue << colorBitReduction_);
340 colorInt = ((avgRed ^ diffRed) << 0) |
341 ((avgGreen ^ diffGreen) << 8) |
342 ((avgBlue ^ diffBlue) << 16);
347 colorInt = (avgRed << 0) | (avgGreen << 8) | (avgBlue << 16);
350 char* idxPointPtr =
reinterpret_cast<char*
> (&outputCloud_arg->points[beginIdx_arg + i]);
351 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
364 setDefaultColor (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
367 unsigned int pointCount;
369 assert (beginIdx_arg <= endIdx_arg);
372 pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
375 for (i = 0; i < pointCount; i++)
377 char* idxPointPtr =
reinterpret_cast<char*
> (&outputCloud_arg->points[beginIdx_arg + i]);
378 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
380 pointColor = defaultColor_;
391 std::vector<char> pointAvgColorDataVector_;
394 std::vector<char>::const_iterator pointAvgColorDataVector_Iterator_;
397 std::vector<char> pointDiffColorDataVector_;
400 std::vector<char>::const_iterator pointDiffColorDataVector_Iterator_;
403 unsigned char colorBitReduction_;
406 static const int defaultColor_;
411 template<
typename Po
intT>
412 const int ColorCoding<PointT>::defaultColor_ = ((255) << 0) |
419 #define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>;