]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
Solve pb when structure (list, map, ...) is empty.
[gdcm.git] / src / gdcmHeader.cxx
index e5e2511fda699873ddade4585532566ac71d7be2..2830ff3ceffeb003fe128bc124f6017863e84185 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/08 15:03:59 $
-  Version:   $Revision: 1.227 $
+  Date:      $Date: 2005/01/17 11:13:21 $
+  Version:   $Revision: 1.233 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,6 +22,7 @@
 #include "gdcmDebug.h"
 #include "gdcmTS.h"
 #include "gdcmValEntry.h"
+#include "gdcmBinEntry.h"
 #include <stdio.h> //sscanf
 
 #include <vector>
@@ -44,7 +45,7 @@ Header::Header( std::string const &filename ):
    // is found by indirection through the "Image Location").
    // Inside the group pointed by "Image Location" the searched element
    // is conventionally the element 0x0010 (when the norm is respected).
-   // When the "Image Location" is absent we default to group 0x7fe0.
+   // When the "Image Location" is Missing we default to group 0x7fe0.
    // Note: this IS the right place for the code
  
    // Image Location
@@ -194,8 +195,41 @@ bool Header::Write(std::string fileName, FileType filetype)
           RemoveEntryNoDestroy(e);
       }
    }
+
+/*
+#ifdef GDCM_WORDS_BIGENDIAN
+   // Super Super hack that will make gdcm a BOMB ! but should
+   // Fix temporarily the dashboard
+   BinEntry *b = GetBinEntry(GrPixel,NumPixel);
+   if ( GetPixelSize() ==  16 )
+   {
+      uint16_t *im16 = (uint16_t*)b->GetBinArea();
+      int lgr = b->GetLength();
+      for( int i = 0; i < lgr / 2; i++ )
+      {
+         im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
+      }
+   }
+#endif //GDCM_WORDS_BIGENDIAN
+*/
+
    Document::WriteContent(fp,filetype);
 
+/*
+#ifdef GDCM_WORDS_BIGENDIAN
+   // Flip back the pixel ... I told you this is a hack
+   if ( GetPixelSize() ==  16 )
+   {
+      uint16_t *im16 = (uint16_t*)b->GetBinArea();
+      int lgr = b->GetLength();
+      for( int i = 0; i < lgr / 2; i++ )
+      {
+         im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
+      }
+   }
+#endif //GDCM_WORDS_BIGENDIAN
+*/
+
    fp->close();
    delete fp;
 
@@ -292,7 +326,7 @@ int Header::GetYSize()
  * \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 absent we consider the third dimension as
+ *          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).
  */
@@ -404,17 +438,18 @@ float Header::GetZSpacing()
    //   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
+   //   Si le Spacing Between Slices est Missing
    //   on suppose que les coupes sont jointives
    
    const std::string &strSpacingBSlices = GetEntry(0x0018,0x0088);
 
    if ( strSpacingBSlices == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro("Unfound StrSpacingBSlices");
+      gdcmVerboseMacro("Unfound Spacing Between Slices (0018,0088)");
       const std::string &strSliceThickness = GetEntry(0x0018,0x0050);       
       if ( strSliceThickness == GDCM_UNFOUND )
       {
+         gdcmVerboseMacro("Unfound Slice Thickness (0018,0050)");
          return 1.;
       }
       else
@@ -444,7 +479,7 @@ float Header::GetRescaleIntercept()
       if( sscanf( strRescInter.c_str(), "%f", &resInter) != 1 )
       {
          // bug in the element 0x0028,0x1052
-         gdcmVerboseMacro( "Rescale Intercept is empty." );
+         gdcmVerboseMacro( "Rescale Intercept (0028,1052) is empty." );
       }
    }
 
@@ -465,7 +500,7 @@ float Header::GetRescaleSlope()
       if( sscanf( strRescSlope.c_str(), "%f", &resSlope) != 1)
       {
          // bug in the element 0x0028,0x1053
-         gdcmVerboseMacro( "Rescale Slope is empty.");
+         gdcmVerboseMacro( "Rescale Slope (0028,1053) is empty.");
       }
    }
 
@@ -788,7 +823,7 @@ int Header::GetBitsStored()
    std::string strSize = GetEntry( 0x0028, 0x0101 );
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro("This is supposed to be mandatory");
+      gdcmVerboseMacro("(0028,0101) is supposed to be mandatory");
       return 0;  // It's supposed to be mandatory
                  // the caller will have to check
    }
@@ -797,24 +832,24 @@ int Header::GetBitsStored()
 
 /**
  * \brief   Retrieve the high bit position.
- * \warning The method defaults to 0 when information is absent.
+ * \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 positin when present. 0 when absent.
+ * @return  The high bit positin when present. 0 when Missing.
  */
 int Header::GetHighBitPosition()
 {
    std::string strSize = GetEntry( 0x0028, 0x0102 );
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "This is supposed to be mandatory");
+      gdcmVerboseMacro( "(0028,0102) is supposed to be mandatory");
       return 0;
    }
    return atoi( strSize.c_str() );
 }
 
 /**
- * \brief   Check wether the pixels are signed or UNsigned data.
- * \warning The method defaults to false (UNsigned) when information is absent.
+ * \brief   Check whether the pixels are signed or UNsigned data.
+ * \warning The method defaults to false (UNsigned) when information is Missing.
  *          The responsability of checking this value is left to the caller.
  * @return  True when signed, false when UNsigned
  */
