]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
* src/gdcmFileHelper.cxx : bug fix when having RGB ACR files... there is
[gdcm.git] / src / gdcmFileHelper.cxx
index cec029642f569a7e365e50325ed3e5d49c4782d1..789ca75230fe8055ea35fa5edad7f59790a9182b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/20 16:22:52 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/02/09 18:35:30 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -23,7 +23,9 @@
 #include "gdcmDebug.h"
 #include "gdcmUtil.h"
 #include "gdcmBinEntry.h"
-#include "gdcmHeader.h"
+#include "gdcmValEntry.h"
+#include "gdcmContentEntry.h"
+#include "gdcmFile.h"
 #include "gdcmPixelReadConvert.h"
 #include "gdcmPixelWriteConvert.h"
 #include "gdcmDocEntryArchive.h"
 
 namespace gdcm 
 {
-typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
-
 //-------------------------------------------------------------------------
 // Constructor / Destructor
 /**
  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
- *        file (Header only deals with the ... header)
+ *        file (gdcm::File only deals with the ... header)
  *        Opens (in read only and when possible) an existing file and checks
  *        for DICOM compliance. Returns NULL on failure.
  *        It will be up to the user to load the pixels into memory
- *        (see GetImageData, GetImageDataRaw)
  * \note  the in-memory representation of all available tags found in
  *        the DICOM header is post-poned to first header information access.
  *        This avoid a double parsing of public part of the header when
@@ -51,18 +50,17 @@ typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
  */
 FileHelper::FileHelper( )
 {
-   HeaderInternal = new Header( );
+   FileInternal = new File( );
    SelfHeader = true;
-   Initialise();
+   Initialize();
 }
 
 /**
  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
- *        file (Header only deals with the ... header)
+ *        file (File only deals with the ... header)
  *        Opens (in read only and when possible) an existing file and checks
  *        for DICOM compliance. Returns NULL on failure.
  *        It will be up to the user to load the pixels into memory
- *        (see GetImageData, GetImageDataRaw)
  * \note  the in-memory representation of all available tags found in
  *        the DICOM header is post-poned to first header information access.
  *        This avoid a double parsing of public part of the header when
@@ -70,20 +68,19 @@ FileHelper::FileHelper( )
  *        seen as a side effect).   
  * @param header already built Header
  */
-FileHelper::FileHelper(Header *header)
+FileHelper::FileHelper(File *header)
 {
-   HeaderInternal = header;
+   FileInternal = header;
    SelfHeader = false;
-   Initialise();
+   Initialize();
 }
 
 /**
  * \brief Constructor dedicated to deal with the *pixels* area of a ACR/DICOMV3
- *        file (Header only deals with the ... header)
+ *        file (gdcm::File only deals with the ... header)
  *        Opens (in read only and when possible) an existing file and checks
  *        for DICOM compliance. Returns NULL on failure.
  *        It will be up to the user to load the pixels into memory
- *        (see GetImageData, GetImageDataRaw)
  * \note  the in-memory representation of all available tags found in
  *        the DICOM header is post-poned to first header information access.
  *        This avoid a double parsing of public part of the header when
@@ -91,11 +88,11 @@ FileHelper::FileHelper(Header *header)
  *        seen as a side effect).   
  * @param filename file to be opened for parsing
  */
-FileHelper::FileHelper(std::string const & filename )
+FileHelper::FileHelper(std::string const &filename )
 {
-   HeaderInternal = new Header( filename );
+   FileInternal = new File( filename );
    SelfHeader = true;
-   Initialise();
+   Initialize();
 }
 
 /**
@@ -120,24 +117,89 @@ FileHelper::~FileHelper()
 
    if( SelfHeader )
    {
-      delete HeaderInternal;
+      delete FileInternal;
    }
-   HeaderInternal = 0;
+   FileInternal = 0;
 }
 
 //-----------------------------------------------------------------------------
-// Print
-void FileHelper::Print(std::ostream &os, std::string const &)
+// Public
+/**
+ * \brief   Accesses an existing DocEntry (i.e. a Dicom Element)
+ *          through it's (group, element) and modifies it's content with
+ *          the given value.
+ * @param   content new value (string) to substitute with
+ * @param   group  group number of the Dicom Element to modify
+ * @param   elem element number of the Dicom Element to modify
+ */
+bool FileHelper::SetValEntry(std::string const &content,
+                             uint16_t group, uint16_t elem)
+{ 
+   return FileInternal->SetValEntry(content,group,elem);
+}
+
+
+/**
+ * \brief   Accesses an existing DocEntry (i.e. a Dicom Element)
+ *          through it's (group, element) and modifies it's content with
+ *          the given value.
+ * @param   content new value (void*  -> uint8_t*) to substitute with
+ * @param   lgth new value length
+ * @param   group  group number of the Dicom Element to modify
+ * @param   elem element number of the Dicom Element to modify
+ */
+bool FileHelper::SetBinEntry(uint8_t *content, int lgth,
+                             uint16_t group, uint16_t elem)
 {
-   HeaderInternal->SetPrintLevel(PrintLevel);
-   HeaderInternal->Print(os);
+   return FileInternal->SetBinEntry(content,lgth,group,elem);
+}
 
-   PixelReadConverter->SetPrintLevel(PrintLevel);
-   PixelReadConverter->Print(os);
+/**
+ * \brief   Modifies the value of a given DocEntry (Dicom entry)
+ *          when it exists. Create it with the given value when unexistant.
+ * @param   content (string) Value to be set
+ * @param   group   Group number of the Entry 
+ * @param   elem  Element number of the Entry
+ * \return  pointer to the modified/created Dicom entry (NULL when creation
+ *          failed).
+ */ 
+ValEntry *FileHelper::InsertValEntry(std::string const &content,
+                                     uint16_t group, uint16_t elem)
+{
+   return FileInternal->InsertValEntry(content,group,elem);
+}
+
+/**
+ * \brief   Modifies the value of a given DocEntry (Dicom entry)
+ *          when it exists. Create it with the given value when unexistant.
+ *          A copy of the binArea is made to be kept in the Document.
+ * @param   binArea (binary) value to be set
+ * @param   lgth new value length
+ * @param   group   Group number of the Entry 
+ * @param   elem  Element number of the Entry
+ * \return  pointer to the modified/created Dicom entry (NULL when creation
+ *          failed).
+ */
+BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth,
+                                     uint16_t group, uint16_t elem)
+{
+   return FileInternal->InsertBinEntry(binArea,lgth,group,elem);
+}
+
+/**
+ * \brief   Modifies the value of a given DocEntry (Dicom entry)
+ *          when it exists. Create it with the given value when unexistant.
+ *          A copy of the binArea is made to be kept in the Document.
+ * @param   group   Group number of the Entry 
+ * @param   elem  Element number of the Entry
+ * \return  pointer to the modified/created Dicom entry (NULL when creation
+ *          failed).
+ */
+SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem)
+{
+   return FileInternal->InsertSeqEntry(group,elem);
 }
 
