]> Creatis software - gdcm.git/commitdiff
some useless tests removed
authorjpr <jpr>
Tue, 1 Jul 2003 17:22:44 +0000 (17:22 +0000)
committerjpr <jpr>
Tue, 1 Jul 2003 17:22:44 +0000 (17:22 +0000)
src/gdcmFile.cxx
src/gdcmHeader.cxx

index b47418923c9edb0a8c2d5f781172085faff5477e..7003c29a67f1a38bcc4711c114add9fab8f1bb94 100644 (file)
@@ -114,7 +114,7 @@ bool gdcmFile::ReadPixelData(void* destination) {
      
   // ------------------------------- Position on begining of Jpeg Pixels
   
-       int ln;
+      int ln;
       fseek(fp,4,SEEK_CUR);
       fread(&ln,4,1,fp); 
       if(GetSwapCode()) 
@@ -127,29 +127,18 @@ bool gdcmFile::ReadPixelData(void* destination) {
       if(GetSwapCode()) 
          ln=SwapLong(ln);
       if (DEBUG) 
-         printf ("ln image comprimée %d\n",ln);
-         
+         printf ("ln image comprimée %d\n",ln);        
           
   // ------------------------------- JPEG LossLess : call to Jpeg Libido
    
    if (IsJPEGLossless()) {
  
-       ClbJpeg* jpg = _IdDcmJpegRead(fp);
+      ClbJpeg* jpg = _IdDcmJpegRead(fp);
       if(jpg == NULL) {
          CloseFile();
          return false;
       } 
-      // Gros soucis : 
-      //  jpg->DataImg est alloue en int32 systematiquement :
-      //  il faut le copier pixel par pixel dans destination ...
-      //  ... qui est un void *
-      // --> du CAST sportif a faire ... 
-      
-     // memcpy(destination,jpg->DataImg,lgrTotale);
-     
-     // Bon ...
-     // ... y'a p't etre + ruse (?)
-          
+
       int nb;
       string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100);
       if (str_nb == "gdcm::Unfound" ) {
@@ -162,14 +151,11 @@ bool gdcmFile::ReadPixelData(void* destination) {
       int * dataJpg = jpg->DataImg;
       int taille = GetXSize() *  GetYSize() *  GetZSize() * GetSamplesPerPixel();
           
-      switch (nBytes) {
-      
+      switch (nBytes) {   
          case 1:
          {
             unsigned short *dest = (unsigned short *)destination;
             for (int i=0; i<taille; i++) {
-               if (DEBUG) 
-                  if (*(dataJpg +i) >255) printf("data %d\n",*(dataJpg +i) );
                *((unsigned char *)dest+i) = *(dataJpg +i);    
             }
          }
@@ -178,21 +164,14 @@ bool gdcmFile::ReadPixelData(void* destination) {
          case 2:
          {
             unsigned short *dest = (unsigned short *)destination;
-            
-            // etonnant (?)
-            // la ligne commentee ci-dessous fait passer l'exec de 0.15 sec a 5.5 sec
-            // pour la meme image 512*512 ...
-            // optimiseur pas mis en oeuvre (?)
-            //for (int i=0; i<GetXSize() *  GetYSize() *  GetZSize(); i++) 
-            
-             for (int i=0; i<taille; i++) {           
+            for (int i=0; i<taille; i++) {           
                *((unsigned short *)dest+i) = *(dataJpg +i);    
             }
          }
          break;
             
-          case 4:
-          {
+         case 4:
+         {
             unsigned int *dest=(unsigned int *)destination;
             for (int i=0;i<taille; i++) {
                *((unsigned int *)dest+i) = *(dataJpg +i);    
@@ -210,6 +189,7 @@ bool gdcmFile::ReadPixelData(void* destination) {
   // TODO : faire qq chose d'intelligent pour limiter 
   // la duplication du code JPEG <bits=8 / bits=12>
   // TODO : eplucher icelui pour traiter *egalement* bits=16
+  
       int nBS;        
       if  ((nBS = GetBitsStored()) != 12) {
          printf("Sorry, Bits Stored = %d not yet taken into account\n",nBS);
@@ -220,7 +200,6 @@ bool gdcmFile::ReadPixelData(void* destination) {
          if (DEBUG) 
             printf ("res : %d\n",res);
       return res;
 }   
 
 /**
@@ -334,69 +313,67 @@ guint32 s32;
 guint16 fort,faible;
 int i;
 
-if(nb == 16)
-    
-       switch(swap) {
-               case 0:
-               case 12:
-               case 1234:
-                       break;
+if(nb == 16)  
+   switch(swap) {
+      case 0:
+      case 12:
+      case 1234:
+         break;
                
-               case 21:
-               case 3412:
-               case 2143:
-               case 4321:
-
-                       for(i=0;i<lgr;i++)
-                               ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
-                                               | ((((unsigned short int*)im)[i])<<8);
-                       break;
+         case 21:
+         case 3412:
+         case 2143:
+         case 4321:
+
+            for(i=0;i<lgr;i++)
+               ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
+                                           | ((((unsigned short int*)im)[i])<<8);
+               break;
                        
-               default:
-                       printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
-       
+         default:
+            printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
+   } 
  
 if( nb == 32 )
+   switch (swap) {
+      case 0:
+      case 1234:
+         break;
 
-       switch (swap) {
-               case 0:
-               case 1234:
-                        break;
-
-               case 4321:
-                        for(i=0;i<lgr;i++) {
-                               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 4321 */
-                                       fort  =((unsigned long int*)im)[i]>>16;
-                               fort=  (fort>>8)   | (fort<<8);
-                               faible=(faible>>8) | (faible<<8);
-                               s32=faible;
-                               ((unsigned long int*)im)[i]=(s32<<16)|fort;
-                               }
-                       break;
-
-               case 2143:
-                       for(i=0;i<lgr;i++) {
-                                       faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 2143 */
-                                       fort=((unsigned long int*)im)[i]>>16;
-                                       fort=  (fort>>8)   | (fort<<8);
-                                       faible=(faible>>8) | (faible<<8);
-                                       s32=fort; 
-                                       ((unsigned long int*)im)[i]=(s32<<16)|faible;
-                       }
-                       break;
+      case 4321:
+         for(i=0;i<lgr;i++) {
+            faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 4321 */
+            fort  =((unsigned long int*)im)[i]>>16;
+            fort=  (fort>>8)   | (fort<<8);
+            faible=(faible>>8) | (faible<<8);
+            s32=faible;
+            ((unsigned long int*)im)[i]=(s32<<16)|fort;
+         }
+         break;
+
+         case 2143:
+            for(i=0;i<lgr;i++) {
+               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 2143 */
+               fort=((unsigned long int*)im)[i]>>16;
+               fort=  (fort>>8)   | (fort<<8);
+               faible=(faible>>8) | (faible<<8);
+               s32=fort; 
+               ((unsigned long int*)im)[i]=(s32<<16)|faible;
+            }
+            break;
   
-               case 3412:
-                       for(i=0;i<lgr;i++) {
-                               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 3412 */
-                                       fort=((unsigned long int*)im)[i]>>16;                  
-                                       s32=faible; 
-                                       ((unsigned long int*)im)[i]=(s32<<16)|fort;
-                       }                 
-                       break; 
+         case 3412:
+            for(i=0;i<lgr;i++) {
+               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 3412 */
+               fort=((unsigned long int*)im)[i]>>16;                  
+               s32=faible; 
+               ((unsigned long int*)im)[i]=(s32<<16)|fort;
+            }                 
+            break; 
                                
-               default:
-                       printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);
-       
+         default:
+            printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);
+   } 
 return;
 }
 
@@ -436,20 +413,20 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) {
 
 void gdcmFile::SetImageDataSize(size_t ImageDataSize) {
 
-       string content1;
-       char car[20];
+   string content1;
+   char car[20];
        
-       // suppose que le ElValue (0x7fe0, 0x0010) existe ...
+   // suppose que le ElValue (0x7fe0, 0x0010) existe ...
        
-       sprintf(car,"%d",ImageDataSize);
+   sprintf(car,"%d",ImageDataSize);
  
-       gdcmElValue*a = GetElValueByNumber(0x7fe0, 0x0010);
-       a->SetLength(ImageDataSize);
+   gdcmElValue*a = GetElValueByNumber(0x7fe0, 0x0010);
+   a->SetLength(ImageDataSize);
                
-       ImageDataSize+=8;
-       sprintf(car,"%d",ImageDataSize);
-       content1=car;   
-       SetPubElValByNumber(content1, 0x7fe0, 0x0000);
+   ImageDataSize+=8;
+   sprintf(car,"%d",ImageDataSize);
+   content1=car;       
+   SetPubElValByNumber(content1, 0x7fe0, 0x0000);
 }
 
 
@@ -468,16 +445,16 @@ void gdcmFile::SetImageDataSize(size_t ImageDataSize) {
 
 int gdcmFile::WriteRawData (string nomFichier) {
 
-       FILE * fp1;
-       fp1 = fopen(nomFichier.c_str(),"wb");
-       if (fp1 == NULL) {
-               printf("Echec ouverture (ecriture) Fichier [%s] \n",nomFichier.c_str());
-               return (0);
-       
+   FILE * fp1;
+   fp1 = fopen(nomFichier.c_str(),"wb");
+   if (fp1 == NULL) {
+      printf("Echec ouverture (ecriture) Fichier [%s] \n",nomFichier.c_str());
+      return (0);
+   } 
        
-       fwrite (PixelData,lgrTotale, 1, fp1);
-       fclose (fp1);
-       return(1);
+   fwrite (PixelData,lgrTotale, 1, fp1);
+   fclose (fp1);
+   return(1);
 }
 
 
index b280fd62ca0cbcd718182c7551bb43de47429793..284bbdc61e680e47d83f954710db566ae03abaab 100644 (file)
@@ -1,5 +1,5 @@
 
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.74 2003/07/01 15:48:27 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.75 2003/07/01 17:22:44 jpr Exp $
 
 #include <stdio.h>
 #include <cerrno>
@@ -193,8 +193,8 @@ void gdcmHeader::CheckSwap()
       // Use gdcmHeader::dicom_vr to test all the possibilities
       // instead of just checking for UL, OB and UI !?
       if(  (memcmp(entCur, "UL", (size_t)2) == 0) ||
-         (memcmp(entCur, "OB", (size_t)2) == 0) ||
-         (memcmp(entCur, "UI", (size_t)2) == 0) )
+          (memcmp(entCur, "OB", (size_t)2) == 0) ||
+          (memcmp(entCur, "UI", (size_t)2) == 0) )
        {
          filetype = ExplicitVR;
          dbg.Verbose(1, "gdcmHeader::CheckSwap:",
@@ -299,6 +299,7 @@ void gdcmHeader::SwitchSwapToBigEndian(void) {
 /**
  * \ingroup   gdcmHeader
  * \brief     Find the value representation of the current tag.
+ * @param ElVal
  */
 void gdcmHeader::FindVR( gdcmElValue *ElVal) {
    if (filetype != ExplicitVR)
@@ -872,8 +873,7 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
    // four bytes properly i.e. as an integer as opposed to a string.
        
        // pour les elements de Value Multiplicity > 1
-       // on aura en fait une serie d'entiers
-       
+       // on aura en fait une serie d'entiers  
        // on devrait pouvoir faire + compact (?)
                
    if ( IsAnInteger(ElVal) ) {
@@ -1033,7 +1033,9 @@ gdcmElValue* gdcmHeader::NewElValueByNumber(guint16 Group, guint16 Elem) {
 /**
  * \ingroup gdcmHeader
  * \brief   TODO
- * @param   
+ * @param   Value
+ * @param   Group
+ * @param   Elem
  */
 int gdcmHeader::ReplaceOrCreateByNumber(string Value, guint16 Group, guint16 Elem ) {
 
@@ -1054,7 +1056,9 @@ int gdcmHeader::ReplaceOrCreateByNumber(string Value, guint16 Group, guint16 Ele
 /**
  * \ingroup gdcmHeader
  * \brief   TODO
- * @param   
+ * @param   Value
+ * @param   Group
+ * @param   Elem 
  */
 int gdcmHeader::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
 
@@ -1068,7 +1072,8 @@ int gdcmHeader::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem
 /**
  * \ingroup gdcmHeader
  * \brief   TODO
- * @param   
+ * @param   Group
+ * @param   Elem  
  */
  
 int gdcmHeader::CheckIfExistByNumber(guint16 Group, guint16 Elem ) {
@@ -1726,11 +1731,11 @@ bool gdcmHeader::IsReadable(void) {
       && atoi(GetElValByName("Image Dimensions").c_str()) > 4 ) {
       return false;
    }
-   if ( GetElValByName("Bits Allocated") == "gdcm::Unfound" )
+   if ( GetElValByName("Bits Allocated")       == "gdcm::Unfound" )
       return false;
-   if ( GetElValByName("Bits Stored") == "gdcm::Unfound" )
+   if ( GetElValByName("Bits Stored")          == "gdcm::Unfound" )
       return false;
-   if ( GetElValByName("High Bit") == "gdcm::Unfound" )
+   if ( GetElValByName("High Bit")             == "gdcm::Unfound" )
       return false;
    if ( GetElValByName("Pixel Representation") == "gdcm::Unfound" )
       return false;
@@ -1801,23 +1806,23 @@ void gdcmHeader::PrintPubDict(std::ostream & os) {
   * \ingroup gdcmHeader
   * \brief
   * @return
-  */
-  
+  */ 
 int gdcmHeader::Write(FILE * fp, FileType type) {
    return PubElValSet.Write(fp, type);
 }
 
 /**
   * \ingroup gdcmHeader
-  * \brief
-  * @return
+  * \brief gets the info from 0028,0030 : Pixel Spacing
+  * \           else 1.
+  * @return X dimension of a pixel
   */
 float gdcmHeader::GetXSpacing(void) {
     float xspacing, yspacing;
     string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
 
     if (StrSpacing == "gdcm::Unfound") {
-       dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing");
+       dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
        return 1.;
      }
    if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
@@ -1828,23 +1833,21 @@ float gdcmHeader::GetXSpacing(void) {
 
 /**
   * \ingroup gdcmHeader
-  * \brief
-  * @return
+  * \brief gets the info from 0028,0030 : Pixel Spacing
+  * \           else 1.
+  * @return Y dimension of a pixel
   */
 float gdcmHeader::GetYSpacing(void) {
    float xspacing, yspacing;
    string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
   
    if (StrSpacing == "gdcm::Unfound") {
-      dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing");
+      dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
       return 1.;
     }
-
   if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2)
     return 0.;
-
-  if (yspacing == 0.)
-  {
+  if (yspacing == 0.) {
     dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
     // seems to be a bug in the header ...
     sscanf( StrSpacing.c_str(), "%f\\0\\%f", &xspacing, &yspacing);
@@ -1854,9 +1857,11 @@ float gdcmHeader::GetYSpacing(void) {
 
 
 /**
-  * \ingroup gdcmHeader
-  * \brief
-  * @return
+  *\ingroup gdcmHeader
+  *\brief gets the info from 0018,0088 : Space Between Slices
+  *\               else from 0018,0050 : Slice Thickness
+  *\               else 1.
+  * @return Z dimension of a voxel-to be
   */
 float gdcmHeader::GetZSpacing(void) {
    // TODO : translate into English
@@ -1889,25 +1894,25 @@ float gdcmHeader::GetZSpacing(void) {
 }
 
 //
-// Image Position Patient (0020,0032):
-// If not found (ACR_NEMA) we try Image Position (0020,0030)
-// If not found (ACR-NEMA), we consider Slice Location (20,1041)
+// Image Position Patient                              (0020,0032):
+// If not found (ACR_NEMA) we try Image Position       (0020,0030)
+// If not found (ACR-NEMA), we consider Slice Location (0020,1041)
 //                                   or Location       (0020,0050) 
 // as the Z coordinate, 
 // 0. for all the coordinates if nothing is found
 // TODO : find a way to inform the caller nothing was found
 // TODO : How to tell the caller a wrong number of values was found?
+
+
 /**
   * \ingroup gdcmHeader
-  * \brief
-  * @return
+  * \brief gets the info from 0020,0032 : Image Position Patient
+  *\                else from 0020,0030 : Image Position (RET)
+  *\                else 0.
+  * @return up-left image corner position
   */
 float gdcmHeader::GetXImagePosition(void) {
-    float xImPos, yImPos, zImPos;
-    // 0020,0032 : Image Position Patient
-    // 0020,0030 : Image Position (RET)
-    // 0020,1041 : Slice Location
-   
+    float xImPos, yImPos, zImPos;  
     string StrImPos = GetPubElValByNumber(0x0020,0x0032);
 
     if (StrImPos == "gdcm::Unfound") {
@@ -1915,31 +1920,24 @@ float gdcmHeader::GetXImagePosition(void) {
        StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
        if (StrImPos == "gdcm::Unfound") {
           dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
-          string StrSliceLoc = GetPubElValByNumber(0x0020,0x1041); // for *very* old ACR-NEMA images
-          if (StrSliceLoc == "gdcm::Unfound") {
-            dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Slice Location (0020,1041)");
-             // How to tell the caller nothing was found?
-          } 
+          // How to tell the caller nothing was found ?
        }  
        return 0.;
      }
    if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
-     // How to tell the caller a wrong number of values was found?
      return 0.;
-   //else
    return xImPos;
 }
 
 /**
   * \ingroup gdcmHeader
-  * \brief
-  * @return
+  * \brief gets the info from 0020,0032 : Image Position Patient
+  * \               else from 0020,0030 : Image Position (RET)
+  * \               else 0.
+  * @return up-left image corner position
   */
 float gdcmHeader::GetYImagePosition(void) {
     float xImPos, yImPos, zImPos;
-    // 0020,0032 : Image Position Patient
-    // 0020,1041 : Slice Location
-    // 0020,0050 : Location
     string StrImPos = GetPubElValByNumber(0x0020,0x0032);
 
     if (StrImPos == "gdcm::Unfound") {
@@ -1947,34 +1945,25 @@ float gdcmHeader::GetYImagePosition(void) {
        StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
        if (StrImPos == "gdcm::Unfound") {
           dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
-          string StrSliceLoc = GetPubElValByNumber(0x0020,0x1041); // for *very* old ACR-NEMA images
-          if (StrSliceLoc == "gdcm::Unfound") {
-            dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location (0020,1041)");
-            // How to tell the caller nothing was found?
-          } 
        }  
        return 0.;
      }
    if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
-     // How to tell the caller a wrong number of values was found?
      return 0.;
    return yImPos;
 }
 
 /**
   * \ingroup gdcmHeader
-  * \brief
-  * @return
+  * \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 position
   */
 float gdcmHeader::GetZImagePosition(void) {
-   float xImPos, yImPos, zImPos;
-    // 0020,0032 : Image Position Patient
-    // 0020,1041 : Slice Location
-    // 0020,0050 : Location
-   
-   // TODO : How to tell the caller nothing was found?
-   // TODO : How to tell the caller a wrong number of values was found?
-  
+   float xImPos, yImPos, zImPos; 
    string StrImPos = GetPubElValByNumber(0x0020,0x0032);
    if (StrImPos != "gdcm::Unfound") {
       if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
@@ -1983,8 +1972,7 @@ float gdcmHeader::GetZImagePosition(void) {
       } else {
          return zImPos;
       }    
-   }
-   
+   }  
    StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
    if (StrImPos != "gdcm::Unfound") {
       if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
@@ -1993,8 +1981,7 @@ float gdcmHeader::GetZImagePosition(void) {
       } else {
          return zImPos;
       }    
-   }
-                 
+   }                
    string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
    if (StrSliceLocation != "gdcm::Unfound") {
       if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
@@ -2005,7 +1992,6 @@ float gdcmHeader::GetZImagePosition(void) {
       }
    }   
    dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
-
    string StrLocation = GetPubElValByNumber(0x0020,0x0050);
    if (StrLocation != "gdcm::Unfound") {
       if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
@@ -2015,8 +2001,7 @@ float gdcmHeader::GetZImagePosition(void) {
          return zImPos;
       }
    }
-   dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Slice Location");
-   
+   dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");  
    return 0.; // Hopeless
 }