2015-11-22 18:08:32 -05:00
/*
2016-07-17 21:57:10 -04:00
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
2015-11-22 18:08:32 -05:00
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/RegistrationIcp.h>
#include <rtabmap/core/util3d_registration.h>
#include <rtabmap/core/util3d_surface.h>
#include <rtabmap/core/util3d.h>
#include <rtabmap/core/util3d_transforms.h>
#include <rtabmap/core/util3d_filtering.h>
#include <rtabmap/utilite/ULogger.h>
#include <rtabmap/utilite/UConversion.h>
#include <rtabmap/utilite/UMath.h>
2016-01-08 19:15:49 -05:00
#include <rtabmap/utilite/UTimer.h>
2015-11-22 18:08:32 -05:00
#include <pcl/io/pcd_io.h>
namespace rtabmap {
2016-01-06 17:26:55 -05:00
RegistrationIcp :: RegistrationIcp ( const ParametersMap & parameters , Registration * child ) :
Registration ( parameters , child ),
2015-11-25 12:15:41 -05:00
_maxTranslation ( Parameters :: defaultIcpMaxTranslation ()),
_maxRotation ( Parameters :: defaultIcpMaxRotation ()),
_voxelSize ( Parameters :: defaultIcpVoxelSize ()),
_downsamplingStep ( Parameters :: defaultIcpDownsamplingStep ()),
_maxCorrespondenceDistance ( Parameters :: defaultIcpMaxCorrespondenceDistance ()),
_maxIterations ( Parameters :: defaultIcpIterations ()),
2016-01-12 11:37:50 -05:00
_epsilon ( Parameters :: defaultIcpEpsilon ()),
2015-11-25 12:15:41 -05:00
_correspondenceRatio ( Parameters :: defaultIcpCorrespondenceRatio ()),
_pointToPlane ( Parameters :: defaultIcpPointToPlane ()),
_pointToPlaneNormalNeighbors ( Parameters :: defaultIcpPointToPlaneNormalNeighbors ())
2015-11-22 18:08:32 -05:00
{
this -> parseParameters ( parameters );
}
void RegistrationIcp :: parseParameters ( const ParametersMap & parameters )
{
Registration :: parseParameters ( parameters );
2015-11-25 12:15:41 -05:00
Parameters :: parse ( parameters , Parameters :: kIcpMaxTranslation (), _maxTranslation );
Parameters :: parse ( parameters , Parameters :: kIcpMaxRotation (), _maxRotation );
Parameters :: parse ( parameters , Parameters :: kIcpVoxelSize (), _voxelSize );
Parameters :: parse ( parameters , Parameters :: kIcpDownsamplingStep (), _downsamplingStep );
Parameters :: parse ( parameters , Parameters :: kIcpMaxCorrespondenceDistance (), _maxCorrespondenceDistance );
Parameters :: parse ( parameters , Parameters :: kIcpIterations (), _maxIterations );
2016-01-12 11:37:50 -05:00
Parameters :: parse ( parameters , Parameters :: kIcpEpsilon (), _epsilon );
2015-11-25 12:15:41 -05:00
Parameters :: parse ( parameters , Parameters :: kIcpCorrespondenceRatio (), _correspondenceRatio );
Parameters :: parse ( parameters , Parameters :: kIcpPointToPlane (), _pointToPlane );
Parameters :: parse ( parameters , Parameters :: kIcpPointToPlaneNormalNeighbors (), _pointToPlaneNormalNeighbors );
2015-11-22 18:08:32 -05:00
2015-11-25 12:15:41 -05:00
UASSERT_MSG ( _voxelSize >= 0 , uFormat ( "value=%d" , _voxelSize ). c_str ());
UASSERT_MSG ( _downsamplingStep >= 0 , uFormat ( "value=%d" , _downsamplingStep ). c_str ());
UASSERT_MSG ( _maxCorrespondenceDistance > 0.0f , uFormat ( "value=%f" , _maxCorrespondenceDistance ). c_str ());
UASSERT_MSG ( _maxIterations > 0 , uFormat ( "value=%d" , _maxIterations ). c_str ());
2016-01-12 11:37:50 -05:00
UASSERT ( _epsilon >= 0.0f );
2015-11-25 12:15:41 -05:00
UASSERT_MSG ( _correspondenceRatio >= 0.0f && _correspondenceRatio <= 1.0f , uFormat ( "value=%f" , _correspondenceRatio ). c_str ());
UASSERT_MSG ( _pointToPlaneNormalNeighbors > 0 , uFormat ( "value=%d" , _pointToPlaneNormalNeighbors ). c_str ());
2015-11-22 18:08:32 -05:00
}
2016-01-06 17:26:55 -05:00
Transform RegistrationIcp :: computeTransformationImpl (
2015-12-21 17:27:05 -05:00
Signature & fromSignature ,
Signature & toSignature ,
2015-11-22 18:08:32 -05:00
Transform guess ,
2016-01-06 17:26:55 -05:00
RegistrationInfo & info ) const
2015-11-22 18:08:32 -05:00
{
UDEBUG ( "Guess transform = %s" , guess . prettyPrint (). c_str ());
2015-11-25 12:15:41 -05:00
UDEBUG ( "Voxel size=%f" , _voxelSize );
UDEBUG ( "PointToPlane=%d" , _pointToPlane ? 1 : 0 );
UDEBUG ( "Normal neighborhood=%d" , _pointToPlaneNormalNeighbors );
UDEBUG ( "Max corrrespondence distance=%f" , _maxCorrespondenceDistance );
UDEBUG ( "Max Iterations=%d" , _maxIterations );
UDEBUG ( "Correspondence Ratio=%f" , _correspondenceRatio );
UDEBUG ( "Max translation=%f" , _maxTranslation );
UDEBUG ( "Max rotation=%f" , _maxRotation );
UDEBUG ( "Downsampling step=%d" , _downsamplingStep );
2015-11-22 18:08:32 -05:00
2016-01-08 19:15:49 -05:00
UTimer timer ;
2015-11-22 18:08:32 -05:00
std :: string msg ;
Transform transform ;
2016-01-06 17:26:55 -05:00
SensorData & dataFrom = fromSignature . sensorData ();
SensorData & dataTo = toSignature . sensorData ();
2016-01-10 12:57:49 -05:00
UDEBUG ( "size from=%d (channels=%d) to=%d (channels=%d)" ,
dataFrom . laserScanRaw (). cols ,
dataFrom . laserScanRaw (). channels (),
dataTo . laserScanRaw (). cols ,
dataTo . laserScanRaw (). channels ());
2016-01-08 19:15:49 -05:00
2016-03-06 15:11:09 -05:00
if ( ! guess . isNull () && ! dataFrom . laserScanRaw (). empty () && ! dataTo . laserScanRaw (). empty ())
2015-11-22 18:08:32 -05:00
{
2016-03-06 15:11:09 -05:00
// ICP with guess transform
2016-08-21 19:33:01 -04:00
int maxLaserScansTo = dataTo . laserScanInfo (). maxPoints ();
int maxLaserScansFrom = dataFrom . laserScanInfo (). maxPoints ();
2015-11-22 18:08:32 -05:00
cv :: Mat fromScan = dataFrom . laserScanRaw ();
cv :: Mat toScan = dataTo . laserScanRaw ();
2016-08-21 19:33:01 -04:00
Transform fromLocalTransform = dataFrom . laserScanInfo (). localTransform ();
Transform toLocalTransform = dataTo . laserScanInfo (). localTransform ();
2015-11-25 12:15:41 -05:00
if ( _downsamplingStep > 1 )
2015-11-22 18:08:32 -05:00
{
2015-11-25 12:15:41 -05:00
fromScan = util3d :: downsample ( fromScan , _downsamplingStep );
toScan = util3d :: downsample ( toScan , _downsamplingStep );
2016-06-25 13:18:09 -04:00
maxLaserScansTo /= _downsamplingStep ;
maxLaserScansFrom /= _downsamplingStep ;
2016-01-08 19:15:49 -05:00
UDEBUG ( "Downsampling time (step=%d) = %f s" , _downsamplingStep , timer . ticks ());
2015-11-22 18:08:32 -05:00
}
2016-01-08 19:15:49 -05:00
if ( fromScan . cols && toScan . cols )
2015-11-22 18:08:32 -05:00
{
Transform icpT ;
bool hasConverged = false ;
float correspondencesRatio = 0.0f ;
int correspondences = 0 ;
double variance = 1.0 ;
2016-01-08 19:15:49 -05:00
2016-03-06 15:11:09 -05:00
if ( _pointToPlane &&
2016-01-08 19:15:49 -05:00
_voxelSize == 0.0f &&
fromScan . channels () == 6 &&
toScan . channels () == 6 )
2015-11-22 18:08:32 -05:00
{
2016-01-08 19:15:49 -05:00
//special case if we have already normals computed and there is no filtering
2016-08-21 19:33:01 -04:00
pcl :: PointCloud < pcl :: PointNormal >:: Ptr fromCloudNormals = util3d :: laserScanToPointCloudNormal ( fromScan , fromLocalTransform );
2016-08-24 12:15:32 -04:00
pcl :: PointCloud < pcl :: PointNormal >:: Ptr toCloudNormals = util3d :: laserScanToPointCloudNormal ( toScan , guess * toLocalTransform );
2016-06-25 13:18:09 -04:00
2016-01-10 12:57:49 -05:00
UDEBUG ( "Conversion time = %f s" , timer . ticks ());
2016-01-08 19:15:49 -05:00
pcl :: PointCloud < pcl :: PointNormal >:: Ptr fromCloudNormalsRegistered ( new pcl :: PointCloud < pcl :: PointNormal > ());
icpT = util3d :: icpPointToPlane (
fromCloudNormals ,
toCloudNormals ,
_maxCorrespondenceDistance ,
_maxIterations ,
hasConverged ,
2016-03-06 15:11:09 -05:00
* fromCloudNormalsRegistered ,
_epsilon ,
this -> force3DoF ());
2016-01-08 19:15:49 -05:00
if ( ! icpT . isNull () && hasConverged )
{
util3d :: computeVarianceAndCorrespondences (
fromCloudNormalsRegistered ,
toCloudNormals ,
_maxCorrespondenceDistance ,
variance ,
correspondences );
2016-03-06 15:11:09 -05:00
/*
UWARN("icpT=%s", icpT.prettyPrint().c_str());
pcl::io::savePCDFile("fromCloud.pcd", *fromCloudNormals);
pcl::io::savePCDFile("toCloud.pcd", *toCloudNormals);
UWARN("saved fromCloud.pcd and toCloud.pcd");
if(!icpT.isNull())
{
pcl::PointCloud<pcl::PointNormal>::Ptr fromCloudTmp = util3d::transformPointCloud(fromCloudNormals, icpT);
pcl::io::savePCDFile("fromCloudFinal.pcd", *fromCloudTmp);
pcl::io::savePCDFile("fromCloudFinal2.pcd", *fromCloudNormalsRegistered);
UWARN("saved fromCloudFinal.pcd");
}
*/
2016-01-08 19:15:49 -05:00
}
}
else
{
2016-08-21 19:33:01 -04:00
pcl :: PointCloud < pcl :: PointXYZ >:: Ptr fromCloud = util3d :: laserScanToPointCloud ( fromScan , fromLocalTransform );
2016-08-24 12:15:32 -04:00
pcl :: PointCloud < pcl :: PointXYZ >:: Ptr toCloud = util3d :: laserScanToPointCloud ( toScan , guess * toLocalTransform );
2016-01-10 12:57:49 -05:00
UDEBUG ( "Conversion time = %f s" , timer . ticks ());
2016-03-11 16:54:54 -05:00
2016-01-08 19:15:49 -05:00
pcl :: PointCloud < pcl :: PointXYZ >:: Ptr fromCloudFiltered = fromCloud ;
pcl :: PointCloud < pcl :: PointXYZ >:: Ptr toCloudFiltered = toCloud ;
bool filtered = false ;
if ( _voxelSize > 0.0f )
{
2016-06-25 13:18:09 -04:00
int pointsBeforeFiltering = fromCloudFiltered -> size ();
2016-01-08 19:15:49 -05:00
fromCloudFiltered = util3d :: voxelize ( fromCloudFiltered , _voxelSize );
2016-06-25 13:18:09 -04:00
maxLaserScansFrom = maxLaserScansFrom * fromCloudFiltered -> size () / pointsBeforeFiltering ;
pointsBeforeFiltering = toCloudFiltered -> size ();
2016-01-08 19:15:49 -05:00
toCloudFiltered = util3d :: voxelize ( toCloudFiltered , _voxelSize );
2016-06-25 13:18:09 -04:00
maxLaserScansTo = maxLaserScansTo * toCloudFiltered -> size () / pointsBeforeFiltering ;
2016-01-08 19:15:49 -05:00
filtered = true ;
UDEBUG ( "Voxel filtering time (voxel=%f m) = %f s" , _voxelSize , timer . ticks ());
2016-03-11 20:13:24 -05:00
//Adjust maxLaserScans
2016-06-25 13:18:09 -04:00
2016-01-08 19:15:49 -05:00
}
bool correspondencesComputed = false ;
pcl :: PointCloud < pcl :: PointXYZ >:: Ptr fromCloudRegistered ( new pcl :: PointCloud < pcl :: PointXYZ > ());
2016-03-06 15:11:09 -05:00
if ( _pointToPlane ) // ICP Point To Plane, only in 3D
2015-11-22 18:08:32 -05:00
{
2016-06-12 13:51:49 -04:00
pcl :: PointCloud < pcl :: Normal >:: Ptr normals ;
normals = util3d :: computeNormals ( fromCloudFiltered , _pointToPlaneNormalNeighbors );
pcl :: PointCloud < pcl :: PointNormal >:: Ptr fromCloudNormals ( new pcl :: PointCloud < pcl :: PointNormal > );
pcl :: concatenateFields ( * fromCloudFiltered , * normals , * fromCloudNormals );
normals = util3d :: computeNormals ( toCloudFiltered , _pointToPlaneNormalNeighbors );
pcl :: PointCloud < pcl :: PointNormal >:: Ptr toCloudNormals ( new pcl :: PointCloud < pcl :: PointNormal > );
pcl :: concatenateFields ( * toCloudFiltered , * normals , * toCloudNormals );
2015-11-22 18:08:32 -05:00
std :: vector < int > indices ;
toCloudNormals = util3d :: removeNaNNormalsFromPointCloud ( toCloudNormals );
fromCloudNormals = util3d :: removeNaNNormalsFromPointCloud ( fromCloudNormals );
2016-06-25 13:18:09 -04:00
// update output scans
2016-08-21 19:33:01 -04:00
fromSignature . sensorData (). setLaserScanRaw ( util3d :: laserScanFromPointCloud ( * fromCloudNormals , fromLocalTransform . inverse ()), LaserScanInfo ( maxLaserScansFrom , fromSignature . sensorData (). laserScanInfo (). maxRange (), fromLocalTransform ));
2016-08-24 12:15:32 -04:00
toSignature . sensorData (). setLaserScanRaw ( util3d :: laserScanFromPointCloud ( * toCloudNormals , ( guess * toLocalTransform ). inverse ()), LaserScanInfo ( maxLaserScansTo , toSignature . sensorData (). laserScanInfo (). maxRange (), toLocalTransform ));
2016-06-25 13:18:09 -04:00
2016-01-08 19:15:49 -05:00
UDEBUG ( "Compute normals time = %f s" , timer . ticks ());
2015-11-22 18:08:32 -05:00
if ( toCloudNormals -> size () && fromCloudNormals -> size ())
{
2015-11-26 16:03:03 -05:00
pcl :: PointCloud < pcl :: PointNormal >:: Ptr fromCloudNormalsRegistered ( new pcl :: PointCloud < pcl :: PointNormal > ());
2015-11-22 18:08:32 -05:00
icpT = util3d :: icpPointToPlane (
fromCloudNormals ,
2015-11-26 16:03:03 -05:00
toCloudNormals ,
2015-11-25 12:15:41 -05:00
_maxCorrespondenceDistance ,
_maxIterations ,
2015-11-22 18:08:32 -05:00
hasConverged ,
2016-03-06 15:11:09 -05:00
* fromCloudNormalsRegistered ,
_epsilon ,
this -> force3DoF ());
2015-11-22 18:08:32 -05:00
if ( ! filtered &&
! icpT . isNull () &&
hasConverged )
{
util3d :: computeVarianceAndCorrespondences (
2015-11-26 16:03:03 -05:00
fromCloudNormalsRegistered ,
2016-01-08 19:15:49 -05:00
toCloudNormals ,
2015-11-26 16:03:03 -05:00
_maxCorrespondenceDistance ,
variance ,
correspondences );
2015-11-22 18:08:32 -05:00
correspondencesComputed = true ;
}
}
}
2016-01-08 19:15:49 -05:00
else // ICP Point to Point
2015-11-22 18:08:32 -05:00
{
2016-06-25 13:18:09 -04:00
if ( _voxelSize > 0.0f )
{
// update output scans
2016-08-21 19:33:01 -04:00
fromSignature . sensorData (). setLaserScanRaw ( util3d :: laserScanFromPointCloud ( * fromCloudFiltered , fromLocalTransform . inverse ()), LaserScanInfo ( maxLaserScansFrom , fromSignature . sensorData (). laserScanInfo (). maxRange (), fromLocalTransform ));
2016-08-24 12:15:32 -04:00
toSignature . sensorData (). setLaserScanRaw ( util3d :: laserScanFromPointCloud ( * toCloudFiltered , ( guess * toLocalTransform ). inverse ()), LaserScanInfo ( maxLaserScansTo , toSignature . sensorData (). laserScanInfo (). maxRange (), toLocalTransform ));
2016-06-25 13:18:09 -04:00
}
2015-11-22 18:08:32 -05:00
icpT = util3d :: icp (
fromCloudFiltered ,
2015-11-26 16:03:03 -05:00
toCloudFiltered ,
2016-01-08 19:15:49 -05:00
_maxCorrespondenceDistance ,
_maxIterations ,
hasConverged ,
* fromCloudRegistered ,
2016-01-12 11:37:50 -05:00
_epsilon ,
2016-02-19 15:10:28 -05:00
this -> force3DoF ()); // icp2D
2016-01-08 19:15:49 -05:00
}
/*pcl::io::savePCDFile("fromCloud.pcd", *fromCloud);
pcl::io::savePCDFile("toCloud.pcd", *toCloud);
UWARN("saved fromCloud.pcd and toCloud.pcd");
if(!icpT.isNull())
{
pcl::PointCloud<pcl::PointXYZ>::Ptr fromCloudTmp = util3d::transformPointCloud(fromCloud, icpT);
pcl::io::savePCDFile("fromCloudFinal.pcd", *fromCloudTmp);
UWARN("saved fromCloudFinal.pcd");
}*/
if ( ! icpT . isNull () &&
hasConverged &&
! correspondencesComputed )
{
if ( filtered )
{
fromCloud = util3d :: transformPointCloud ( fromCloud , icpT );
}
else
{
fromCloud = fromCloudRegistered ;
}
util3d :: computeVarianceAndCorrespondences (
fromCloud ,
toCloud ,
2015-11-25 12:15:41 -05:00
_maxCorrespondenceDistance ,
2016-01-08 19:15:49 -05:00
variance ,
correspondences );
2015-11-22 18:08:32 -05:00
}
}
2016-01-08 19:15:49 -05:00
UDEBUG ( "ICP (iterations=%d) time = %f s" , _maxIterations , timer . ticks ());
2015-11-22 18:08:32 -05:00
if ( ! icpT . isNull () &&
hasConverged )
{
float ix , iy , iz , iroll , ipitch , iyaw ;
2016-03-06 15:11:09 -05:00
Transform icpInTargetReferential = guess . inverse () * icpT . inverse () * guess ; // actual local ICP refinement
icpInTargetReferential . getTranslationAndEulerAngles ( ix , iy , iz , iroll , ipitch , iyaw );
2016-07-05 11:23:59 -04:00
info . icpTranslation = uMax3 ( fabs ( ix ), fabs ( iy ), fabs ( iz ));
info . icpRotation = uMax3 ( fabs ( iroll ), fabs ( ipitch ), fabs ( iyaw ));
2015-11-25 12:15:41 -05:00
if (( _maxTranslation > 0.0f &&
2016-07-05 11:23:59 -04:00
info . icpTranslation > _maxTranslation )
2016-03-06 15:11:09 -05:00
||
( _maxRotation > 0.0f &&
2016-07-05 11:23:59 -04:00
info . icpRotation > _maxRotation ))
2015-11-22 18:08:32 -05:00
{
msg = uFormat ( "Cannot compute transform (ICP correction too large -> %f m %f rad, limits=%f m, %f rad)" ,
2016-07-05 11:23:59 -04:00
info . icpTranslation ,
info . icpRotation ,
2015-11-25 12:15:41 -05:00
_maxTranslation ,
_maxRotation );
2015-11-22 18:08:32 -05:00
UINFO ( msg . c_str ());
}
else
{
// verify if there are enough correspondences
2016-06-25 13:18:09 -04:00
int maxLaserScans = maxLaserScansTo ? maxLaserScansTo : maxLaserScansFrom ;
2015-11-22 18:08:32 -05:00
if ( maxLaserScans )
{
correspondencesRatio = float ( correspondences ) / float ( maxLaserScans );
}
else
{
2016-05-20 11:44:50 -04:00
static bool warningShown = false ;
if ( ! warningShown )
{
UWARN ( "Maximum laser scans points not set for signature %d, correspondences ratio set relative instead of absolute! This message will only appear once." ,
dataTo . id ());
warningShown = true ;
}
2016-01-08 19:15:49 -05:00
correspondencesRatio = float ( correspondences ) / float ( toScan . cols > fromScan . cols ? toScan . cols : fromScan . cols );
2015-11-22 18:08:32 -05:00
}
2016-08-12 18:43:12 -04:00
UDEBUG ( "%d->%d hasConverged=%s, variance=%f, correspondences=%d/%d (%f%%), from guess: trans=%f rot=%f" ,
2015-11-22 18:08:32 -05:00
dataTo . id (), dataFrom . id (),
hasConverged ? "true" : "false" ,
variance ,
correspondences ,
2016-06-25 13:18:09 -04:00
maxLaserScans > 0 ? maxLaserScans :( int )( toScan . cols > fromScan . cols ? toScan . cols : fromScan . cols ),
2016-08-12 18:43:12 -04:00
correspondencesRatio * 100.0f ,
info . icpTranslation ,
info . icpRotation );
2015-11-22 18:08:32 -05:00
2017-05-04 16:13:45 -04:00
info . covariance = cv :: Mat :: eye ( 6 , 6 , CV_64FC1 ) * ( variance > 0.0001 ? variance : 0.0001 ); // epsilon if exact transform
2016-01-08 19:15:49 -05:00
info . icpInliersRatio = correspondencesRatio ;
2015-11-22 18:08:32 -05:00
2015-11-25 12:15:41 -05:00
if ( correspondencesRatio < _correspondenceRatio )
2015-11-22 18:08:32 -05:00
{
msg = uFormat ( "Cannot compute transform (cor=%d corrRatio=%f/%f)" ,
2015-11-25 12:15:41 -05:00
correspondences , correspondencesRatio , _correspondenceRatio );
2015-11-22 18:08:32 -05:00
UINFO ( msg . c_str ());
}
else
{
2015-11-26 16:03:03 -05:00
transform = icpT . inverse () * guess ;
2015-11-22 18:08:32 -05:00
}
}
}
else
{
msg = uFormat ( "Cannot compute transform (converged=%s var=%f)" ,
hasConverged ? "true" : "false" , variance );
UINFO ( msg . c_str ());
}
}
else
{
msg = "Laser scans empty ?!?" ;
UWARN ( msg . c_str ());
}
}
2016-03-06 15:11:09 -05:00
else if ( dataTo . isValid ())
2015-11-22 18:08:32 -05:00
{
2016-03-06 15:11:09 -05:00
if ( guess . isNull ())
{
msg = "RegistrationIcp cannot do registration with a null guess." ;
}
else
{
msg = uFormat ( "Laser scans empty?!? (new[%d]=%d old[%d]=%d)" ,
dataTo . id (), dataTo . laserScanRaw (). total (),
dataFrom . id (), dataFrom . laserScanRaw (). total ());
}
2015-11-22 18:08:32 -05:00
UERROR ( msg . c_str ());
}
2016-01-07 13:59:21 -05:00
info . rejectedMsg = msg ;
2015-11-22 18:08:32 -05:00
UDEBUG ( "New transform = %s" , transform . prettyPrint (). c_str ());
return transform ;
}
}