]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
Add verbosity when something wrong happens
[gdcm.git] / src / gdcmDocument.cxx
index 9ddb8a5739dd14ead91f8e00ad0fb713da913f23..fbc717435e6030132b576b6619da0410fc71ded7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/05/12 09:37:45 $
-  Version:   $Revision: 1.348 $
+  Date:      $Date: 2006/06/21 14:06:56 $
+  Version:   $Revision: 1.351 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -95,19 +95,22 @@ bool Document::Load(  )
    return DoTheLoadingDocumentJob( );
 }
 
-#ifndef GDCM_LEGACY_REMOVE
+
+//#ifndef GDCM_LEGACY_REMOVE
 /**
  * \brief   Loader. (DEPRECATED : not to break the API)   
  * @param   fileName 'Document' (File or DicomDir) to be open for parsing
  * @return false if file cannot be open or no swap info was found,
  *         or no tag was found.
  */
+ /*
 bool Document::Load( std::string const &fileName ) 
 {
    Filename = fileName;
    return DoTheLoadingDocumentJob( );
 }
-#endif
+*/
+//#endif
 
 /**
  * \brief   Performs the Loading Job (internal use only)  
@@ -260,7 +263,7 @@ bool Document::DoTheLoadingDocumentJob(  )
       LoadDocEntry(d, true);
    }
 
-   CloseFile(); 
+   CloseFile();
   
    // ----------------------------
    // Specific code to allow gdcm to read ACR-LibIDO formated images
@@ -621,7 +624,6 @@ std::ifstream *Document::OpenFile()
    }
  
    //-- Broken ACR or DICOM with no Preamble; may start with a Shadow Group --
-   
    // FIXME : We cannot be sure the preable is only zeroes..
    //         (see ACUSON-24-YBR_FULL-RLE.dcm )
    if ( 
@@ -1046,7 +1048,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
    DocEntry *newDocEntry;
    DataEntry *newDataEntry;
    SeqEntry *newSeqEntry;
-   VRKey vr;
+   //VRKey vr;
    bool used; // will be set to false when something wrong happens to an Entry.
               // (Entry will then be deleted)
    bool delim_mode_intern = delim_mode;
@@ -1072,19 +1074,20 @@ void Document::ParseDES(DocEntrySet *set, long offset,
          {
             break;
          }
-      newDocEntry = ReadNextDocEntry( );
 
-      // Uncoment this cerr line to be able to 'follow' the DocEntries
-      // when something *very* strange happens
-      if( Debug::GetDebugFlag() ) 
-         std::cerr<<newDocEntry->GetKey()<<" "<<newDocEntry->GetVR()<<std::endl;
+      newDocEntry = ReadNextDocEntry( );
 
       if ( !newDocEntry )
       {
          break;
       }
+      
+      // Uncoment this cerr line to be able to 'follow' the DocEntries
+      // when something *very* strange happens
+      if( Debug::GetDebugFlag() ) 
+         std::cerr<<newDocEntry->GetKey()<<" "<<newDocEntry->GetVR()<<std::endl;
 
-       // an Item Starter found elsewhere but the first position
+       // an Item Starter found elsewhere but in the first position
        // of a SeqEntry means previous entry was a Sequence
        // but we didn't get it (private Sequence + Implicit VR)
        // we have to backtrack.
@@ -1105,7 +1108,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
       {
          //////////////////////////// DataEntry
  
-         vr = newDocEntry->GetVR();
+         //vr = newDocEntry->GetVR(); // useless ?
 
          if ( !set->AddEntry( newDataEntry ) )
          {
@@ -1377,10 +1380,10 @@ DocEntry *Document::Backtrack(DocEntry *docEntry)
  */
 void Document::LoadDocEntry(DocEntry *entry, bool forceLoad)
 {
-   uint16_t group  = entry->GetGroup();
-   uint16_t elem  = entry->GetElement();
+   uint16_t group   = entry->GetGroup();
+   uint16_t elem    = entry->GetElement();
    const VRKey  &vr = entry->GetVR();
-   uint32_t length = entry->GetLength();
+   uint32_t length  = entry->GetLength();
 
  //  Fp->seekg((long)entry->GetOffset(), std::ios::beg); // JPRx
 
@@ -1990,6 +1993,9 @@ bool Document::CheckSwap()
          //  Find a trick to tell it the caller...
       
          s16 = *((uint16_t *)(deb));
+         gdcmDebugMacro("not a DicomV3 nor a 'clean' ACR/NEMA;"
+                     << " (->despaired wild guesses !)"); 
       
          switch ( s16 )
          {
@@ -2154,8 +2160,8 @@ DocEntry *Document::ReadNextDocEntry()
          // We thought this was explicit VR, but we end up with an
          // implicit VR tag. Let's backtrack.
  
-         //if ( newEntry->GetGroup() != 0xfffe )
-         if (CurrentGroup != 0xfffe )
+         //if ( newEntry->GetGroup() != 0xfffe ) 
+         if (CurrentGroup != 0xfffe)
          { 
             int offset = Fp->tellg();//Only when heuristic for Explicit/Implicit was wrong
 
@@ -2178,7 +2184,6 @@ DocEntry *Document::ReadNextDocEntry()
    }
 
    newEntry->SetOffset(Fp->tellg());  // for each DocEntry
-   
    return newEntry;
 }
 
@@ -2190,6 +2195,23 @@ DocEntry *Document::ReadNextDocEntry()
  */
 void Document::HandleBrokenEndian(uint16_t &group, uint16_t &elem)
 {
+ // for strange PMS Gyroscan Intera images
+ // Item 'starter' has a tag : 0x3f3f,0x3f00, for no apparent reason
+ // --- Feel free to remove this test *on your own coy of gdcm*
+ //     if you are sure you'll never face this problem.
+   if ((group == 0x3f3f) && (elem == 0x3f00))
+   {
+     // start endian swap mark for group found
+     gdcmDebugMacro( " delimiter 0x3f3f  found." );
+     // fix the tag
+     group = 0xfffe;
+     elem  = 0xe000;
+     return;
+   }
+   // --- End of removable code
+   
    // Endian reversion. 
    // Some files contain groups of tags with reversed endianess.
    static int reversedEndian = 0;