- float resSlope = 1.;
- 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");
- // bug in the element 0x0028,0x1053
- }
- }
- return resSlope;
-}
-
-/**
- * \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();
-}
-
-std::string gdcmHeaderHelper::GetStudyUID()
-{
- 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
-}
-
-std::string gdcmHeaderHelper::GetClassUID()
-{
- 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
-}
-
-// Image Position Patient (0020,0032):
-// If not found (ACR_NEMA) we try Image Position (0020,0030)
-// If not found (ACR-NEMA), we consider Slice Location (0020,1041)
-// or Location (0020,0050)
-// as the Z coordinate,
-// 0. for all the coordinates if nothing is found
-
-// TODO : find a way to inform the caller nothing was found
-// TODO : How to tell the caller a wrong number of values was found?
-/**
- * \ingroup gdcmHeaderHelper
- * \brief gets the info from 0020,0032 : Image Position Patient
- *\ else from 0020,0030 : Image Position (RET)
- *\ else 0.
- * @return up-left image corner position
- */
-float gdcmHeaderHelper::GetXOrigin() {
- float xImPos, yImPos, zImPos;
- std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
-
- if (StrImPos == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
- StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
- if (StrImPos == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
- // How to tell the caller nothing was found ?
- return 0.;
- }
- }
- if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
- return 0.;
- return xImPos;
-}
-
-/**
- * \ingroup gdcmHeaderHelper
- * \brief gets the info from 0020,0032 : Image Position Patient
- * \ else from 0020,0030 : Image Position (RET)
- * \ else 0.
- * @return up-left image corner position
- */
-float gdcmHeaderHelper::GetYOrigin() {
- float xImPos, yImPos, zImPos;
- std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
-
- if (StrImPos == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
- StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
- if (StrImPos == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
- // How to tell the caller nothing was found ?
- return 0.;
- }
- }
- if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
- return 0.;
- return yImPos;
-}
-
-/**
- * \ingroup gdcmHeaderHelper
- * \brief gets the info from 0020,0032 : Image Position Patient
- * \ else from 0020,0030 : Image Position (RET)
- * \ else from 0020,1041 : Slice Location
- * \ else from 0020,0050 : Location
- * \ else 0.
- * @return up-left image corner position
- */
-float gdcmHeaderHelper::GetZOrigin() {
- float xImPos, yImPos, zImPos;
- std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
- if (StrImPos != GDCM_UNFOUND) {
- if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
- dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position Patient (0020,0032)");
- return 0.; // bug in the element 0x0020,0x0032
- } else {
- return zImPos;
- }
- }
- StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
- if (StrImPos != GDCM_UNFOUND) {
- if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
- dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
- return 0.; // bug in the element 0x0020,0x0032
- } else {
- return zImPos;
- }
- }
- std::string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
- if (StrSliceLocation != GDCM_UNFOUND) {
- if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
- dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
- return 0.; // bug in the element 0x0020,0x1041
- } else {
- return zImPos;
- }
- }
- dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
- std::string StrLocation = GetPubElValByNumber(0x0020,0x0050);
- if (StrLocation != GDCM_UNFOUND) {
- if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
- dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
- return 0.; // bug in the element 0x0020,0x0050
- } else {
- return zImPos;
- }