Skip to content

Commit

Permalink
STYLE: Prefer error checked std::stod over atof
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Rit committed Mar 15, 2022
1 parent d2d22bb commit e6c48eb
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/rtkDbf.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RTK_EXPORT DbfFile
double
GetFieldAsDouble(std::string fldName)
{
return atof(GetFieldAsString(fldName).c_str());
return std::stod(GetFieldAsString(fldName).c_str());
}

private:
Expand Down
62 changes: 31 additions & 31 deletions include/rtkImagXGeometryReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI2p1()
std::string tagValue = list_it.second.c_str();
if (!subTagName.compare("xPlus"))
{
F.xPlus = std::atof(tagValue.c_str());
F.xPlus = std::stod(tagValue.c_str());
xPlusFound = true;
}
else if (!subTagName.compare("xMinus"))
{
F.xMinus = std::atof(tagValue.c_str());
F.xMinus = std::stod(tagValue.c_str());
xMinusFound = true;
}
}
Expand All @@ -131,17 +131,17 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI2p1()
std::string subTagValue = list_it.second.c_str();
if (!subTagName.compare("sid"))
{
F.sdd = std::atof(subTagValue.c_str());
F.sdd = std::stod(subTagValue.c_str());
sidFound = true;
}
else if (!subTagName.compare("sad"))
{
F.sid = std::atof(subTagValue.c_str());
F.sid = std::stod(subTagValue.c_str());
sadFound = true;
}
else if (!subTagName.compare("sourceToNozzleOffsetAngle"))
{
F.sourceToNozzleOffsetAngle = 0; // std::atof(subTagValue.c_str());
F.sourceToNozzleOffsetAngle = 0; // std::stod(subTagValue.c_str());
angleOffsetFound = true;
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI2p1()
{
std::string substr;
std::getline(iss, substr, ',');
v.push_back(std::atof(substr.c_str()));
v.push_back(std::stod(substr.c_str()));
}

if (v.size() == 10)
Expand Down Expand Up @@ -283,10 +283,10 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5()
std::istringstream is(roomSetupInfo);
parser->Update(is);

Cm.sid = atof(parser->GetOutput()->GetChild("Axis")->GetChild("Distances")->GetAttribute("sid").c_str());
Cm.sdd = atof(parser->GetOutput()->GetChild("Axis")->GetChild("Distances")->GetAttribute("sdd").c_str());
Cm.sid = std::stod(parser->GetOutput()->GetChild("Axis")->GetChild("Distances")->GetAttribute("sid").c_str());
Cm.sdd = std::stod(parser->GetOutput()->GetChild("Axis")->GetChild("Distances")->GetAttribute("sdd").c_str());
Cm.sourceToNozzleOffsetAngle =
atof(parser->GetOutput()->GetChild("Axis")->GetChild("AngleOffset")->GetAttribute("projection").c_str());
std::stod(parser->GetOutput()->GetChild("Axis")->GetChild("AngleOffset")->GetAttribute("projection").c_str());

// Read calibration model's parameters in the DICOM info of the first projection
std::string calibrationTagKey = "3001|0013";
Expand Down Expand Up @@ -324,23 +324,23 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5()
for (unsigned int i = 0; i < 5; i++)
{
listPx.pop_front();
Cm.Px[i] = atof(listPx.front().second.c_str());
Cm.Px[i] = std::stod(listPx.front().second.c_str());
listPy.pop_front();
Cm.Py[i] = atof(listPy.front().second.c_str());
Cm.Py[i] = std::stod(listPy.front().second.c_str());
listPz.pop_front();
Cm.Pz[i] = atof(listPz.front().second.c_str());
Cm.Pz[i] = std::stod(listPz.front().second.c_str());
listRx.pop_front();
Cm.Rx[i] = atof(listRx.front().second.c_str());
Cm.Rx[i] = std::stod(listRx.front().second.c_str());
listRy.pop_front();
Cm.Ry[i] = atof(listRy.front().second.c_str());
Cm.Ry[i] = std::stod(listRy.front().second.c_str());
listRz.pop_front();
Cm.Rz[i] = atof(listRz.front().second.c_str());
Cm.Rz[i] = std::stod(listRz.front().second.c_str());
listTx.pop_front();
Cm.Tx[i] = atof(listTx.front().second.c_str());
Cm.Tx[i] = std::stod(listTx.front().second.c_str());
listTy.pop_front();
Cm.Ty[i] = atof(listTy.front().second.c_str());
Cm.Ty[i] = std::stod(listTy.front().second.c_str());
listTz.pop_front();
Cm.Tz[i] = atof(listTz.front().second.c_str());
Cm.Tz[i] = std::stod(listTz.front().second.c_str());
}

Cm.isValid = true;
Expand Down Expand Up @@ -397,31 +397,31 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5FromXMLFiles()
for (auto list_it = list2.begin(); list_it != list2.end(); list_it++, m++)
{
if ((list_child3[n]->GetName() == std::string("Px")) && ((*list_it).first.c_str() != std::string("MSE")))
C.Px[m - 1] = std::atof((*list_it).second.c_str());
C.Px[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Py")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Py[m - 1] = std::atof((*list_it).second.c_str());
C.Py[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Pz")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Pz[m - 1] = std::atof((*list_it).second.c_str());
C.Pz[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Rx")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Rx[m - 1] = std::atof((*list_it).second.c_str());
C.Rx[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Ry")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Ry[m - 1] = std::atof((*list_it).second.c_str());
C.Ry[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Rz")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Rz[m - 1] = std::atof((*list_it).second.c_str());
C.Rz[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Tx")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Tx[m - 1] = std::atof((*list_it).second.c_str());
C.Tx[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Ty")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Ty[m - 1] = std::atof((*list_it).second.c_str());
C.Ty[m - 1] = std::stod((*list_it).second.c_str());
else if ((list_child3[n]->GetName() == std::string("Tz")) &&
((*list_it).first.c_str() != std::string("MSE")))
C.Tz[m - 1] = std::atof((*list_it).second.c_str());
C.Tz[m - 1] = std::stod((*list_it).second.c_str());
}
}
}
Expand Down Expand Up @@ -466,8 +466,8 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5FromXMLFiles()
}
}
}
C.sid = std::atof(sid_s.c_str());
C.sdd = std::atof(sdd_s.c_str());
C.sid = std::stod(sid_s.c_str());
C.sdd = std::stod(sdd_s.c_str());

return C;
}
Expand Down Expand Up @@ -563,12 +563,12 @@ ImagXGeometryReader<TInputImage>::GenerateData()

if (isImagX1p5 || isImagX1p2) // Using CalibModel
{
float gantryAngle = std::atof(value.c_str());
float gantryAngle = std::stod(value.c_str());
addEntryToGeometry(calibModel, gantryAngle);
}
else if (isImagX2pX) // Using flexmap
{
float cbctTubeAngle = std::atof(value.c_str());
float cbctTubeAngle = std::stod(value.c_str());
float gantryAngle =
cbctTubeAngle; // Warning: no correction by sourceToNozzleOffsetAngle as radiographic angle read
gantryAngle = (gantryAngle > 180.f) ? (gantryAngle - 360.f) : gantryAngle;
Expand Down
4 changes: 2 additions & 2 deletions src/rtkBioscanGeometryReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ BioscanGeometryReader::GenerateData()
// See https://github.com/JStrydhorst/win-cone-ct/blob/master/ct_recon_win.h#L111
const std::vector<float> zOffsets = GetVectorTagValue(ds, 0x0009, 0x1046);
const std::vector<float> yOffsets = GetVectorTagValue(ds, 0x0009, 0x1047);
const double sdd = atof(GetStringTagValue(ds, 0x0018, 0x1110).c_str());
const double sid = atof(GetStringTagValue(ds, 0x0018, 0x1111).c_str());
const double sdd = std::stod(GetStringTagValue(ds, 0x0018, 0x1110).c_str());
const double sid = std::stod(GetStringTagValue(ds, 0x0018, 0x1111).c_str());
// const double spacing = GetFloatTagValue(ds, 0x0018, 0x9306);
const double angle = GetFloatTagValue(ds, 0x0009, 0x1036);

Expand Down
2 changes: 1 addition & 1 deletion src/rtkDigisensGeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ DigisensGeometryXMLFileReader::EndElement(const char * name)
#define ENCAPLULATE_META_DATA_DOUBLE(section, metaName) \
if (m_CurrentSection == section && itksys::SystemTools::Strucmp(name, metaName) == 0) \
{ \
double d = atof(m_CurCharacterData.c_str()); \
double d = std::stod(m_CurCharacterData.c_str()); \
itk::EncapsulateMetaData<double>(m_Dictionary, #section metaName, d); \
}

Expand Down
2 changes: 1 addition & 1 deletion src/rtkEdfImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ rtk::EdfImageIO::ReadImageInformation()
double spacing = 1.;
if ((p = edf_findInHeader(header, "optic_used")))
{
spacing = atof(p);
spacing = std::stod(p);
if (spacing == 0.)
spacing = 1.;
}
Expand Down
6 changes: 3 additions & 3 deletions src/rtkElektaXVI5GeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ ElektaXVI5GeometryXMLFileReader::EndElement(const char * name)
if (itksys::SystemTools::Strucmp(name, "GantryAngle") == 0 ||
itksys::SystemTools::Strucmp(name, "Angle") == 0) // Second one for backward compatibility
{
m_GantryAngle = atof(this->m_CurCharacterData.c_str());
m_GantryAngle = std::stod(this->m_CurCharacterData.c_str());
if (m_GantryAngle < 0)
m_GantryAngle = m_GantryAngle + 360.0;
}

// Regarding PanelOffset, XVI5 specifies position of the center(UCentre, VCentre) instead of offset.
// Therefore, negation is required to get classical m_ProjectionOffsetX and m_ProjectionOffsetY values.
if (itksys::SystemTools::Strucmp(name, "UCentre") == 0)
m_ProjectionOffsetX = atof(this->m_CurCharacterData.c_str()) * -1.0;
m_ProjectionOffsetX = std::stod(this->m_CurCharacterData.c_str()) * -1.0;

if (itksys::SystemTools::Strucmp(name, "VCentre") == 0)
{
m_ProjectionOffsetY = atof(this->m_CurCharacterData.c_str()) * -1.0;
m_ProjectionOffsetY = std::stod(this->m_CurCharacterData.c_str()) * -1.0;
}

if (itksys::SystemTools::Strucmp(name, "Frame") == 0)
Expand Down
14 changes: 7 additions & 7 deletions src/rtkForbildPhantomFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ ForbildPhantomFileReader::FindParameterInString(const std::string & name, const
itkExceptionMacro(<< "Could not compile " << regex);
bool bFound = re.find(s.c_str());
if (bFound)
param = atof(re.match(1).c_str());
param = std::stod(re.match(1).c_str());
return bFound;
}

Expand All @@ -404,7 +404,7 @@ ForbildPhantomFileReader::FindVectorInString(const std::string & name, const std
{
for (size_t i = 0; i < 3; i++)
{
vec[i] = atof(re.match(i + 1).c_str());
vec[i] = std::stod(re.match(i + 1).c_str());
}
}
return bFound;
Expand Down Expand Up @@ -451,11 +451,11 @@ ForbildPhantomFileReader::FindClipPlanes(const std::string & s)
VectorType vec;
for (size_t i = 0; i < 3; i++)
{
vec[i] = atof(re.match(i + 1).c_str());
vec[i] = std::stod(re.match(i + 1).c_str());
}
vec /= vec.GetNorm();
ScalarType sign = (re.match(4) == std::string("<")) ? 1. : -1.;
ScalarType expr = atof(re.match(5).c_str());
ScalarType expr = std::stod(re.match(5).c_str());
m_ConvexShape->AddClipPlane(sign * vec, sign * expr);
currs += re.end();
}
Expand All @@ -471,7 +471,7 @@ ForbildPhantomFileReader::FindClipPlanes(const std::string & s)
vec.Fill(0.);
vec[0] = 1.;
ScalarType sign = (re.match(1) == std::string("<")) ? 1. : -1.;
ScalarType expr = atof(re.match(2).c_str());
ScalarType expr = std::stod(re.match(2).c_str());
m_ConvexShape->AddClipPlane(sign * vec, sign * expr);
currs += re.end();
}
Expand All @@ -487,7 +487,7 @@ ForbildPhantomFileReader::FindClipPlanes(const std::string & s)
vec.Fill(0.);
vec[1] = 1.;
ScalarType sign = (re.match(1) == std::string("<")) ? 1. : -1.;
ScalarType expr = atof(re.match(2).c_str());
ScalarType expr = std::stod(re.match(2).c_str());
m_ConvexShape->AddClipPlane(sign * vec, sign * expr);
currs += re.end();
}
Expand All @@ -503,7 +503,7 @@ ForbildPhantomFileReader::FindClipPlanes(const std::string & s)
vec.Fill(0.);
vec[2] = 1.;
ScalarType sign = (re.match(1) == std::string("<")) ? 1. : -1.;
ScalarType expr = atof(re.match(2).c_str());
ScalarType expr = std::stod(re.match(2).c_str());
m_ConvexShape->AddClipPlane(sign * vec, sign * expr);
currs += re.end();
}
Expand Down
4 changes: 2 additions & 2 deletions src/rtkImagXXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ImagXXMLFileReader::StartElement(const char * name, const char ** atts)
#define ENCAPLULATE_META_DATA_INT(metaName) \
if (itksys::SystemTools::Strucmp(atts[i], metaName) == 0) \
{ \
double d = atof(atts[i + 1]); \
double d = std::stod(atts[i + 1]); \
itk::EncapsulateMetaData<int>(m_Dictionary, metaName, d); \
}

Expand Down Expand Up @@ -79,7 +79,7 @@ ImagXXMLFileReader::StartElement(const char * name, const char ** atts)
#define ENCAPLULATE_META_DATA_DOUBLE(metaName) \
if (itksys::SystemTools::Strucmp(atts[i], metaName) == 0) \
{ \
double d = atof(atts[i + 1]); \
double d = std::stod(atts[i + 1]); \
itk::EncapsulateMetaData<double>(m_Dictionary, std::string("spacing_") + std::string(metaName), d); \
}
for (int i = 0; atts[i] != nullptr; i += 2)
Expand Down
2 changes: 1 addition & 1 deletion src/rtkOraXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ OraXMLFileReader ::EncapsulateDouble(const char * metaName, const char * name)
{
if (itksys::SystemTools::Strucmp(name, metaName) == 0)
{
double d = atof(m_CurCharacterData.c_str());
double d = std::stod(m_CurCharacterData.c_str());
itk::EncapsulateMetaData<double>(m_Dictionary, metaName, d);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtkPhaseReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PhaseReader::Parse()
for (unsigned int j = 0; j < NumberOfProjections; j++)
{
this->GetNextField(entry);
m_Phases.push_back(atof(entry.c_str()));
m_Phases.push_back(std::stod(entry.c_str()));
}

this->m_InputStream.close();
Expand Down
2 changes: 1 addition & 1 deletion src/rtkPhasesToInterpolationWeights.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ PhasesToInterpolationWeights::Parse()
{
this->GetNextField(entry);
if ((m_SelectedProjections.empty()) || (m_SelectedProjections[j]))
projectionPhases.push_back(itk::Math::Round<float>(atof(entry.c_str()) * 1000.) / 1000.);
projectionPhases.push_back(itk::Math::Round<float>(std::stod(entry.c_str()) * 1000.) / 1000.);
}

// Compute the instant of the cycle each phase represents
Expand Down
28 changes: 14 additions & 14 deletions src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,50 +76,50 @@ void
ThreeDCircularProjectionGeometryXMLFileReader::EndElement(const char * name)
{
if (itksys::SystemTools::Strucmp(name, "InPlaneAngle") == 0)
m_InPlaneAngle = atof(this->m_CurCharacterData.c_str());
m_InPlaneAngle = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "GantryAngle") == 0 ||
itksys::SystemTools::Strucmp(name, "Angle") == 0) // Second one for backward compatibility
m_GantryAngle = atof(this->m_CurCharacterData.c_str());
m_GantryAngle = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "OutOfPlaneAngle") == 0)
m_OutOfPlaneAngle = atof(this->m_CurCharacterData.c_str());
m_OutOfPlaneAngle = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "SourceToIsocenterDistance") == 0)
m_SourceToIsocenterDistance = atof(this->m_CurCharacterData.c_str());
m_SourceToIsocenterDistance = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "SourceOffsetX") == 0)
m_SourceOffsetX = atof(this->m_CurCharacterData.c_str());
m_SourceOffsetX = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "SourceOffsetY") == 0)
m_SourceOffsetY = atof(this->m_CurCharacterData.c_str());
m_SourceOffsetY = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "SourceToDetectorDistance") == 0)
m_SourceToDetectorDistance = atof(this->m_CurCharacterData.c_str());
m_SourceToDetectorDistance = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "ProjectionOffsetX") == 0)
m_ProjectionOffsetX = atof(this->m_CurCharacterData.c_str());
m_ProjectionOffsetX = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "ProjectionOffsetY") == 0)
m_ProjectionOffsetY = atof(this->m_CurCharacterData.c_str());
m_ProjectionOffsetY = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "RadiusCylindricalDetector") == 0)
{
double radiusCylindricalDetector = atof(this->m_CurCharacterData.c_str());
double radiusCylindricalDetector = std::stod(this->m_CurCharacterData.c_str());
this->m_OutputObject->SetRadiusCylindricalDetector(radiusCylindricalDetector);
}

if (itksys::SystemTools::Strucmp(name, "CollimationUInf") == 0)
m_CollimationUInf = atof(this->m_CurCharacterData.c_str());
m_CollimationUInf = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "CollimationUSup") == 0)
m_CollimationUSup = atof(this->m_CurCharacterData.c_str());
m_CollimationUSup = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "CollimationVInf") == 0)
m_CollimationVInf = atof(this->m_CurCharacterData.c_str());
m_CollimationVInf = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "CollimationVSup") == 0)
m_CollimationVSup = atof(this->m_CurCharacterData.c_str());
m_CollimationVSup = std::stod(this->m_CurCharacterData.c_str());

if (itksys::SystemTools::Strucmp(name, "Matrix") == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/rtkVarianObiXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ VarianObiXMLFileReader::EndElement(const char * name)
#define ENCAPLULATE_META_DATA_DOUBLE(metaName) \
if (itksys::SystemTools::Strucmp(name, metaName) == 0) \
{ \
double d = atof(m_CurCharacterData.c_str()); \
double d = std::stod(m_CurCharacterData.c_str()); \
itk::EncapsulateMetaData<double>(m_Dictionary, metaName, d); \
}

Expand Down
Loading

0 comments on commit e6c48eb

Please sign in to comment.