+ * \brief gets the info from 0028,0030 : Pixel Spacing
+ * else 1.0
+ * @return X dimension of a pixel
+ */
+float gdcmHeader::GetXSpacing()
+{
+ float xspacing, yspacing;
+ std::string strSpacing = GetEntryByNumber(0x0028,0x0030);
+
+ if ( strSpacing == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
+ return 1.;
+ }
+
+ int nbValues;
+ if( ( nbValues = sscanf( strSpacing.c_str(),
+ "%f\\%f", &yspacing, &xspacing)) != 2 )
+ {
+ // if single value is found, xspacing is defaulted to yspacing
+ if ( nbValues == 1 )
+ {
+ 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 ...
+ sscanf( strSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
+ }
+
+ return xspacing;
+}
+
+/**
+ * \brief gets the info from 0028,0030 : Pixel Spacing
+ * else 1.0
+ * @return Y dimension of a pixel
+ */
+float gdcmHeader::GetYSpacing()
+{
+ float yspacing = 0;
+ std::string strSpacing = GetEntryByNumber(0x0028,0x0030);
+
+ if ( strSpacing == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
+ return 1.;
+ }
+
+ // if sscanf cannot read any float value, it won't affect yspacing
+ sscanf( strSpacing.c_str(), "%f", &yspacing);
+
+ return yspacing;
+}
+
+/**
+ * \brief gets the info from 0018,0088 : Space Between Slices
+ * else from 0018,0050 : Slice Thickness
+ * else 1.0
+ * @return Z dimension of a voxel-to be
+ */
+float gdcmHeader::GetZSpacing()
+{
+ // Spacing Between Slices : distance entre le milieu de chaque coupe
+ // Les coupes peuvent etre :
+ // jointives (Spacing between Slices = Slice Thickness)
+ // chevauchantes (Spacing between Slices < Slice Thickness)
+ // disjointes (Spacing between Slices > Slice Thickness)
+ // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
+ // ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
+ // Si le Spacing Between Slices est absent,
+ // on suppose que les coupes sont jointives
+
+ std::string strSpacingBSlices = GetEntryByNumber(0x0018,0x0088);
+
+ if ( strSpacingBSlices == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
+ std::string strSliceThickness = GetEntryByNumber(0x0018,0x0050);
+ if ( strSliceThickness == GDCM_UNFOUND )
+ {
+ return 1.;
+ }
+ else
+ {
+ // if no 'Spacing Between Slices' is found,
+ // we assume slices join together
+ // (no overlapping, no interslice gap)
+ // if they don't, we're fucked up
+ return atof( strSliceThickness.c_str() );
+ }
+ }
+ else
+ {
+ return atof( strSpacingBSlices.c_str() );
+ }
+}
+
+/**
+ *\brief gets the info from 0028,1052 : Rescale Intercept
+ * @return Rescale Intercept
+ */
+float gdcmHeader::GetRescaleIntercept()
+{
+ float resInter = 0.;
+ /// 0028 1052 DS IMG Rescale Intercept
+ std::string strRescInter = GetEntryByNumber(0x0028,0x1052);
+ if ( strRescInter != GDCM_UNFOUND )
+ {
+ if( sscanf( strRescInter.c_str(), "%f", &resInter) != 1 )
+ {
+ // bug in the element 0x0028,0x1052
+ dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope "
+ "is empty");
+ }
+ }
+
+ return resInter;
+}
+
+/**
+ *\brief gets the info from 0028,1053 : Rescale Slope
+ * @return Rescale Slope
+ */
+float gdcmHeader::GetRescaleSlope()
+{
+ float resSlope = 1.;
+ //0028 1053 DS IMG Rescale Slope
+ std::string strRescSlope = GetEntryByNumber(0x0028,0x1053);
+ if ( strRescSlope != GDCM_UNFOUND )
+ {
+ if( sscanf( strRescSlope.c_str(), "%f", &resSlope) != 1)
+ {
+ // bug in the element 0x0028,0x1053
+ dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty");
+ }
+ }
+
+ return resSlope;
+}
+
+/**
+ * \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 ...)
+ * \warning to be used with GetImagePixels()
+ * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
+ */
+int gdcmHeader::GetNumberOfScalarComponents()
+{
+ if ( GetSamplesPerPixel() == 3 )
+ {
+ return 3;
+ }
+
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old RGB images)
+ if ( GetEntryByNumber(0x0028,0x0100) == "24" )
+ {
+ return 3;
+ }
+
+ std::string strPhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
+
+ if ( ( strPhotometricInterpretation == "PALETTE COLOR ") )
+ {
+ if ( HasLUT() )// PALETTE COLOR is NOT enough
+ {
+ return 3;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ // beware of trailing space at end of string
+ // DICOM tags are never of odd length
+ if ( strPhotometricInterpretation == GDCM_UNFOUND ||
+ strPhotometricInterpretation == "MONOCHROME1 " ||
+ strPhotometricInterpretation == "MONOCHROME2 " )
+ {
+ return 1;
+ }
+ else
+ {
+ // we assume that *all* kinds of YBR are dealt with
+ return 3;
+ }
+}
+
+/**
+ * \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 gdcmHeader::GetNumberOfScalarComponentsRaw()
+{
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old RGB images)
+ if ( gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24" )
+ {
+ return 3;
+ }
+
+ // we assume that *all* kinds of YBR are dealt with
+ return GetSamplesPerPixel();
+}
+
+//
+// -------------- Remember ! ----------------------------------
+//
+// 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?
+//
+// ---------------------------------------------------------------
+//
+
+/**
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ * else from 0020,0030 : Image Position (RET)
+ * else 0.
+ * @return up-left image corner X position
+ */
+float gdcmHeader::GetXOrigin()
+{
+ float xImPos, yImPos, zImPos;
+ std::string strImPos = GetEntryByNumber(0x0020,0x0032);
+
+ if ( strImPos == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image "
+ "Position Patient (0020,0032)");
+ strImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
+ if ( strImPos == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image "
+ "Position (RET) (0020,0030)");
+ /// \todo 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;
+}
+
+/**
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ * else from 0020,0030 : Image Position (RET)
+ * else 0.
+ * @return up-left image corner Y position
+ */
+float gdcmHeader::GetYOrigin()
+{
+ float xImPos, yImPos, zImPos;
+ std::string strImPos = GetEntryByNumber(0x0020,0x0032);
+
+ if ( strImPos == GDCM_UNFOUND)
+ {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image "
+ "Position Patient (0020,0032)");
+ strImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
+ if ( strImPos == GDCM_UNFOUND )
+ {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image "
+ "Position (RET) (0020,0030)");
+ /// \todo 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;
+}
+
+/**
+ * \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 Z position
+ */
+float gdcmHeader::GetZOrigin()
+{
+ float xImPos, yImPos, zImPos;
+ std::string strImPos = GetEntryByNumber(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 = GetEntryByNumber(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 = GetEntryByNumber(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 = GetEntryByNumber(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;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");
+
+ return 0.; // Hopeless
+}
+
+/**
+ * \brief gets the info from 0020,0013 : Image Number else 0.
+ * @return image number
+ */
+int gdcmHeader::GetImageNumber()
+{
+ // The function i atoi() takes the address of an area of memory as
+ // parameter and converts the string stored at that location to an integer
+ // using the external decimal to internal binary conversion rules. This may
+ // be preferable to sscanf() since atoi() is a much smaller, simpler and
+ // faster function. sscanf() can do all possible conversions whereas
+ // atoi() can only do single decimal integer conversions.
+ //0020 0013 IS REL Image Number
+ std::string strImNumber = GetEntryByNumber(0x0020,0x0013);
+ if ( strImNumber != GDCM_UNFOUND )
+ {
+ return atoi( strImNumber.c_str() );
+ }
+ return 0; //Hopeless
+}
+
+/**
+ * \brief gets the info from 0008,0060 : Modality
+ * @return Modality Type
+ */
+ModalityType gdcmHeader::GetModality()
+{
+ // 0008 0060 CS ID Modality
+ std::string strModality = GetEntryByNumber(0x0008,0x0060);
+ if ( strModality != GDCM_UNFOUND )
+ {
+ if ( strModality.find("AU") < strModality.length()) return AU;
+ else if ( strModality.find("AS") < strModality.length()) return AS;
+ else if ( strModality.find("BI") < strModality.length()) return BI;
+ else if ( strModality.find("CF") < strModality.length()) return CF;
+ else if ( strModality.find("CP") < strModality.length()) return CP;
+ else if ( strModality.find("CR") < strModality.length()) return CR;
+ else if ( strModality.find("CT") < strModality.length()) return CT;
+ else if ( strModality.find("CS") < strModality.length()) return CS;
+ else if ( strModality.find("DD") < strModality.length()) return DD;
+ else if ( strModality.find("DF") < strModality.length()) return DF;
+ else if ( strModality.find("DG") < strModality.length()) return DG;
+ else if ( strModality.find("DM") < strModality.length()) return DM;
+ else if ( strModality.find("DS") < strModality.length()) return DS;
+ else if ( strModality.find("DX") < strModality.length()) return DX;
+ else if ( strModality.find("ECG") < strModality.length()) return ECG;
+ else if ( strModality.find("EPS") < strModality.length()) return EPS;
+ else if ( strModality.find("FA") < strModality.length()) return FA;
+ else if ( strModality.find("FS") < strModality.length()) return FS;
+ else if ( strModality.find("HC") < strModality.length()) return HC;
+ else if ( strModality.find("HD") < strModality.length()) return HD;
+ else if ( strModality.find("LP") < strModality.length()) return LP;
+ else if ( strModality.find("LS") < strModality.length()) return LS;
+ else if ( strModality.find("MA") < strModality.length()) return MA;
+ else if ( strModality.find("MR") < strModality.length()) return MR;
+ else if ( strModality.find("NM") < strModality.length()) return NM;
+ else if ( strModality.find("OT") < strModality.length()) return OT;
+ 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("SM") < strModality.length()) return SM;
+ else if ( strModality.find("ST") < strModality.length()) return ST;
+ else if ( strModality.find("TG") < strModality.length()) return TG;
+ else if ( strModality.find("US") < strModality.length()) return US;
+ else if ( strModality.find("VF") < strModality.length()) return VF;
+ else if ( strModality.find("XA") < strModality.length()) return XA;
+ else if ( strModality.find("XC") < strModality.length()) return XC;
+
+ else
+ {
+ /// \todo throw error return value ???
+ /// specified <> unknow in our database
+ return Unknow;
+ }
+ }
+
+ return Unknow;
+}
+
+/**