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
namespace gdcm
{
+//-----------------------------------------------------------------------------
static const char *TransferSyntaxStrings[] = {
// Implicit VR Little Endian
"1.2.840.10008.1.2",
// Unknown
"Unknown Transfer Syntax"
};
-
+
//-----------------------------------------------------------------------------
// Refer to Document::CheckSwap()
const unsigned int Document::HEADER_LENGTH_TO_READ = 256;
* (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
* UpdateGroupLength(true,ACR);
*/
- ElementSet::Write(fp, filetype); // This one is recursive
-
+ ElementSet::WriteContent(fp, filetype); // This one is recursive
}
/**
return true;
}
+std::string Document::GetTransferSyntaxValue(TransferSyntaxType type)
+{
+ return TransferSyntaxStrings[type];
+}
+
//-----------------------------------------------------------------------------
// Protected
* @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
( ((TagHT.equal_range(key)).first)->second )->SetLength(l);
return true ;
-}
+}*/
/**
* \brief Gets (from Header) the offset of a 'non string' element value
* @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)
return 0;
}
return entry->GetOffset();
-}
+}*/
/**
* \brief Gets (from Header) a 'non string' element value
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.");
- }*/
}
/**
*/
void Document::LoadEntryBinArea(BinEntry* element)
{
+ if(element->GetBinArea())
+ return;
+
bool openFile = !Fp;
if(openFile)
OpenFile();
* @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);
}
return false;
-}
+}*/
/**
* \brief Update the entries with the shadow dictionary.
*/
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);
+ }
}
/**
}
//////////////////// 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
// representation of a 32 bits integer. Hence the following dirty
// trick :
s32 = *((uint32_t *)(entCur));
-
+
switch( s32 )
{
case 0x00040000 :