00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/core/Link.h"
00029 #include <rtabmap/utilite/ULogger.h>
00030 #include <rtabmap/utilite/UMath.h>
00031 #include <rtabmap/utilite/UConversion.h>
00032 #include <rtabmap/core/Compression.h>
00033
00034 namespace rtabmap {
00035
00036 Link::Link() :
00037 from_(0),
00038 to_(0),
00039 type_(kUndef),
00040 infMatrix_(cv::Mat::eye(6,6,CV_64FC1))
00041 {
00042 }
00043 Link::Link(int from,
00044 int to,
00045 Type type,
00046 const Transform & transform,
00047 const cv::Mat & infMatrix,
00048 const cv::Mat & userData) :
00049 from_(from),
00050 to_(to),
00051 transform_(transform),
00052 type_(type)
00053 {
00054 setInfMatrix(infMatrix);
00055
00056 if(userData.type() == CV_8UC1)
00057 {
00058 _userDataCompressed = userData;
00059 }
00060 else
00061 {
00062 _userDataRaw = userData;
00063 }
00064 }
00065
00066 double Link::rotVariance() const
00067 {
00068 double min = uMax3(infMatrix_.at<double>(3,3), infMatrix_.at<double>(4,4), infMatrix_.at<double>(5,5));
00069 UASSERT(min > 0.0);
00070 return 1.0/min;
00071 }
00072 double Link::transVariance() const
00073 {
00074 double min = uMax3(infMatrix_.at<double>(0,0), infMatrix_.at<double>(1,1), infMatrix_.at<double>(2,2));
00075 UASSERT(min > 0.0);
00076 return 1.0/min;
00077 }
00078
00079 void Link::setInfMatrix(const cv::Mat & infMatrix) {
00080 UASSERT(infMatrix.cols == 6 && infMatrix.rows == 6 && infMatrix.type() == CV_64FC1);
00081 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());
00082 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());
00083 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());
00084 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());
00085 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());
00086 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());
00087 infMatrix_ = infMatrix;
00088 }
00089
00090 void Link::uncompressUserData()
00091 {
00092 cv::Mat dataRaw = uncompressUserDataConst();
00093 if(!dataRaw.empty() && _userDataRaw.empty())
00094 {
00095 _userDataRaw = dataRaw;
00096 }
00097 }
00098
00099 cv::Mat Link::uncompressUserDataConst() const
00100 {
00101 if(!_userDataRaw.empty())
00102 {
00103 return _userDataRaw;
00104 }
00105 return uncompressData(_userDataCompressed);
00106 }
00107
00108 Link Link::merge(const Link & link, Type outputType) const
00109 {
00110 UASSERT(to_ == link.from());
00111 UASSERT(outputType != Link::kUndef);
00112 UASSERT((link.transform().isNull() && transform_.isNull()) || (!link.transform().isNull() && !transform_.isNull()));
00113 UASSERT(infMatrix_.cols == 6 && infMatrix_.rows == 6 && infMatrix_.type() == CV_64FC1);
00114 UASSERT(link.infMatrix().cols == 6 && link.infMatrix().rows == 6 && link.infMatrix().type() == CV_64FC1);
00115 return Link(
00116 from_,
00117 link.to(),
00118 outputType,
00119 transform_.isNull()?Transform():transform_ * link.transform(),
00120 transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.at<double>(0,0)<link.infMatrix().at<double>(0,0)?infMatrix_:link.infMatrix()));
00121
00122 }
00123
00124 Link Link::inverse() const
00125 {
00126 return Link(
00127 to_,
00128 from_,
00129 type_,
00130 transform_.isNull()?Transform():transform_.inverse(),
00131 transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):infMatrix_);
00132 }
00133
00134 }