-//-----------------------------------------------------------------------------
-// Public
 /**
  * \brief   Get the size of the image data
  *          If the image can be RGB (with a lut or by default), the size 
@@ -174,9 +236,9 @@ size_t FileHelper::GetImageDataRawSize()
 }
 
 /**
- * \brief   - Allocates necessary memory, 
+ * \brief   - Allocates necessary memory,
  *          - Reads the pixels from disk (uncompress if necessary),
- *          - Transforms YBR pixels, if any, into RGB pixels
+ *          - Transforms YBR pixels, if any, into RGB pixels,
  *          - Transforms 3 planes R, G, B, if any, into a single RGB Plane
  *          - Transforms single Grey plane + 3 Palettes into a RGB Plane
  *          - Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
@@ -196,7 +258,7 @@ uint8_t *FileHelper::GetImageData()
       return 0;
    }
 
-   if ( HeaderInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
+   if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
    {
       return PixelReadConverter->GetRGB();
    }
@@ -254,11 +316,11 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
       return 0;
    }
 
-   if ( HeaderInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
+   if ( FileInternal->HasLUT() && PixelReadConverter->BuildRGBImage() )
    {
       if ( PixelReadConverter->GetRGBSize() > maxSize )
       {
-         gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
+         gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
          return 0;
       }
       memcpy( destination,
@@ -270,7 +332,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
    // Either no LUT conversion necessary or LUT conversion failed
    if ( PixelReadConverter->GetRawSize() > maxSize )
    {
-      gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize");
+      gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize");
       return 0;
    }
    memcpy( destination,
@@ -285,10 +347,12 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize)
  *          'image' Pixels are presented as C-like 2D arrays : line per line.
  *          'volume'Pixels are presented as C-like 3D arrays : plane per plane 
  * \warning Since the pixels are not copied, it is the caller's responsability
- *          not to deallocate it's data before gdcm uses them (e.g. with
- *          the Write() method.
- * @param inData user supplied pixel area
- * @param expectedSize total image size, in Bytes
+ *          not to deallocate its data before gdcm uses them (e.g. with
+ *          the Write() method )
+ * @param inData user supplied pixel area (uint8_t* is just for the compiler.
+ *               user is allowed to pass any kind of pixelsn since the size is
+ *               given in bytes) 
+ * @param expectedSize total image size, *in Bytes*
  *
  * @return boolean
  */
