Link.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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) // Bytes
00057         {
00058                 _userDataCompressed = userData; // assume compressed
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(), // FIXME, should be inf1^-1(inf1*t1 + inf2*t2)
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                         //transform_.isNull()?cv::Mat::eye(6,6,CV_64FC1):(infMatrix_.inv() + link.infMatrix().inv()).inv());
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 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20