+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetXSpacing(void) {
+ float xspacing, yspacing;
+ string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+
+ if (StrSpacing == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing");
+ return 1.;
+ }
+ if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
+ return 0.;
+ //else
+ return xspacing;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetYSpacing(void) {
+ float xspacing, yspacing;
+ string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+
+ if (StrSpacing == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing");
+ return 1.;
+ }
+
+ if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
+ return 0.;
+
+ if (yspacing == 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);
+ }
+ return yspacing;
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetZSpacing(void) {
+ // TODO : translate into English
+ // 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
+
+ string StrSpacingBSlices = GetPubElValByNumber(0x0018,0x0088);
+
+ if (StrSpacingBSlices == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
+ string StrSliceThickness = GetPubElValByNumber(0x0018,0x0050);
+ if (StrSliceThickness == "gdcm::Unfound")
+ return 1.;
+ else
+ return atof(StrSliceThickness.c_str());
+ } else {
+ return atof(StrSpacingBSlices.c_str());
+ }
+}
+
+//
+// Image Position Patient :
+// If not found (AVR-NEMA), we consider Slice Location (20,1041)
+// or Location (20,50) as the Z coordinate,
+// 0. for all the coordinates if Slice Location not 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 gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetXImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ // 0020,0032 : Image Position Patient
+ // 0020,1041 : Slice Location
+ string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient");
+ string StrSliceLoc = GetPubElValByNumber(0x0020,0x1041);
+ if (StrSliceLoc == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Slice Location");
+ // How to tell the caller nothing was found?
+ }
+ return 0.;
+ }
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
+ // How to tell the caller a wrong number of values was found?
+ return 0.;
+ //else
+ return xImPos;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetYImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ // 0020,0032 : Image Position Patient
+ // 0020,1041 : Slice Location
+ // 0020,0050 : Location
+ string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+
+ if (StrImPos == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient");
+ string StrSliceLoc = GetPubElValByNumber(0x0020,0x1041);
+ if (StrSliceLoc == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location");
+ // How to tell the caller nothing was found?
+ string StrLocation = GetPubElValByNumber(0x0020,0x0050);
+ if (StrSliceLoc == "gdcm::Unfound") {
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location");
+ }
+ }
+ return 0.;
+ }
+ if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
+ // How to tell the caller a wrong number of values was found?
+ return 0.;
+ //else
+ return yImPos;
+}
+
+/**
+ * \ingroup gdcmHeader
+ * \brief
+ * @return
+ */
+float gdcmHeader::GetZImagePosition(void) {
+ float xImPos, yImPos, zImPos;
+ // 0020,0032 : Image Position Patient
+ // 0020,1041 : Slice Location
+ // 0020,0050 : Location
+
+ // TODO : How to tell the caller nothing was found?
+ // TODO : How to tell the caller a wrong number of values was found?
+
+ 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");
+ return 0.; // bug in the element 0x0020,0x0032
+ } else {
+ return zImPos;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient");
+
+ string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);
+ if (StrSliceLocation != "gdcm::Unfound") {
+ if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location");
+ return 0.; // bug in the element 0x0020,0x1041
+ } else {
+ return zImPos;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location");
+
+ string StrLocation = GetPubElValByNumber(0x0020,0x0050);
+ if (StrLocation != "gdcm::Unfound") {
+ if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
+ dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location");
+ return 0.; // bug in the element 0x0020,0x0050
+ } else {
+ return zImPos;
+ }
+ }
+ dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location");
+
+ return 0.; // Hopeless
+}
+
+
+