@@ -298,17 +362,22 @@ void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize)
 }
 
 /**
- * \brief   Set the image datas defined by the user
- * \warning When writting the file, this datas are get as default datas to write
+ * \brief   Set the image data defined by the user
+ * \warning When writting the file, this data are get as default data to write
+ * @param inData user supplied pixel area (uint8_t* is just for the compiler.
+ *               user is allowed to pass any kind of pixelsn since the size is
+ *               given in bytes) 
+ * @param expectedSize total image size, *in Bytes*
  */
-void FileHelper::SetUserData(uint8_t *data, size_t expectedSize)
+void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize)
 {
-   PixelWriteConverter->SetUserData(data,expectedSize);
+   PixelWriteConverter->SetUserData(inData,expectedSize);
 }
 
 /**
- * \brief   Get the image datas defined by the user
- * \warning When writting the file, this datas are get as default data to write
+ * \brief   Get the image data defined by the user
+ * \warning When writting the file, this data are get as default data to write
  */
 uint8_t *FileHelper::GetUserData()
 {
@@ -317,7 +386,7 @@ uint8_t *FileHelper::GetUserData()
 
 /**
  * \brief   Get the image data size defined by the user
- * \warning When writting the file, this datas are get as default data to write
+ * \warning When writting the file, this data are get as default data to write
  */
 size_t FileHelper::GetUserDataSize()
 {
@@ -325,7 +394,7 @@ size_t FileHelper::GetUserDataSize()
 }
 
 /**
- * \brief   Get the image datas from the file.
+ * \brief   Get the image data from the file.
  *          If a LUT is found, the data are expanded to be RGB
  */
 uint8_t *FileHelper::GetRGBData()
@@ -343,8 +412,8 @@ size_t FileHelper::GetRGBDataSize()
 }
 
 /**
- * \brief   Get the image datas from the file.
- *          If a LUT is found, the datas are not expanded !
+ * \brief   Get the image data from the file.
+ *          If a LUT is found, the data are not expanded !
  */
 uint8_t *FileHelper::GetRawData()
 {
@@ -360,6 +429,14 @@ size_t FileHelper::GetRawDataSize()
    return PixelReadConverter->GetRawSize();
 }
 
