38 #ifndef COLOR_COMPRESSION_H 39 #define COLOR_COMPRESSION_H 63 template<
typename Po
intT>
69 typedef boost::shared_ptr<PointCloud> PointCloudPtr;
70 typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
78 output_ (), pointAvgColorDataVector_ (), pointAvgColorDataVector_Iterator_ (),
79 pointDiffColorDataVector_ (), pointDiffColorDataVector_Iterator_ (), colorBitReduction_ (0)
96 colorBitReduction_ = static_cast<unsigned char> (8 - bitDepth_arg);
105 return (static_cast<unsigned char> (8 - colorBitReduction_));
114 pointAvgColorDataVector_.reserve (voxelCount_arg * 3);
124 pointDiffColorDataVector_.reserve (pointCount_arg * 3);
132 pointAvgColorDataVector_.clear ();
134 pointDiffColorDataVector_.clear ();
142 pointAvgColorDataVector_Iterator_ = pointAvgColorDataVector_.begin ();
144 pointDiffColorDataVector_Iterator_ = pointDiffColorDataVector_.begin ();
152 return pointAvgColorDataVector_;
160 return pointDiffColorDataVector_;
169 encodeAverageOfPoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
174 unsigned int avgGreen;
175 unsigned int avgBlue;
178 avgRed = avgGreen = avgBlue = 0;
181 len = indexVector_arg.size ();
182 for (i = 0; i < len; i++)
185 const int& idx = indexVector_arg[i];
186 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
187 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
190 avgRed += (colorInt >> 0) & 0xFF;
191 avgGreen += (colorInt >> 8) & 0xFF;
192 avgBlue += (colorInt >> 16) & 0xFF;
199 avgRed /= static_cast<unsigned int> (len);
200 avgGreen /= static_cast<unsigned int> (len);
201 avgBlue /= static_cast<unsigned int> (len);
205 avgRed >>= colorBitReduction_;
206 avgGreen >>= colorBitReduction_;
207 avgBlue >>= colorBitReduction_;
210 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
211 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
212 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
221 encodePoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
226 unsigned int avgGreen;
227 unsigned int avgBlue;
230 avgRed = avgGreen = avgBlue = 0;
233 len = indexVector_arg.size ();
234 for (i = 0; i < len; i++)
237 const int& idx = indexVector_arg[i];
238 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
239 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
242 avgRed += (colorInt >> 0) & 0xFF;
243 avgGreen += (colorInt >> 8) & 0xFF;
244 avgBlue += (colorInt >> 16) & 0xFF;
250 unsigned char diffRed;
251 unsigned char diffGreen;
252 unsigned char diffBlue;
255 avgRed /= static_cast<unsigned int> (len);
256 avgGreen /= static_cast<unsigned int> (len);
257 avgBlue /= static_cast<unsigned int> (len);
260 for (i = 0; i < len; i++)
262 const int& idx = indexVector_arg[i];
263 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
264 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
267 diffRed = (static_cast<unsigned char> (avgRed)) ^ static_cast<unsigned char> (((colorInt >> 0) & 0xFF));
268 diffGreen = (static_cast<unsigned char> (avgGreen)) ^ static_cast<unsigned char> (((colorInt >> 8) & 0xFF));
269 diffBlue = (static_cast<unsigned char> (avgBlue)) ^ static_cast<unsigned char> (((colorInt >> 16) & 0xFF));
272 diffRed = static_cast<unsigned char> (diffRed >> colorBitReduction_);
273 diffGreen = static_cast<unsigned char> (diffGreen >> colorBitReduction_);
274 diffBlue = static_cast<unsigned char> (diffBlue >> colorBitReduction_);
277 pointDiffColorDataVector_.push_back (static_cast<char> (diffRed));
278 pointDiffColorDataVector_.push_back (static_cast<char> (diffGreen));
279 pointDiffColorDataVector_.push_back (static_cast<char> (diffBlue));
284 avgRed >>= colorBitReduction_;
285 avgGreen >>= colorBitReduction_;
286 avgBlue >>= colorBitReduction_;
289 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
290 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
291 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
302 decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
305 unsigned int pointCount;
306 unsigned int colorInt;
308 assert (beginIdx_arg <= endIdx_arg);
311 pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
314 unsigned char avgRed = *(pointAvgColorDataVector_Iterator_++);
315 unsigned char avgGreen = *(pointAvgColorDataVector_Iterator_++);
316 unsigned char avgBlue = *(pointAvgColorDataVector_Iterator_++);
319 avgRed = static_cast<unsigned char> (avgRed << colorBitReduction_);
320 avgGreen = static_cast<unsigned char> (avgGreen << colorBitReduction_);
321 avgBlue = static_cast<unsigned char> (avgBlue << colorBitReduction_);
324 for (i = 0; i < pointCount; i++)
329 unsigned char diffRed = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
330 unsigned char diffGreen = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
331 unsigned char diffBlue = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
334 diffRed = static_cast<unsigned char> (diffRed << colorBitReduction_);
335 diffGreen = static_cast<unsigned char> (diffGreen << colorBitReduction_);
336 diffBlue = static_cast<unsigned char> (diffBlue << colorBitReduction_);
339 colorInt = ((avgRed ^ diffRed) << 0) |
340 ((avgGreen ^ diffGreen) << 8) |
341 ((avgBlue ^ diffBlue) << 16);
346 colorInt = (avgRed << 0) | (avgGreen << 8) | (avgBlue << 16);
349 char* idxPointPtr = reinterpret_cast<char*> (&outputCloud_arg->points[beginIdx_arg + i]);
350 int& pointColor = *reinterpret_cast<int*> (idxPointPtr+rgba_offset_arg);
363 setDefaultColor (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
366 unsigned int pointCount;
368 assert (beginIdx_arg <= endIdx_arg);
371 pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
374 for (i = 0; i < pointCount; i++)
376 char* idxPointPtr = reinterpret_cast<char*> (&outputCloud_arg->points[beginIdx_arg + i]);
377 int& pointColor = *reinterpret_cast<int*> (idxPointPtr+rgba_offset_arg);
379 pointColor = defaultColor_;
410 template<
typename Po
intT>
418 #define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>; 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.
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.