]> Creatis software - gdcm.git/commitdiff
* src/gdcmCommon.h: FileType enum entry DICOMDIR removed (since
authorfrog <frog>
Mon, 29 Mar 2004 12:20:46 +0000 (12:20 +0000)
committerfrog <frog>
Mon, 29 Mar 2004 12:20:46 +0000 (12:20 +0000)
       equivalent to ExplicitVR in existing code).
     * code clean up.

ChangeLog
src/gdcmCommon.h
src/gdcmDicomDir.cxx
src/gdcmFile.cxx
src/gdcmParser.cxx

index 9f4052071a8406ae7c0ce048d25800d94dfb1a34..cdfd23c0fc585af4d40c39a9eb6b79e48f30e855 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2004-03-29  Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
      * src/gdcmParser.cxx: removal of all TAB character. Indentation fixed.
      * src/gdcmUtil.cxx: added forgotten iostream include.  
+     * src/gdcmCommon.h: FileType enum entry DICOMDIR removed (since 
+       equivalent to ExplicitVR in existing code).
 
 2004-03-27  Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
      * src/gdcmUtil.[cxx|h] split in two. Additional file gdcmGlobal.[cxx|h]
index 56c64a2bf985a9cb84522396a3977798729f488c..173fba77914867722a5dfe28a327aa18c2aad314 100644 (file)
@@ -67,11 +67,10 @@ typedef std::string TagName;
 
 enum FileType {
       Unknown = 0,
-      ExplicitVR,
+      ExplicitVR, // gdcmDicomDir are in this case
       ImplicitVR,
       ACR,
-      ACR_LIBIDO,
-      DICOMDIR
+      ACR_LIBIDO
 };
 
 //For now gdcm is not willing cmake, try to be more quiet
index db6f357fadb67a9e1e560cf8cc3bac36660b70e6..44214cbbabed77204625747e3d4144cb705e8df6 100644 (file)
@@ -340,28 +340,28 @@ void gdcmDicomDir::WriteDicomDirEntries(FILE *_fp)
    
    ptrMeta= GetDicomDirMeta();
    for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) {
-      WriteEntry(*i,_fp,DICOMDIR);
+      WriteEntry(*i,_fp, ExplicitVR);
    }   
     
    itPatient = GetDicomDirPatients().begin(); 
    while ( itPatient != GetDicomDirPatients().end() ) {
       for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) {
-         WriteEntry(*i,_fp,DICOMDIR);
+         WriteEntry(*i,_fp, ExplicitVR);
       }
       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();        
       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {   
          for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) {
-            WriteEntry(*i,_fp,DICOMDIR);
+            WriteEntry(*i,_fp, ExplicitVR);
          } 
          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
             for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) {
-               WriteEntry(*i,_fp,DICOMDIR);
+               WriteEntry(*i,_fp, ExplicitVR);
             }
             itImage = ((*itSerie)->GetDicomDirImages()).begin();
             while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
                for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) {
-                  WriteEntry(*i,_fp,DICOMDIR);
+                  WriteEntry(*i,_fp, ExplicitVR);
                }
                ++itImage;                  
            }
