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 #include <rtabmap/core/LaserScan.h>
00029 #include <rtabmap/utilite/ULogger.h>
00030 #include <rtabmap/utilite/UConversion.h>
00031
00032 namespace rtabmap {
00033
00034 int LaserScan::channels(Format format)
00035 {
00036 int channels=0;
00037 switch (format) {
00038 case kXY:
00039 channels = 2;
00040 break;
00041 case kXYZ:
00042 case kXYI:
00043 channels = 3;
00044 break;
00045 case kXYZI:
00046 case kXYZRGB:
00047 channels = 4;
00048 break;
00049 case kXYNormal:
00050 channels = 5;
00051 break;
00052 case kXYZNormal:
00053 case kXYINormal:
00054 channels = 6;
00055 break;
00056 case kXYZINormal:
00057 case kXYZRGBNormal:
00058 channels = 7;
00059 break;
00060 default:
00061 UFATAL("Unhandled type %d!", (int)format);
00062 break;
00063 }
00064 return channels;
00065 }
00066
00067 bool LaserScan::isScan2d(const Format & format)
00068 {
00069 return format==kXY || format==kXYI || format == kXYNormal || format == kXYINormal;
00070 }
00071 bool LaserScan::isScanHasNormals(const Format & format)
00072 {
00073 return format==kXYZNormal || format==kXYZINormal || format==kXYZRGBNormal || format == kXYNormal || format == kXYINormal;
00074 }
00075 bool LaserScan::isScanHasRGB(const Format & format)
00076 {
00077 return format==kXYZRGB || format==kXYZRGBNormal;
00078 }
00079 bool LaserScan::isScanHasIntensity(const Format & format)
00080 {
00081 return format==kXYZI || format==kXYZINormal || format == kXYI || format == kXYINormal;
00082 }
00083
00084 LaserScan LaserScan::backwardCompatibility(const cv::Mat & oldScanFormat, int maxPoints, int maxRange, const Transform & localTransform)
00085 {
00086 if(!oldScanFormat.empty())
00087 {
00088 if(oldScanFormat.channels() == 2)
00089 {
00090 return LaserScan(oldScanFormat, maxPoints, maxRange, kXY, localTransform);
00091 }
00092 else if(oldScanFormat.channels() == 3)
00093 {
00094 return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZ, localTransform);
00095 }
00096 else if(oldScanFormat.channels() == 4)
00097 {
00098 return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZRGB, localTransform);
00099 }
00100 else if(oldScanFormat.channels() == 5)
00101 {
00102 return LaserScan(oldScanFormat, maxPoints, maxRange, kXYNormal, localTransform);
00103 }
00104 else if(oldScanFormat.channels() == 6)
00105 {
00106 return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZNormal, localTransform);
00107 }
00108 else if(oldScanFormat.channels() == 7)
00109 {
00110 return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZRGBNormal, localTransform);
00111 }
00112 }
00113 return LaserScan();
00114 }
00115
00116 LaserScan::LaserScan() :
00117 maxPoints_(0),
00118 maxRange_(0),
00119 format_(kUnknown),
00120 localTransform_(Transform::getIdentity())
00121 {
00122 }
00123
00124 LaserScan::LaserScan(const cv::Mat & data, int maxPoints, float maxRange, Format format, const Transform & localTransform) :
00125 data_(data),
00126 maxPoints_(maxPoints),
00127 maxRange_(maxRange),
00128 format_(format),
00129 localTransform_(localTransform)
00130 {
00131 UASSERT(data.empty() || data.rows == 1);
00132 UASSERT(data.empty() || data.type() == CV_8UC1 || data.type() == CV_32FC2 || data.type() == CV_32FC3 || data.type() == CV_32FC(4) || data.type() == CV_32FC(5) || data.type() == CV_32FC(6) || data.type() == CV_32FC(7));
00133 UASSERT(!localTransform.isNull());
00134
00135 if(!data.empty() && !isCompressed())
00136 {
00137 if(format == kUnknown)
00138 {
00139 *this = backwardCompatibility(data_, maxPoints_, maxRange_, localTransform_);
00140 }
00141 else
00142 {
00143 UASSERT_MSG(data.channels() != 2 || (data.channels() == 2 && format == kXY), uFormat("format=%d", format).c_str());
00144 UASSERT_MSG(data.channels() != 3 || (data.channels() == 3 && (format == kXYZ || format == kXYI)), uFormat("format=%d", format).c_str());
00145 UASSERT_MSG(data.channels() != 4 || (data.channels() == 4 && (format == kXYZI || format == kXYZRGB)), uFormat("format=%d", format).c_str());
00146 UASSERT_MSG(data.channels() != 5 || (data.channels() == 5 && (format == kXYNormal)), uFormat("format=%d", format).c_str());
00147 UASSERT_MSG(data.channels() != 6 || (data.channels() == 6 && (format == kXYINormal || format == kXYZNormal)), uFormat("format=%d", format).c_str());
00148 UASSERT_MSG(data.channels() != 7 || (data.channels() == 7 && (format == kXYZRGBNormal || format == kXYZINormal)), uFormat("format=%d", format).c_str());
00149 }
00150 }
00151 }
00152
00153 }