LaserScan.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include <rtabmap/core/LaserScan.h>
31 
32 namespace rtabmap {
33 
35 {
36  int channels=0;
37  switch (format) {
38  case kXY:
39  channels = 2;
40  break;
41  case kXYZ:
42  case kXYI:
43  channels = 3;
44  break;
45  case kXYZI:
46  case kXYZRGB:
47  channels = 4;
48  break;
49  case kXYNormal:
50  channels = 5;
51  break;
52  case kXYZNormal:
53  case kXYINormal:
54  channels = 6;
55  break;
56  case kXYZINormal:
57  case kXYZRGBNormal:
58  channels = 7;
59  break;
60  default:
61  UFATAL("Unhandled type %d!", (int)format);
62  break;
63  }
64  return channels;
65 }
66 
68 {
69  return format==kXY || format==kXYI || format == kXYNormal || format == kXYINormal;
70 }
72 {
73  return format==kXYZNormal || format==kXYZINormal || format==kXYZRGBNormal || format == kXYNormal || format == kXYINormal;
74 }
76 {
77  return format==kXYZRGB || format==kXYZRGBNormal;
78 }
80 {
81  return format==kXYZI || format==kXYZINormal || format == kXYI || format == kXYINormal;
82 }
83 
84 LaserScan LaserScan::backwardCompatibility(const cv::Mat & oldScanFormat, int maxPoints, int maxRange, const Transform & localTransform)
85 {
86  if(!oldScanFormat.empty())
87  {
88  if(oldScanFormat.channels() == 2)
89  {
90  return LaserScan(oldScanFormat, maxPoints, maxRange, kXY, localTransform);
91  }
92  else if(oldScanFormat.channels() == 3)
93  {
94  return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZ, localTransform);
95  }
96  else if(oldScanFormat.channels() == 4)
97  {
98  return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZRGB, localTransform);
99  }
100  else if(oldScanFormat.channels() == 5)
101  {
102  return LaserScan(oldScanFormat, maxPoints, maxRange, kXYNormal, localTransform);
103  }
104  else if(oldScanFormat.channels() == 6)
105  {
106  return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZNormal, localTransform);
107  }
108  else if(oldScanFormat.channels() == 7)
109  {
110  return LaserScan(oldScanFormat, maxPoints, maxRange, kXYZRGBNormal, localTransform);
111  }
112  }
113  return LaserScan();
114 }
115 
117  maxPoints_(0),
118  maxRange_(0),
119  format_(kUnknown),
120  localTransform_(Transform::getIdentity())
121 {
122 }
123 
125  data_(data),
126  maxPoints_(maxPoints),
127  maxRange_(maxRange),
128  format_(format),
129  localTransform_(localTransform)
130 {
131  UASSERT(data.empty() || data.rows == 1);
132  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));
133  UASSERT(!localTransform.isNull());
134 
135  if(!data.empty() && !isCompressed())
136  {
137  if(format == kUnknown)
138  {
140  }
141  else // verify that format corresponds to expected number of channels
142  {
143  UASSERT_MSG(data.channels() != 2 || (data.channels() == 2 && format == kXY), uFormat("format=%d", format).c_str());
144  UASSERT_MSG(data.channels() != 3 || (data.channels() == 3 && (format == kXYZ || format == kXYI)), uFormat("format=%d", format).c_str());
145  UASSERT_MSG(data.channels() != 4 || (data.channels() == 4 && (format == kXYZI || format == kXYZRGB)), uFormat("format=%d", format).c_str());
146  UASSERT_MSG(data.channels() != 5 || (data.channels() == 5 && (format == kXYNormal)), uFormat("format=%d", format).c_str());
147  UASSERT_MSG(data.channels() != 6 || (data.channels() == 6 && (format == kXYINormal || format == kXYZNormal)), uFormat("format=%d", format).c_str());
148  UASSERT_MSG(data.channels() != 7 || (data.channels() == 7 && (format == kXYZRGBNormal || format == kXYZINormal)), uFormat("format=%d", format).c_str());
149  }
150  }
151 }
152 
153 }
const cv::Mat & data() const
Definition: LaserScan.h:63
Format format() const
Definition: LaserScan.h:66
float maxRange() const
Definition: LaserScan.h:65
static int channels(Format format)
Definition: LaserScan.cpp:34
int maxPoints() const
Definition: LaserScan.h:64
Some conversion functions.
#define UFATAL(...)
static bool isScanHasNormals(const Format &format)
Definition: LaserScan.cpp:71
#define UASSERT(condition)
bool isNull() const
Definition: Transform.cpp:107
#define UASSERT_MSG(condition, msg_str)
Definition: ULogger.h:67
static bool isScanHasRGB(const Format &format)
Definition: LaserScan.cpp:75
bool isCompressed() const
Definition: LaserScan.h:76
Transform localTransform() const
Definition: LaserScan.h:67
ULogger class and convenient macros.
static bool isScan2d(const Format &format)
Definition: LaserScan.cpp:67
Transform localTransform_
Definition: LaserScan.h:90
static bool isScanHasIntensity(const Format &format)
Definition: LaserScan.cpp:79
std::string UTILITE_EXP uFormat(const char *fmt,...)
static LaserScan backwardCompatibility(const cv::Mat &oldScanFormat, int maxPoints=0, int maxRange=0, const Transform &localTransform=Transform::getIdentity())
Definition: LaserScan.cpp:84


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31