+/**
+ * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
+ */
+uint8_t* FileHelper::GetLutRGBA()
+{
+   return PixelReadConverter->GetLutRGBA();
+}
+
 /**
  * \brief Writes on disk A SINGLE Dicom file
  *        NO test is performed on  processor "Endiannity".
@@ -368,13 +445,12 @@ size_t FileHelper::GetRawDataSize()
  *                 (any already existing file is over written)
  * @return false if write fails
  */
-
 bool FileHelper::WriteRawData(std::string const &fileName)
 {
   std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
    if (!fp1)
    {
-      gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str());
+      gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str());
       return false;
    }
 
@@ -508,7 +584,7 @@ bool FileHelper::Write(std::string const &fileName)
    bool check = CheckWriteIntegrity();
    if(check)
    {
-      check = HeaderInternal->Write(fileName,WriteType);
+      check = FileInternal->Write(fileName,WriteType);
    }
 
    RestoreWrite();
@@ -517,7 +593,7 @@ bool FileHelper::Write(std::string const &fileName)
    // --------------------------------------------------------------
    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
    // 
-   // ...and we restore the Header to be Dicom Compliant again 
+   // ...and we restore the header to be Dicom Compliant again 
    // just after writting
    RestoreWriteOfLibido();
    // ----------------- End of Special Patch ----------------
@@ -525,103 +601,33 @@ bool FileHelper::Write(std::string const &fileName)
    return check;
 }
 
-/**
- * \brief   Accesses an existing DocEntry (i.e. a Dicom Element)
- *          through it's (group, element) and modifies it's content with
- *          the given value.
- * @param   content new value (string) to substitute with
- * @param   group     group number of the Dicom Element to modify
- * @param   elem element number of the Dicom Element to modify
- */
-bool FileHelper::SetEntry(std::string const &content,
-                    uint16_t group, uint16_t elem)
-{ 
-   return HeaderInternal->SetEntry(content,group,elem);
-}
-
-
-/**
- * \brief   Accesses an existing DocEntry (i.e. a Dicom Element)
- *          through it's (group, element) and modifies it's content with
- *          the given value.
- * @param   content new value (void*  -> uint8_t*) to substitute with
- * @param   lgth new value length
- * @param   group     group number of the Dicom Element to modify
- * @param   elem element number of the Dicom Element to modify
- */
-bool FileHelper::SetEntry(uint8_t *content, int lgth,
-                    uint16_t group, uint16_t elem)
-{
-   return HeaderInternal->SetEntry(content,lgth,group,elem);
-}
-
-/**
- * \brief   Modifies the value of a given Doc Entry (Dicom Element)
- *          when it exists. Create it with the given value when unexistant.
- * @param   content (string) Value to be set
- * @param   group   Group number of the Entry 
- * @param   elem  Element number of the Entry
- * \return  pointer to the modified/created Header Entry (NULL when creation
- *          failed).
- */ 
-bool FileHelper::ReplaceOrCreate(std::string const &content,
-                           uint16_t group, uint16_t elem)
-{
-   return HeaderInternal->ReplaceOrCreate(content,group,elem) != NULL;
-}
-
-/*
- * \brief   Modifies the value of a given Header Entry (Dicom Element)
- *          when it exists. Create it with the given value when unexistant.
- *          A copy of the binArea is made to be kept in the Document.
- * @param   binArea (binary) value to be set
- * @param   group   Group number of the Entry 
- * @param   elem  Element number of the Entry
- * \return  pointer to the modified/created Header Entry (NULL when creation
- *          failed).
- */
-bool FileHelper::ReplaceOrCreate(uint8_t *binArea, int lgth,
-                           uint16_t group, uint16_t elem)
-{
-   return HeaderInternal->ReplaceOrCreate(binArea,lgth,group,elem) != NULL;
-}
-
-/**
- * \brief Access to the underlying \ref PixelReadConverter RGBA LUT
- */
-uint8_t* FileHelper::GetLutRGBA()
-{
-   return PixelReadConverter->GetLutRGBA();
-}
-
 //-----------------------------------------------------------------------------
 // Protected
