+ }
+ return true;
+}
+/**
+ * \brief This predicate, based on hopefully reasonable heuristics,
+ * decides whether or not the current File was properly parsed
+ * and contains the mandatory information for being considered as
+ * a well formed and usable Dicom/Acr File.
+ * @return true when File is the one of a reasonable Dicom/Acr file,
+ * false otherwise.
+ */
+bool File::IsReadable()
+{
+ if ( !Document::IsReadable() )
+ {
+ return false;
+ }
+
+ const std::string &res = GetEntryValue(0x0028, 0x0005);
+ if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 )
+ {
+ gdcmWarningMacro("Wrong Image Dimensions" << res);
+ return false; // Image Dimensions
+ }
+ bool b0028_0100 = true;
+ if ( !GetDocEntry(0x0028, 0x0100) )
+ {
+ gdcmWarningMacro("Bits Allocated (0028|0100) not found");
+ //return false; // "Bits Allocated"
+ b0028_0100 = false;
+ }
+ bool b0028_0101 = true;
+ if ( !GetDocEntry(0x0028, 0x0101) )
+ {
+ gdcmWarningMacro("Bits Stored (0028|0101) not found");
+ //return false; // "Bits Stored"
+ b0028_0101 = false;
+ }
+ bool b0028_0102 = true;
+ if ( !GetDocEntry(0x0028, 0x0102) )
+ {
+ gdcmWarningMacro("Hight Bit (0028|0102) not found");
+ //return false; // "High Bit"
+ b0028_0102 = false;
+ }
+ bool b0028_0103 = true;
+ if ( !GetDocEntry(0x0028, 0x0103) )
+ {
+ gdcmWarningMacro("Pixel Representation (0028|0103) not found");
+ //return false; // "Pixel Representation" i.e. 'Sign' ( 0 : unsigned, 1 : signed)
+ b0028_0103 = false;
+ }
+
+ if ( !b0028_0100 && !b0028_0101 && !b0028_0102 && !b0028_0103)
+ {
+ gdcmWarningMacro("Too much mandatory Tags missing !");
+ return false;
+ }
+
+ if ( !GetDocEntry(GrPixel, NumPixel) )
+ {
+ gdcmWarningMacro("Pixel Dicom Element " << std::hex <<
+ GrPixel << "|" << NumPixel << "not found");
+ return false; // Pixel Dicom Element not found :-(
+ }
+ return true;
+}
+
+/**
+ * \brief gets the info from 0020,0013 : Image Number else 0.
+ * @return image number
+ */
+int File::GetImageNumber()
+{
+ //0020 0013 : Image Number
+ std::string strImNumber = GetEntryValue(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 File::GetModality()
+{
+ // 0008 0060 : Modality
+ std::string strModality = GetEntryValue(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 <> unknown in our database
+ return Unknow;
+ }
+ }
+ return Unknow;
+}
+
+/**
+ * \brief Retrieve the number of columns of image.
+ * @return The encountered size when found, 0 by default.
+ * 0 means the file is NOT USABLE. The caller will have to check
+ */
+int File::GetXSize()
+{
+ const std::string &strSize = GetEntryValue(0x0028,0x0011);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ return 0;
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the number of lines of image.
+ * \warning The defaulted value is 1 as opposed to File::GetXSize()
+ * @return The encountered size when found, 1 by default
+ * (The ACR-NEMA file contains a Signal, not an Image).
+ */
+int File::GetYSize()
+{
+ const std::string &strSize = GetEntryValue(0x0028,0x0010);
+ if ( strSize != GDCM_UNFOUND )
+ {
+ return atoi( strSize.c_str() );
+ }
+ if ( IsDicomV3() )
+ {
+ return 0;
+ }
+
+ // The Rows (0028,0010) entry was optional for ACR/NEMA.
+ // (at least some images didn't have it.)
+ // It might hence be a signal (1D image). So we default to 1:
+ return 1;
+}
+
+/**
+ * \brief Retrieve the number of planes of volume or the number
+ * of frames of a multiframe.
+ * \warning When present we consider the "Number of Frames" as the third
+ * dimension. When missing we consider the third dimension as
+ * being the ACR-NEMA "Planes" tag content.
+ * @return The encountered size when found, 1 by default (single image).
+ */
+int File::GetZSize()
+{
+ // Both DicomV3 and ACR/Nema consider the "Number of Frames"
+ // as the third dimension.
+ const std::string &strSize = GetEntryValue(0x0028,0x0008);
+ if ( strSize != GDCM_UNFOUND )
+ {
+ return atoi( strSize.c_str() );
+ }
+
+ // We then consider the "Planes" entry as the third dimension
+ const std::string &strSize2 = GetEntryValue(0x0028,0x0012);
+ if ( strSize2 != GDCM_UNFOUND )
+ {
+ return atoi( strSize2.c_str() );
+ }
+ return 1;
+}
+
+/**
+ * \brief gets the info from 0018,1164 : ImagerPixelSpacing
+ * then 0028,0030 : Pixel Spacing
+ * else 1.0
+ * @return X dimension of a pixel
+ */
+float File::GetXSpacing()
+{
+ float xspacing = 1.0;
+ float yspacing = 1.0;
+ int nbValues;
+
+ // To follow David Clunie's advice, we first check ImagerPixelSpacing
+
+ const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
+ if ( strImagerPixelSpacing != GDCM_UNFOUND )
+ {
+ if ( ( nbValues = sscanf( strImagerPixelSpacing.c_str(),
+ "%f\\%f", &yspacing, &xspacing)) != 2 )
+ {
+ // if no values, xspacing is set to 1.0
+ if ( nbValues == 0 )
+ xspacing = 1.0;
+ // if single value is found, xspacing is defaulted to yspacing
+ if ( nbValues == 1 )
+ xspacing = yspacing;
+
+ if ( xspacing == 0.0 )
+ xspacing = 1.0;
+
+ return xspacing;
+ }
+ }
+
+ const std::string &strSpacing = GetEntryValue(0x0028,0x0030);
+
+ if ( strSpacing == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" );
+ return 1.;
+ }
+
+ if ( ( nbValues = sscanf( strSpacing.c_str(),
+ "%f \\%f ", &yspacing, &xspacing)) != 2 )
+ {
+ // if no values, xspacing is set to 1.0
+ if ( nbValues == 0 )
+ xspacing = 1.0;
+ // if single value is found, xspacing is defaulted to yspacing
+ if ( nbValues == 1 )
+ xspacing = yspacing;
+
+ if ( xspacing == 0.0 )
+ xspacing = 1.0;
+
+ return xspacing;
+ }
+
+ // to avoid troubles with David Clunie's-like images (at least one)
+ if ( xspacing == 0. && yspacing == 0.)
+ return 1.;
+
+ if ( xspacing == 0.)
+ {
+ gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm-like problem");
+ // seems to be a bug in the header ...
+ nbValues = sscanf( strSpacing.c_str(), "%f \\0\\%f ", &yspacing, &xspacing);
+ gdcmAssertMacro( nbValues == 2 );
+ }
+
+ return xspacing;
+}
+
+/**
+ * \brief gets the info from 0018,1164 : ImagerPixelSpacing
+ * then from 0028,0030 : Pixel Spacing
+ * else 1.0
+ * @return Y dimension of a pixel
+ */
+float File::GetYSpacing()
+{
+ float yspacing = 1.;
+ int nbValues;
+ // To follow David Clunie's advice, we first check ImagerPixelSpacing
+
+ const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164);
+ if ( strImagerPixelSpacing != GDCM_UNFOUND )
+ {
+ nbValues = sscanf( strImagerPixelSpacing.c_str(), "%f", &yspacing);
+
+ // if sscanf cannot read any float value, it won't affect yspacing
+ if ( nbValues == 0 )
+ yspacing = 1.0;
+
+ if ( yspacing == 0.0 )
+ yspacing = 1.0;
+
+ return yspacing;
+ }
+
+ std::string strSpacing = GetEntryValue(0x0028,0x0030);
+ if ( strSpacing == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro("Unfound Pixel Spacing (0028,0030)");
+ return 1.;
+ }
+
+ // if sscanf cannot read any float value, it won't affect yspacing
+ nbValues = sscanf( strSpacing.c_str(), "%f", &yspacing);
+
+ // if no values, yspacing is set to 1.0
+ if ( nbValues == 0 )
+ yspacing = 1.0;
+
+ if ( yspacing == 0.0 )
+ yspacing = 1.0;
+
+ 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 File::GetZSpacing()
+{
+ // Spacing Between Slices : distance between the middle of 2 slices
+ // Slices may be :
+ // jointives (Spacing between Slices = Slice Thickness)
+ // overlapping (Spacing between Slices < Slice Thickness)
+ // disjointes (Spacing between Slices > Slice Thickness)
+ // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
+ // It only concerns the MRI guys, not people wanting to visualize volumes
+ // If Spacing Between Slices is missing,
+ // we suppose slices joint together