index 633d4d2fb8c33b346f7ae35ed676487ab16750b3..2ae2bd0974f56f11139cbdb2f3928b8d42833701 100644 (file)
@@ -646,16 +646,14 @@ bool gdcmFile::WriteAcr (std::string fileName) {
  *        (used by WriteDcmExplVR, WriteDcmImplVR, WriteAcr, etc)
  * @param fileName name of the file to be created
  *                 (any already existing file is overwritten)
- * @param  type file type (ExplicitVR, ImplicitVR, DICOMDIR, ...)
+ * @param  type file type (ExplicitVR, ImplicitVR, ...)
  * @return false if write fails                
  */
 bool gdcmFile::WriteBase (std::string fileName, FileType type) {
 
    FILE * fp1;
    
-   if (PixelRead==-1 && type != DICOMDIR) {
-/*      std::cout << "U never Read the pixels; U cannot write the file" 
-                << std::endl;*/
+   if (PixelRead==-1 && type != ExplicitVR) {
       return false;               
    }
 
index 8c3ca926c578762074aa707bed9751ebc6c7a8d0..24669fdc4b3727b58af8826b929bd5c5aeb1842b 100644 (file)
@@ -989,59 +989,44 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) {
  */
 void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
 {
-   guint16 gr, el;
-   guint32 lgr;
-   std::string value;
-   const char * val;
-   std::string vr;
-   guint32 val_uint32;
-   guint16 val_uint16;
-   guint16 valZero =0;
-   void *voidArea;
-   std::vector<std::string> tokens;
-
-   void *ptr;
-   int ff=0xffffffff;
-   // TODO (?) tester les echecs en ecriture (apres chaque fwrite)
-   int compte =0;
-   itsTimeToWritePixels = false;
+   guint16 group  = tag->GetGroup();
+   std::string vr = tag->GetVR();
+   guint32 length = tag->GetLength();
+   guint16 el     = tag->GetElement();
+   guint32 lgr    = tag->GetReadLength();
 
-   gr    = tag->GetGroup();
-   el    = tag->GetElement();
-   lgr   = tag->GetReadLength();
-   val   = tag->GetValue().c_str();
-   vr    = tag->GetVR();
-   voidArea = tag->GetVoidArea();
-           
    // === Deal with the length
    //     --------------------
-   if((tag->GetLength())%2==1)
+   if(length%2==1)
    { 
       tag->SetValue(tag->GetValue()+"\0");
       tag->SetLength(tag->GetReadLength()+1);
    }
 
-   fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp);  //group
+   fwrite ( &group,(size_t)2 ,(size_t)1 ,_fp);  //group
    fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp);  //element
       
-   if ( (type == ExplicitVR) || (type == DICOMDIR) ) {
-      // EXPLICIT VR
-      guint16 z=0, shortLgr;
-
-      if (gr == 0xfffe) { // NO Value Representation for 'delimiters'
-                          // no length : write ffffffff
-
-          // special patch to make some MR PHILIPS images e-film readable
-          // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm
-          // from Hospital Guy de Chauliac, Montpellier
-          // we just ignore spurious fffe|0000 tag !
-          if (el == 0x0000) return;
+   if ( type == ExplicitVR ) {
+
+      // Special case of delimiters:
+      if (group == 0xfffe) {
+         // Delimiters have NO Value Representation and have NO length.
+         // Hence we skip writing the VR and length and we pad by writing
+         // 0xffffffff
+
+         if (el == 0x0000)
+            // Fix in order to make some MR PHILIPS images e-film readable
+            // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
+            // we just ignore spurious fffe|0000 tag !
+            return;
 
+         int ff=0xffffffff;
          fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp);
-         return;       // NO value for 'delimiters'
+         return;
       }
 
-      shortLgr=lgr;
+      guint16 z=0;
+      guint16 shortLgr = lgr;
       if (vr == "unkn") {     // Unknown was 'written'
          // deal with Little Endian            
          fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
@@ -1065,8 +1050,24 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
    // === Deal with the value
    //     -------------------
    if (vr == "SQ")  return; // no "value" to write for the SEQuences
-   if (gr == 0xfffe)return; // no "value" to write for the delimiters
+   if (group == 0xfffe)return; // no "value" to write for the delimiters
+
+   // Pixels are never loaded in the element !
+   // we stop writting when Pixel are processed
+   // FIX : we loose trailing elements (RAB, right now)           
+            
+   int compte =0;
+   itsTimeToWritePixels = false;
+   if ((group == GrPixel) && (el == NumPixel) ) {
+      compte++;
+      if (compte == countGrPixel) {// we passed *all* the GrPixel,NumPixel   
+         itsTimeToWritePixels = true;
+         return;
+      }
+   }       
       
+   void *voidArea;
+   voidArea = tag->GetVoidArea();
    if (voidArea != NULL) 
    { // there is a 'non string' LUT, overlay, etc
       fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
@@ -1075,12 +1076,13 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
       
    if (vr == "US" || vr == "SS") 
    {
+      std::vector<std::string> tokens;
       tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
       Tokenize (tag->GetValue(), tokens, "\\");
       for (unsigned int i=0; i<tokens.size();i++) 
       {
-         val_uint16 = atoi(tokens[i].c_str());
-         ptr = &val_uint16;
+         guint16 val_uint16 = atoi(tokens[i].c_str());
+         void *ptr = &val_uint16;
          fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
       }
       tokens.clear();
@@ -1089,30 +1091,20 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
 
    if (vr == "UL" || vr == "SL") 
    {
+      std::vector<std::string> tokens;
       tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
       Tokenize (tag->GetValue(), tokens, "\\");
       for (unsigned int i=0; i<tokens.size();i++) 
       {
-         val_uint32 = atoi(tokens[i].c_str());
-         ptr = &val_uint32;
+         guint32 val_uint32 = atoi(tokens[i].c_str());
+         void *ptr = &val_uint32;
          fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
       }
       tokens.clear();
       return;
    } 
           
-   // Pixels are never loaded in the element !
-   // we stop writting when Pixel are processed
-   // FIX : we loose trailing elements (RAB, right now)           
-            
-   if ((gr == GrPixel) && (el == NumPixel) ) {
-      compte++;
-      if (compte == countGrPixel) {// we passed *all* the GrPixel,NumPixel   
-         itsTimeToWritePixels = true;
-         return;
-      }
-   }       
-   fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
+   fwrite (tag->GetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value
 }
 
 /**
@@ -1140,17 +1132,23 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type)
                           ++tag2)
    {
       if ( type == ACR ){ 
-         if ((*tag2)->GetGroup() < 0x0008)   continue; // ignore pure DICOM V3 groups
-         if ((*tag2)->GetElement() %2)       continue; // ignore shadow groups
-         if ((*tag2)->GetVR() == "SQ" )      continue; // ignore Sequences
-         // TODO : find a trick to *skip* the SeQuences !
-         // Not only ignore the SQ element
-        // --> will be done with the next organization
-         if ((*tag2)->GetGroup() == 0xfffe ) continue; // ignore delimiters
-   } 
-   WriteEntry(*tag2,_fp,type);
-   if (itsTimeToWritePixels) 
-      break;
+         if ((*tag2)->GetGroup() < 0x0008)
+            // Ignore pure DICOM V3 groups
+            continue;
+         if ((*tag2)->GetElement() %2)
+            // Ignore the "shadow" groups
+            continue;
+         if ((*tag2)->GetVR() == "SQ" )
+            // For the time being sequences are simply ignored
+            // TODO : find a trick not to *skip* the SeQuences !
+            continue;
+         if ((*tag2)->GetGroup() == 0xfffe )
+            // Ignore the documented delimiter
+            continue;
+      } 
+      WriteEntry(*tag2,_fp,type);
+      if (itsTimeToWritePixels) 
+         break;
    }
 }