1 /*=========================================================================
4 Module: $RCSfile: gdcmDicomDirMeta.cxx,v $
6 Date: $Date: 2007/03/23 15:30:15 $
7 Version: $Revision: 1.36 $
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"
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
33 DicomDirMeta::DicomDirMeta(bool empty):
38 ListDicomDirStudyElem const &elemList =
39 Global::GetDicomDirElements()->GetDicomDirMetaElements();
45 * \brief Canonical destructor.
47 DicomDirMeta::~DicomDirMeta()
51 //-----------------------------------------------------------------------------
54 * \brief Writes the Meta Elements
55 * @param fp ofstream to write to
56 * @param filetype type of the file (ImplicitVR, ExplicitVR, ...)
59 void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype)
61 // 'File Meta Information Version'
63 uint8_t fmiv[2] = {0x02,0x00};
64 // FIXME : the following doesn't make the job (?!?)
65 //SetEntryBinArea(fmiv, 0x0002,0x0001, 2);
66 DataEntry *e00002_0001 = GetDataEntry(0x0002,0x0001);
67 e00002_0001->CopyBinArea(fmiv, 2);
69 // 'Media Storage SOP Instance UID'
70 DataEntry *e00002_0003 = GetDataEntry(0x0002,0x0003);
71 e00002_0003->SetString(Util::CreateUniqueUID());
73 // 'Implementation Class UID'
74 DataEntry *e00002_0012 = GetDataEntry(0x0002,0x0012);
75 e00002_0012->SetString(Util::CreateUniqueUID());
77 // Entry : 0002|0000 = group length -> recalculated
78 DataEntry *e0000 = GetDataEntry(0x0002,0x0000);
79 std::ostringstream sLen;
80 sLen << ComputeGroup0002Length( );
81 e0000->SetString(sLen.str());
83 for (ListDocEntry::iterator i = DocEntries.begin();
87 (*i)->WriteContent(fp, filetype);
92 * \brief Re-computes the length of the Dicom group 0002 (in the DicomDirMeta)
94 int DicomDirMeta::ComputeGroup0002Length( )
100 bool found0002 = false;
102 // for each Tag in the DicomDirMeta
103 DocEntry *entry = GetFirstEntry();
106 gr = entry->GetGroup();
112 if ( entry->GetElement() != 0x0000 )
120 groupLength += 2 + 2 + 4 + entry->GetLength();
126 entry = GetNextEntry();
131 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
140 * \brief Prints the Meta Elements
141 * @param os ostream to write to
142 * @param indent Indentation string to be prepended during printing
144 void DicomDirMeta::Print(std::ostream &os, std::string const & )
146 os << "META" << std::endl;
147 // warning : META doesn't behave exactly like a Objet
148 for (ListDocEntry::iterator i = DocEntries.begin();
149 i != DocEntries.end();
152 (*i)->SetPrintLevel(PrintLevel);
158 //-----------------------------------------------------------------------------
159 } // end namespace gdcm