]> Creatis software - gdcm.git/commitdiff
// User should ask gdcm to write an image in Explicit VR mode
authorjpr <jpr>
Mon, 13 Mar 2006 14:44:07 +0000 (14:44 +0000)
committerjpr <jpr>
Mon, 13 Mar 2006 14:44:07 +0000 (14:44 +0000)
    // only when he is sure the VR of *all* the DataElements is known.
    // i.e : when there are *only* Public Groups,
    // or *all* the Shadow Groups are fully described in
    // the relevant Shadow Dictionnary.
    // Let's just *dream* about it; *never* trust a user !
    // If he doesn't, it write process will produce an 'illegal' Dicom image.
    // (it doesn't bother most of Dicom readers, but ...
    // Therae are enought illegal Dicom image in the world.
    // Don't add illegal gdcm-written Dicom images !

In order to avoid furter troubles,
We turn to Implicit VR if at least the VR of one element is unknown.

src/gdcmCommon.h
src/gdcmDataEntry.cxx
src/gdcmFileHelper.cxx

index 4e35401c802a72624d53ab47edc112d30553858f..145a8300701c6baa2dacb95b539245e86f927816 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmCommon.h,v $
   Language:  C++
-  Date:      $Date: 2006/03/01 15:32:52 $
-  Version:   $Revision: 1.106 $
+  Date:      $Date: 2006/03/13 14:44:07 $
+  Version:   $Revision: 1.107 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -91,6 +91,8 @@ enum FileType {
    ImplicitVR,
    ACR,
    ACR_LIBIDO,
+   /// \todo FIXME : an encapsulated JPEG file may be 
+   ///              either ExplicitVR or ImplicitVR, right?
    JPEG
 };
 
index 121c62c9ab341d921b0b50bda3a978e71e2af3f9..c5be15df66e9f811214c995052b298e3c9fa9cb4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/03/01 09:29:29 $
-  Version:   $Revision: 1.32 $
+  Date:      $Date: 2006/03/13 14:44:07 $
+  Version:   $Revision: 1.33 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -175,7 +175,7 @@ double DataEntry::GetValue(const uint32_t &id) const
    if( !BinArea )
    {
    /// \todo warn the user there was a problem !
-      gdcmErrorMacro("BinArea not set. Can't get the value");
+      gdcmErrorMacro("BinArea not set" << std::hex << GetGroup() << " " << GetElement() << " Can't get the value");
       return 0.0;
    }
 
index 3547fc4f5b918a218d3f109b79a780f7c18c9e77..ad26ffde02c88b4a5c24a5dd8174fcfb385b92fd 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2006/03/01 09:45:04 $
-  Version:   $Revision: 1.96 $
+  Date:      $Date: 2006/03/13 14:44:07 $
+  Version:   $Revision: 1.97 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include "gdcmSeqEntry.h"
 #include "gdcmSQItem.h"
 #include "gdcmDataEntry.h"
+#include "gdcmDocEntry.h"
 #include "gdcmFile.h"
 #include "gdcmPixelReadConvert.h"
 #include "gdcmPixelWriteConvert.h"
 #include "gdcmDocEntryArchive.h"
 #include "gdcmDictSet.h"
 #include "gdcmOrientation.h"
-
 #if defined(__BORLANDC__)
    #include <mem.h> // for memset
 #endif 
@@ -73,7 +74,7 @@ fh->SetImageData( userPixels, userPixelsLength);
 fh->SetTypeToRaw(); // Even if it was possible to convert Palette to RGB
                      // (WriteMode is set)
  
-fh->SetWriteTypeToDcmExpl(); // he wants Explicit Value Representation
+fh->SetWriteTypeToDcmExpl();  // he wants Explicit Value Representation
                               // Little Endian is the default
                               // no other value is allowed
                                 (-->SetWriteType(ExplicitVR);)
@@ -660,15 +661,44 @@ bool FileHelper::WriteAcr (std::string const &fileName)
  */
 bool FileHelper::Write(std::string const &fileName)
 {
+   bool flag = false;
+   DocEntry *e;   
    switch(WriteType)
    {
       case ImplicitVR:
          SetWriteFileTypeToImplicitVR();
          break;
       case Unknown:  // should never happen; ExplicitVR is the default value
       case ExplicitVR:
-         SetWriteFileTypeToExplicitVR();
+      
+   // User should ask gdcm to write an image in Explicit VR mode
+   // only when he is sure *all* the VR of *all* the DataElements is known.
+   // i.e : when there are *only* Public Groups
+   // or *all* the Shadow Groups are fully described in the relevant Shadow
+   // Dictionnary
+   // Let's just *dream* about it; *never* trust a user !
+   // We turn to Implicit VR if at least the VR of one element is unknown.
+   
+         e = FileInternal->GetFirstEntry();
+         while (e != 0)
+         {
+            if (e->GetVR() == "  ")
+            {
+               SetWriteTypeToDcmImplVR();
+               SetWriteFileTypeToImplicitVR();
+               flag = true;
+               break;         
+            } 
+            e = FileInternal->GetNextEntry();
+         }        
+
+         if (!flag)
+         {
+            SetWriteFileTypeToExplicitVR();
+         }
          break;
       case ACR:
       case ACR_LIBIDO:
       // NOTHING is done here just for LibIDO.
@@ -682,10 +712,13 @@ bool FileHelper::Write(std::string const &fileName)
          SetWriteFileTypeToACR();
         // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
          break;
+      /// \todo FIXME : JPEG may be either ExplicitVR or ImplicitVR
       case JPEG:
          SetWriteFileTypeToJPEG();
          break;
    }
+   
    CheckMandatoryElements();
 
    // --------------------------------------------------------------
@@ -1023,7 +1056,6 @@ void FileHelper::SetWriteFileTypeToExplicitVR()
 
    DataEntry *tss = CopyDataEntry(0x0002,0x0010);
    tss->SetString(ts);
-
    Archive->Push(tss);
    tss->Delete();
 }
@@ -1038,7 +1070,6 @@ void FileHelper::SetWriteFileTypeToImplicitVR()
 
    DataEntry *tss = CopyDataEntry(0x0002,0x0010);
    tss->SetString(ts);
-
    Archive->Push(tss);
    tss->Delete();
 }
@@ -1635,10 +1666,10 @@ void FileHelper::CheckMandatoryElements()
    // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
    CheckMandatoryEntry(0x0008,0x0090,"");
 
+ /*
    // Deal with element 0x0000 (group length) of each group.
    // First stage : get all the different Groups
    
- /*
   GroupHT grHT;
   DocEntry *d = FileInternal->GetFirstEntry();
   while(d)
@@ -1652,7 +1683,8 @@ void FileHelper::CheckMandatoryElements()
       CheckMandatoryEntry(it->first, 0x0000, "0"); 
   }    
   // Third stage : update all 'zero level' groups length
-*/   
+*/ 
+
 } 
 
 void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value)