Link.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/Link.h"
30 #include <rtabmap/utilite/UMath.h>
33 
34 namespace rtabmap {
35 
36 std::string Link::typeName(Type type)
37 {
38  if(type == Link::kNeighbor)
39  return "Neighbor";
40  if(type == Link::kGlobalClosure)
41  return "GlobalClosure";
42  if(type == Link::kLocalSpaceClosure)
43  return "LocalSpaceClosure";
44  if(type == Link::kLocalTimeClosure)
45  return "LocalTimeClosure";
46  if(type == Link::kUserClosure)
47  return "UserClosure";
48  if(type == Link::kVirtualClosure)
49  return "VirtualClosure";
50  if(type == Link::kNeighborMerged)
51  return "NeighborMerged";
52  if(type == Link::kPosePrior)
53  return "PosePrior";
54  if(type == Link::kLandmark)
55  return "Landmark";
56  if(type == Link::kGravity)
57  return "Gravity";
58  return "Undefined";
59 }
60 
62  from_(0),
63  to_(0),
64  type_(kUndef),
65  infMatrix_(cv::Mat::eye(6,6,CV_64FC1))
66 {
67 }
69  int to,
70  Type type,
71  const Transform & transform,
72  const cv::Mat & infMatrix,
73  const cv::Mat & userData) :
74  from_(from),
75  to_(to),
76  transform_(transform),
77  type_(type)
78 {
79  setInfMatrix(infMatrix);
80 
81  if(userData.type() == CV_8UC1) // Bytes
82  {
83  _userDataCompressed = userData; // assume compressed
84  }
85  else
86  {
87  _userDataRaw = userData;
88  }
89 }
90 
91 double Link::rotVariance(bool minimum) const
92 {
93  double value;
94  if(minimum)
95  {
96  value = uMax3(infMatrix_.at<double>(3,3), infMatrix_.at<double>(4,4), infMatrix_.at<double>(5,5));
97  }
98  else
99  {
100  value = uMin3(
101  infMatrix_.at<double>(3,3) <= 0.0001?9999999.0:infMatrix_.at<double>(3,3),
102  infMatrix_.at<double>(4,4) <= 0.0001?9999999.0:infMatrix_.at<double>(4,4),
103  infMatrix_.at<double>(5,5) <= 0.0001?9999999.0:infMatrix_.at<double>(5,5));
104  if(value == 9999999.0)
105  {
106  value = 0.0001;
107  }
108  }
109  UASSERT(value > 0.0);
110  return 1.0/value;
111 }
112 double Link::transVariance(bool minimum) const
113 {
114  double value;
115  if(minimum)
116  {
117  value = uMax3(infMatrix_.at<double>(0,0), infMatrix_.at<double>(1,1), infMatrix_.at<double>(2,2));
118  }
119  else
120  {
121  value = uMin3(
122  infMatrix_.at<double>(0,0) <= 0.0001?9999999.0:infMatrix_.at<double>(0,0),
123  infMatrix_.at<double>(1,1) <= 0.0001?9999999.0:infMatrix_.at<double>(1,1),
124  infMatrix_.at<double>(2,2) <= 0.0001?9999999.0:infMatrix_.at<double>(2,2));
125  if(value == 9999999.0)
126  {
127  value = 0.0001;
128  }
129  }
130  UASSERT(value > 0.0);
131  return 1.0/value;
132 }
133 
134 void Link::setInfMatrix(const cv::Mat & infMatrix) {
135  UASSERT(infMatrix.cols == 6 && infMatrix.rows == 6 && infMatrix.type() == CV_64FC1);
136  UASSERT_MSG(uIsFinite(infMatrix.at<double>(0,0)) && infMatrix.at<double>(0,0)>0, uFormat("Linear information X should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(0,0)).c_str());
137  UASSERT_MSG(uIsFinite(infMatrix.at<double>(1,1)) && infMatrix.at<double>(1,1)>0, uFormat("Linear information Y should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(1,1)).c_str());
138  UASSERT_MSG(uIsFinite(infMatrix.at<double>(2,2)) && infMatrix.at<double>(2,2)>0, uFormat("Linear information Z should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(2,2)).c_str());
139  UASSERT_MSG(uIsFinite(infMatrix.at<double>(3,3)) && infMatrix.at<double>(3,3)>0, uFormat("Angular information roll should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(3,3)).c_str());
140  UASSERT_MSG(uIsFinite(infMatrix.at<double>(4,4)) && infMatrix.at<double>(4,4)>0, uFormat("Angular information pitch should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(4,4)).c_str());
141  UASSERT_MSG(uIsFinite(infMatrix.at<double>(5,5)) && infMatrix.at<double>(5,5)>0, uFormat("Angular information yaw should not be null! Value=%f (set to 1 if unknown or <=1/9999 to be ignored in some computations).", infMatrix.at<double>(5,5)).c_str());
143 }
144 
146 {
147  cv::Mat dataRaw = uncompressUserDataConst();
148  if(!dataRaw.empty() && _userDataRaw.empty())
149  {
150  _userDataRaw = dataRaw;
151  }
152 }
153 
155 {
156  if(!_userDataRaw.empty())
157  {
158  return _userDataRaw;
159  }
161 }
162 
163 Link Link::merge(const Link & link, Type outputType) const
164 {
165  UASSERT(to_ == link.from());
166  UASSERT(outputType != Link::kUndef);
167  UASSERT((link.transform().isNull() && transform_.isNull()) || (!link.transform().isNull() && !transform_.isNull()));
168  UASSERT(infMatrix_.cols == 6 && infMatrix_.rows == 6 && infMatrix_.type() == CV_64FC1);
169  UASSERT(link.infMatrix().cols == 6 && link.infMatrix().rows == 6 && link.infMatrix().type() == CV_64FC1);
170  if(outputType == kNeighborMerged)
171  {
172  return Link(
173  from_,
174  link.to(),
175  outputType,
177  transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.inv() + link.infMatrix().inv()).inv());
178  }
179  return Link(
180  from_,
181  link.to(),
182  outputType,
183  transform_.isNull()?Transform():transform_ * link.transform(), // FIXME, should be inf1^-1(inf1*t1 + inf2*t2)
184  transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.at<double>(0,0)<link.infMatrix().at<double>(0,0)?infMatrix_:link.infMatrix()));
185  //transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.inv() + link.infMatrix().inv()).inv());
186 }
187 
189 {
190  return Link(
191  to_,
192  from_,
193  type_,
195  transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):infMatrix_);
196 }
197 
198 }
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
T uMin3(const T &a, const T &b, const T &c)
Definition: UMath.h:69
Basic mathematics functions.
Some conversion functions.
Definition: Features2d.h:41
bool uIsFinite(const T &value)
Definition: UMath.h:55
#define UASSERT(condition)
T uMax3(const T &a, const T &b, const T &c)
Definition: UMath.h:80
bool isNull() const
Definition: Transform.cpp:107
#define UASSERT_MSG(condition, msg_str)
Definition: ULogger.h:67
ULogger class and convenient macros.
Transform inverse() const
Definition: Transform.cpp:178
std::string UTILITE_EXP uFormat(const char *fmt,...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59