X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeaderHelper.cxx;h=a5f78136d3eb6dcac4bb06e8be5420330c254f6c;hb=191decf8eab0497d96e871b0a49bf1d12d7b4529;hp=eeca030fcd5932e381e11cdd1c8534779c801aaf;hpb=cd02bf0b364af71772cca99034f332642ac9e486;p=gdcm.git diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index eeca030f..a5f78136 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -1,17 +1,7 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.7 2003/09/24 14:01:04 jpr Exp $ - -//This is needed when compiling in debug mode -#ifdef _MSC_VER -#pragma warning ( disable : 4800 ) -// 'identifier' : class 'type' needs to have dll-interface to be used by -// clients of class 'type2' -#pragma warning ( disable : 4251 ) -// 'identifier' : identifier was truncated to 'number' characters in the -// debug information -#pragma warning ( disable : 4786 ) -#endif //_MSC_VER +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.14 2003/10/27 14:01:12 jpr Exp $ #include "gdcmHeaderHelper.h" + #include "gdcmUtil.h" //for debug #include #include @@ -99,6 +89,33 @@ int gdcmHeaderHelper::GetPixelSize() { dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type"); return 0; } + +//---------------------------------------------------------------------------- +/** + * \ingroup gdcmHeaderHelper + * \brief gets the info from 0028,0004 : Photometric Interp + * \ else 1. + * @return 1 if Gray level, 3 if Color + */ +int gdcmHeaderHelper::GetNumberOfScalarComponents() { + std::string PhotometricInterpretation = + gdcmHeader::GetPubElValByNumber(0x0028,0x0004); + + +// The compiler will optimze, if it feels like ! + + //beware of trailing space at end of string + if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() || + PhotometricInterpretation.find("MONOCHROME1") < PhotometricInterpretation.length() || + PhotometricInterpretation.find("MONOCHROME2") < PhotometricInterpretation.length() ) return 1; + + // WARNING : quick and dirty trick to produce a single plane Grey image + // See also gdcmFile::GetImageDataIntoVector() + // if(GetPubElValVoidAreaByNumber(0x0028,0x1201)==NULL) return 1; // Lut Red + // end of dirty trick + + return 3; +} //---------------------------------------------------------------------------- /** * \ingroup gdcmHeaderHelper @@ -146,15 +163,19 @@ std::string gdcmHeaderHelper::GetPixelType() { float gdcmHeaderHelper::GetXSpacing() { float xspacing, yspacing; std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030); - - if (StrSpacing == GDCM_UNFOUND) { - dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)"); - return 1.; - } - if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2) - return 0.; - //else - return xspacing; + + if (StrSpacing == GDCM_UNFOUND) { + dbg.Verbose(0, "gdcmHeader::GetXSpacing: 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); + } + return xspacing; } //---------------------------------------------------------------------------- /** @@ -171,12 +192,12 @@ float gdcmHeaderHelper::GetYSpacing() { dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)"); return 1.; } - if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2) + if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2) return 0.; - if (yspacing == 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", &xspacing, &yspacing); + sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing); } return yspacing; } @@ -389,10 +410,10 @@ ModalityType gdcmHeaderHelper::GetModality(void) { else if ( StrModality.find("PT") < StrModality.length()) return PT; else if ( StrModality.find("RF") < StrModality.length()) return RF; else if ( StrModality.find("RG") < StrModality.length()) return RG; - else if ( StrModality.find("RTDOSE") < StrModality.length()) return RTDOSE; - else if ( StrModality.find("RTIMAGE") < StrModality.length()) return RTIMAGE; - else if ( StrModality.find("RTPLAN") < StrModality.length()) return RTPLAN; - else if ( StrModality.find("RTSTRUCT") < StrModality.length()) return RTSTRUCT; + else if ( StrModality.find("RTDOSE") < StrModality.length()) return RTDOSE; + else if ( StrModality.find("RTIMAGE") < StrModality.length()) return RTIMAGE; + else if ( StrModality.find("RTPLAN") < StrModality.length()) return RTPLAN; + else if ( StrModality.find("RTSTRUCT")< StrModality.length()) return RTSTRUCT; else if ( StrModality.find("SM") < StrModality.length()) return SM; else if ( StrModality.find("ST") < StrModality.length()) return ST; else if ( StrModality.find("TG") < StrModality.length()) return TG; @@ -414,22 +435,22 @@ ModalityType gdcmHeaderHelper::GetModality(void) { //---------------------------------------------------------------------------- std::string gdcmHeaderHelper::GetStudyUID() { - return GetPubElValByNumber(0x0020,0x000d); //!0020 000d UI REL Study Instance UID + return GetPubElValByNumber(0x0020,0x000d); //0020 000d UI REL Study Instance UID } //---------------------------------------------------------------------------- std::string gdcmHeaderHelper::GetSeriesUID() { - return GetPubElValByNumber(0x0020,0x000e); //!0020 000e UI REL Series Instance UID + return GetPubElValByNumber(0x0020,0x000e); //0020 000e UI REL Series Instance UID } //---------------------------------------------------------------------------- std::string gdcmHeaderHelper::GetClassUID() { - return GetPubElValByNumber(0x0008,0x0016); //!0008 0016 UI ID SOP Class UID + return GetPubElValByNumber(0x0008,0x0016); //0008 0016 UI ID SOP Class UID } //---------------------------------------------------------------------------- std::string gdcmHeaderHelper::GetInstanceUID() { - return GetPubElValByNumber(0x0008,0x0018); //!0008 0018 UI ID SOP Instance UID + return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID } @@ -524,7 +545,7 @@ void gdcmSerieHeaderHelper::SetDirectory(std::string dir) //---------------------------------------------------------------------------- //This could be implemented in a 'Strategy Pattern' approach //But as I don't know how to do it, I leave it this way -//BTW, this is also a Strategy, I don't know this is the best approcah :) +//BTW, this is also a Strategy, I don't know this is the best approach :) void gdcmSerieHeaderHelper::OrderGdcmFileList() { if( ImagePositionPatientOrdering() )