]> Creatis software - gdcm.git/commitdiff
2004-04-22 Jean-Pierre Roux
authorjpr <jpr>
Fri, 23 Apr 2004 16:21:58 +0000 (16:21 +0000)
committerjpr <jpr>
Fri, 23 Apr 2004 16:21:58 +0000 (16:21 +0000)
     * ENH Minor changes to the Print() methods
     * ADD gdcmParser::PrintEntryNiceSQ() to allow SQ-indented
           Header printing. Example given with :
   PrintHeader fileName  2 new
          (SQ based tree-like structure still to be done for the Header ...)

ChangeLog
src/gdcmHeaderEntry.cxx
src/gdcmHeaderEntry.h
src/gdcmParser.cxx
src/gdcmParser.h
vtk/vtkGdcmReader.cxx
vtk/vtkgdcmViewer.cxx

index 081c392999514e8dc85dca0ada6c8d7de59f22c1..5873b1ddf06a24651c58cb4758799382c8f0394b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,32 @@
+2004-04-22  Jean-Pierre Roux
+     * ENH Minor changes to the Print() methods
+     * ADD gdcmParser::PrintEntryNiceSQ() to allow SQ-indented
+           Header printing. Example given with :
+          PrintHeader fileName  2 new
+          (SQ based tree-like structure still to be done for the Header ...)
+          
 2004-04-22  Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
      * ENH: Some cosmetic clean up for compilation with -W -Wall -Werror
-                * ENH: Change malloc/calloc/free with c++ equivalent
-
-2004-21-02  Jean-Pierre Roux
+         1. I have added some unsigned where needed
+         2. Some function parameter not used -> (void)
+         3. In gdcmDicomDir.cxx, add GDCM_DICOMDIR_NONE case
+         4. g++ don't like character '\' in comment
+         5. #define jpeg_create_decompress  jCreaDecompress
+                    this really need to be fixed
+         6. virtualize destructor of gdcmObject ... leakage
+         7. sscanf(g->first.c_str(),"%x",&gr_bid); 
+                    this also really need to be fixed
+         8. gdcm/src/jpeg/libijg8/CMakeLists.txt, 
+                    remove compression file 
+                    (as we only do decompression, right ?)     
+     * ENH: Change malloc/calloc/free with c++ equivalent
+
+2004-04-21  Jean-Pierre Roux
      * FIX gdcmHeaderHelper::GetXSpacing
-           when a single value is found, xpacing is now defaulted to yspacing
+           when a single value is found (bug ?), xpacing is now 
+           defaulted to yspacing
           
-2004-19-02  Jean-Pierre Roux
+2004-04-19  Jean-Pierre Roux
      * ADD gdcmData/Wrist.pap (PAPYRUS 3.0 -single frame-) for checking purpose
      * ENH add parameters :
                bool  exception_on_error = false, 
@@ -16,7 +36,7 @@
      * FIX vtk/vtkGdcmReader.cxx now uses  enable_sequences = true in gdcmFile
            to allow reading of PAPYRUS 3.0 files 
              
-2004-06-02  Jean-Pierre Roux
+2004-04-06  Jean-Pierre Roux
      * ADD gdcmData/E00001S03I0015.dcm for SQ checking purpose
      
 2004-04-02  Jean-Pierre Roux
index cdb3522e988b27557296cdc71f00b173bffbbff9..fef886cbf9eb9ce432c3ce17a1be11d991ddc9d0 100644 (file)
@@ -104,7 +104,7 @@ void gdcmHeaderEntry::Print(std::ostream & os) {
          s << " [gdcm::too long for print (" << GetLength() << ") ]";
    }
    
