58 template<
typename Po
intT>
161 encodeAverageOfPoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
163 unsigned int avgRed = 0;
164 unsigned int avgGreen = 0;
165 unsigned int avgBlue = 0;
168 std::size_t len = indexVector_arg.size ();
169 for (std::size_t i = 0; i < len; i++)
172 const int& idx = indexVector_arg[i];
173 const char* idxPointPtr =
reinterpret_cast<const char*
> (&(*inputCloud_arg)[idx]);
174 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
177 avgRed += (colorInt >> 0) & 0xFF;
178 avgGreen += (colorInt >> 8) & 0xFF;
179 avgBlue += (colorInt >> 16) & 0xFF;
186 avgRed /=
static_cast<unsigned int> (len);
187 avgGreen /=
static_cast<unsigned int> (len);
188 avgBlue /=
static_cast<unsigned int> (len);
208 encodePoints (
const typename std::vector<int>& indexVector_arg,
unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
211 unsigned int avgGreen;
212 unsigned int avgBlue;
215 avgRed = avgGreen = avgBlue = 0;
218 std::size_t len = indexVector_arg.size ();
219 for (std::size_t i = 0; i < len; i++)
222 const int& idx = indexVector_arg[i];
223 const char* idxPointPtr =
reinterpret_cast<const char*
> (&(*inputCloud_arg)[idx]);
224 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
227 avgRed += (colorInt >> 0) & 0xFF;
228 avgGreen += (colorInt >> 8) & 0xFF;
229 avgBlue += (colorInt >> 16) & 0xFF;
235 unsigned char diffRed;
236 unsigned char diffGreen;
237 unsigned char diffBlue;
240 avgRed /=
static_cast<unsigned int> (len);
241 avgGreen /=
static_cast<unsigned int> (len);
242 avgBlue /=
static_cast<unsigned int> (len);
245 for (std::size_t i = 0; i < len; i++)
247 const int& idx = indexVector_arg[i];
248 const char* idxPointPtr =
reinterpret_cast<const char*
> (&(*inputCloud_arg)[idx]);
249 const int& colorInt = *
reinterpret_cast<const int*
> (idxPointPtr+rgba_offset_arg);
252 diffRed = (
static_cast<unsigned char> (avgRed)) ^
static_cast<unsigned char> (((colorInt >> 0) & 0xFF));
253 diffGreen = (
static_cast<unsigned char> (avgGreen)) ^
static_cast<unsigned char> (((colorInt >> 8) & 0xFF));
254 diffBlue = (
static_cast<unsigned char> (avgBlue)) ^
static_cast<unsigned char> (((colorInt >> 16) & 0xFF));
287 decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
289 assert (beginIdx_arg <= endIdx_arg);
292 unsigned int pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
305 for (std::size_t i = 0; i < pointCount; i++)
307 unsigned int colorInt;
321 colorInt = ((avgRed ^ diffRed) << 0) |
322 ((avgGreen ^ diffGreen) << 8) |
323 ((avgBlue ^ diffBlue) << 16);
328 colorInt = (avgRed << 0) | (avgGreen << 8) | (avgBlue << 16);
331 char* idxPointPtr =
reinterpret_cast<char*
> (&(*outputCloud_arg)[beginIdx_arg + i]);
332 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
345 setDefaultColor (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg,
unsigned char rgba_offset_arg)
347 assert (beginIdx_arg <= endIdx_arg);
350 unsigned int pointCount =
static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
353 for (std::size_t i = 0; i < pointCount; i++)
355 char* idxPointPtr =
reinterpret_cast<char*
> (&(*outputCloud_arg)[beginIdx_arg + i]);
356 int& pointColor = *
reinterpret_cast<int*
> (idxPointPtr+rgba_offset_arg);
386 template<
typename Po
intT>
394 #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.