Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2006/05/31 16:11:51 $
- Version: $Revision: 1.320 $
+ Date: $Date: 2007/04/12 13:22:49 $
+ Version: $Revision: 1.329 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <stdio.h> //sscanf
#include <stdlib.h> // for atoi
-namespace gdcm
+namespace gdcm
{
//-----------------------------------------------------------------------------
* @return false if file cannot be open or no swap info was found,
* or no tag was found.
*/
+
bool File::Load( )
{
if ( ! this->Document::Load( ) )
}
else
{
+
GrPixel = (uint16_t) atoi( imgLocation.c_str() );
}
{
float xspacing = 1.0;
uint32_t nbValue;
+ DataEntry *entry;
+ bool ok = false;
+/*
+From:David Clunie - view profile
+Date:Wed, May 24 2006 1:12 pm
+Email:David Clunie <dclu...@dclunie.com>
+Groups:comp.protocols.dicom
+
+The short answer is that:
+
+- (0018,1164) describes a spacing equivalent to that which
+ would be measured off a film in projection radiography
+
+- (0018,7022) does not describe the image pixels themselves,
+ since detector elements may have been binned to produce
+ pixels
+
+- (0018,7020) may be different from (0018,7022) since there
+ may be non-sensitive material separating individual
+ detectors (i.e. the size is smaller than the spacing
+ between centers)
+
+Only (0018,1164) is relevant when measuring things; the
+detector-specific attributes are there to describe the
+acquisition.
+
+David
+
+PS. For ultrasound you need to use Region Calibration.
+*/
+
+/*
+It *SHOULD* first find the IOD and then deduce which tags to read
+Eg: Cross section this is in Pixel Spacing (0028,0030)
+CR is in Imager Pixel Spacing (0018,1164)
+US is in Pixel Aspect Ratio (0028,0034)
+RT is in :
+(3002,0011) Image Plane Pixel Spacing
+(3002,0012) RT Image Position
+and
+(3004,000c) for deducing Z spacing
+*/
+
+ std::string SOPClassUID = GetEntryString(0x0008,0x0016);
+
+ /// \todo check the various SOP Class
+ /// to get the Pixel Spacing at the proper location
+
+ ///\todo find images to check if it *actually* works
+
+ if (Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.6")
+ // Ultrasound Image Storage (Retired)
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.6.1")
+ // Ultrasound Image Storage
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.3")
+ // Ultrasound Multi-Frame Storage (Retired)
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.3.1") )
+ // Ultrasound Multi-FrameImage Storage
+ {
+ // - check if SOPClassUID contains 2 parts (e.g. "4\3")
+ // - guess how to deduce the spacing (FOV ?, ??)
+
+ entry = GetDataEntry(0x0028,0x0034);
+ if ( entry )
+ {
+ nbValue = entry->GetValueCount();
+ if( nbValue !=2 ) {
+ gdcmWarningMacro("PixelAspectRatio (0x0028,0x0034) "
+ << "has a wrong number of values :" << nbValue);
+ }
+ xspacing = 1.0; // We get Pixel Aspect Ratio, not Spacing ...
+ ok = true;
+ }
+
+ if (ok)
+ return xspacing;
+ }
+/*
+ if (Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.1") )
+ // Computed Radiography Image Storage
+
+ // CR is in Imager Pixel Spacing (0018,1164)//
+*/
+ // go on with old method ...
+ // ---------------------
// To follow David Clunie's advice, we first check ImagerPixelSpacing
- DataEntry *entry = GetDataEntry(0x0018,0x1164);
+ entry = GetDataEntry(0x0018,0x1164);
if( entry )
{
nbValue = entry->GetValueCount();
*/
float File::GetYSpacing()
{
- float yspacing = 1.0;
+ float yspacing;
+ uint32_t nbValue;
+ DataEntry *entry;
+ bool ok = false;
+
+ std::string SOPClassUID = GetEntryString(0x0008,0x0016);
+
+ /// \todo check the various SOP Class
+ /// to get the Pixel Spacing at the proper location
+
+ ///\todo find images to check if it *actually* works
+
+ if (Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.6")
+ // Ultrasound Image Storage (Retired)
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.6.1")
+ // Ultrasound Image Storage
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.3")
+ // Ultrasound Multi-Frame Storage (Retired)
+ || Util::DicomStringEqual( SOPClassUID,"1.2.840.10008.5.1.4.1.1.3.1") )
+ // Ultrasound Multi-FrameImage Storage
+ {
+ // - check if SOPClassUID contains 2 parts (e.g. "4\3")
+ // - no way to deduce the spacing/
+
+ entry = GetDataEntry(0x0028,0x0034);
+ if ( entry )
+ {
+ nbValue = entry->GetValueCount();
+ if( nbValue ==2 ) {
+ yspacing = (float)entry->GetValue(0)/(float)entry->GetValue(1);
+ //std::cout << "ys " << yspacing << std::endl;
+ ok = true;
+ }
+ else
+ {
+ gdcmWarningMacro("PixelAspectRatio (0x0028,0x0034) "
+ << "has a wrong number of values :" << nbValue);
+ if (nbValue == 0 ) {
+ ok = false;
+ }
+ else if (nbValue == 1 ) {
+ yspacing = 1.0; // We get Pixel Aspect Ratio, not Spacing ...
+ ok = true;
+ }
+ }
+ }
+
+ if (ok)
+ return yspacing;
+ }
+
+ // go on with old method ...
+ // ---------------------
+ // To follow David Clunie's advice, we first check ImagerPixelSpacing
+ yspacing = 1.0;
// To follow David Clunie's advice, we first check ImagerPixelSpacing
- DataEntry *entry = GetDataEntry(0x0018,0x1164);
+ entry = GetDataEntry(0x0018,0x1164);
if( entry )
{
yspacing = (float)entry->GetValue(0);
// we suppose slices joint together
DataEntry *entry = GetDataEntry(0x0018,0x0088);
if( entry )
- {
- zspacing = (float)entry->GetValue(0);
+ { zspacing = (float)entry->GetValue(0);
if ( zspacing == 0.0 )
zspacing = 1.0;
return false;
}
+/**
+ * \brief gets the cosine of image X axis, against patient X axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image X axis, against patient X axis
+ */
+float File::GetXCosineOnX()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[0]);
+}
+
+/**
+ * \brief gets the cosine of image X axis, against patient Y axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image X axis, against patient Y axis
+ */
+float File::GetXCosineOnY()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[1]);
+}
+
+/**
+ * \brief gets the cosine of image X axis, against patient Z axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image X axis, against patient Z axis
+ */
+float File::GetXCosineOnZ()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[2]);
+}
+
+/**
+ * \brief gets the cosine of image Y axis, against patient X axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image Y axis, against patient X axis
+ */
+float File::GetYCosineOnX()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[3]);
+}
+
+/**
+ * \brief gets the cosine of image Y axis, against patient Y axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image Y axis, against patient Y axis
+ */
+float File::GetYCosineOnY()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[4]);
+}
+
+/**
+ * \brief gets the cosine of image Y axis, against patient Z axis
+ * (Sorry, but Python needs it :-( )
+ * @return cosine of image Y axis, against patient Z axis
+ */
+float File::GetYCosineOnZ()
+{
+ float iop[6];
+ GetImageOrientationPatient( iop );
+ return(iop[5]);
+}
+/**
+ * \brief gets the info from 0020,0032 : Image Position Patient
+ * or from 0020 0030 : Image Position (RET)
+ *
+ * @param ipp adress of the (3)float array to receive values.
+ * (defaulted as 0.,0.,0. if nothing -or inconsistent stuff-
+ * is found.
+ * @return true when one of the tag -with consistent values- is found
+ * false when nothing or inconsistent stuff - is found
+ */
+bool File::GetImagePositionPatient( float ipp[3] )
+{
+ std::string strImPosiPat;
+ //ipp is supposed to be float[3]
+ ipp[0] = ipp[1] = ipp[2] = 0.;
+
+ // 0020 0032 DS REL Image Position (Patient)
+ strImPosiPat = GetEntryString(0x0020,0x0032);
+ if ( strImPosiPat != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImPosiPat.c_str(), "%f \\ %f \\%f ",
+ &ipp[0], &ipp[1], &ipp[2]) != 3 )
+ {
+ gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)."
+ << " Less than 3 values were found." );
+ return false;
+ }
+ return true;
+ }
+ //For ACR-NEMA
+ // 0020 0030 DS REL Image Position (RET)
+ else if ( (strImPosiPat = GetEntryString(0x0020,0x0030)) != GDCM_UNFOUND )
+ {
+ if ( sscanf( strImPosiPat.c_str(), "%f \\ %f \\%f ",
+ &ipp[0], &ipp[1], &ipp[2]) != 3 )
+ {
+ gdcmWarningMacro( "wrong Image Position Patient (0020,0030). "
+ << "Less than 3 values were found." );
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
/**
* \brief Retrieve the number of Bits Stored (actually used)
* (as opposed to number of Bits Allocated)
bitsAlloc = "16"; // default and arbitrary value, not to polute the output
}
- if ( bitsAlloc == "64" )
+ else if ( bitsAlloc == "64" )
{
return "FD";
}
+ // useless since we have to bypass a bug ( >8 && < 16)
else if ( bitsAlloc == "12" )
{
// It will be unpacked
bitsAlloc = "16";
}
+
else if ( bitsAlloc == "24" )
{
// (in order no to be messed up by old RGB images)
bitsAlloc = "8";
}
-
+
+ int i= atoi(bitsAlloc.c_str()); // fix a bug in some headers
+ if ( i > 8 && i < 16 )
+ {
+ bitsAlloc = "16";
+ }
+
std::string sign;
if( IsSignedPixelData() )
{
* is modified to point after the tag.
* On failure (i.e. when the tag wasn't the expected tag
* (TestGroup, TestElem) the internal file pointer
- * \ref Document::Fp is restored to it's original position.
+ * \ref Document::Fp is restored to its original position.
* @param testGroup The expected group of the tag.
* @param testElem The expected Element of the tag.
* @return True on success, false otherwise.
* is placed at the beginning of a tag (TestGroup, TestElement),
* read the length associated to the Tag.
* \warning On success the internal file pointer \ref Document::Fp
- * is modified to point after the tag and it's length.
+ * is modified to point after the tag and its length.
* On failure (i.e. when the tag wasn't the expected tag
* (TestGroup, TestElement) the internal file pointer
- * \ref Document::Fp is restored to it's original position.
+ * \ref Document::Fp is restored to its original position.
* @param testGroup The expected Group of the tag.
* @param testElem The expected Element of the tag.
* @return On success returns the length associated to the tag. On failure
// When present, read the basic offset table itself.
// Notes: - since the presence of this basic offset table is optional
// we can't rely on it for the implementation, and we will simply
- // trash it's content (when present).
+ // trash its content (when present).
// - still, when present, we could add some further checks on the
// lengths, but we won't bother with such fuses for the time being.
if ( itemLength != 0 )