]> Creatis software - gdcm.git/commitdiff
ENH: Minor patch, mostly cosmetic clean up
authormalaterre <malaterre>
Sat, 31 Jul 2004 23:30:04 +0000 (23:30 +0000)
committermalaterre <malaterre>
Sat, 31 Jul 2004 23:30:04 +0000 (23:30 +0000)
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmHeader.cxx
src/gdcmHeader.h

index ccd0b644be13c468d5c272c8c0223d3eff4a0451..af9d840d54a538d5fa2e4ac774e421ceac4f1427 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/30 16:09:27 $
-  Version:   $Revision: 1.60 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.61 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -110,7 +110,7 @@ gdcmDocument::gdcmDocument( std::string const & filename,
    long beg = ftell(Fp);
    lgt -= beg;
    
-   SQDepthLevel=0;
+   SQDepthLevel = 0;
    
    long l = ParseDES( this, beg, lgt, false); // le Load sera fait a la volee
    (void)l; //is l used anywhere ?
@@ -524,7 +524,7 @@ FILE *gdcmDocument::OpenFile(bool exception_on_error)
 bool gdcmDocument::CloseFile()
 {
   int closed = fclose(Fp);
-  Fp = (FILE *)0;
+  Fp = 0;
 
   return closed;
 }
@@ -599,7 +599,7 @@ void gdcmDocument::Write(FILE* fp,FileType filetype)
  */
   
 gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
-                                         std::string value, 
+                                         std::string const & value, 
                                          uint16_t group, 
                                          uint16_t elem )
 {
@@ -693,11 +693,10 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
  * @param Elem element number of the Entry
  * \return  boolean 
  */
-bool gdcmDocument::ReplaceIfExistByNumber(const char* value, uint16_t group,
-                                          uint16_t elem ) 
+bool gdcmDocument::ReplaceIfExistByNumber(std::string const & value, 
+                                          uint16_t group, uint16_t elem ) 
 {
-   const std::string v = value;
-   SetEntryByNumber(v, group, elem);
+   SetEntryByNumber(value, group, elem);
 
    return true;
 } 
@@ -713,7 +712,7 @@ bool gdcmDocument::ReplaceIfExistByNumber(const char* value, uint16_t group,
  */
 int gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
 {
-   std::string key = gdcmDictEntry::TranslateToKey(group, element );
+   const std::string &key = gdcmDictEntry::TranslateToKey(group, element );
    return TagHT.count(key);
 }
 
@@ -726,7 +725,7 @@ int gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
  * @return  Corresponding element value when it exists,
  *          and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
  */
-std::string gdcmDocument::GetEntryByName(TagName tagName)
+std::string gdcmDocument::GetEntryByName(TagName const & tagName)
 {
    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
    if( !dictEntry )
@@ -750,7 +749,7 @@ std::string gdcmDocument::GetEntryByName(TagName tagName)
  * @return  Corresponding element value representation when it exists,
  *          and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
  */
-std::string gdcmDocument::GetEntryVRByName(TagName tagName)
+std::string gdcmDocument::GetEntryVRByName(TagName const & tagName)
 {
    gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
    if( dictEntry == NULL)
@@ -758,8 +757,8 @@ std::string gdcmDocument::GetEntryVRByName(TagName tagName)
       return GDCM_UNFOUND;
    }
 
-   gdcmDocEntry* elem =  GetDocEntryByNumber(dictEntry->GetGroup(),
-                                             dictEntry->GetElement());
+   gdcmDocEntry* elem = GetDocEntryByNumber(dictEntry->GetGroup(),
+                                            dictEntry->GetElement());
    return elem->GetVR();
 }
 
@@ -1222,7 +1221,7 @@ uint32_t gdcmDocument::SwapLong(uint32_t a)
       default :
          std::cout << "swapCode= " << SwapCode << std::endl;
          dbg.Error(" gdcmDocument::SwapLong : unset swap code");
-         a=0;
+         a = 0;
    }
    return a;
 } 
index e8d61d81bf149c3833fed5154fdacf1c687b0583..c5b4eac08a97b3b21b05405004ff230afe71aefa 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/07/31 18:43:43 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.27 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -136,12 +136,12 @@ public:
 
    void Write(FILE* fp, FileType type);
 
