changed all std::atof() to uStr2Float() to fix locale comma float conversion problem

This commit is contained in:
Mathieu Labbe
2015-02-04 21:20:17 -05:00
parent f8b625c7c7
commit 3d1eccbce1
15 changed files with 75 additions and 38 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ void BayesFilter::setPredictionLC(const std::string & prediction)
bool valid = true;
for(std::list<std::string>::iterator iter = strValues.begin(); iter!=strValues.end(); ++iter)
{
tmpValues[i] = std::atof((*iter).c_str());
tmpValues[i] = uStr2Float((*iter).c_str());
//UINFO("%d=%e", i, tmpValues[i]);
if(tmpValues[i] < 0.0 || tmpValues[i]>1.0)
{
+1 -1
View File
@@ -251,7 +251,7 @@ cv::Rect Feature2D::computeRoi(const cv::Mat & image, const std::string & roiRat
unsigned int i=0;
for(std::list<std::string>::iterator iter = strValues.begin(); iter!=strValues.end(); ++iter)
{
values[i] = std::atof((*iter).c_str());
values[i] = uStr2Float(*iter);
++i;
}
+12 -12
View File
@@ -439,12 +439,12 @@ bool loadTOROGraph(const std::string & fileName,
{
//VERTEX3
int id = atoi(strList[1].c_str());
float x = atof(strList[2].c_str());
float y = atof(strList[3].c_str());
float z = atof(strList[4].c_str());
float roll = atof(strList[5].c_str());
float pitch = atof(strList[6].c_str());
float yaw = atof(strList[7].c_str());
float x = uStr2Float(strList[2]);
float y = uStr2Float(strList[3]);
float z = uStr2Float(strList[4]);
float roll = uStr2Float(strList[5]);
float pitch = uStr2Float(strList[6]);
float yaw = uStr2Float(strList[7]);
Transform pose = Transform::fromEigen3f(pcl::getTransformation(x, y, z, roll, pitch, yaw));
std::map<int, Transform>::iterator iter = poses.find(id);
if(iter != poses.end())
@@ -461,12 +461,12 @@ bool loadTOROGraph(const std::string & fileName,
//EDGE3
int idFrom = atoi(strList[1].c_str());
int idTo = atoi(strList[2].c_str());
float x = atof(strList[3].c_str());
float y = atof(strList[4].c_str());
float z = atof(strList[5].c_str());
float roll = atof(strList[6].c_str());
float pitch = atof(strList[7].c_str());
float yaw = atof(strList[8].c_str());
float x = uStr2Float(strList[3]);
float y = uStr2Float(strList[4]);
float z = uStr2Float(strList[5]);
float roll = uStr2Float(strList[6]);
float pitch = uStr2Float(strList[7]);
float yaw = uStr2Float(strList[8]);
Transform transform = Transform::fromEigen3f(pcl::getTransformation(x, y, z, roll, pitch, yaw));
if(poses.find(idFrom) != poses.end() && poses.find(idTo) != poses.end())
{
+1 -1
View File
@@ -611,7 +611,7 @@ void Memory::setRoi(const std::string & roi)
unsigned int i=0;
for(std::list<std::string>::iterator iter = strValues.begin(); iter!=strValues.end(); ++iter)
{
tmpValues[i] = std::atof((*iter).c_str());
tmpValues[i] = uStr2Float(*iter);
++i;
}
+3 -2
View File
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/utilite/UConversion.h>
#include <math.h>
#include <stdlib.h>
#include <sstream>
namespace rtabmap
{
@@ -112,7 +113,7 @@ void Parameters::parse(const ParametersMap & parameters, const std::string & key
ParametersMap::const_iterator iter = parameters.find(key);
if(iter != parameters.end())
{
value = atof(iter->second.c_str());
value = uStr2Float(iter->second);
}
}
void Parameters::parse(const ParametersMap & parameters, const std::string & key, double & value)
@@ -120,7 +121,7 @@ void Parameters::parse(const ParametersMap & parameters, const std::string & key
ParametersMap::const_iterator iter = parameters.find(key);
if(iter != parameters.end())
{
value = atof(iter->second.c_str());
value = uStr2Double(iter->second);
}
}
void Parameters::parse(const ParametersMap & parameters, const std::string & key, std::string & value)
+2 -2
View File
@@ -71,7 +71,7 @@ void VWDictionary::parseParameters(const ParametersMap & parameters)
Parameters::parse(parameters, Parameters::kKpNndrRatio(), _nndrRatio);
Parameters::parse(parameters, Parameters::kKpNewWordsComparedTogether(), _newWordsComparedTogether);
UASSERT(_nndrRatio > 0.0f);
UASSERT_MSG(_nndrRatio > 0.0f, uFormat("String=%s value=%f", uContains(parameters, Parameters::kKpNndrRatio())?parameters.at(Parameters::kKpNndrRatio()).c_str():"", _nndrRatio).c_str());
std::string dictionaryPath = _dictionaryPath;
bool incrementalDictionary = _incrementalDictionary;
@@ -167,7 +167,7 @@ void VWDictionary::setFixedDictionary(const std::string & dictionaryPath)
//get descriptor
for(;i<dimension && iter != strList.end(); ++i, ++iter)
{
descriptor.at<float>(i) = std::atof(iter->c_str());
descriptor.at<float>(i) = uStr2Float(*iter);
}
if(i != dimension)
{
+4 -4
View File
@@ -423,7 +423,7 @@ MainWindow::MainWindow(PreferencesDialog * prefDialog, QWidget * parent) :
// update loop closure viewer parameters
ParametersMap parameters = _preferencesDialog->getAllParameters();
_ui->widget_loopClosureViewer->setDecimation(atoi(parameters.at(Parameters::kLccIcp3Decimation()).c_str()));
_ui->widget_loopClosureViewer->setMaxDepth(atof(parameters.at(Parameters::kLccIcp3MaxDepth()).c_str()));
_ui->widget_loopClosureViewer->setMaxDepth(uStr2Float(parameters.at(Parameters::kLccIcp3MaxDepth())));
_ui->widget_loopClosureViewer->setSamples(atoi(parameters.at(Parameters::kLccIcp3Samples()).c_str()));
//update ui
@@ -1942,7 +1942,7 @@ void MainWindow::applyPrefSettings(const rtabmap::ParametersMap & parameters)
}
if(uContains(parameters, Parameters::kLccIcp3MaxDepth()))
{
_ui->widget_loopClosureViewer->setMaxDepth(atof(parameters.at(Parameters::kLccIcp3MaxDepth()).c_str()));
_ui->widget_loopClosureViewer->setMaxDepth(uStr2Float(parameters.at(Parameters::kLccIcp3MaxDepth())));
}
if(uContains(parameters, Parameters::kLccIcp3Samples()))
{
@@ -2320,8 +2320,8 @@ void MainWindow::startDetection()
_preferencesDialog->isSourceDatabaseUsed())
{
float inputRate = _preferencesDialog->getGeneralInputRate();
float detectionRate = std::atof(parameters.at(Parameters::kRtabmapDetectionRate()).c_str());
int bufferingSize = std::atof(parameters.at(Parameters::kRtabmapImageBufferSize()).c_str());
float detectionRate = uStr2Float(parameters.at(Parameters::kRtabmapDetectionRate()));
int bufferingSize = uStr2Float(parameters.at(Parameters::kRtabmapImageBufferSize()));
if((detectionRate!=0.0f && detectionRate < inputRate) || (detectionRate > 0.0f && inputRate == 0.0f))
{
int button = QMessageBox::question(this,
+2 -1
View File
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/utilite/ULogger.h"
#include "rtabmap/utilite/UFile.h"
#include "rtabmap/utilite/UDirectory.h"
#include "rtabmap/utilite/UConversion.h"
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
@@ -61,7 +62,7 @@ int main(int argc, char * argv[])
++i;
if(i < argc)
{
rate = std::atof(argv[i]);
rate = uStr2Float(argv[i]);
if(rate < 0)
{
showUsage();
+2 -2
View File
@@ -144,7 +144,7 @@ int main(int argc, char * argv[])
++i;
if(i < argc)
{
rate = std::atof(argv[i]);
rate = uStr2Float(argv[i]);
if(rate < 0)
{
showUsage();
@@ -161,7 +161,7 @@ int main(int argc, char * argv[])
++i;
if(i < argc)
{
rate = std::atof(argv[i]);
rate = uStr2Float(argv[i]);
if(rate < 0)
{
showUsage();
+2 -1
View File
@@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/utilite/ULogger.h>
#include <rtabmap/utilite/UFile.h>
#include <rtabmap/utilite/UConversion.h>
#include <rtabmap/core/CameraThread.h>
#include <rtabmap/core/CameraRGBD.h>
#include <rtabmap/core/Camera.h>
@@ -91,7 +92,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
rate = std::atof(argv[i]);
rate = uStr2Float(argv[i]);
if(rate < 0.0f)
{
showUsage();
+3 -3
View File
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
++i;
if(i < argc)
{
planeDistanceThreshold = std::atof(argv[i]);
planeDistanceThreshold = uStr2Float(argv[i]);
if(planeDistanceThreshold < 0.0f)
{
showUsage();
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
++i;
if(i < argc)
{
planeEpsAngle = std::atof(argv[i]);
planeEpsAngle = uStr2Float(argv[i]);
if(planeEpsAngle < 0.0f)
{
showUsage();
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
++i;
if(i < argc)
{
clusterTolerance = std::atof(argv[i]);
clusterTolerance = uStr2Float(argv[i]);
if(clusterTolerance <= 0.0f)
{
showUsage();
+7 -7
View File
@@ -175,7 +175,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
nndr = std::atof(argv[i]);
nndr = uStr2Float(argv[i]);
if(nndr < 0.0f)
{
showUsage();
@@ -192,7 +192,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
rate = std::atof(argv[i]);
rate = uStr2Float(argv[i]);
if(rate < 0)
{
showUsage();
@@ -244,7 +244,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
sec = std::atof(argv[i]);
sec = uStr2Float(argv[i]);
if(sec < 0.0f)
{
showUsage();
@@ -261,7 +261,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
distance = std::atof(argv[i]);
distance = uStr2Float(argv[i]);
if(distance <= 0)
{
showUsage();
@@ -312,7 +312,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
maxDepth = std::atof(argv[i]);
maxDepth = uStr2Float(argv[i]);
if(maxDepth < 0)
{
showUsage();
@@ -380,7 +380,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
voxel = std::atof(argv[i]);
voxel = uStr2Float(argv[i]);
if(voxel < 0)
{
showUsage();
@@ -414,7 +414,7 @@ int main (int argc, char * argv[])
++i;
if(i < argc)
{
ratio = std::atof(argv[i]);
ratio = uStr2Float(argv[i]);
if(ratio < 0.0f)
{
showUsage();
+1 -1
View File
@@ -117,7 +117,7 @@ int main(int argc, char * argv[])
//get descriptor
for(;i<dimension && iter != strList.end(); ++i, ++iter)
{
descriptor[i] = std::atof(iter->c_str());
descriptor[i] = uStr2Float(*iter);
}
if(i != dimension)
{
@@ -117,6 +117,22 @@ std::string UTILITE_EXP uNumber2Str(float number);
*/
std::string UTILITE_EXP uNumber2Str(double number);
/**
* Convert a string to a float independent of the locale (comma/dot).
* @param the string
* @return the number
*/
float UTILITE_EXP uStr2Float(const std::string & str);
/**
* Convert a string to a double independent of the locale (comma/dot).
* @param the string
* @return the number
*/
double UTILITE_EXP uStr2Double(const std::string & str);
/**
* Convert a bool to a string.
* The format used is "true" and "false".
+18
View File
@@ -113,6 +113,24 @@ std::string uNumber2Str(double number)
return s.str();
}
float uStr2Float(const std::string & str)
{
float value = 0.0f;
std::istringstream istr(uReplaceChar(str, ',', '.').c_str());
istr.imbue(std::locale("C"));
istr >> value;
return value;
}
double uStr2Double(const std::string & str)
{
double value = 0.0;
std::istringstream istr(uReplaceChar(str, ',', '.').c_str());
istr.imbue(std::locale("C"));
istr >> value;
return value;
}
std::string uBool2Str(bool boolean)
{
std::string s;