-
 /**
  * \brief Check the write integrity
  *
  * The tests made are :
  *  - verify the size of the image to write with the possible write
  *    when the user set an image data
- * @return true if the check successfulls
+ * @return true if check is successfull
  */
 bool FileHelper::CheckWriteIntegrity()
 {
    if(PixelWriteConverter->GetUserData())
    {
-      int numberBitsAllocated = HeaderInternal->GetBitsAllocated();
+      int numberBitsAllocated = FileInternal->GetBitsAllocated();
       if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 )
       {
          numberBitsAllocated = 16;
       }
 
-      size_t decSize = HeaderInternal->GetXSize()
-                    * HeaderInternal->GetYSize() 
-                    * HeaderInternal->GetZSize()
+      size_t decSize = FileInternal->GetXSize()
+                    * FileInternal->GetYSize() 
+                    * FileInternal->GetZSize()
                     * ( numberBitsAllocated / 8 )
-                    * HeaderInternal->GetSamplesPerPixel();
+                    * FileInternal->GetSamplesPerPixel();
       size_t rgbSize = decSize;
-      if( HeaderInternal->HasLUT() )
+      if( FileInternal->HasLUT() )
          rgbSize = decSize * 3;
 
       switch(WriteMode)
@@ -629,16 +635,18 @@ bool FileHelper::CheckWriteIntegrity()
          case WMODE_RAW :
             if( decSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size is incorrect (Raw)" << decSize 
-                    << " / " << PixelWriteConverter->GetUserDataSize() );
+               gdcmWarningMacro( "Data size (Raw) is incorrect. Should be " 
+                           << decSize << " / Found :" 
+                           << PixelWriteConverter->GetUserDataSize() );
                return false;
             }
             break;
          case WMODE_RGB :
             if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size is incorrect (RGB)" << decSize
-                   << " / " << PixelWriteConverter->GetUserDataSize() );
+               gdcmWarningMacro( "Data size (RGB) is incorrect. Should be " 
+                          << decSize << " / Found " 
+                          << PixelWriteConverter->GetUserDataSize() );
                return false;
             }
             break;
@@ -649,19 +657,19 @@ bool FileHelper::CheckWriteIntegrity()
 }
 
 /**
- * \brief   
+ * \brief Update the File to write RAW datas  
  */ 
 void FileHelper::SetWriteToRaw()
 {
-   if( HeaderInternal->GetNumberOfScalarComponents() == 3 
-    && !HeaderInternal->HasLUT())
+   if( FileInternal->GetNumberOfScalarComponents() == 3 
+    && !FileInternal->HasLUT())
    {
       SetWriteToRGB();
    } 
    else
    {
       ValEntry *photInt = CopyValEntry(0x0028,0x0004);
-      if(HeaderInternal->HasLUT())
+      if(FileInternal->HasLUT())
       {
          photInt->SetValue("PALETTE COLOR ");
       }
@@ -673,8 +681,13 @@ void FileHelper::SetWriteToRaw()
       PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
                                        PixelReadConverter->GetRawSize());
 
+      std::string vr = "OB";
+      if( FileInternal->GetBitsAllocated()>8 )
+         vr = "OW";
+      if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
+         vr = "OB";
       BinEntry *pixel = 
-         CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
       pixel->SetValue(GDCM_BINLOADED);
       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
       pixel->SetLength(PixelWriteConverter->GetDataSize());
@@ -684,13 +697,12 @@ void FileHelper::SetWriteToRaw()
    }
 }
 
-
 /**
- * \brief   
+ * \brief Update the File to write RGB datas  
  */ 
 void FileHelper::SetWriteToRGB()
 {
-   if(HeaderInternal->GetNumberOfScalarComponents()==3)
+   if(FileInternal->GetNumberOfScalarComponents()==3)
    {
       PixelReadConverter->BuildRGBImage();
       
@@ -714,8 +726,13 @@ void FileHelper::SetWriteToRGB()
                                           PixelReadConverter->GetRawSize());
       }
 
