Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef COLOR_COMPRESSION_H
00039 #define COLOR_COMPRESSION_H
00040
00041 #include <iterator>
00042 #include <iostream>
00043 #include <vector>
00044 #include <string.h>
00045 #include <iostream>
00046 #include <stdio.h>
00047 #include <string.h>
00048
00049 namespace pcl
00050 {
00051 namespace octree
00052 {
00053 using namespace std;
00054
00056
00062
00063 template<typename PointT>
00064 class ColorCoding
00065 {
00066
00067
00068 typedef pcl::PointCloud<PointT> PointCloud;
00069 typedef boost::shared_ptr<PointCloud> PointCloudPtr;
00070 typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
00071
00072 public:
00073
00077 ColorCoding () :
00078 output_ (), pointAvgColorDataVector_ (), pointAvgColorDataVector_Iterator_ (),
00079 pointDiffColorDataVector_ (), pointDiffColorDataVector_Iterator_ (), colorBitReduction_ (0)
00080 {
00081 }
00082
00084 virtual
00085 ~ColorCoding ()
00086 {
00087 }
00088
00092 inline
00093 void
00094 setBitDepth (unsigned char bitDepth_arg)
00095 {
00096 assert (bitDepth_arg <= bitDepth_arg);
00097 colorBitReduction_ = static_cast<unsigned char> (8 - bitDepth_arg);
00098 }
00099
00103 inline unsigned char
00104 getBitDepth ()
00105 {
00106 return (static_cast<unsigned char> (8 - colorBitReduction_));
00107 }
00108
00112 inline void
00113 setVoxelCount (unsigned int voxelCount_arg)
00114 {
00115 pointAvgColorDataVector_.reserve (voxelCount_arg * 3);
00116 }
00117
00121 inline
00122 void
00123 setPointCount (unsigned int pointCount_arg)
00124 {
00125 pointDiffColorDataVector_.reserve (pointCount_arg * 3);
00126 }
00127
00130 void
00131 initializeEncoding ()
00132 {
00133 pointAvgColorDataVector_.clear ();
00134
00135 pointDiffColorDataVector_.clear ();
00136 }
00137
00140 void
00141 initializeDecoding ()
00142 {
00143 pointAvgColorDataVector_Iterator_ = pointAvgColorDataVector_.begin ();
00144
00145 pointDiffColorDataVector_Iterator_ = pointDiffColorDataVector_.begin ();
00146 }
00147
00150 std::vector<char>&
00151 getAverageDataVector ()
00152 {
00153 return pointAvgColorDataVector_;
00154 }
00155
00158 std::vector<char>&
00159 getDifferentialDataVector ()
00160 {
00161 return pointDiffColorDataVector_;
00162 }
00163
00169 void
00170 encodeAverageOfPoints (const typename std::vector<int>& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
00171 {
00172 std::size_t i, len;
00173
00174 unsigned int avgRed;
00175 unsigned int avgGreen;
00176 unsigned int avgBlue;
00177
00178
00179 avgRed = avgGreen = avgBlue = 0;
00180
00181
00182 len = indexVector_arg.size ();
00183 for (i = 0; i < len; i++)
00184 {
00185
00186 const int& idx = indexVector_arg[i];
00187 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
00188 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
00189
00190
00191 avgRed += (colorInt >> 0) & 0xFF;
00192 avgGreen += (colorInt >> 8) & 0xFF;
00193 avgBlue += (colorInt >> 16) & 0xFF;
00194
00195 }
00196
00197
00198 if (len > 1)
00199 {
00200 avgRed /= static_cast<unsigned int> (len);
00201 avgGreen /= static_cast<unsigned int> (len);
00202 avgBlue /= static_cast<unsigned int> (len);
00203 }
00204
00205
00206 avgRed >>= colorBitReduction_;
00207 avgGreen >>= colorBitReduction_;
00208 avgBlue >>= colorBitReduction_;
00209
00210
00211 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
00212 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
00213 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
00214 }
00215
00221 void
00222 encodePoints (const typename std::vector<int>& indexVector_arg, unsigned char rgba_offset_arg, PointCloudConstPtr inputCloud_arg)
00223 {
00224 std::size_t i, len;
00225
00226 unsigned int avgRed;
00227 unsigned int avgGreen;
00228 unsigned int avgBlue;
00229
00230
00231 avgRed = avgGreen = avgBlue = 0;
00232
00233
00234 len = indexVector_arg.size ();
00235 for (i = 0; i < len; i++)
00236 {
00237
00238 const int& idx = indexVector_arg[i];
00239 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
00240 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
00241
00242
00243 avgRed += (colorInt >> 0) & 0xFF;
00244 avgGreen += (colorInt >> 8) & 0xFF;
00245 avgBlue += (colorInt >> 16) & 0xFF;
00246
00247 }
00248
00249 if (len > 1)
00250 {
00251 unsigned char diffRed;
00252 unsigned char diffGreen;
00253 unsigned char diffBlue;
00254
00255
00256 avgRed /= static_cast<unsigned int> (len);
00257 avgGreen /= static_cast<unsigned int> (len);
00258 avgBlue /= static_cast<unsigned int> (len);
00259
00260
00261 for (i = 0; i < len; i++)
00262 {
00263 const int& idx = indexVector_arg[i];
00264 const char* idxPointPtr = reinterpret_cast<const char*> (&inputCloud_arg->points[idx]);
00265 const int& colorInt = *reinterpret_cast<const int*> (idxPointPtr+rgba_offset_arg);
00266
00267
00268 diffRed = (static_cast<unsigned char> (avgRed)) ^ static_cast<unsigned char> (((colorInt >> 0) & 0xFF));
00269 diffGreen = (static_cast<unsigned char> (avgGreen)) ^ static_cast<unsigned char> (((colorInt >> 8) & 0xFF));
00270 diffBlue = (static_cast<unsigned char> (avgBlue)) ^ static_cast<unsigned char> (((colorInt >> 16) & 0xFF));
00271
00272
00273 diffRed = static_cast<unsigned char> (diffRed >> colorBitReduction_);
00274 diffGreen = static_cast<unsigned char> (diffGreen >> colorBitReduction_);
00275 diffBlue = static_cast<unsigned char> (diffBlue >> colorBitReduction_);
00276
00277
00278 pointDiffColorDataVector_.push_back (static_cast<char> (diffRed));
00279 pointDiffColorDataVector_.push_back (static_cast<char> (diffGreen));
00280 pointDiffColorDataVector_.push_back (static_cast<char> (diffBlue));
00281 }
00282 }
00283
00284
00285 avgRed >>= colorBitReduction_;
00286 avgGreen >>= colorBitReduction_;
00287 avgBlue >>= colorBitReduction_;
00288
00289
00290 pointAvgColorDataVector_.push_back (static_cast<char> (avgRed));
00291 pointAvgColorDataVector_.push_back (static_cast<char> (avgGreen));
00292 pointAvgColorDataVector_.push_back (static_cast<char> (avgBlue));
00293
00294 }
00295
00302 void
00303 decodePoints (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg, unsigned char rgba_offset_arg)
00304 {
00305 std::size_t i;
00306 unsigned int pointCount;
00307 unsigned int colorInt;
00308
00309 assert (beginIdx_arg <= endIdx_arg);
00310
00311
00312 pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
00313
00314
00315 unsigned char avgRed = *(pointAvgColorDataVector_Iterator_++);
00316 unsigned char avgGreen = *(pointAvgColorDataVector_Iterator_++);
00317 unsigned char avgBlue = *(pointAvgColorDataVector_Iterator_++);
00318
00319
00320 avgRed = static_cast<unsigned char> (avgRed << colorBitReduction_);
00321 avgGreen = static_cast<unsigned char> (avgGreen << colorBitReduction_);
00322 avgBlue = static_cast<unsigned char> (avgBlue << colorBitReduction_);
00323
00324
00325 for (i = 0; i < pointCount; i++)
00326 {
00327 if (pointCount > 1)
00328 {
00329
00330 unsigned char diffRed = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
00331 unsigned char diffGreen = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
00332 unsigned char diffBlue = static_cast<unsigned char> (*(pointDiffColorDataVector_Iterator_++));
00333
00334
00335 diffRed = static_cast<unsigned char> (diffRed << colorBitReduction_);
00336 diffGreen = static_cast<unsigned char> (diffGreen << colorBitReduction_);
00337 diffBlue = static_cast<unsigned char> (diffBlue << colorBitReduction_);
00338
00339
00340 colorInt = ((avgRed ^ diffRed) << 0) |
00341 ((avgGreen ^ diffGreen) << 8) |
00342 ((avgBlue ^ diffBlue) << 16);
00343 }
00344 else
00345 {
00346
00347 colorInt = (avgRed << 0) | (avgGreen << 8) | (avgBlue << 16);
00348 }
00349
00350 char* idxPointPtr = reinterpret_cast<char*> (&outputCloud_arg->points[beginIdx_arg + i]);
00351 int& pointColor = *reinterpret_cast<int*> (idxPointPtr+rgba_offset_arg);
00352
00353 pointColor=colorInt;
00354 }
00355 }
00356
00363 void
00364 setDefaultColor (PointCloudPtr outputCloud_arg, std::size_t beginIdx_arg, std::size_t endIdx_arg, unsigned char rgba_offset_arg)
00365 {
00366 std::size_t i;
00367 unsigned int pointCount;
00368
00369 assert (beginIdx_arg <= endIdx_arg);
00370
00371
00372 pointCount = static_cast<unsigned int> (endIdx_arg - beginIdx_arg);
00373
00374
00375 for (i = 0; i < pointCount; i++)
00376 {
00377 char* idxPointPtr = reinterpret_cast<char*> (&outputCloud_arg->points[beginIdx_arg + i]);
00378 int& pointColor = *reinterpret_cast<int*> (idxPointPtr+rgba_offset_arg);
00379
00380 pointColor = defaultColor_;
00381 }
00382 }
00383
00384
00385 protected:
00386
00388 PointCloudPtr output_;
00389
00391 std::vector<char> pointAvgColorDataVector_;
00392
00394 std::vector<char>::const_iterator pointAvgColorDataVector_Iterator_;
00395
00397 std::vector<char> pointDiffColorDataVector_;
00398
00400 std::vector<char>::const_iterator pointDiffColorDataVector_Iterator_;
00401
00403 unsigned char colorBitReduction_;
00404
00405
00406 static const int defaultColor_;
00407
00408 };
00409
00410
00411 template<typename PointT>
00412 const int ColorCoding<PointT>::defaultColor_ = ((255) << 0) |
00413 ((255) << 8) |
00414 ((255) << 16);
00415
00416 }
00417 }
00418
00419 #define PCL_INSTANTIATE_ColorCoding(T) template class PCL_EXPORTS pcl::octree::ColorCoding<T>;
00420
00421 #endif