@@ -823,7 +858,7 @@ bool Header::IsSignedPixelData()
    std::string strSize = GetEntry( 0x0028, 0x0103 );
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "This is supposed to be mandatory");
+      gdcmVerboseMacro( "(0028,0103) is supposed to be mandatory");
       return false;
    }
    int sign = atoi( strSize.c_str() );
@@ -845,7 +880,7 @@ int Header::GetBitsAllocated()
    std::string strSize = GetEntry(0x0028,0x0100);
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "This is supposed to be mandatory");
+      gdcmVerboseMacro( "(0028,0100) is supposed to be mandatory");
       return 0; // It's supposed to be mandatory
                 // the caller will have to check
    }
@@ -863,7 +898,7 @@ int Header::GetSamplesPerPixel()
    const std::string& strSize = GetEntry(0x0028,0x0002);
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "This is supposed to be mandatory");
+      gdcmVerboseMacro( "(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
    }
@@ -871,7 +906,7 @@ int Header::GetSamplesPerPixel()
 }
 
 /**
- * \brief   Check wether this a monochrome picture or not by accessing
+ * \brief   Check whether this a monochrome picture or not by accessing
  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
  * @return  true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
  */
@@ -885,13 +920,13 @@ bool Header::IsMonochrome()
    }
    if ( PhotometricInterp == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Absent Photometric Interpretation");
+      gdcmVerboseMacro( "Not found : Photometric Interpretation (0028,0004)");
    }
    return false;
 }
 
 /**
- * \brief   Check wether this a "PALETTE COLOR" picture or not by accessing
+ * \brief   Check whether this a "PALETTE COLOR" picture or not by accessing
  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
  * @return  true when "PALETTE COLOR". False otherwise.
  */
@@ -904,13 +939,13 @@ bool Header::IsPaletteColor()
    }
    if ( PhotometricInterp == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Absent Palette color");
+      gdcmVerboseMacro( "Not found : Palette color (0028,0004)");
    }
    return false;
 }
 
 /**
- * \brief   Check wether this a "YBR_FULL" color picture or not by accessing
+ * \brief   Check whether this a "YBR_FULL" color picture or not by accessing
  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
  * @return  true when "YBR_FULL". False otherwise.
  */
@@ -923,7 +958,7 @@ bool Header::IsYBRFull()
    }
    if ( PhotometricInterp == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Absent YBR Full");
+      gdcmVerboseMacro( "Not found : YBR Full (0028,0004)");
    }
    return false;
 }
@@ -938,7 +973,7 @@ int Header::GetPlanarConfiguration()
    std::string strSize = GetEntry(0x0028,0x0006);
    if ( strSize == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Absent Planar Configuration");
+      gdcmVerboseMacro( "Not found : Planar Configuration (0028,0006)");
       return 0;
    }
    return atoi( strSize.c_str() );
@@ -996,7 +1031,7 @@ std::string Header::GetPixelType()
    std::string bitsAlloc = GetEntry(0x0028, 0x0100); // Bits Allocated
    if ( bitsAlloc == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Unfound Bits Allocated");
+      gdcmVerboseMacro( "Missing  Bits Allocated (0028,0100)");
       bitsAlloc = "16";
    }
 
@@ -1019,7 +1054,7 @@ std::string Header::GetPixelType()
 
    if (sign == GDCM_UNFOUND )
    {
-      gdcmVerboseMacro( "Unfound Pixel Representation");
+      gdcmVerboseMacro( "Missing Pixel Representation (0028,0103)");
       bitsAlloc = "0";
    }
    else if ( sign == "0" )
@@ -1162,39 +1197,6 @@ int Header::GetLUTNbits()
    return lutNbits;
 }
 
-/**
- * \brief Accesses the info from 0002,0010 : Transfert Syntax and TS
- *        else 1.
- * @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID)
- */
-std::string Header::GetTransfertSyntaxName()
-{
-   // use the TS (TS : Transfert Syntax)
-   std::string transfertSyntax = GetEntry(0x0002,0x0010);
-
-   if ( transfertSyntax == GDCM_NOTLOADED )
-   {
-      gdcmVerboseMacro( "Transfert Syntax not loaded. " << std::endl
-               << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" );
-      return "Uncompressed ACR-NEMA";
-   }
-   if ( transfertSyntax == GDCM_UNFOUND )
-   {
-      gdcmVerboseMacro( "Unfound Transfert Syntax (0002,0010)");
-      return "Uncompressed ACR-NEMA";
-   }
-
-   while ( ! isdigit((unsigned char)transfertSyntax[transfertSyntax.length()-1]) )
-   {
-      transfertSyntax.erase(transfertSyntax.length()-1, 1);
-   }
-   // we do it only when we need it
-   TS* ts         = Global::GetTS();
-   std::string tsName = ts->GetValue( transfertSyntax );
-
-   //delete ts; /// \todo Seg Fault when deleted ?!
-   return tsName;
-}
 
 //-----------------------------------------------------------------------------
 // Protected