Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions libsrc/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,32 @@ namespace dcmqi {


string Helper::floatToStrScientific(float f) {
string formatted_f;
/*
- mantissa sign (1)
- mantissa leading number (1)
- dot (1)
- mantissa after the dot (8)
- E (1)
- exponent sign (1)
- exponent (2 OR 3 (Win))
*/

ostringstream sstream;
sstream << setprecision(8) << scientific << f;
formatted_f = sstream.str();

// somehow this was resulting in more than 16 characters in local tests and on CI
/*
ostringstream sstream;
sstream << scientific << f;
return sstream.str();
sstream.imbue(std::locale::classic());
sstream << setprecision(14) << f;
formatted_f = sstream.str();
cout << "Formatted float: " << formatted_f << endl;
cout << "Size: " << formatted_f.size() << endl;
*/

return formatted_f;
}

void Helper::checkValidityOfFirstSrcImage(DcmSegmentation *segdoc) {
Expand Down
11 changes: 5 additions & 6 deletions libsrc/ImageSEGConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ namespace dcmqi {
{
FGPixelMeasures *pixmsr = new FGPixelMeasures();

ShortImageType::SpacingType labelSpacing = segmentations[0]->GetSpacing();
ShortImageType::SpacingType labelSpacing = segmentations[0]->GetSpacing();
ostringstream spacingSStream;
spacingSStream << scientific << labelSpacing[0] << "\\" << labelSpacing[1];
spacingSStream << Helper::floatToStrScientific(labelSpacing[0]) << "\\" << Helper::floatToStrScientific(labelSpacing[1]);
CHECK_COND(pixmsr->setPixelSpacing(spacingSStream.str().c_str()));

spacingSStream.clear(); spacingSStream.str("");
spacingSStream << scientific << labelSpacing[2];
CHECK_COND(pixmsr->setSpacingBetweenSlices(spacingSStream.str().c_str()));
CHECK_COND(pixmsr->setSliceThickness(spacingSStream.str().c_str()));
string sliceThicknessStr = Helper::floatToStrScientific(labelSpacing[2]);
CHECK_COND(pixmsr->setSpacingBetweenSlices(sliceThicknessStr.c_str()));
CHECK_COND(pixmsr->setSliceThickness(sliceThicknessStr.c_str()));
CHECK_COND(segdoc->addForAllFrames(*pixmsr));
delete pixmsr;
}
Expand Down
16 changes: 8 additions & 8 deletions libsrc/ParaMapConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <itkCastImageFilter.h>

// DCMQI includes
#include "dcmqi/Helper.h"
#include "dcmqi/ParaMapConverter.h"
#include "dcmqi/ImageSEGConverter.h"

Expand Down Expand Up @@ -77,15 +78,14 @@ namespace dcmqi {
{
FGPixelMeasures *pixmsr = new FGPixelMeasures();

FloatImageType::SpacingType labelSpacing = parametricMapImage->GetSpacing();
FloatImageType::SpacingType pmSpacing = parametricMapImage->GetSpacing();
ostringstream spacingSStream;
spacingSStream << scientific << labelSpacing[0] << "\\" << labelSpacing[1];
spacingSStream << Helper::floatToStrScientific(pmSpacing[0]) << "\\" << Helper::floatToStrScientific(pmSpacing[1]);
CHECK_COND(pixmsr->setPixelSpacing(spacingSStream.str().c_str()));

spacingSStream.clear(); spacingSStream.str("");
spacingSStream << scientific << labelSpacing[2];
CHECK_COND(pixmsr->setSpacingBetweenSlices(spacingSStream.str().c_str()));
CHECK_COND(pixmsr->setSliceThickness(spacingSStream.str().c_str()));
string sliceThicknessStr = Helper::floatToStrScientific(pmSpacing[2]);
CHECK_COND(pixmsr->setSpacingBetweenSlices(sliceThicknessStr.c_str()));
CHECK_COND(pixmsr->setSliceThickness(sliceThicknessStr.c_str()));
CHECK_COND(pMapDoc->addForAllFrames(*pixmsr));
}

Expand Down Expand Up @@ -252,7 +252,7 @@ namespace dcmqi {
slice2derimg = getSliceMapForSegmentation2DerivationImage(dcmDatasets, cast->GetOutput());
cout << "Mapping from the ITK image slices to the DICOM instances in the input list" << endl;
for(size_t i=0;i<slice2derimg.size();i++){
cout << " Slice " << i << ": ";
//cout << " Slice " << i << ": ";
for(size_t j=0;j<slice2derimg[i].size();j++){
cout << slice2derimg[i][j] << " ";
hasDerivationImages = true;
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace dcmqi {
DPMParametricMapIOD::FramesType frames = pMapDoc->getFrames();
result = OFget<DPMParametricMapIOD::Frames<FloatPixelType> >(&frames)->addFrame(&*data.begin(), frameSize, perFrameFGs);

cout << "Frame " << sliceNumber << " added" << endl;
//cout << "Frame " << sliceNumber << " added" << endl;
}

// remove derivation image FG from the per-frame FGs, only if applicable!
Expand Down