-   // Display the UID value (instead of displaying the rough code)  
+   // Display the UID value (instead of displaying only the rough code)  
    if (g == 0x0002) {  // Any more to be displayed ?
       if ( (e == 0x0010) || (e == 0x0002) )
          s << "  ==>\t[" << ts->GetValue(v) << "]";
index 3d86e54cc2f7b6d17841b33458cc0074e14084dc..8210809b0eacca4d61515b9e6232b65c7190d485 100644 (file)
@@ -120,6 +120,7 @@ public:
     *          of the current Dicom Header Entry
     */ 
    inline void         SetReadLength(guint32 l)  { ReadLength   = l; };
+
    /**
     * \ingroup gdcmHeaderEntry
     * \brief   Sets only 'Usable Length' (*not* 'Read Length')
index 7df4696954e9f1635a6488d7fe6b9ab1d38690d0..0ec0e22f9731edc23beab9e3b06c5d34dc5e1c51 100644 (file)
 #define UI1_2_840_10008_1_2_2    "1.2.840.10008.1.2.2"
 #define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
 
+typedef struct {
+   guint32 totalSQlength;
+   guint32 alreadyParsedlength;
+} pileElem;
+
 //-----------------------------------------------------------------------------
 // Refer to gdcmParser::CheckSwap()
 const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
@@ -126,7 +131,7 @@ void gdcmParser::PrintEntry(std::ostream & os) {
   * \ingroup gdcmParser
   * \brief   Prints the Header Entries (Dicom Elements)
   *          from the chained list
-  *          and skips the elements belonging to a SeQuence
+  *          and skips the elements belonging to a 'no length' SeQuence
   * @return
   */ 
 void gdcmParser::PrintEntryNoSQ(std::ostream & os) {
@@ -155,38 +160,115 @@ void gdcmParser::PrintEntryNoSQ(std::ostream & os) {
   * \ingroup gdcmParser
   * \brief   Prints the Header Entries (Dicom Elements)
   *          from the chained list
-  *          and indents the elements belonging to a SeQuence
+  *          and indents the elements belonging to any SeQuence
+  * \warning : will be removed
   * @return
   */ 
 void gdcmParser::PrintEntryNiceSQ(std::ostream & os) {
+   pileElem pile[50]; // Hope embedded sequence depth is no more than 50
+   int top =-1;
    int countSQ = 0;
+   int currentParsedlength = 0;
+   int totalElementlength;
    std::ostringstream tab; 
    tab << "   ";
+   
+   int DEBUG = 0;  // Sorry; Dealing with e-film breaker images
+                   // will (certainly) cause a lot of troubles ...
+                   // I prefer keeping my 'trace' on .            
+   
    for (ListTag::iterator i = listEntries.begin();  
-        i != listEntries.end();
-        ++i)
-   {
-       // we ignore '0 length' SeQuences
-       if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength()!=0){
-          countSQ ++;
-       }
-       // a SeQuence is over when a Sequence Delimiter Item is found
-       // pb : 'actual length' Sequence have NO Sequence Delimiter
-       // --> They 'never' finish : check the global length !
-       if ( (*i)->GetGroup() == 0xfffe  && (*i)->GetElement() == 0xe0dd){
-          countSQ --;
-          continue;
-       } 
-
-                    
-       if (countSQ != 0) { 
-          for (int i=0;i<countSQ;i++)
-            os << tab.str();
-       } 
-       (*i)->SetPrintLevel(printLevel);
-       (*i)->Print(os);         
-   } 
+      i != listEntries.end();
+       ++i) {
+      if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength() != 0) {   // SQ found
+         countSQ++;
+        top ++;         
+           if ( top >= 50) {
+               std::cout << "Kaie ! Kaie! SQ stack overflow" << std::endl;
+              return;
+            }
+        if (DEBUG) cout << "\n >>>>> empile niveau " << top 
+                        << "; Lgr SeQ: " << (*i)->GetReadLength() 
+                         << "\n" <<endl;
+                
+        pile[top].totalSQlength = (*i)->GetReadLength();
+        pile[top].alreadyParsedlength = 0; 
+        currentParsedlength = 0;                      
+
+      } else {                              // non SQ found
+      
+         if (countSQ != 0) {                // we are 'inside a SeQuence'
+            if ( (*i)->GetGroup()==0xfffe  && (*i)->GetElement()==0xe0dd){
+              // we just found 'end of SeQuence'
+               
+              if (DEBUG)
+                   std::cout << "fffe,e0dd : depile" << std::endl;
+               currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2                                    
+              countSQ --;
+               top --; 
+               pile[top].alreadyParsedlength +=  currentParsedlength;
+            } else {
+              // we are on a 'standard' elem
+              // or a Zero-length SeQuence
+              
+              totalElementlength =  (*i)->GetFullLength();            
+              currentParsedlength += totalElementlength;                                
+               pile[top].alreadyParsedlength += totalElementlength;
+              
+               if (pile[top].totalSQlength == 0xffffffff) {
+                  if (DEBUG)
+                    std::cout << "totalSeQlength == 0xffffffff" 
+                               << std::endl; 
+               } else {
+                 if (DEBUG) 
+                       cout << "alrdyPseLgt:"
+                      << pile[top].alreadyParsedlength << " totSeQlgt: " 
+                      << pile[top].totalSQlength << " curPseLgt: " 
+                      << currentParsedlength
+                      << endl;
+                  while (pile[top].alreadyParsedlength==pile[top].totalSQlength) {
+                 
+                    if (DEBUG) 
+                         std::cout << " \n<<<<<< On depile niveau " << top 
+                                   << "\n" <<  std::endl;
+                    
+                     currentParsedlength = pile[top].alreadyParsedlength;
+                     countSQ --;
+                     top --;
+                    if (top >=0) {
+                       
+                        pile[top].alreadyParsedlength +=  currentParsedlength +12;
+                                               // 12 : length of 'SQ embedded' SQ element
+                        currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2
+                                                                                            
+                       if (DEBUG)
+                             std::cout << pile[top].alreadyParsedlength << " " 
+                                       << pile[top].totalSQlength << " " 
+                                       << currentParsedlength
+                                       << std::endl;
+                     }                              
+                    if (top == -1) {
+                        currentParsedlength = 0;
+                        break;
+                     }                                                      
+                  }
+               }                               
+            }              
+         }   // end : 'inside a SeQuence'   
+      }
+      
+      if (countSQ != 0) { 
+         for (int i=0;i<countSQ;i++)
+           os << tab.str();
+      } 
+      (*i)->SetPrintLevel(printLevel);
+      (*i)->Print(os);
+             
+   } // end for     
 }
