RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
LaserScan.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON 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
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef CORELIB_INCLUDE_RTABMAP_CORE_LASERSCAN_H_
29#define CORELIB_INCLUDE_RTABMAP_CORE_LASERSCAN_H_
30
31#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
32
33#include <rtabmap/core/Transform.h>
34
35namespace rtabmap {
36
45class RTABMAP_CORE_EXPORT LaserScan
46{
47public:
55 enum Format{
56 kUnknown=0,
57 kXY=1,
58 kXYI=2,
59 kXYNormal=3,
60 kXYINormal=4,
61 kXYZ=5,
62 kXYZI=6,
63 kXYZRGB=7,
64 kXYZNormal=8,
65 kXYZINormal=9,
66 kXYZRGBNormal=10,
67 kXYZIT=11,
68 kXYZIRT=12
69 };
70
73 static std::string formatName(const Format & format);
74 static int channels(const Format & format);
75 static bool isScan2d(const Format & format);
76 static bool isScanHasNormals(const Format & format);
77 static bool isScanHasRGB(const Format & format);
78 static bool isScanHasIntensity(const Format & format);
79 static bool isScanHasTime(const Format & format);
80 static bool isScanHasRing(const Format & format);
81 static float packRGB(unsigned char r, unsigned char g, unsigned char b);
82 static void unpackRGB(float rgb, unsigned char & r, unsigned char & g, unsigned char & b);
83
88 const cv::Mat & oldScanFormat,
89 int maxPoints = 0,
90 int maxRange = 0,
91 const Transform & localTransform = Transform::getIdentity());
92
97 const cv::Mat & oldScanFormat,
98 float minRange,
99 float maxRange,
100 float angleMin,
101 float angleMax,
102 float angleInc,
103 const Transform & localTransform = Transform::getIdentity());
105
106public:
107
110 LaserScan();
111 LaserScan(const LaserScan & data,
112 int maxPoints,
113 float maxRange,
114 const Transform & localTransform = Transform::getIdentity());
115
117 RTABMAP_DEPRECATED LaserScan(const LaserScan & data,
118 int maxPoints,
119 float maxRange,
120 Format format,
121 const Transform & localTransform = Transform::getIdentity());
122 LaserScan(const cv::Mat & data,
123 int maxPoints,
124 float maxRange,
125 Format format,
126 const Transform & localTransform = Transform::getIdentity());
127
129 RTABMAP_DEPRECATED LaserScan(const LaserScan & data,
130 Format format,
131 float minRange,
132 float maxRange,
133 float angleMin,
134 float angleMax,
135 float angleIncrement,
136 const Transform & localTransform = Transform::getIdentity());
137 LaserScan(const LaserScan & data,
138 float minRange,
139 float maxRange,
140 float angleMin,
141 float angleMax,
142 float angleIncrement,
143 const Transform & localTransform = Transform::getIdentity());
144 LaserScan(const cv::Mat & data,
145 Format format,
146 float minRange,
147 float maxRange,
148 float angleMin,
149 float angleMax,
150 float angleIncrement,
151 const Transform & localTransform = Transform::getIdentity());
153
156 const cv::Mat & data() const {return data_;}
157 Format format() const {return format_;}
158 std::string formatName() const {return formatName(format_);}
159 int channels() const {return data_.channels();}
160 int maxPoints() const {return maxPoints_;}
161 float rangeMin() const {return rangeMin_;}
162 float rangeMax() const {return rangeMax_;}
163 float angleMin() const {return angleMin_;}
164 float angleMax() const {return angleMax_;}
165 float angleIncrement() const {return angleIncrement_;}
166 void setLocalTransform(const Transform & t) {localTransform_ = t;}
167 Transform localTransform() const {return localTransform_;}
169
172 bool empty() const {return data_.empty();}
173 bool isEmpty() const {return data_.empty();}
174 int size() const {return static_cast<int>(data_.total());}
175 int dataType() const {return data_.type();}
176 bool is2d() const {return isScan2d(format_);}
177 bool hasNormals() const {return isScanHasNormals(format_);}
178 bool hasRGB() const {return isScanHasRGB(format_);}
179 bool hasIntensity() const {return isScanHasIntensity(format_);}
180 bool hasTime() const {return isScanHasTime(format_);}
181 bool hasRing() const {return isScanHasRing(format_);}
183 bool isCompressed() const {return !data_.empty() && data_.type()==CV_8UC1;}
184 bool isOrganized() const {return data_.rows > 1;}
185 LaserScan clone() const;
186 LaserScan densify() const;
188
191 int getIntensityOffset() const {return hasIntensity()?(is2d()?2:3):-1;}
192 int getRGBOffset() const {return hasRGB()?(is2d()?2:3):-1;}
193 int getNormalsOffset() const {return hasNormals()?(2 + (is2d()?0:1) + ((hasRGB() || hasIntensity())?1:0)):-1;}
194 int getRingOffset() const {return format_==kXYZIRT?4:-1;}
195 int getTimeOffset() const {return format_==kXYZIT?4:(format_==kXYZIRT?5:-1);}
196
204 float & field(unsigned int pointIndex, unsigned int channelOffset);
205
209 void clear() {data_ = cv::Mat();}
210
220
221private:
222 void init(const cv::Mat & data,
223 Format format,
224 float minRange,
225 float maxRange,
226 float angleMin,
227 float angleMax,
228 float angleIncrement,
229 int maxPoints,
230 const Transform & localTransform = Transform::getIdentity());
231
232private:
233 cv::Mat data_;
234 Format format_;
235 int maxPoints_;
236 float rangeMin_;
237 float rangeMax_;
238 float angleMin_;
239 float angleMax_;
240 float angleIncrement_;
241 Transform localTransform_;
242};
243
244} // namespace rtabmap
245
246#endif /* CORELIB_INCLUDE_RTABMAP_CORE_LASERSCAN_H_ */
Represents 2D or 3D laser scan data with support for multiple point data formats.
Definition LaserScan.h:46
RTABMAP_DEPRECATED LaserScan(const LaserScan &data, int maxPoints, float maxRange, Format format, const Transform &localTransform=Transform::getIdentity())
bool isCompressed() const
True if the scan is stored compressed (single-row CV_8UC1 blob) instead of raw points.
Definition LaserScan.h:183
Format
Enumeration of possible formats for laser scan data.
Definition LaserScan.h:55
float & field(unsigned int pointIndex, unsigned int channelOffset)
Access a specific field value of a point.
static LaserScan backwardCompatibility(const cv::Mat &oldScanFormat, float minRange, float maxRange, float angleMin, float angleMax, float angleInc, const Transform &localTransform=Transform::getIdentity())
Converts legacy scan format with additional metadata to a LaserScan.
RTABMAP_DEPRECATED LaserScan(const LaserScan &data, Format format, float minRange, float maxRange, float angleMin, float angleMax, float angleIncrement, const Transform &localTransform=Transform::getIdentity())
static LaserScan backwardCompatibility(const cv::Mat &oldScanFormat, int maxPoints=0, int maxRange=0, const Transform &localTransform=Transform::getIdentity())
Converts legacy scan format to a LaserScan object.
LaserScan operator+(const LaserScan &)
Concatenate scan's data (localTransform is ignored).
void clear()
Clear the scan data.
Definition LaserScan.h:209
LaserScan & operator+=(const LaserScan &)
Concatenate scan's data (localTransform is ignored).
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53