Skip to content

Commit

Permalink
BUG: serialize floats with maximum precision
Browse files Browse the repository at this point in the history
API-breaking change: Helper::floatToStrScientific() was renamed to
Helper::floatToStr().

Signed-off-by: Stefan Dinkelacker <[email protected]>
  • Loading branch information
kislinsk committed Feb 3, 2021
1 parent ee9711c commit edfc39d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Design/DICOMSegmentationConverter.puml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ package dcmqi {
class Helper {
+ {static} tokenizeString(string str, vector<string> &tokens, string delimiter): void
+ {static} splitString(string str, string &head, string &tail, string delimiter): void
+ {static} floatToStrScientific(float f): string
+ {static} floatToStr(float f): string
---
+ {static} stringToCodeSequenceMacro(std::string str): CodeSequenceMacro
+ {static} stringToDSRCodedEntryValue(std::string str): DSRCodedEntryValue
Expand Down Expand Up @@ -96,4 +96,4 @@ class SegmentAttributes {
+ PrintSelf() : void
}

@enduml
@enduml
4 changes: 3 additions & 1 deletion include/dcmqi/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <vector>
#include <map>
#include <algorithm>
#include <limits>
#include <locale>

// DCMQI includes
#include "dcmqi/Exceptions.h"
Expand Down Expand Up @@ -45,7 +47,7 @@ namespace dcmqi {
static vector<string> getFileListRecursively(string directory);
static vector<DcmDataset*> loadDatasets(const vector<string>& dicomImageFiles);

static string floatToStrScientific(float f);
static string floatToStr(float f);
static void tokenizeString(string str, vector<string> &tokens, string delimiter);
static void splitString(string str, string &head, string &tail, string delimiter);

Expand Down
6 changes: 4 additions & 2 deletions libsrc/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ namespace dcmqi {
}


string Helper::floatToStrScientific(float f) {
string Helper::floatToStr(float f) {
ostringstream sstream;
sstream << scientific << f;
sstream.imbue(std::locale::classic());
sstream.precision(std::numeric_limits<float>::max_digits10);
sstream << f;
return sstream.str();
}

Expand Down
18 changes: 9 additions & 9 deletions libsrc/ImageSEGConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ namespace dcmqi {

FGPlaneOrientationPatient *planor =
FGPlaneOrientationPatient::createMinimal(
Helper::floatToStrScientific(labelDirMatrix[0][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[1][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[2][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[0][1]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[1][1]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[2][1]).c_str());
Helper::floatToStr(labelDirMatrix[0][0]).c_str(),
Helper::floatToStr(labelDirMatrix[1][0]).c_str(),
Helper::floatToStr(labelDirMatrix[2][0]).c_str(),
Helper::floatToStr(labelDirMatrix[0][1]).c_str(),
Helper::floatToStr(labelDirMatrix[1][1]).c_str(),
Helper::floatToStr(labelDirMatrix[2][1]).c_str());

CHECK_COND(segdoc->addForAllFrames(*planor));
}
Expand Down Expand Up @@ -311,9 +311,9 @@ namespace dcmqi {
segmentations[segFileNumber]->TransformIndexToPhysicalPoint(prevIndex, prevOrigin);
}
fgppp->setImagePositionPatient(
Helper::floatToStrScientific(sliceOriginPoint[0]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[1]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[2]).c_str());
Helper::floatToStr(sliceOriginPoint[0]).c_str(),
Helper::floatToStr(sliceOriginPoint[1]).c_str(),
Helper::floatToStr(sliceOriginPoint[2]).c_str());
}

/* Add frame that references this segment */
Expand Down
26 changes: 13 additions & 13 deletions libsrc/ParaMapConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ namespace dcmqi {

FGPlaneOrientationPatient *planor =
FGPlaneOrientationPatient::createMinimal(
Helper::floatToStrScientific(labelDirMatrix[0][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[1][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[2][0]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[0][1]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[1][1]).c_str(),
Helper::floatToStrScientific(labelDirMatrix[2][1]).c_str());
Helper::floatToStr(labelDirMatrix[0][0]).c_str(),
Helper::floatToStr(labelDirMatrix[1][0]).c_str(),
Helper::floatToStr(labelDirMatrix[2][0]).c_str(),
Helper::floatToStr(labelDirMatrix[0][1]).c_str(),
Helper::floatToStr(labelDirMatrix[1][1]).c_str(),
Helper::floatToStr(labelDirMatrix[2][1]).c_str());

//CHECK_COND(planor->setImageOrientationPatient(imageOrientationPatientStr));
CHECK_COND(pMapDoc->addForAllFrames(*planor));
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace dcmqi {
// initialize optional items, if available
if(metaInfo.metaInfoRoot.isMember("MeasurementMethodCode")){
ContentItemMacro* measureMethod = new ContentItemMacro;

CodeSequenceMacro* qCodeName = new CodeSequenceMacro("370129005", "SCT", "Measurement Method");
CodeSequenceMacro* qSpec = new CodeSequenceMacro(
metaInfo.metaInfoRoot["MeasurementMethodCode"]["CodeValue"].asCString(),
Expand Down Expand Up @@ -383,9 +383,9 @@ namespace dcmqi {
FloatImageType::PointType sliceOriginPoint;
parametricMapImage->TransformIndexToPhysicalPoint(sliceIndex, sliceOriginPoint);
fgppp->setImagePositionPatient(
Helper::floatToStrScientific(sliceOriginPoint[0]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[1]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[2]).c_str());
Helper::floatToStr(sliceOriginPoint[0]).c_str(),
Helper::floatToStr(sliceOriginPoint[1]).c_str(),
Helper::floatToStr(sliceOriginPoint[2]).c_str());

// Frame Content
OFCondition result = fgfc->setDimensionIndexValues(sliceNumber+1 /* value within dimension */, 0 /* first dimension */);
Expand Down Expand Up @@ -606,9 +606,9 @@ namespace dcmqi {
FloatImageType::PointType sliceOriginPoint;
parametricMapImage->TransformIndexToPhysicalPoint(sliceIndex, sliceOriginPoint);
fgPlanePos->setImagePositionPatient(
Helper::floatToStrScientific(sliceOriginPoint[0]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[1]).c_str(),
Helper::floatToStrScientific(sliceOriginPoint[2]).c_str());
Helper::floatToStr(sliceOriginPoint[0]).c_str(),
Helper::floatToStr(sliceOriginPoint[1]).c_str(),
Helper::floatToStr(sliceOriginPoint[2]).c_str());

// Frame Content
OFCondition result = fgFracon->setDimensionIndexValues(frameNo+1 /* value within dimension */, 0 /* first dimension */);
Expand Down

0 comments on commit edfc39d

Please sign in to comment.