+
+
+
 /**
   * \brief   Prints The Dict Entries of THE public Dicom Dictionary
   * @return
@@ -1380,25 +1462,14 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)  {
    guint16 group  = Entry->GetGroup();
    std::string  vr= Entry->GetVR();
    guint32 length = Entry->GetLength();
-   bool SkipLoad  = false;
 
    fseek(fp, (long)Entry->GetOffset(), SEEK_SET);
-   
-   // the test was commented out to 'go inside' the SeQuences
-   // we don't any longer skip them !
-    
-   // if( vr == "SQ" )  //  (DO NOT remove this comment)
-   //    SkipLoad = true;
 
    // A SeQuence "contains" a set of Elements.  
    //          (fffe e000) tells us an Element is beginning
    //          (fffe e00d) tells us an Element just ended
    //          (fffe e0dd) tells us the current SeQuence just ended
-   if( group == 0xfffe )
-      SkipLoad = true;
-
-   if ( SkipLoad ) {
-      Entry->SetLength(0);
+   if( group == 0xfffe ) {
       Entry->SetValue("gdcm::Skipped");
       return;
    }
@@ -1508,6 +1579,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) {
    //guint16 group   = Entry->GetGroup(); //FIXME
    std::string  vr = Entry->GetVR();
    guint16 length16;
+       
    
    if ( (filetype == ExplicitVR) && (! Entry->IsImplicitVR()) ) 
    {
@@ -1862,8 +1934,7 @@ void gdcmParser::SkipHeaderEntry(gdcmHeaderEntry *entry)
  */
 void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 FoundLength) 
 {
-   Entry->SetReadLength(FoundLength); // will be updated only if a bug is found
-     
+   Entry->SetReadLength(FoundLength); // will be updated only if a bug is found        
    if ( FoundLength == 0xffffffff) {
       FoundLength = 0;
    }
@@ -1879,7 +1950,7 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found
    }
       
    // Sorry for the patch!  