-   gdcmValEntry* ReplaceOrCreateByNumber(std::string value,
+   gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
                                          uint16_t group, uint16_t elem);
 
    gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
                                          uint16_t group, uint16_t elem);
-   bool ReplaceIfExistByNumber (const char* value, uint16_t group, uint16_t elem);
+   bool ReplaceIfExistByNumber (std::string const & value, uint16_t group, uint16_t elem);
    
    virtual void* LoadEntryVoidArea(uint16_t group, uint16_t elem);
    virtual void* LoadEntryVoidArea(gdcmBinEntry* entry);
@@ -165,8 +165,8 @@ protected:
    // Entry
    int CheckIfEntryExistByNumber(uint16_t group, uint16_t elem ); // int !
 public:
-   virtual std::string GetEntryByName    (TagName tagName);
-   virtual std::string GetEntryVRByName  (TagName tagName);
+   virtual std::string GetEntryByName    (TagName const & tagName);
+   virtual std::string GetEntryVRByName  (TagName const & tagName);
    virtual std::string GetEntryByNumber  (uint16_t group, uint16_t elem);
    virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
    virtual int     GetEntryLengthByNumber(uint16_t group, uint16_t elem);
index 248fc34daeaac29a9aa2f3d0579b166f88af0199..975b0a4f7ac07d1c1faf0b47bccfc5e9290e2e90 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/30 16:09:27 $
-  Version:   $Revision: 1.118 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.119 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -155,7 +155,7 @@ void gdcmFile::SetPixelDataSizeFromHeader()
    std::string str_PhotometricInterpretation = 
                              Header->GetEntryByNumber(0x0028,0x0004);
     
-   /*if ( str_PhotometricInterpretation == "PALETTE COLOR " )*/
+   // if ( str_PhotometricInterpretation == "PALETTE COLOR " )
    // pb when undealt Segmented Palette Color
    
    if ( Header->HasLUT() )
@@ -832,7 +832,7 @@ void gdcmFile::SwapZone(void *im, int swap, int lgr, int nb)
          case 4321:
             for(i=0; i < lgr/2; i++)
             {
-            im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
+               im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
             }
             break;
          default:
@@ -1041,7 +1041,7 @@ bool gdcmFile::ReadPixelData(void *destination)
       if ( jpg2000 )
       {
       // JPEG 2000 :    call to ???
-      res = (bool)gdcm_read_JPEG2000_file (fp,destination);  // Not Yet written 
+      res = gdcm_read_JPEG2000_file (fp,destination);  // Not Yet written 
       // ------------------------------------- endif (JPEG2000)
       }
       else if (jpgLossless)
@@ -1059,12 +1059,12 @@ bool gdcmFile::ReadPixelData(void *destination)
          if ( Header->GetBitsStored() == 8)
          {
             // Reading Fragment pixels
-            res = (bool)gdcm_read_JPEG_file (fp,destination);
+            res = gdcm_read_JPEG_file (fp,destination);
          }
          else
          {
             // Reading Fragment pixels
-            res = (bool)gdcm_read_JPEG_file12 (fp,destination);
+            res = gdcm_read_JPEG_file12 (fp,destination);
          }
          // ------------------------------------- endif (JPEGLossy)
       }
index b7a395827c8a4488c26e522afad87fc4de0f6118..b58a6b595beb31ba146a9d09d5e8bb06da4f387f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/07/30 16:09:27 $
-  Version:   $Revision: 1.40 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.41 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -33,7 +33,7 @@ class GDCM_EXPORT gdcmFile
 public:
    gdcmFile(gdcmHeader *header);
    gdcmFile(std::string const & filename, 
-            bool  exception_on_error = false);
+            bool exception_on_error = false);
  
    virtual ~gdcmFile();
 
@@ -49,13 +49,13 @@ public:
    void * GetImageDataRaw();
    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
 