+      std::string vr = "OB";
+      if( FileInternal->GetBitsAllocated()>8 )
+         vr = "OW";
+      if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
+         vr = "OB";
       BinEntry *pixel = 
-         CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+         CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr);
       pixel->SetValue(GDCM_BINLOADED);
       pixel->SetBinArea(PixelWriteConverter->GetData(),false);
       pixel->SetLength(PixelWriteConverter->GetDataSize());
@@ -736,7 +753,7 @@ void FileHelper::SetWriteToRGB()
       // For old ACR-NEMA
       // Thus, we have a RGB image and the bits allocated = 24 and 
       // samples per pixels = 1 (in the read file)
-      if(HeaderInternal->GetBitsAllocated()==24) 
+      if(FileInternal->GetBitsAllocated()==24) 
       {
          ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100);
          bitsAlloc->SetValue("8 ");
@@ -759,14 +776,14 @@ void FileHelper::SetWriteToRGB()
 }
 
 /**
- * \brief   
+ * \brief Restore the File write mode  
  */ 
 void FileHelper::RestoreWrite()
 {
    Archive->Restore(0x0028,0x0002);
    Archive->Restore(0x0028,0x0004);
    Archive->Restore(0x0028,0x0006);
-   Archive->Restore(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
+   Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel());
 
    // For old ACR-NEMA (24 bits problem)
    Archive->Restore(0x0028,0x0100);
@@ -783,7 +800,7 @@ void FileHelper::RestoreWrite()
 }
 
 /**
- * \brief   
+ * \brief Set in the File the write type to ACR
  */ 
 void FileHelper::SetWriteFileTypeToACR()
 {
@@ -791,7 +808,7 @@ void FileHelper::SetWriteFileTypeToACR()
 }
 
 /**
- * \brief   
+ * \brief Set in the File the write type to Explicit VR   
  */ 
 void FileHelper::SetWriteFileTypeToExplicitVR()
 {
@@ -805,7 +822,7 @@ void FileHelper::SetWriteFileTypeToExplicitVR()
 }
 
 /**
- * \brief   
+ * \brief Set in the File the write type to Implicit VR   
  */ 
 void FileHelper::SetWriteFileTypeToImplicitVR()
 {
@@ -820,19 +837,22 @@ void FileHelper::SetWriteFileTypeToImplicitVR()
 
 
 /**
- * \brief   
+ * \brief Restore in the File the write type
  */ 
 void FileHelper::RestoreWriteFileType()
 {
    Archive->Restore(0x0002,0x0010);
 }
 
+/**
+ * \brief Set the Write not to Libido format
+ */ 
 void FileHelper::SetWriteToLibido()
 {
    ValEntry *oldRow = dynamic_cast<ValEntry *>
-                (HeaderInternal->GetDocEntry(0x0028, 0x0010));
+                (FileInternal->GetDocEntry(0x0028, 0x0010));
    ValEntry *oldCol = dynamic_cast<ValEntry *>
-                (HeaderInternal->GetDocEntry(0x0028, 0x0011));
+                (FileInternal->GetDocEntry(0x0028, 0x0011));
    
    if( oldRow && oldCol )
    {
@@ -857,12 +877,12 @@ void FileHelper::SetWriteToLibido()
 }
 
 /**
- * \brief   
+ * \brief Set the Write not to No Libido format
  */ 
 void FileHelper::SetWriteToNoLibido()
 {
    ValEntry *recCode = dynamic_cast<ValEntry *>
-                (HeaderInternal->GetDocEntry(0x0008,0x0010));
+                (FileInternal->GetDocEntry(0x0008,0x0010));
    if( recCode )
    {
       if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" )
@@ -875,7 +895,7 @@ void FileHelper::SetWriteToNoLibido()
 }
 
 /**
- * \brief   
+ * \brief Restore the Write format
  */ 
 void FileHelper::RestoreWriteOfLibido()
 {
@@ -884,19 +904,26 @@ void FileHelper::RestoreWriteOfLibido()
    Archive->Restore(0x0008,0x0010);
 }
 
+/**
+ * \brief Copy a ValEntry content
+ * @param   group   Group number of the Entry 
+ * @param   elem  Element number of the Entry
+ * \return  pointer to the modified/created Val Entry (NULL when creation
+ *          failed).
+ */ 
 ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
 {
-   DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem);
+   DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
    ValEntry *newE;
 
-   if(oldE)
+   if( oldE )
    {
       newE = new ValEntry(oldE->GetDictEntry());
       newE->Copy(oldE);
    }
    else
    {
-      newE = GetHeader()->NewValEntry(group,elem);
+      newE = GetFile()->NewValEntry(group,elem);
    }
 
    return newE;
@@ -905,47 +932,50 @@ ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem)
 /**
  * \brief   Modifies the value of a given Bin Entry (Dicom Element)
  *          when it exists. Create it with the given value when unexistant.
- * @param   content (string) Value to be set
  * @param   group   Group number of the Entry 
  * @param   elem  Element number of the Entry
  * \return  pointer to the modified/created Bin Entry (NULL when creation
  *          failed).
  */ 
-BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem)
+BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem,const std::string &vr)
 {
-   DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem);
+   DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
    BinEntry *newE;
 