-   // XMedCom did the trick to read some nasty GE images ...
+   // XMedCom did the trick to read some naughty GE images ...
    if (FoundLength == 13) {
       // The following 'if' will be removed when there is no more
       // images on Creatis HDs with a 13 length for Manufacturer...
@@ -1907,15 +1978,16 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found
          FoundLength =0;      // ReadLength is unchanged 
    } 
     
-   // a SeQuence Element is beginning                                          
-   // fffe|e000 is just a marker, its length *should be* zero                                               
+   // we found a 'delimiter' element                                         
+   // fffe|xxxx is just a marker, we don't take its length into account                                                   
    else if(Entry->GetGroup() == 0xfffe)
-   { 
+   {    
                                          // *normally, fffe|0000 doesn't exist ! 
      if( Entry->GetElement() != 0x0000 ) // gdcm-MR-PHILIPS-16-Multi-Seq.dcm
-                                         // causes extra troubles :-(                                                        
-         FoundLength =0;
-   }         
+                                         // causes extra troubles :-(                                                                  
+        FoundLength =0;
+   } 
+           
    Entry->SetUsableLength(FoundLength);
 }
 
index 4cd3311e1dcd786ea76cce72b28a04b247f0a41f..239ff64417a71a74c1bae9b931f660730ae99d42 100644 (file)
@@ -107,8 +107,8 @@ public:
       {PrintEntry(os);};
    virtual void PrintEntry      (std::ostream &os = std::cout);
    virtual void PrintEntryNoSQ  (std::ostream &os = std::cout);
+   // the 2 following will be merged
    virtual void PrintEntryNiceSQ(std::ostream &os = std::cout);
-
    virtual void PrintPubDict (std::ostream &os = std::cout);
    virtual void PrintShaDict (std::ostream &os = std::cout);
 
index 0b240f61ba8e7ef5e19fab6276d5a34b6dce8031..34f53f257c92b132bfd882086e2168f16b68bd37 100644 (file)
@@ -422,7 +422,6 @@ int vtkGdcmReader::CheckFileCoherence()
       }
       fclose(fp);
 
-      cout << " Try to gdcmHeader ... " << endl;   
       // Stage 1.2: check for Gdcm parsability
       gdcmHeaderHelper GdcmHeader(FileName->c_str(), false, true);
       //                             true : for enableSequences
@@ -635,7 +634,8 @@ size_t vtkGdcmReader::LoadImageInMemory(
    {
       size        = GdcmFile.GetImageDataSize();
       Source      = (unsigned char*)GdcmFile.GetImageData();
-   }
+   } 
+   
    unsigned char * pSource     = Source; //pointer for later deletion
    unsigned char * Destination = Dest + size - LineSize;
 
@@ -655,6 +655,16 @@ size_t vtkGdcmReader::LoadImageInMemory(
          UpdateProgressCount++;
       }
    }
+   
+// DO NOT remove this commented out code .
+// Nobody knows what's expecting you ...
+// Just to 'see' what was actually read on disk :-(
+
+//   FILE * f2;
+//   f2 = fopen("SpuriousFile.RAW","wb");
+//   fwrite(Dest,size,1,f2);
+//   fclose(f2); 
+   
    //GetImageData allocate a (void*)malloc, remove it:
    free(pSource);
    return size;
index e0a17943fa76e999a7a0ac8f4875d7c034f5eb9e..b9caec87947b68c0ffdcc00c532a9ed525e23b12 100644 (file)
@@ -67,6 +67,7 @@ int main(int argc, char *argv[])
   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
 
   vtkImageViewer2 *viewer = vtkImageViewer2::New();
+  
   if( reader->GetLookupTable() )
   {
     //convert to color:
@@ -78,6 +79,7 @@ int main(int argc, char *argv[])
     map->Delete();
   }
   else
+  
   {
     viewer->SetInput ( reader->GetOutput() );
   }