-      // Allocates ExpectedSize bytes of memory at this->Data and copies the
-      // pointed data to it. Copying the image might look useless but
-      // the caller might destroy it's image (without knowing it: think
-      // of a complicated interface where display is done with a library
-      // e.g. VTK) before calling the Write
+   // Allocates ExpectedSize bytes of memory at this->Data and copies the
+   // pointed data to it. Copying the image might look useless but
+   // the caller might destroy it's image (without knowing it: think
+   // of a complicated interface where display is done with a library
+   // e.g. VTK) before calling the Write
       
-   // voir gdcmHeader::SetImageDataSize ?!?         
+   // see also gdcmHeader::SetImageDataSize ?!?         
    bool SetImageData (void * data, size_t expectedSize);
 
    /// \todo When the caller is aware we simply point to the data:
@@ -92,15 +92,17 @@ private:
    bool gdcm_read_JPEG_file     (FILE *fp, void * image_buffer); 
    static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode, 
                                      long uncompressedSegmentSize, FILE *fp);
+
    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
    bool gdcm_read_JPEG_file12   (FILE *fp, void* image_buffer);
+
    // For JPEG 2000, body in file gdcmJpeg2000.cxx
    bool gdcm_read_JPEG2000_file (FILE *fp, void* image_buffer);
 
    // For Run Length Encoding (TOCHECK)
    bool gdcm_read_RLE_file      (FILE *fp, void* image_buffer); 
 
-// Variables
+// members variables:
 
    /// \brief Header to use to load the file
    gdcmHeader *Header;
index 5023fad1f5d3598b7061e5f69c3acd7747a645c2..90299a8a0ab45d4a08a4d685b8f7533b1390f508 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/30 16:09:27 $
-  Version:   $Revision: 1.180 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.181 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -104,10 +104,11 @@ gdcmHeader::~gdcmHeader ()
  * @param filetype Type of the File to be written 
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  */
-void gdcmHeader::Write(FILE* fp,FileType filetype) {
-   
+void gdcmHeader::Write(FILE* fp,FileType filetype)
+{
    // Bits Allocated
-   if ( GetEntryByNumber(0x0028,0x0100) ==  "12") {
+   if ( GetEntryByNumber(0x0028,0x0100) ==  "12")
+   {
       SetEntryByNumber("16", 0x0028,0x0100);
    }
 
@@ -117,43 +118,55 @@ void gdcmHeader::Write(FILE* fp,FileType filetype) {
    //        (only gdcmHeader knows GrPixel, NumPixel)
 
    int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel);
-   if (i_lgPix != -2) { // no (GrPixel, NumPixel) element
-      char * dumm = new char[20];
+   if (i_lgPix != -2)
+   {
+      // no (GrPixel, NumPixel) element
+      char* dumm = new char[20];
       sprintf(dumm ,"%d", i_lgPix+12);
       std::string s_lgPix = dumm;
-      delete dumm;
+      delete[] dumm;
       ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000);
    }
   
    // Drop Palette Color, if necessary
    
-   if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) {
-    // if SamplesPerPixel = 3, sure we don't need any LUT !   
-    // Drop 0028|1101, 0028|1102, 0028|1103
-    // Drop 0028|1201, 0028|1202, 0028|1203
-
-     gdcmDocEntry *e;
-     e=GetDocEntryByNumber(0x0028,0x01101);
-     if (e) 
-        RemoveEntry(e);
-     e=GetDocEntryByNumber(0x0028,0x1102);
-     if (e) 
-        RemoveEntry(e);
-     e=GetDocEntryByNumber(0x0028,0x1103);
-
-     if (e) 
-        RemoveEntry(e);
-     e=GetDocEntryByNumber(0x0028,0x01201);
-     if (e) 
-        RemoveEntry(e);
-     e=GetDocEntryByNumber(0x0028,0x1202);
-     if (e) 
-        RemoveEntry(e);
-     e=GetDocEntryByNumber(0x0028,0x1203);
-     if (e) 
-       RemoveEntry(e);
-   }
+   if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' )
+   {
+      // if SamplesPerPixel = 3, sure we don't need any LUT !   
+      // Drop 0028|1101, 0028|1102, 0028|1103
+      // Drop 0028|1201, 0028|1202, 0028|1203
 
+      gdcmDocEntry* e = GetDocEntryByNumber(0x0028,0x01101);
+      if (e)
+      {
+         RemoveEntry(e);
+      }
+      e = GetDocEntryByNumber(0x0028,0x1102);
+      if (e)
+      {
+         RemoveEntry(e);
+      }
+      e = GetDocEntryByNumber(0x0028,0x1103);
+      if (e)
+      {
+         RemoveEntry(e);
+      }
+      e = GetDocEntryByNumber(0x0028,0x01201);
+      if (e)
+      {
+         RemoveEntry(e);
+      }
+      e = GetDocEntryByNumber(0x0028,0x1202);
+      if (e)
+      {
+         RemoveEntry(e);
+      }
+      e = GetDocEntryByNumber(0x0028,0x1203);
+      if (e)
+      {
+          RemoveEntry(e);
+      }
+   }
    gdcmDocument::Write(fp,filetype);
 }
 
@@ -396,7 +409,7 @@ float gdcmHeader::GetRescaleIntercept()
       }
    }
 
