X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeaderHelper.cxx;h=cc3053cb9b986ec688ec5653fe9cef669cb22a67;hb=ea14e11cdd726f9c7e6d6384c7e9e508bc6efc2d;hp=02690541380fc2a364efcdff2e787622dfdff290;hpb=e076cec25dcf959255d710a5cffdbe96d2998a7d;p=gdcm.git diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index 02690541..cc3053cb 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -1,17 +1,7 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.8 2003/09/24 16:46:38 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.16 2003/11/07 14:57:58 malaterre Exp $ #include "gdcmHeaderHelper.h" + #include "gdcmUtil.h" //for debug #include #include @@ -89,6 +79,12 @@ gdcmHeaderHelper::gdcmHeaderHelper(const char *InFilename, * */ int gdcmHeaderHelper::GetPixelSize() { + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") + return 3; + std::string PixelType = GetPixelType(); if (PixelType == "8U" || PixelType == "8S") return 1; @@ -99,6 +95,69 @@ int gdcmHeaderHelper::GetPixelSize() { dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type"); return 0; } + +//---------------------------------------------------------------------------- +/** + * \ingroup gdcmHeaderHelper + * \brief This function is intended to user who doesn't whan + * \ 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) + */ +int gdcmHeaderHelper::GetNumberOfScalarComponents() { + + if (GetSamplesPerPixel() ==3) + return 3; + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") + return 3; + + std::string PhotometricInterpretation = + gdcmHeader::GetPubElValByNumber(0x0028,0x0004); + + if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) { + if (HasLUT()) // PALETTE COLOR is NOT enough + return 3; + else + return 1; + } + + //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; + else + // we assume that *all* kinds of YBR are dealt with + return 3; +} + +//---------------------------------------------------------------------------- +/** + * \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 - + * \warning to be used with GetImagePixelsRaw() + * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -) + */ +int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() { + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") + return 3; + + // we assume that *all* kinds of YBR are dealt with + return GetSamplesPerPixel(); +} + //---------------------------------------------------------------------------- /** * \ingroup gdcmHeaderHelper @@ -111,6 +170,7 @@ int gdcmHeaderHelper::GetPixelSize() { * - 32U unsigned 32 bit, * - 32S signed 32 bit, * \warning 12 bit images appear as 16 bit. + * \ 24 bit images appear as 8 bit * @return */ std::string gdcmHeaderHelper::GetPixelType() { @@ -120,9 +180,11 @@ std::string gdcmHeaderHelper::GetPixelType() { dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated"); BitsAlloc = std::string("16"); } - if (BitsAlloc == "12") + if (BitsAlloc == "12") // It will be unpacked BitsAlloc = std::string("16"); - + else if (BitsAlloc == "24") // (in order no to be messed up + BitsAlloc = std::string("8"); // by old RGB images) + std::string Signed; Signed = GetElValByName("Pixel Representation"); if (Signed == GDCM_UNFOUND) { @@ -146,15 +208,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 +237,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; } @@ -431,6 +497,35 @@ std::string gdcmHeaderHelper::GetInstanceUID() { return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID } +//---------------------------------------------------------------------------- +float gdcmHeaderHelper::GetRescaleIntercept() +{ + float resInter; + std::string StrRescInter = GetPubElValByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept + if (StrRescInter != GDCM_UNFOUND) { + if( sscanf( StrRescInter.c_str(), "%f", &resInter) != 1) { + dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty"); + return 0.; // bug in the element 0x0028,0x1052 + } else { + return resInter; + } + } +} +//---------------------------------------------------------------------------- +float gdcmHeaderHelper::GetRescaleSlope() +{ + float resSlope; + std::string StrRescSlope = GetPubElValByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope + if (StrRescSlope != GDCM_UNFOUND) { + if( sscanf( StrRescSlope.c_str(), "%f", &resSlope) != 1) { + dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty"); + return 1.; // bug in the element 0x0028,0x1053 + } else { + return resSlope; + } + } + +}