#include "gdcmHeaderHelper.h"
#include "gdcmDirList.h"
-#include "gdcmUtil.h" //for debug
+#include "gdcmDebug.h"
#include <math.h>
#include <algorithm>
+#include <vector>
-/*#ifdef _MSC_VER
- #include <windows.h>
-
- int GetDir(std::string dPath, std::list<std::string> &filenames)
- {
- //For now dPath should have an ending "\"
- WIN32_FIND_DATA FileData;
- HANDLE hFile;
- hFile = FindFirstFile((dPath+"*").c_str(), &FileData);
- if ( hFile == INVALID_HANDLE_VALUE )
- {
- //No files !
- return false;
- }
-
- if( strncmp(FileData.cFileName, ".", 1) != 0 )
- filenames.push_back( dPath+FileData.cFileName );
- while( FindNextFile(hFile, &FileData ) != 0)
- {
- if( strncmp(FileData.cFileName, ".", 1) != 0 )
- filenames.push_back( dPath+FileData.cFileName );
- }
- return true;
- }
-
-#else
- #include <dirent.h>
-
- int GetDir(std::string dPath, std::list<std::string> &filenames)
- {
- DIR *dir = opendir( dPath.c_str() );
- if (dir == NULL)
- return false;
- struct dirent *entry;
- while((entry = readdir(dir)) != NULL)
- {
- // if( strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0)
- if( strncmp(entry->d_name, ".", 1) != 0 )
- {
- filenames.push_back( dPath + "/" + entry->d_name );
- }
- }
- closedir(dir);
- return true;
- }
-
-#endif*/
-
-//-----------------------------------------------------------------------------
-// gdcmHeaderHelper
//-----------------------------------------------------------------------------
-// Constructor / Destructor
/**
* \ingroup gdcmHeaderHelper
* \brief constructor
/**
* \ingroup gdcmHeaderHelper
* \brief gets the info from 0028,0030 : Pixel Spacing
- * \ else 1.
+ * else 1.0
* @return X dimension of a pixel
*/
float gdcmHeaderHelper::GetXSpacing() {
dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
return 1.;
}
- if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
- return 0.;
+ int nbValues;
+ if( (nbValues = sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing)) != 2) {
+ if (nbValues==1) // if single value is found, xspacing is defaulted to yspacing
+ return yspacing;
+ }
if (xspacing == 0.) {
dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
// seems to be a bug in the header ...
/**
* \ingroup gdcmHeaderHelper
* \brief gets the info from 0028,0030 : Pixel Spacing
- * \ else 1.
+ * else 1.0
* @return Y dimension of a pixel
*/
float gdcmHeaderHelper::GetYSpacing() {
- float xspacing, yspacing;
+ float yspacing;
std::string StrSpacing = GetEntryByNumber(0x0028,0x0030);
if (StrSpacing == GDCM_UNFOUND) {
dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
return 1.;
}
- if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
- return 0.;
- if (xspacing == 0.) {
- dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
- // seems to be a bug in the header ...
- sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
- }
+ sscanf( StrSpacing.c_str(), "%f", &yspacing);
return yspacing;
}
/**
*\ingroup gdcmHeaderHelper
*\brief gets the info from 0018,0088 : Space Between Slices
- *\ else from 0018,0050 : Slice Thickness
- *\ else 1.
+ * else from 0018,0050 : Slice Thickness
+ * else 1.0
* @return Z dimension of a voxel-to be
*/
float gdcmHeaderHelper::GetZSpacing() {
/**
* \ingroup gdcmHeaderHelper
* \brief This function is intended to user who doesn't want
- * \ to have to manage a LUT and expects to get an RBG Pixel image
- * \ (or a monochrome one ...)
+ * to have to manage a LUT and expects to get an RBG Pixel image
+ * (or a monochrome one ...)
* \warning to be used with GetImagePixels()
* @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
*/
/**
* \ingroup gdcmHeaderHelper
* \brief This function is intended to user that DOESN'T want
- * \to get RGB pixels image when it's stored as a PALETTE COLOR image
- * \ - the (vtk) user is supposed to know how deal with LUTs -
+ * to get RGB pixels image when it's stored as a PALETTE COLOR image
+ * - the (vtk) user is supposed to know how deal with LUTs -
* \warning to be used with GetImagePixelsRaw()
* @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
*/
/**
* \ingroup gdcmHeaderHelper
* \brief gets the info from 0020,0032 : Image Position Patient
- *\ else from 0020,0030 : Image Position (RET)
- *\ else 0.
+ * else from 0020,0030 : Image Position (RET)
+ * else 0.
* @return up-left image corner X position
*/
/**
* \ingroup gdcmHeaderHelper
* \brief gets the info from 0020,0032 : Image Position Patient
- * \ else from 0020,0030 : Image Position (RET)
- * \ else 0.
+ * else from 0020,0030 : Image Position (RET)
+ * else 0.
* @return up-left image corner Y position
*/
float gdcmHeaderHelper::GetYOrigin() {
bool gdcmSerieHeaderHelper::ImageNumberOrdering() {
int min, max, pos;
- int n = 0;//CoherentGdcmFileList.size(); //O(N) operation !!
+ int n = 0;//CoherentGdcmFileList.size() is a O(N) operation !!
unsigned char *partition;
std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();