-  return resInter;
+   return resInter;
 }
 
 /**
@@ -534,7 +547,7 @@ float gdcmHeader::GetXOrigin()
 
    if( sscanf( strImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3 )
    {
-     return 0.;
+      return 0.;
    }
 
    return xImPos;
@@ -1232,17 +1245,16 @@ std::string gdcmHeader::GetTransfertSyntaxName()
  */
 void gdcmHeader::SetImageDataSize(size_t ImageDataSize)
 {
-   std::string content1;
    char car[20];
-
    sprintf(car,"%d",ImageDataSize);
  
    gdcmDocEntry *a = GetDocEntryByNumber(GrPixel, NumPixel);
    a->SetLength(ImageDataSize);
 
-   ImageDataSize+=8;
+   ImageDataSize += 8;
    sprintf(car,"%d",ImageDataSize);
-   content1=car;
+
+   const std::string content1 = car;
    SetEntryByNumber(content1, GrPixel, NumPixel);
 }
 
@@ -1334,43 +1346,33 @@ bool gdcmHeader::AnonymizeHeader()
   * @param iop adress of the (6)float aray to receive values
   * @return cosines of image orientation patient
   */
-void gdcmHeader::GetImageOrientationPatient( float* iop )
+void gdcmHeader::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;
+   iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.;
 
    // 0020 0037 DS REL Image Orientation (Patient)
-   std::string strImOriPat = GetEntryByNumber(0x0020,0x0037);
-   if ( strImOriPat != GDCM_UNFOUND )
+   if ( (strImOriPat = GetEntryByNumber(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 )
       {
          dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0037)");
-         return ;  // bug in the element 0x0020,0x0037
-      }
-      else
-      {
-         return ;
+         // bug in the element 0x0020,0x0037
       }
    }
-
    //For ACR-NEMA
    // 0020 0035 DS REL Image Orientation (RET)
-   strImOriPat = GetEntryByNumber(0x0020,0x0035);
-   if ( strImOriPat != GDCM_UNFOUND )
+   else if ( (strImOriPat = GetEntryByNumber(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 )
       {
          dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0035)");
-         return ;  // bug in the element 0x0020,0x0035
+         // bug in the element 0x0020,0x0035
       }
    }
-   else
-   {
-      return;
-   }
 }
 
 //-----------------------------------------------------------------------------
index 043b79ac3cc8dbd4e02569d2e318dff1733fa922..9110e023bba15dbfbd8e40c790827691022701c1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.h,v $
   Language:  C++
-  Date:      $Date: 2004/07/31 18:43:43 $
-  Version:   $Revision: 1.84 $
+  Date:      $Date: 2004/07/31 23:30:04 $
+  Version:   $Revision: 1.85 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -167,11 +167,11 @@ public:
    /// Read (used in gdcmFile)
    void SetImageDataSize(size_t expectedSize);
 
-   void Write(FILE* fp,FileType filetype);
+   void Write(FILE* fp, FileType filetype);
  
 protected:
    bool AnonymizeHeader();
-   void GetImageOrientationPatient( float* iop );
+   void GetImageOrientationPatient( float iop[6] );
 
 private:
   friend class gdcmSerieHeader;