LaserScan.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 // verify that format corresponds to expected number of channels
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 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20