+float File::GetYOrigin()
+{
+ float xImPos, yImPos, zImPos;
+ std::string strImPos = GetEntryValue(0x0020,0x0032);
+
+ if ( strImPos == GDCM_UNFOUND)
+ {
+ gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
+ strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
+ if ( strImPos == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
+ 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 File::GetZOrigin()
+{
+ float xImPos, yImPos, zImPos;
+ std::string strImPos = GetEntryValue(0x0020,0x0032);
+
+ if ( strImPos != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos) != 3)
+ {
+ gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)");
+ return 0.; // bug in the element 0x0020,0x0032
+ }
+ else
+ {
+ return zImPos;
+ }
+ }
+
+ strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images
+ if ( strImPos != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImPos.c_str(),
+ "%f \\%f \\%f ", &xImPos, &yImPos, &zImPos ) != 3 )
+ {
+ gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)");
+ return 0.; // bug in the element 0x0020,0x0032
+ }
+ else
+ {
+ return zImPos;
+ }
+ }
+
+ // for *very* old ACR-NEMA images
+ std::string strSliceLocation = GetEntryValue(0x0020,0x1041);
+ if ( strSliceLocation != GDCM_UNFOUND )
+ {
+ if ( sscanf( strSliceLocation.c_str(), "%f ", &zImPos) != 1)
+ {
+ gdcmWarningMacro( "Wrong Slice Location (0020,1041)");
+ return 0.; // bug in the element 0x0020,0x1041
+ }
+ else
+ {
+ return zImPos;
+ }
+ }
+ gdcmWarningMacro( "Unfound Slice Location (0020,1041)");
+
+ std::string strLocation = GetEntryValue(0x0020,0x0050);
+ if ( strLocation != GDCM_UNFOUND )
+ {
+ if ( sscanf( strLocation.c_str(), "%f ", &zImPos) != 1 )
+ {
+ gdcmWarningMacro( "Wrong Location (0020,0050)");
+ return 0.; // bug in the element 0x0020,0x0050
+ }
+ else
+ {
+ return zImPos;
+ }
+ }
+ gdcmWarningMacro( "Unfound Location (0020,0050)");
+
+ return 0.; // Hopeless
+}
+
+/**
+ * \brief gets the info from 0020,0037 : Image Orientation Patient
+ * (needed to organize DICOM files based on their x,y,z position)
+ * @param iop adress of the (6)float array to receive values
+ * @return cosines of image orientation patient
+ */
+bool File::GetImageOrientationPatient( float iop[6] )
+{
+ std::string strImOriPat;
+ //iop is supposed to be float[6]
+ iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.;
+
+ // 0020 0037 DS REL Image Orientation (Patient)
+ if ( (strImOriPat = GetEntryValue(0x0020,0x0037)) != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
+ &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
+ {
+ gdcmWarningMacro( "Wrong Image Orientation Patient (0020,0037). Less than 6 values were found." );
+ return false;
+ }
+ }
+ //For ACR-NEMA
+ // 0020 0035 DS REL Image Orientation (RET)
+ else if ( (strImOriPat = GetEntryValue(0x0020,0x0035)) != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ",
+ &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 )
+ {
+ gdcmWarningMacro( "wrong Image Orientation Patient (0020,0035). Less than 6 values were found." );
+ return false;
+ }
+ }
+ return true;
+}
+
+/**
+ * \brief Retrieve the number of Bits Stored (actually used)
+ * (as opposed to number of Bits Allocated)
+ * @return The encountered number of Bits Stored, 0 by default.
+ * 0 means the file is NOT USABLE. The caller has to check it !
+ */
+int File::GetBitsStored()
+{
+ std::string strSize = GetEntryValue( 0x0028, 0x0101 );
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro("(0028,0101) is supposed to be mandatory");
+ return 0; // It's supposed to be mandatory
+ // the caller will have to check
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the number of Bits Allocated
+ * (8, 12 -compacted ACR-NEMA files-, 16, 24 -old RGB ACR-NEMA files-,)
+ * @return The encountered Number of Bits Allocated, 0 by default.
+ * 0 means the file is NOT USABLE. The caller has to check it !
+ */
+int File::GetBitsAllocated()
+{
+ std::string strSize = GetEntryValue(0x0028,0x0100);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0100) is supposed to be mandatory");
+ return 0; // It's supposed to be mandatory
+ // the caller will have to check
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the high bit position.
+ * \warning The method defaults to 0 when information is missing.
+ * The responsability of checking this value is left to the caller.
+ * @return The high bit position when present. 0 when missing.
+ */
+int File::GetHighBitPosition()
+{
+ std::string strSize = GetEntryValue( 0x0028, 0x0102 );
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0102) is supposed to be mandatory");
+ return 0;
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the number of Samples Per Pixel
+ * (1 : gray level, 3 : RGB/YBR -1 or 3 Planes-)
+ * @return The encountered number of Samples Per Pixel, 1 by default.
+ * (we assume Gray level Pixels)
+ */
+int File::GetSamplesPerPixel()
+{
+ const std::string &strSize = GetEntryValue(0x0028,0x0002);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0002) is supposed to be mandatory");
+ return 1; // Well, it's supposed to be mandatory ...
+ // but sometimes it's missing : *we* assume Gray pixels
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the Planar Configuration for RGB images
+ * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
+ * @return The encountered Planar Configuration, 0 by default.
+ */
+int File::GetPlanarConfiguration()
+{
+ std::string strSize = GetEntryValue(0x0028,0x0006);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)");
+ return 0;
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Return the size (in bytes) of a single pixel of data.
+ * @return The size in bytes of a single pixel of data; 0 by default
+ * 0 means the file is NOT USABLE; the caller will have to check
+ */
+int File::GetPixelSize()
+{
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old ACR-NEMA RGB images)
+ // if (File::GetEntryValue(0x0028,0x0100) == "24")
+ // return 3;
+
+ std::string pixelType = GetPixelType();
+ if ( pixelType == "8U" || pixelType == "8S" )
+ {
+ return 1;
+ }
+ if ( pixelType == "16U" || pixelType == "16S")
+ {
+ return 2;
+ }
+ if ( pixelType == "32U" || pixelType == "32S")
+ {
+ return 4;
+ }
+ if ( pixelType == "FD" )
+ {
+ return 8;
+ }
+ gdcmWarningMacro( "Unknown pixel type");
+ return 0;