]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
* Remove some useless methods in gdcm::Document, gdcm::Header and gdcm::File
[gdcm.git] / src / gdcmDocument.cxx
index c5d391396cc11c60b7b040b24e07c9d19869ce90..a26f291edc4ebf3b1392c682f2330db799bb2809 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/24 11:17:47 $
-  Version:   $Revision: 1.136 $
+  Date:      $Date: 2004/11/26 10:55:04 $
+  Version:   $Revision: 1.142 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,6 +36,7 @@
 
 namespace gdcm 
 {
+//-----------------------------------------------------------------------------
 static const char *TransferSyntaxStrings[] =  {
   // Implicit VR Little Endian
   "1.2.840.10008.1.2",
@@ -70,7 +71,7 @@ static const char *TransferSyntaxStrings[] =  {
   // Unknown
   "Unknown Transfer Syntax"
 };
-
+                                                                                
 //-----------------------------------------------------------------------------
 // Refer to Document::CheckSwap()
 const unsigned int Document::HEADER_LENGTH_TO_READ = 256;
@@ -481,41 +482,22 @@ bool Document::CloseFile()
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  * \return Always true.
  */
-void Document::Write(std::ofstream* fp, FileType filetype)
+void Document::WriteContent(std::ofstream* fp, FileType filetype)
 {
    /// \todo move the following lines (and a lot of others, to be written)
    /// to a future function CheckAndCorrectHeader  
    /// (necessary if user wants to write a DICOM V3 file
    /// starting from an  ACR-NEMA (V2)  Header
 
-   if (filetype == ImplicitVR) 
-   {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       in the following case we have to padd manually with a 0
-      
-      SetEntryLengthByNumber(18, 0x0002, 0x0010);
-   } 
-
-   if (filetype == ExplicitVR)
+   if ( filetype == ImplicitVR || filetype == ExplicitVR )
    {
-      std::string ts = 
-         Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
-      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); //LEAK
-      
-      /// \todo Refer to standards on page 21, chapter 6.2
-      ///       "Value representation": values with a VR of UI shall be
-      ///       padded with a single trailing null
-      ///       Dans le cas suivant on doit pader manuellement avec un 0
-      
-      SetEntryLengthByNumber(20, 0x0002, 0x0010);
+      // writing Dicom File Preamble
+      char filePreamble[128];
+      memset(filePreamble, 0, 128);
+      fp->write(filePreamble, 128);
+      fp->write("DICM", 4);
    }
-  
+
 /**
  * \todo rewrite later, if really usefull
  *       - 'Group Length' element is optional in DICOM
@@ -528,8 +510,7 @@ void Document::Write(std::ofstream* fp, FileType filetype)
  *    UpdateGroupLength(true,ACR);
  */
  
-   ElementSet::Write(fp, filetype); // This one is recursive
-
+   ElementSet::WriteContent(fp, filetype); // This one is recursive
 }
 
 /**
@@ -757,6 +738,11 @@ bool Document::ReplaceIfExistByNumber(std::string const & value,
    return true;
 } 
 
+std::string Document::GetTransferSyntaxValue(TransferSyntaxType type)
+{
+   return TransferSyntaxStrings[type];
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
@@ -993,7 +979,7 @@ bool Document::SetEntryByNumber(uint8_t*content, int lgth,
  * @param element element number of the Entry to modify
  * @return  true on success, false otherwise.
  */
-bool Document::SetEntryLengthByNumber(uint32_t l, 
+/*bool Document::SetEntryLengthByNumber(uint32_t l, 
                                       uint16_t group, uint16_t element) 
 {
    /// \todo use map methods, instead of multimap JPR
@@ -1009,7 +995,7 @@ bool Document::SetEntryLengthByNumber(uint32_t l,
    ( ((TagHT.equal_range(key)).first)->second )->SetLength(l); 
 
    return true ;
-}
+}*/
 
 /**
  * \brief   Gets (from Header) the offset  of a 'non string' element value 
@@ -1018,7 +1004,7 @@ bool Document::SetEntryLengthByNumber(uint32_t l,
  * @param elem  element number of the Entry
  * @return File Offset of the Element Value 
  */
-size_t Document::GetEntryOffsetByNumber(uint16_t group, uint16_t elem) 
+/*size_t Document::GetEntryOffsetByNumber(uint16_t group, uint16_t elem) 
 {
    DocEntry* entry = GetDocEntryByNumber(group, elem);
    if (!entry) 
@@ -1027,7 +1013,7 @@ size_t Document::GetEntryOffsetByNumber(uint16_t group, uint16_t elem)
       return 0;
    }
    return entry->GetOffset();
-}
+}*/
 
 /**
  * \brief   Gets (from Header) a 'non string' element value 
@@ -1070,30 +1056,6 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
       return;
 
    LoadEntryBinArea(binElement);
-/*   size_t o =(size_t)docElement->GetOffset();
-   Fp->seekg( o, std::ios_base::beg);
-   size_t l = docElement->GetLength();
-   uint8_t* a = new uint8_t[l];
-   if(!a)
-   {
-      dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
-      return;
-   }
-
-   // Read the value
-   Fp->read((char*)a, l);
-   if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1
-   {
-      delete[] a;
-      return;
-   }
-
-   // Set the value to the DocEntry
-   if( !SetEntryBinAreaByNumber( a, group, elem ) )
-   {
-      delete[] a;
-      dbg.Verbose(0, "Document::LoadEntryBinArea setting failed.");
-   }*/
 }
 
 /**
@@ -1103,6 +1065,9 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
  */
 void Document::LoadEntryBinArea(BinEntry* element) 
 {
+   if(element->GetBinArea())
+      return;
+
    bool openFile = !Fp;
    if(openFile)
       OpenFile();
@@ -1139,7 +1104,7 @@ void Document::LoadEntryBinArea(BinEntry* element)
  * @param   element Element number of the searched Dicom Element 
  * @return  
  */
-bool Document::SetEntryBinAreaByNumber(uint8_t* area,
+/*bool Document::SetEntryBinAreaByNumber(uint8_t* area,
                                        uint16_t group, uint16_t element) 
 {
    DocEntry* currentEntry = GetDocEntryByNumber(group, element);
@@ -1155,7 +1120,7 @@ bool Document::SetEntryBinAreaByNumber(uint8_t* area,
    }
 
    return false;
-}
+}*/
 
 /**
  * \brief   Update the entries with the shadow dictionary. 
@@ -1274,9 +1239,12 @@ ValEntry* Document::GetValEntryByNumber(uint16_t group, uint16_t element)
  */
 void Document::LoadDocEntrySafe(DocEntry * entry)
 {
-   long PositionOnEntry = Fp->tellg();
-   LoadDocEntry(entry);
-   Fp->seekg(PositionOnEntry, std::ios_base::beg);
+   if(Fp)
+   {
+      long PositionOnEntry = Fp->tellg();
+      LoadDocEntry(entry);
+      Fp->seekg(PositionOnEntry, std::ios_base::beg);
+   }
 }
 
 /**
@@ -1422,9 +1390,6 @@ void Document::ParseDES(DocEntrySet *set, long offset,
             }
 
          //////////////////// BinEntry or UNKOWN VR:
-/*            BinEntry* newBinEntry =
-               new BinEntry( newDocEntry->GetDictEntry() );  //LEAK
-            newBinEntry->Copy( newDocEntry );*/
             BinEntry* newBinEntry = new BinEntry( newDocEntry );  //LEAK
 
             // When "this" is a Document the Key is simply of the
@@ -2554,7 +2519,7 @@ bool Document::CheckSwap()
    // representation of a 32 bits integer. Hence the following dirty
    // trick :
    s32 = *((uint32_t *)(entCur));
-      
+
    switch( s32 )
    {
       case 0x00040000 :