1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirMeta.cxx,v $
6 Date: $Date: 2005/11/03 17:40:22 $
7 Version: $Revision: 1.33 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDicomDirMeta.h"
20 #include "gdcmDocument.h"
21 #include "gdcmDocEntry.h"
22 #include "gdcmGlobal.h"
24 #include "gdcmDataEntry.h"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
32 DicomDirMeta::DicomDirMeta(bool empty):
37 ListDicomDirStudyElem const &elemList =
38 Global::GetDicomDirElements()->GetDicomDirMetaElements();
44 * \brief Canonical destructor.
46 DicomDirMeta::~DicomDirMeta()
50 //-----------------------------------------------------------------------------
53 * \brief Writes the Meta Elements
54 * @param fp ofstream to write to
55 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
58 void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype)
60 // 'File Meta Information Version'
62 uint8_t fmiv[2] = {0x02,0x00};
63 //SetEntryBinArea(fmiv, 0x0002,0x0001, 2);
64 DataEntry *e00002_0001 = GetDataEntry(0x0002,0x0001);
65 e00002_0001->CopyBinArea(fmiv, 2);
67 // 'Media Storage SOP Instance UID'
68 DataEntry *e00002_0003 = GetDataEntry(0x0002,0x0003);
69 e00002_0003->SetString(Util::CreateUniqueUID());
71 // 'Implementation Class UID'
72 DataEntry *e00002_0012 = GetDataEntry(0x0002,0x0012);
73 e00002_0012->SetString(Util::CreateUniqueUID());
75 // Entry : 0002|0000 = group length -> recalculated
76 DataEntry *e0000 = GetDataEntry(0x0002,0x0000);
77 std::ostringstream sLen;
78 sLen << ComputeGroup0002Length( );
79 e0000->SetString(sLen.str());
81 for (ListDocEntry::iterator i = DocEntries.begin();
82 i != DocEntries.end();
85 (*i)->WriteContent(fp, filetype);
90 * \brief Re-computes the length of the Dicom group 0002 (in the DicomDirMeta)
92 int DicomDirMeta::ComputeGroup0002Length( )
98 bool found0002 = false;
100 // for each Tag in the DicomDirMeta
101 DocEntry *entry = GetFirstEntry();
104 gr = entry->GetGroup();
110 if ( entry->GetElement() != 0x0000 )
118 groupLength += 2 + 2 + 4 + entry->GetLength();
124 entry = GetNextEntry();
129 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
135 //-----------------------------------------------------------------------------
138 * \brief Prints the Meta Elements
139 * @param os ostream to write to
140 * @param indent Indentation string to be prepended during printing
142 void DicomDirMeta::Print(std::ostream &os, std::string const & )
144 os << "META" << std::endl;
145 // warning : META doesn't behave exactly like a Objet
146 for (ListDocEntry::iterator i = DocEntries.begin();
147 i != DocEntries.end();
150 (*i)->SetPrintLevel(PrintLevel);
156 //-----------------------------------------------------------------------------
157 } // end namespace gdcm