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 
37  from_(0),
38  to_(0),
39  type_(kUndef),
40  infMatrix_(cv::Mat::eye(6,6,CV_64FC1))
41 {
42 }
44  int to,
45  Type type,
46  const Transform & transform,
47  const cv::Mat & infMatrix,
48  const cv::Mat & userData) :
49  from_(from),
50  to_(to),
51  transform_(transform),
52  type_(type)
53 {
54  setInfMatrix(infMatrix);
55 
56  if(userData.type() == CV_8UC1) // Bytes
57  {
58  _userDataCompressed = userData; // assume compressed
59  }
60  else
61  {
62  _userDataRaw = userData;
63  }
64 }
65 
66 double Link::rotVariance() const
67 {
68  double min = uMax3(infMatrix_.at<double>(3,3), infMatrix_.at<double>(4,4), infMatrix_.at<double>(5,5));
69  UASSERT(min > 0.0);
70  return 1.0/min;
71 }
72 double Link::transVariance() const
73 {
74  double min = uMax3(infMatrix_.at<double>(0,0), infMatrix_.at<double>(1,1), infMatrix_.at<double>(2,2));
75  UASSERT(min > 0.0);
76  return 1.0/min;
77 }
78 
79 void Link::setInfMatrix(const cv::Mat & infMatrix) {
80  UASSERT(infMatrix.cols == 6 && infMatrix.rows == 6 && infMatrix.type() == CV_64FC1);
81  UASSERT_MSG(uIsFinite(infMatrix.at<double>(0,0)) && infMatrix.at<double>(0,0)>0, uFormat("Linear information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(0,0)).c_str());
82  UASSERT_MSG(uIsFinite(infMatrix.at<double>(1,1)) && infMatrix.at<double>(1,1)>0, uFormat("Linear information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(1,1)).c_str());
83  UASSERT_MSG(uIsFinite(infMatrix.at<double>(2,2)) && infMatrix.at<double>(2,2)>0, uFormat("Linear information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(2,2)).c_str());
84  UASSERT_MSG(uIsFinite(infMatrix.at<double>(3,3)) && infMatrix.at<double>(3,3)>0, uFormat("Angular information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(3,3)).c_str());
85  UASSERT_MSG(uIsFinite(infMatrix.at<double>(4,4)) && infMatrix.at<double>(4,4)>0, uFormat("Angular information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(4,4)).c_str());
86  UASSERT_MSG(uIsFinite(infMatrix.at<double>(5,5)) && infMatrix.at<double>(5,5)>0, uFormat("Angular information should not be null! Value=%f (set to 1 if unknown).", infMatrix.at<double>(5,5)).c_str());
88 }
89 
91 {
92  cv::Mat dataRaw = uncompressUserDataConst();
93  if(!dataRaw.empty() && _userDataRaw.empty())
94  {
95  _userDataRaw = dataRaw;
96  }
97 }
98 
100 {
101  if(!_userDataRaw.empty())
102  {
103  return _userDataRaw;
104  }
106 }
107 
108 Link Link::merge(const Link & link, Type outputType) const
109 {
110  UASSERT(to_ == link.from());
111  UASSERT(outputType != Link::kUndef);
112  UASSERT((link.transform().isNull() && transform_.isNull()) || (!link.transform().isNull() && !transform_.isNull()));
113  UASSERT(infMatrix_.cols == 6 && infMatrix_.rows == 6 && infMatrix_.type() == CV_64FC1);
114  UASSERT(link.infMatrix().cols == 6 && link.infMatrix().rows == 6 && link.infMatrix().type() == CV_64FC1);
115  return Link(
116  from_,
117  link.to(),
118  outputType,
119  transform_.isNull()?Transform():transform_ * link.transform(), // FIXME, should be inf1^-1(inf1*t1 + inf2*t2)
120  transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.at<double>(0,0)<link.infMatrix().at<double>(0,0)?infMatrix_:link.infMatrix()));
121  //transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.inv() + link.infMatrix().inv()).inv());
122 }
123 
125 {
126  return Link(
127  to_,
128  from_,
129  type_,
131  transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):infMatrix_);
132 }
133 
134 }
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
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:169
std::string UTILITE_EXP uFormat(const char *fmt,...)


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