-   if(oldE)
+   if( oldE )
+      if( oldE->GetVR()!=vr )
+         oldE = NULL;
+
+   if( oldE )
    {
       newE = new BinEntry(oldE->GetDictEntry());
       newE->Copy(oldE);
    }
    else
    {
-      newE = GetHeader()->NewBinEntry(group,elem);
+      newE = GetFile()->NewBinEntry(group,elem,vr);
    }
 
    return newE;
 }
 
 //-----------------------------------------------------------------------------
-// Protected
+// Private
 /**
  * \brief Factorization for various forms of constructors.
  */
-void FileHelper::Initialise()
+void FileHelper::Initialize()
 {
    WriteMode = WMODE_RAW;
    WriteType = ExplicitVR;
 
    PixelReadConverter = new PixelReadConvert;
    PixelWriteConverter = new PixelWriteConvert;
-   Archive = new DocEntryArchive( HeaderInternal );
+   Archive = new DocEntryArchive( FileInternal );
 
-   if ( HeaderInternal->IsReadable() )
+   if ( FileInternal->IsReadable() )
    {
-      PixelReadConverter->GrabInformationsFromHeader( HeaderInternal );
+      PixelReadConverter->GrabInformationsFromFile( FileInternal );
    }
 }
 
@@ -958,15 +988,15 @@ uint8_t *FileHelper::GetRaw()
    if ( ! raw )
    {
       // The Raw image migth not be loaded yet:
-      std::ifstream *fp = HeaderInternal->OpenFile();
+      std::ifstream *fp = FileInternal->OpenFile();
       PixelReadConverter->ReadAndDecompressPixelData( fp );
       if(fp) 
-         HeaderInternal->CloseFile();
+         FileInternal->CloseFile();
 
       raw = PixelReadConverter->GetRaw();
       if ( ! raw )
       {
-         gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong.");
+         gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong.");
          return 0;
       }
    }
@@ -975,8 +1005,15 @@ uint8_t *FileHelper::GetRaw()
 }
 
 //-----------------------------------------------------------------------------
-// Private
+// Print
+void FileHelper::Print(std::ostream &os, std::string const &)
+{
+   FileInternal->SetPrintLevel(PrintLevel);
+   FileInternal->Print(os);
+
+   PixelReadConverter->SetPrintLevel(PrintLevel);
+   PixelReadConverter->Print(os);
+}
 
 //-----------------------------------------------------------------------------
 } // end namespace gdcm
-