]> Creatis software - gdcm.git/blobdiff - src/gdcmHeaderHelper.cxx
gdcmParser::CheckSwap() now defaults the filetype to ACR when 'dirty Acr' is
[gdcm.git] / src / gdcmHeaderHelper.cxx
index 1f38148f95c259b7c94010d1da930901ba49b3c3..398dc340f92e88897b67d2a5583ec82fa34b2ee7 100644 (file)
@@ -88,7 +88,7 @@ int gdcmHeaderHelper::GetPixelSize() {
 
      // 0028 0100 US IMG Bits Allocated
      // (in order no to be messed up by old RGB images)
-   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+   if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
       return 3;
         
    std::string PixelType = GetPixelType();
@@ -118,7 +118,7 @@ int gdcmHeaderHelper::GetPixelSize() {
  */
 std::string gdcmHeaderHelper::GetPixelType() {
    std::string BitsAlloc;
-   BitsAlloc = GetPubElValByNumber(0x0028, 0x0100);
+   BitsAlloc = GetEntryByNumber(0x0028, 0x0100);
    if (BitsAlloc == GDCM_UNFOUND) { // Bits Allocated
       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
       BitsAlloc = std::string("16");
@@ -129,7 +129,7 @@ std::string gdcmHeaderHelper::GetPixelType() {
       BitsAlloc = std::string("8"); // by old RGB images)
       
    std::string Signed;
-   Signed = GetPubElValByNumber(0x0028, 0x0103);
+   Signed = GetEntryByNumber(0x0028, 0x0103);
    if (Signed == GDCM_UNFOUND) { // "Pixel Representation"
       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
       BitsAlloc = std::string("0");
@@ -150,7 +150,7 @@ std::string gdcmHeaderHelper::GetPixelType() {
   */
 float gdcmHeaderHelper::GetXSpacing() {
     float xspacing, yspacing;
-    std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+    std::string StrSpacing = GetEntryByNumber(0x0028,0x0030);
     
    if (StrSpacing == GDCM_UNFOUND) {
       dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
@@ -174,7 +174,7 @@ float gdcmHeaderHelper::GetXSpacing() {
   */
 float gdcmHeaderHelper::GetYSpacing() {
    float xspacing, yspacing;
-   std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
+   std::string StrSpacing = GetEntryByNumber(0x0028,0x0030);
   
    if (StrSpacing == GDCM_UNFOUND) {
       dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
@@ -208,11 +208,11 @@ float gdcmHeaderHelper::GetZSpacing() {
    //   Si le Spacing Between Slices est absent, 
    //   on suppose que les coupes sont jointives
    
-   std::string StrSpacingBSlices = GetPubElValByNumber(0x0018,0x0088);
+   std::string StrSpacingBSlices = GetEntryByNumber(0x0018,0x0088);
 
    if (StrSpacingBSlices == GDCM_UNFOUND) {
       dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
-      std::string StrSliceThickness = GetPubElValByNumber(0x0018,0x0050);       
+      std::string StrSliceThickness = GetEntryByNumber(0x0018,0x0050);       
       if (StrSliceThickness == GDCM_UNFOUND)
          return 1.;
       else
@@ -226,10 +226,9 @@ float gdcmHeaderHelper::GetZSpacing() {
    }
 }
 
-float gdcmHeaderHelper::GetRescaleIntercept()
-{
+float gdcmHeaderHelper::GetRescaleIntercept() {
   float resInter = 0.;
-  std::string StrRescInter = GetPubElValByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept
+  std::string StrRescInter = GetEntryByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept
   if (StrRescInter != GDCM_UNFOUND) {
       if( sscanf( StrRescInter.c_str(), "%f", &resInter) != 1) {
          dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty");
@@ -239,10 +238,9 @@ float gdcmHeaderHelper::GetRescaleIntercept()
   return resInter;
 }
 
-float gdcmHeaderHelper::GetRescaleSlope()
-{
+float gdcmHeaderHelper::GetRescaleSlope() {
   float resSlope = 1.;
-  std::string StrRescSlope = GetPubElValByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope
+  std::string StrRescSlope = GetEntryByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope
   if (StrRescSlope != GDCM_UNFOUND) {
       if( sscanf( StrRescSlope.c_str(), "%f", &resSlope) != 1) {
          dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty");
@@ -267,11 +265,11 @@ int gdcmHeaderHelper::GetNumberOfScalarComponents() {
       
      // 0028 0100 US IMG Bits Allocated
      // (in order no to be messed up by old RGB images)
-   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+   if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
       return 3;
        
    std::string PhotometricInterpretation = 
-                  gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
+                  gdcmHeader::GetEntryByNumber(0x0028,0x0004);
 
    if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) {
       if (HasLUT())   // PALETTE COLOR is NOT enough
@@ -305,31 +303,27 @@ int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() {
       
      // 0028 0100 US IMG Bits Allocated
      // (in order no to be messed up by old RGB images)
-   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+   if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
       return 3;
 
     // we assume that *all* kinds of YBR are dealt with
       return GetSamplesPerPixel();
 }
 
-std::string gdcmHeaderHelper::GetStudyUID()
-{
-  return GetPubElValByNumber(0x0020,0x000d); //0020 000d UI REL Study Instance UID
+std::string gdcmHeaderHelper::GetStudyUID(){
+  return GetEntryByNumber(0x0020,0x000d); //0020 000d UI REL Study Instance UID
 }
 
-std::string gdcmHeaderHelper::GetSeriesUID()
-{
-  return GetPubElValByNumber(0x0020,0x000e); //0020 000e UI REL Series Instance UID
+std::string gdcmHeaderHelper::GetSeriesUID(){
+  return GetEntryByNumber(0x0020,0x000e); //0020 000e UI REL Series Instance UID
 }
 
-std::string gdcmHeaderHelper::GetClassUID()
-{
-  return GetPubElValByNumber(0x0008,0x0016); //0008 0016 UI ID SOP Class UID
+std::string gdcmHeaderHelper::GetClassUID(){
+  return GetEntryByNumber(0x0008,0x0016); //0008 0016 UI ID SOP Class UID
 }
 
-std::string gdcmHeaderHelper::GetInstanceUID()
-{
-  return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID
+std::string gdcmHeaderHelper::GetInstanceUID(){
+  return GetEntryByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID
 }
 
 // Image Position Patient                              (0020,0032):
@@ -350,11 +344,11 @@ std::string gdcmHeaderHelper::GetInstanceUID()
   */
 float gdcmHeaderHelper::GetXOrigin() {
     float xImPos, yImPos, zImPos;  
-    std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+    std::string StrImPos = GetEntryByNumber(0x0020,0x0032);
 
     if (StrImPos == GDCM_UNFOUND) {
        dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
-       StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+       StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
        if (StrImPos == GDCM_UNFOUND) {
           dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
           // How to tell the caller nothing was found ?
@@ -375,11 +369,11 @@ float gdcmHeaderHelper::GetXOrigin() {
   */
 float gdcmHeaderHelper::GetYOrigin() {
     float xImPos, yImPos, zImPos;
-    std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+    std::string StrImPos = GetEntryByNumber(0x0020,0x0032);
 
     if (StrImPos == GDCM_UNFOUND) {
        dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
-       StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+       StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
        if (StrImPos == GDCM_UNFOUND) {
           dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
           // How to tell the caller nothing was found ?
@@ -402,7 +396,7 @@ float gdcmHeaderHelper::GetYOrigin() {
   */
 float gdcmHeaderHelper::GetZOrigin() {
    float xImPos, yImPos, zImPos; 
-   std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
+   std::string StrImPos = GetEntryByNumber(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 (0020,0032)");
@@ -411,7 +405,7 @@ float gdcmHeaderHelper::GetZOrigin() {
          return zImPos;
       }    
    }  
-   StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
+   StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
    if (StrImPos != GDCM_UNFOUND) {
       if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
@@ -420,7 +414,7 @@ float gdcmHeaderHelper::GetZOrigin() {
          return zImPos;
       }    
    }                
-   std::string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
+   std::string StrSliceLocation = GetEntryByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
    if (StrSliceLocation != GDCM_UNFOUND) {
       if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
@@ -430,7 +424,7 @@ float gdcmHeaderHelper::GetZOrigin() {
       }
    }   
    dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
-   std::string StrLocation = GetPubElValByNumber(0x0020,0x0050);
+   std::string StrLocation = GetEntryByNumber(0x0020,0x0050);
    if (StrLocation != GDCM_UNFOUND) {
       if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
          dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
@@ -455,7 +449,7 @@ int gdcmHeaderHelper::GetImageNumber() {
   //binary conversion rules. This may be preferable to sscanf() since atoi() is a much smaller,
   // simpler and faster function. sscanf() can do all possible conversions whereas atoi() can 
   //only do single decimal integer conversions.
-  std::string StrImNumber = GetPubElValByNumber(0x0020,0x0013); //0020 0013 IS REL Image Number
+  std::string StrImNumber = GetEntryByNumber(0x0020,0x0013); //0020 0013 IS REL Image Number
   if (StrImNumber != GDCM_UNFOUND) {
     return atoi( StrImNumber.c_str() );
   }
@@ -468,7 +462,7 @@ int gdcmHeaderHelper::GetImageNumber() {
   * @return ModalityType
   */
 ModalityType gdcmHeaderHelper::GetModality(void) {
-  std::string StrModality = GetPubElValByNumber(0x0008,0x0060); //0008 0060 CS ID Modality
+  std::string StrModality = GetEntryByNumber(0x0008,0x0060); //0008 0060 CS ID Modality
   if (StrModality != GDCM_UNFOUND) {
          if ( StrModality.find("AU") < StrModality.length()) return AU;
     else if ( StrModality.find("AS") < StrModality.length()) return AS;
@@ -531,7 +525,7 @@ void gdcmHeaderHelper::GetImageOrientationPatient( float* iop ) {
   //iop is supposed to be float[6]
   iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0;
   
-  std::string StrImOriPat = GetPubElValByNumber(0x0020,0x0037); // 0020 0037 DS REL Image Orientation (Patient)
+  std::string StrImOriPat = GetEntryByNumber(0x0020,0x0037); // 0020 0037 DS REL Image Orientation (Patient)
   if (StrImOriPat != 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) {
@@ -543,7 +537,7 @@ void gdcmHeaderHelper::GetImageOrientationPatient( float* iop ) {
   }
   
   //For ACR-NEMA
-  StrImOriPat = GetPubElValByNumber(0x0020,0x0035); //0020 0035 DS REL Image Orientation (RET)
+  StrImOriPat = GetEntryByNumber(0x0020,0x0035); //0020 0035 DS REL Image Orientation (RET)
   if (StrImOriPat != 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) {
@@ -569,8 +563,7 @@ void gdcmHeaderHelper::GetImageOrientationPatient( float* iop ) {
 // gdcmSerieHeaderHelper
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-gdcmSerieHeaderHelper::~gdcmSerieHeaderHelper()
-{
+gdcmSerieHeaderHelper::~gdcmSerieHeaderHelper(){
   //! \todo
   for (std::list<gdcmHeaderHelper*>::iterator it  = CoherentGdcmFileList.begin();
         it != CoherentGdcmFileList.end(); it++)
@@ -589,8 +582,7 @@ gdcmSerieHeaderHelper::~gdcmSerieHeaderHelper()
  * \ingroup gdcmHeaderHelper
  * \brief add a gdcmFile to the list based on file name
  */
-void gdcmSerieHeaderHelper::AddFileName(std::string filename)
-{
+void gdcmSerieHeaderHelper::AddFileName(std::string filename) {
   gdcmHeaderHelper *GdcmFile = new gdcmHeaderHelper( filename.c_str() );
   this->CoherentGdcmFileList.push_back( GdcmFile );
 }
@@ -599,8 +591,7 @@ void gdcmSerieHeaderHelper::AddFileName(std::string filename)
  * \ingroup gdcmHeaderHelper
  * \brief add a gdcmFile to the list
  */
-void gdcmSerieHeaderHelper::AddGdcmFile(gdcmHeaderHelper *file)
-{
+void gdcmSerieHeaderHelper::AddGdcmFile(gdcmHeaderHelper *file){
   this->CoherentGdcmFileList.push_back( file );
 }
 
@@ -608,8 +599,7 @@ void gdcmSerieHeaderHelper::AddGdcmFile(gdcmHeaderHelper *file)
  * \ingroup gdcmHeaderHelper
  * \brief \todo
  */
-void gdcmSerieHeaderHelper::SetDirectory(std::string dir)
-{
+void gdcmSerieHeaderHelper::SetDirectory(std::string dir){
   std::list<std::string> filenames_list;
   GetDir(dir, filenames_list);  //OS specific
   
@@ -624,8 +614,7 @@ void gdcmSerieHeaderHelper::SetDirectory(std::string dir)
 //This could be implemented in a 'Strategy Pattern' approach
 //But as I don't know how to do it, I leave it this way
 //BTW, this is also a Strategy, I don't know this is the best approach :)
-void gdcmSerieHeaderHelper::OrderGdcmFileList()
-{
+void gdcmSerieHeaderHelper::OrderGdcmFileList(){
   if( ImagePositionPatientOrdering() )
   {
     return ;
@@ -640,8 +629,7 @@ void gdcmSerieHeaderHelper::OrderGdcmFileList()
   }
 }
 
-std::list<gdcmHeaderHelper*> &gdcmSerieHeaderHelper::GetGdcmFileList()
-{
+std::list<gdcmHeaderHelper*> &gdcmSerieHeaderHelper::GetGdcmFileList() {
   return CoherentGdcmFileList;
 }
 
@@ -768,8 +756,8 @@ bool gdcmSerieHeaderHelper::ImagePositionPatientOrdering()
 }
 
 //Based on Image Number
-bool gdcmSerieHeaderHelper::ImageNumberOrdering()
-{
+
+bool gdcmSerieHeaderHelper::ImageNumberOrdering() {
   int min, max, pos;
   int n = 0;//CoherentGdcmFileList.size(); //O(N) operation !!
   unsigned char *partition;
@@ -800,7 +788,7 @@ bool gdcmSerieHeaderHelper::ImageNumberOrdering()
     partition[pos - min]++;
   }
   
-  unsigned char mult;
+  unsigned char mult = 1;
   for(int i=0; i<n ; i++)
   {
     mult *= partition[i];
@@ -819,8 +807,7 @@ bool gdcmSerieHeaderHelper::ImageNumberOrdering()
   return (mult!=0);
 }
 
-bool gdcmSerieHeaderHelper::FileNameOrdering()
-{
+bool gdcmSerieHeaderHelper::FileNameOrdering() {
   //using the sort
   //sort(CoherentGdcmFileList.begin(), CoherentGdcmFileList.end());
   return true;