2016-02-22 16:13:14 -05:00
/*
Copyright ( c ) 2010 - 2014 , Mathieu Labbe - IntRoLab - Universite de Sherbrooke
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
* Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
* Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
documentation and / or other materials provided with the distribution .
* Neither the name of the Universite de Sherbrooke nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# include "rtabmap/core/OdometryInfo.h"
# include "rtabmap/core/Memory.h"
# include "rtabmap/core/VisualWord.h"
# include "rtabmap/core/Signature.h"
# include "rtabmap/core/RegistrationVis.h"
# include "rtabmap/core/util3d_transforms.h"
# include "rtabmap/core/util3d_registration.h"
# include "rtabmap/core/util3d_correspondences.h"
# include "rtabmap/core/util3d_motion_estimation.h"
2016-03-06 15:11:09 -05:00
# include "rtabmap/core/util3d_filtering.h"
2016-02-22 16:13:14 -05:00
# include "rtabmap/core/Optimizer.h"
# include "rtabmap/core/VWDictionary.h"
# include "rtabmap/core/util3d.h"
# include "rtabmap/utilite/ULogger.h"
# include "rtabmap/utilite/UTimer.h"
2016-02-27 18:30:00 -05:00
# include "rtabmap/utilite/UMath.h"
2016-02-22 16:13:14 -05:00
# include "rtabmap/utilite/UConversion.h"
# include <opencv2/calib3d/calib3d.hpp>
# include <rtabmap/core/OdometryF2M.h>
# if _MSC_VER
# define ISFINITE(value) _finite(value)
# else
# define ISFINITE(value) std::isfinite(value)
# endif
namespace rtabmap {
OdometryF2M : : OdometryF2M ( const ParametersMap & parameters ) :
Odometry ( parameters ) ,
maximumMapSize_ ( Parameters : : defaultOdomF2MMaxSize ( ) ) ,
2016-03-01 20:47:46 -05:00
keyFrameThr_ ( Parameters : : defaultOdomKeyFrameThr ( ) ) ,
maxNewFeatures_ ( Parameters : : defaultOdomF2MMaxNewFeatures ( ) ) ,
2016-03-06 15:11:09 -05:00
scanKeyFrameThr_ ( Parameters : : defaultOdomScanKeyFrameThr ( ) ) ,
scanMaximumMapSize_ ( Parameters : : defaultOdomF2MScanMaxSize ( ) ) ,
scanSubstractRadius_ ( Parameters : : defaultOdomF2MScanSubstractRadius ( ) ) ,
2016-02-22 16:13:14 -05:00
fixedMapPath_ ( Parameters : : defaultOdomF2MFixedMapPath ( ) ) ,
2016-03-06 15:11:09 -05:00
regPipeline_ ( Registration : : create ( parameters ) ) ,
2016-02-23 11:46:07 -05:00
map_ ( new Signature ( - 1 ) ) ,
lastFrame_ ( new Signature ( 1 ) )
2016-02-22 16:13:14 -05:00
{
UDEBUG ( " " ) ;
Parameters : : parse ( parameters , Parameters : : kOdomF2MMaxSize ( ) , maximumMapSize_ ) ;
2016-03-01 20:47:46 -05:00
Parameters : : parse ( parameters , Parameters : : kOdomKeyFrameThr ( ) , keyFrameThr_ ) ;
Parameters : : parse ( parameters , Parameters : : kOdomF2MMaxNewFeatures ( ) , maxNewFeatures_ ) ;
2016-03-06 15:11:09 -05:00
Parameters : : parse ( parameters , Parameters : : kOdomScanKeyFrameThr ( ) , scanKeyFrameThr_ ) ;
Parameters : : parse ( parameters , Parameters : : kOdomF2MScanMaxSize ( ) , scanMaximumMapSize_ ) ;
Parameters : : parse ( parameters , Parameters : : kOdomF2MScanSubstractRadius ( ) , scanSubstractRadius_ ) ;
2016-02-22 16:13:14 -05:00
Parameters : : parse ( parameters , Parameters : : kOdomF2MFixedMapPath ( ) , fixedMapPath_ ) ;
2016-03-01 20:47:46 -05:00
UASSERT ( maximumMapSize_ > = 0 ) ;
UASSERT ( keyFrameThr_ > = 0.0f & & keyFrameThr_ < = 1.0f ) ;
2016-03-06 15:11:09 -05:00
UASSERT ( scanKeyFrameThr_ > = 0.0f & & scanKeyFrameThr_ < = 1.0f ) ;
2016-03-01 20:47:46 -05:00
UASSERT ( maxNewFeatures_ > = 0 ) ;
2016-02-22 16:13:14 -05:00
if ( ! fixedMapPath_ . empty ( ) )
{
UINFO ( " Init odometry from a fixed database: \" %s \" " , fixedMapPath_ . c_str ( ) ) ;
// init the local map with a all 3D features contained in the database
ParametersMap customParameters ;
customParameters . insert ( ParametersPair ( Parameters : : kMemIncrementalMemory ( ) , " false " ) ) ;
customParameters . insert ( ParametersPair ( Parameters : : kMemInitWMWithAllNodes ( ) , " true " ) ) ;
customParameters . insert ( ParametersPair ( Parameters : : kMemSTMSize ( ) , " 0 " ) ) ;
Memory memory ( customParameters ) ;
if ( ! memory . init ( fixedMapPath_ , false , ParametersMap ( ) ) )
{
UERROR ( " Error initializing the memory for BOW Odometry. " ) ;
}
else
{
// get the graph
std : : map < int , int > ids = memory . getNeighborsId ( memory . getLastSignatureId ( ) , 0 , - 1 ) ;
std : : map < int , Transform > poses ;
std : : multimap < int , Link > links ;
memory . getMetricConstraints ( uKeysSet ( ids ) , poses , links , true ) ;
if ( poses . size ( ) )
{
//optimize the graph
Optimizer * optimizer = Optimizer : : create ( parameters ) ;
std : : map < int , Transform > optimizedPoses = optimizer - > optimize ( poses . begin ( ) - > first , poses , links ) ;
delete optimizer ;
std : : multimap < int , cv : : Point3f > words3D ;
std : : multimap < int , cv : : Mat > wordsDescriptors ;
// fill the local map
for ( std : : map < int , Transform > : : iterator posesIter = optimizedPoses . begin ( ) ;
posesIter ! = optimizedPoses . end ( ) ;
+ + posesIter )
{
const Signature * s = memory . getSignature ( posesIter - > first ) ;
if ( s )
{
// Transform 3D points accordingly to pose and add them to local map
for ( std : : multimap < int , cv : : Point3f > : : const_iterator pointsIter = s - > getWords3 ( ) . begin ( ) ;
pointsIter ! = s - > getWords3 ( ) . end ( ) ;
+ + pointsIter )
{
if ( ! uContains ( words3D , pointsIter - > first ) )
{
words3D . insert ( std : : make_pair ( pointsIter - > first , util3d : : transformPoint ( pointsIter - > second , posesIter - > second ) ) ) ;
if ( s - > getWordsDescriptors ( ) . size ( ) = = s - > getWords3 ( ) . size ( ) )
{
UASSERT ( uContains ( s - > getWordsDescriptors ( ) , pointsIter - > first ) ) ;
wordsDescriptors . insert ( std : : make_pair ( pointsIter - > first , s - > getWordsDescriptors ( ) . find ( pointsIter - > first ) - > second ) ) ;
}
else // load descriptor from dictionary
{
UASSERT ( memory . getVWDictionary ( ) - > getWord ( pointsIter - > first ) ! = 0 ) ;
wordsDescriptors . insert ( std : : make_pair ( pointsIter - > first , memory . getVWDictionary ( ) - > getWord ( pointsIter - > first ) - > getDescriptor ( ) ) ) ;
}
}
}
}
}
UASSERT ( words3D . size ( ) = = wordsDescriptors . size ( ) ) ;
map_ - > setWords3 ( words3D ) ;
map_ - > setWordsDescriptors ( wordsDescriptors ) ;
}
else
{
UERROR ( " No pose loaded from database \" %s \" " , fixedMapPath_ . c_str ( ) ) ;
}
}
2016-03-06 15:11:09 -05:00
if ( ( int ) map_ - > getWords3 ( ) . size ( ) < regPipeline_ - > getMinVisualCorrespondences ( ) | | map_ - > getWords3 ( ) . size ( ) = = 0 )
2016-02-22 16:13:14 -05:00
{
2016-03-06 15:11:09 -05:00
// TODO: support geometric-only maps?
2016-02-22 16:13:14 -05:00
UERROR ( " The loaded fixed map from \" %s \" is too small! Only %d unique features loaded. Odometry won't be computed! " ,
fixedMapPath_ . c_str ( ) , ( int ) map_ - > getWords3 ( ) . size ( ) ) ;
}
}
}
OdometryF2M : : ~ OdometryF2M ( )
{
delete map_ ;
2016-02-23 11:46:07 -05:00
delete lastFrame_ ;
2016-02-22 16:13:14 -05:00
UDEBUG ( " " ) ;
}
void OdometryF2M : : reset ( const Transform & initialPose )
{
2016-03-09 16:32:16 -05:00
Odometry : : reset ( initialPose ) ;
* lastFrame_ = Signature ( 1 ) ;
2016-02-22 16:13:14 -05:00
if ( fixedMapPath_ . empty ( ) )
{
2016-02-24 12:45:00 -05:00
* map_ = Signature ( - 1 ) ;
2016-02-22 16:13:14 -05:00
}
else
{
UWARN ( " Odometry cannot be reset when a fixed local map is set. " ) ;
}
}
// return not null transform if odometry is correctly computed
Transform OdometryF2M : : computeTransform (
2016-02-22 17:57:40 -05:00
SensorData & data ,
2016-02-27 18:30:00 -05:00
const Transform & guess ,
2016-02-22 16:13:14 -05:00
OdometryInfo * info )
{
UTimer timer ;
Transform output ;
if ( info )
{
info - > type = 0 ;
}
RegistrationInfo regInfo ;
int nFeatures = 0 ;
2016-02-23 11:46:07 -05:00
delete lastFrame_ ;
lastFrame_ = new Signature ( data ) ;
2016-02-22 16:13:14 -05:00
// Generate keypoints from the new data
2016-02-23 11:46:07 -05:00
if ( lastFrame_ - > sensorData ( ) . isValid ( ) )
2016-02-22 16:13:14 -05:00
{
2016-03-06 15:11:09 -05:00
if ( ( map_ - > getWords3 ( ) . size ( ) | | ! map_ - > sensorData ( ) . laserScanRaw ( ) . empty ( ) ) & &
lastFrame_ - > sensorData ( ) . isValid ( ) )
2016-02-22 16:13:14 -05:00
{
2016-02-24 12:45:00 -05:00
Signature tmpMap = * map_ ;
2016-03-06 15:11:09 -05:00
Transform transform = regPipeline_ - > computeTransformationMod (
2016-02-27 18:30:00 -05:00
tmpMap ,
* lastFrame_ ,
guess . isNull ( ) ? Transform ( ) : this - > getPose ( ) * guess ,
& regInfo ) ;
2016-02-22 16:13:14 -05:00
2016-02-23 11:46:07 -05:00
data . setFeatures ( lastFrame_ - > sensorData ( ) . keypoints ( ) , lastFrame_ - > sensorData ( ) . descriptors ( ) ) ;
2016-02-22 17:57:40 -05:00
2016-02-22 16:13:14 -05:00
if ( ! transform . isNull ( ) )
{
// make it incremental
transform = this - > getPose ( ) . inverse ( ) * transform ;
}
else if ( ! regInfo . rejectedMsg . empty ( ) )
{
UWARN ( " Registration failed: \" %s \" " , regInfo . rejectedMsg . c_str ( ) ) ;
}
else
{
UWARN ( " Unknown registration error " ) ;
}
2016-02-24 12:45:00 -05:00
if ( ! transform . isNull ( ) )
2016-02-22 16:13:14 -05:00
{
2016-03-06 15:11:09 -05:00
output = transform ;
if ( fixedMapPath_ . empty ( ) )
2016-02-24 12:45:00 -05:00
{
2016-03-06 15:11:09 -05:00
bool modified = false ;
Transform newFramePose = this - > getPose ( ) * output ;
// fields to update
cv : : Mat mapScan = tmpMap . sensorData ( ) . laserScanRaw ( ) ;
2016-03-08 12:31:32 -05:00
std : : multimap < int , cv : : KeyPoint > mapWords = tmpMap . getWords ( ) ;
2016-03-06 15:11:09 -05:00
std : : multimap < int , cv : : Point3f > mapPoints = tmpMap . getWords3 ( ) ;
std : : multimap < int , cv : : Mat > mapDescriptors = tmpMap . getWordsDescriptors ( ) ;
2016-02-22 16:13:14 -05:00
2016-03-06 15:11:09 -05:00
//Visual
2016-02-24 12:45:00 -05:00
int added = 0 ;
int removed = 0 ;
2016-03-08 12:31:32 -05:00
UDEBUG ( " keyframeThr=%f matches=%d inliers=%d features=%d mp=%d " , keyFrameThr_ , regInfo . matches , regInfo . inliers , ( int ) lastFrame_ - > sensorData ( ) . keypoints ( ) . size ( ) , ( int ) mapPoints . size ( ) ) ;
2016-03-06 15:11:09 -05:00
if ( regPipeline_ - > isImageRequired ( ) & &
( keyFrameThr_ = = 0 | | float ( regInfo . inliers ) < = keyFrameThr_ * float ( lastFrame_ - > sensorData ( ) . keypoints ( ) . size ( ) ) ) )
2016-02-22 16:13:14 -05:00
{
2016-03-11 16:54:54 -05:00
UDEBUG ( " Update local map (ratio=%f < %f) " , float ( regInfo . inliers ) / float ( lastFrame_ - > sensorData ( ) . keypoints ( ) . size ( ) ) , keyFrameThr_ ) ;
2016-03-06 15:11:09 -05:00
// update local map
2016-03-08 12:31:32 -05:00
UASSERT ( mapWords . size ( ) = = mapPoints . size ( ) ) ;
2016-03-06 15:11:09 -05:00
UASSERT ( mapPoints . size ( ) = = mapDescriptors . size ( ) ) ;
UASSERT_MSG ( lastFrame_ - > getWordsDescriptors ( ) . size ( ) = = lastFrame_ - > getWords3 ( ) . size ( ) , uFormat ( " %d vs %d " , lastFrame_ - > getWordsDescriptors ( ) . size ( ) , lastFrame_ - > getWords3 ( ) . size ( ) ) . c_str ( ) ) ;
// sort by feature response
2016-03-08 12:31:32 -05:00
std : : multimap < float , std : : pair < int , std : : pair < cv : : KeyPoint , std : : pair < cv : : Point3f , cv : : Mat > > > > newIds ;
2016-03-06 15:11:09 -05:00
UASSERT ( lastFrame_ - > getWords3 ( ) . size ( ) = = lastFrame_ - > getWords ( ) . size ( ) ) ;
std : : multimap < int , cv : : KeyPoint > : : const_iterator iter2D = lastFrame_ - > getWords ( ) . begin ( ) ;
2016-03-08 12:31:32 -05:00
std : : multimap < int , cv : : Mat > : : const_iterator iterDesc = lastFrame_ - > getWordsDescriptors ( ) . begin ( ) ;
for ( std : : multimap < int , cv : : Point3f > : : const_iterator iter = lastFrame_ - > getWords3 ( ) . begin ( ) ; iter ! = lastFrame_ - > getWords3 ( ) . end ( ) ; + + iter , + + iter2D , + + iterDesc )
2016-02-24 12:45:00 -05:00
{
2016-03-08 12:31:32 -05:00
if ( util3d : : isFinite ( iter - > second ) )
2016-03-06 15:11:09 -05:00
{
2016-03-08 12:31:32 -05:00
if ( mapPoints . find ( iter - > first ) = = mapPoints . end ( ) ) // Point not in map
{
newIds . insert (
std : : make_pair ( iter2D - > second . response > 0 ? 1.0f / iter2D - > second . response : 0.0f ,
std : : make_pair ( iter - > first ,
std : : make_pair ( iter2D - > second ,
std : : make_pair ( iter - > second , iterDesc - > second ) ) ) ) ) ;
}
2016-03-06 15:11:09 -05:00
}
2016-03-01 20:47:46 -05:00
}
2016-03-08 12:31:32 -05:00
for ( std : : multimap < float , std : : pair < int , std : : pair < cv : : KeyPoint , std : : pair < cv : : Point3f , cv : : Mat > > > > : : iterator iter = newIds . begin ( ) ;
iter ! = newIds . end ( ) ;
+ + iter )
2016-03-01 20:47:46 -05:00
{
2016-03-06 15:11:09 -05:00
if ( maxNewFeatures_ = = 0 | | added < maxNewFeatures_ )
2016-03-01 20:47:46 -05:00
{
2016-03-08 12:31:32 -05:00
mapWords . insert ( std : : make_pair ( iter - > second . first , iter - > second . second . first ) ) ;
mapPoints . insert ( std : : make_pair ( iter - > second . first , util3d : : transformPoint ( iter - > second . second . second . first , newFramePose ) ) ) ;
mapDescriptors . insert ( std : : make_pair ( iter - > second . first , iter - > second . second . second . second ) ) ;
+ + added ;
2016-03-01 20:47:46 -05:00
}
2016-02-24 12:45:00 -05:00
}
2016-03-06 15:11:09 -05:00
// remove words in map if max size is reached
if ( ( int ) mapPoints . size ( ) > maximumMapSize_ )
{
// remove oldest first, keep matched features
std : : set < int > matches ( regInfo . matchesIDs . begin ( ) , regInfo . matchesIDs . end ( ) ) ;
2016-03-08 12:31:32 -05:00
std : : multimap < int , cv : : Mat > : : iterator iterMapDescriptors = mapDescriptors . begin ( ) ;
std : : multimap < int , cv : : KeyPoint > : : iterator iterMapWords = mapWords . begin ( ) ;
2016-03-06 15:11:09 -05:00
for ( std : : multimap < int , cv : : Point3f > : : iterator iter = mapPoints . begin ( ) ;
iter ! = mapPoints . end ( ) & & ( int ) mapPoints . size ( ) > maximumMapSize_ & & mapPoints . size ( ) > = newIds . size ( ) ; )
{
if ( matches . find ( iter - > first ) = = matches . end ( ) )
{
2016-03-14 18:08:05 -04:00
mapPoints . erase ( iter + + ) ;
mapDescriptors . erase ( iterMapDescriptors + + ) ;
mapWords . erase ( iterMapWords + + ) ;
2016-03-06 15:11:09 -05:00
+ + removed ;
}
else
{
+ + iter ;
2016-03-08 12:31:32 -05:00
+ + iterMapDescriptors ;
2016-03-06 15:11:09 -05:00
+ + iterMapWords ;
}
}
}
modified = true ;
2016-02-22 16:13:14 -05:00
}
2016-03-06 15:11:09 -05:00
// Geometric
UDEBUG ( " scankeyframeThr=%f icpInliersRatio=%f " , scanKeyFrameThr_ , regInfo . icpInliersRatio ) ;
if ( regPipeline_ - > isScanRequired ( ) & &
( scanKeyFrameThr_ = = 0 | | regInfo . icpInliersRatio < = scanKeyFrameThr_ ) )
2016-02-22 16:13:14 -05:00
{
2016-03-11 16:54:54 -05:00
UINFO ( " Update local scan map %d (ratio=%f < %f) " , lastFrame_ - > id ( ) , regInfo . icpInliersRatio , scanKeyFrameThr_ ) ;
2016-03-06 15:11:09 -05:00
pcl : : PointCloud < pcl : : PointNormal > : : Ptr mapCloudNormals = util3d : : laserScanToPointCloudNormal ( mapScan ) ;
pcl : : PointCloud < pcl : : PointNormal > : : Ptr frameCloudNormals = util3d : : laserScanToPointCloudNormal ( lastFrame_ - > sensorData ( ) . laserScanRaw ( ) , newFramePose ) ;
if ( mapCloudNormals - > size ( ) & & scanSubstractRadius_ > 0.0f )
{
frameCloudNormals = util3d : : subtractFiltering ( frameCloudNormals , mapCloudNormals , scanSubstractRadius_ , 0.0f ) ;
}
if ( frameCloudNormals - > size ( ) )
2016-02-22 16:13:14 -05:00
{
2016-03-06 15:11:09 -05:00
scansBuffer_ . insert ( std : : make_pair ( lastFrame_ - > id ( ) , frameCloudNormals ) ) ;
//remove points if too big
UDEBUG ( " scansBuffer=%d, mapSize=%d maxPoints=%d " , ( int ) scansBuffer_ . size ( ) , int ( mapCloudNormals - > size ( ) + frameCloudNormals - > size ( ) ) , scanMaximumMapSize_ ) ;
if ( scansBuffer_ . size ( ) > 1 & & int ( mapCloudNormals - > size ( ) + frameCloudNormals - > size ( ) ) > scanMaximumMapSize_ )
2016-02-24 12:45:00 -05:00
{
2016-03-06 15:11:09 -05:00
//asssemble
mapCloudNormals - > clear ( ) ;
std : : list < int > toRemove ;
for ( std : : map < int , pcl : : PointCloud < pcl : : PointNormal > : : Ptr > : : reverse_iterator iter = scansBuffer_ . rbegin ( ) ;
iter ! = scansBuffer_ . rend ( ) ;
+ + iter )
{
if ( mapCloudNormals - > empty ( ) )
{
* mapCloudNormals = * iter - > second ;
}
else if ( ( int ) mapCloudNormals - > size ( ) < scanMaximumMapSize_ )
{
* mapCloudNormals + = * iter - > second ;
}
else
{
toRemove . push_back ( iter - > first ) ;
}
}
for ( std : : list < int > : : iterator iter = toRemove . begin ( ) ; iter ! = toRemove . end ( ) ; + + iter )
{
scansBuffer_ . erase ( * iter ) ;
}
2016-02-24 12:45:00 -05:00
}
else
{
2016-03-06 15:11:09 -05:00
//assemble
* mapCloudNormals + = * frameCloudNormals ;
2016-02-24 12:45:00 -05:00
}
2016-03-06 15:11:09 -05:00
mapScan = util3d : : laserScanFromPointCloud ( * mapCloudNormals ) ;
modified = true ;
2016-02-22 16:13:14 -05:00
}
}
2016-03-06 15:11:09 -05:00
if ( modified )
{
* map_ = tmpMap ;
map_ - > sensorData ( ) . setLaserScanRaw ( mapScan , 0 , 0 ) ;
2016-03-08 12:31:32 -05:00
map_ - > setWords ( mapWords ) ;
2016-03-06 15:11:09 -05:00
map_ - > setWords3 ( mapPoints ) ;
map_ - > setWordsDescriptors ( mapDescriptors ) ;
}
2016-02-24 12:45:00 -05:00
}
else
{
// fixed local map, don't update with the new signature
}
2016-02-22 16:13:14 -05:00
}
2016-03-01 20:47:46 -05:00
2016-03-06 15:11:09 -05:00
if ( info )
2016-03-01 20:47:46 -05:00
{
// use tmpMap instead of map_ to make sure that correspondences with the new frame matches
info - > localMapSize = ( int ) tmpMap . getWords3 ( ) . size ( ) ;
2016-03-06 15:11:09 -05:00
info - > localScanMapSize = tmpMap . sensorData ( ) . laserScanRaw ( ) . cols ;
if ( this - > isInfoDataFilled ( ) )
{
info - > localMap = uMultimapToMap ( tmpMap . getWords3 ( ) ) ;
info - > localScanMap = tmpMap . sensorData ( ) . laserScanRaw ( ) ;
}
2016-03-01 20:47:46 -05:00
}
2016-02-22 16:13:14 -05:00
}
else
{
// just generate keypoints for the new signature
2016-03-06 15:11:09 -05:00
if ( regPipeline_ - > isImageRequired ( ) )
{
Signature dummy ;
regPipeline_ - > computeTransformationMod (
* lastFrame_ ,
dummy ) ;
}
2016-02-22 16:13:14 -05:00
2016-02-23 11:46:07 -05:00
data . setFeatures ( lastFrame_ - > sensorData ( ) . keypoints ( ) , lastFrame_ - > sensorData ( ) . descriptors ( ) ) ;
2016-02-22 17:57:40 -05:00
2016-03-06 15:11:09 -05:00
if ( fixedMapPath_ . empty ( ) )
2016-02-22 16:13:14 -05:00
{
output . setIdentity ( ) ;
// a very high variance tells that the new pose is not linked with the previous one
regInfo . variance = 9999 ;
2016-03-06 15:11:09 -05:00
Transform newFramePose = this - > getPose ( ) ; // initial pose may be not identity...
if ( regPipeline_ - > isImageRequired ( ) & &
( int ) lastFrame_ - > getWords3 ( ) . size ( ) > = regPipeline_ - > getMinVisualCorrespondences ( ) )
2016-02-22 16:13:14 -05:00
{
2016-03-08 12:31:32 -05:00
// update local map
UASSERT_MSG ( lastFrame_ - > getWordsDescriptors ( ) . size ( ) = = lastFrame_ - > getWords3 ( ) . size ( ) , uFormat ( " %d vs %d " , lastFrame_ - > getWordsDescriptors ( ) . size ( ) , lastFrame_ - > getWords3 ( ) . size ( ) ) . c_str ( ) ) ;
UASSERT ( lastFrame_ - > getWords3 ( ) . size ( ) = = lastFrame_ - > getWords ( ) . size ( ) ) ;
2016-03-09 16:32:16 -05:00
std : : multimap < int , cv : : KeyPoint > words ;
std : : multimap < int , cv : : Point3f > transformedPoints ;
std : : multimap < int , cv : : Mat > descriptors ;
UASSERT ( lastFrame_ - > getWords3 ( ) . size ( ) = = lastFrame_ - > getWordsDescriptors ( ) . size ( ) ) ;
std : : multimap < int , cv : : KeyPoint > : : const_iterator wordsIter = lastFrame_ - > getWords ( ) . begin ( ) ;
std : : multimap < int , cv : : Mat > : : const_iterator descIter = lastFrame_ - > getWordsDescriptors ( ) . begin ( ) ;
for ( std : : multimap < int , cv : : Point3f > : : const_iterator iter = lastFrame_ - > getWords3 ( ) . begin ( ) ;
iter ! = lastFrame_ - > getWords3 ( ) . end ( ) ;
+ + iter , + + descIter , + + wordsIter )
{
if ( util3d : : isFinite ( iter - > second ) )
{
words . insert ( * wordsIter ) ;
transformedPoints . insert ( std : : make_pair ( iter - > first , util3d : : transformPoint ( iter - > second , newFramePose ) ) ) ;
descriptors . insert ( * descIter ) ;
}
}
map_ - > setWords ( words ) ;
map_ - > setWords3 ( transformedPoints ) ;
map_ - > setWordsDescriptors ( descriptors ) ;
2016-03-06 15:11:09 -05:00
map_ - > sensorData ( ) . setCameraModels ( lastFrame_ - > sensorData ( ) . cameraModels ( ) ) ;
map_ - > sensorData ( ) . setStereoCameraModel ( lastFrame_ - > sensorData ( ) . stereoCameraModel ( ) ) ;
}
if ( regPipeline_ - > isScanRequired ( ) )
{
pcl : : PointCloud < pcl : : PointNormal > : : Ptr mapCloudNormals = util3d : : laserScanToPointCloudNormal ( lastFrame_ - > sensorData ( ) . laserScanRaw ( ) , newFramePose ) ;
scansBuffer_ . insert ( std : : make_pair ( lastFrame_ - > id ( ) , mapCloudNormals ) ) ;
map_ - > sensorData ( ) . setLaserScanRaw ( util3d : : laserScanFromPointCloud ( * mapCloudNormals ) , 0 , 0 ) ;
2016-02-22 16:13:14 -05:00
}
}
2016-03-01 20:47:46 -05:00
2016-03-06 15:11:09 -05:00
if ( info )
2016-03-01 20:47:46 -05:00
{
info - > localMapSize = ( int ) map_ - > getWords3 ( ) . size ( ) ;
2016-03-06 15:11:09 -05:00
info - > localScanMapSize = map_ - > sensorData ( ) . laserScanRaw ( ) . cols ;
if ( this - > isInfoDataFilled ( ) )
{
info - > localMap = uMultimapToMap ( map_ - > getWords3 ( ) ) ;
info - > localScanMap = map_ - > sensorData ( ) . laserScanRaw ( ) ;
}
2016-03-01 20:47:46 -05:00
}
2016-02-22 16:13:14 -05:00
}
map_ - > sensorData ( ) . setFeatures ( std : : vector < cv : : KeyPoint > ( ) , cv : : Mat ( ) ) ; // clear sensorData features
2016-02-23 11:46:07 -05:00
nFeatures = lastFrame_ - > getWords ( ) . size ( ) ;
2016-02-22 16:13:14 -05:00
if ( this - > isInfoDataFilled ( ) & & info )
{
2016-03-06 15:11:09 -05:00
if ( regPipeline_ - > isImageRequired ( ) )
{
info - > words = lastFrame_ - > getWords ( ) ;
}
2016-02-22 16:13:14 -05:00
}
}
if ( info )
{
info - > variance = regInfo . variance ;
info - > inliers = regInfo . inliers ;
info - > matches = regInfo . matches ;
2016-03-06 15:11:09 -05:00
info - > icpInliersRatio = regInfo . icpInliersRatio ;
2016-02-22 16:13:14 -05:00
info - > features = nFeatures ;
if ( this - > isInfoDataFilled ( ) )
{
info - > wordMatches = regInfo . matchesIDs ;
info - > wordInliers = regInfo . inliersIDs ;
}
}
2016-03-06 15:11:09 -05:00
UINFO ( " Odom update time = %fs lost=%s features=%d inliers=%d/%d variance=%f local_map=%d local_scan_map=%d " ,
2016-02-22 16:13:14 -05:00
timer . elapsed ( ) ,
output . isNull ( ) ? " true " : " false " ,
nFeatures ,
regInfo . inliers ,
regInfo . matches ,
regInfo . variance ,
2016-03-06 15:11:09 -05:00
regPipeline_ - > isImageRequired ( ) ? ( int ) map_ - > getWords3 ( ) . size ( ) : 0 ,
regPipeline_ - > isScanRequired ( ) ? ( int ) map_ - > sensorData ( ) . laserScanRaw ( ) . cols : 0 ) ;
2016-02-22 16:13:14 -05:00
return output ;
}
} // namespace rtabmap