1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2005/01/26 17:17:31 $
7 Version: $Revision: 1.102 $
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 #ifndef GDCMDOCUMENT_H
20 #define GDCMDOCUMENT_H
24 #include "gdcmElementSet.h"
25 #include "gdcmException.h"
38 //-----------------------------------------------------------------------------
40 * \brief Derived by both gdcm::File and gdcm::DicomDir
42 class GDCM_EXPORT Document : public ElementSet
45 // Informations contained in the gdcm::Document
46 virtual bool IsReadable();
47 FileType GetFileType();
49 std::string GetTransferSyntax();
52 virtual void PrintPubDict (std::ostream &os = std::cout);
53 virtual void PrintShaDict (std::ostream &os = std::cout);
57 bool SetShaDict(Dict* dict);
58 bool SetShaDict(DictKey const &dictName);
61 /// 'Swap code' accessor (see \ref SwapCode )
62 int GetSwapCode() { return SwapCode; }
63 // System access (meaning endian related !?)
64 uint16_t SwapShort(uint16_t); // needed by Document
65 uint32_t SwapLong(uint32_t); // needed by Document
66 uint16_t UnswapShort(uint16_t); // needed by Document
67 uint32_t UnswapLong(uint32_t); // needed by Document
69 // Ordering of Documents
70 bool operator<(Document &document);
74 /// Accessor to \ref Filename
75 const std::string &GetFileName() const { return Filename; }
76 /// Accessor to \ref Filename
77 void SetFileName(std::string const &fileName) { Filename = fileName; }
79 std::ifstream *OpenFile();
81 void WriteContent( std::ofstream *fp, FileType type );
85 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
86 virtual void LoadEntryBinArea(BinEntry *entry);
88 void LoadDocEntrySafe(DocEntry *entry);
90 /// Return the Transfer Syntax as a string
91 std::string GetTransferSyntaxName();
98 // Constructor and destructor are protected to forbid end user
99 // to instanciate from this class Document (only gdcm::File and
100 // gdcm::DicomDir are meaningfull).
102 Document( std::string const &filename );
105 uint16_t ReadInt16() throw ( FormatError );
106 uint32_t ReadInt32() throw ( FormatError );
107 void SkipBytes(uint32_t);
109 int ComputeGroup0002Length( FileType filetype );
112 /// Refering underlying filename.
113 std::string Filename;
115 /// \brief Swap code gives an information on the byte order of a
116 /// supposed to be an int32, as it's read on disc
117 /// (depending on the image Transfer Syntax *and* on the processor endianess)
118 /// as opposed as it should in memory to be dealt as an int32.
120 /// - a 'Little Endian' image, read with a little endian processor
121 /// will have a SwapCode= 1234 (the order is OK; nothing to do)
122 /// - a 'Little Endian' image, read with a big endian procesor
123 /// will have a SwapCode= 4321 (the order is wrong; int32 an int16 must be
125 /// note : values 2143, 4321, 3412 remain for the ACR-NEMA time, and
126 /// the well known 'Bad Big Endian' and 'Bad Little Endian' codes
129 ///\brief whether we already parsed group 0002 (Meta Elements)
130 bool Group0002Parsed;
132 ///\brief whether file has a DCM Preamble
135 /// File Pointer, opened during Document parsing.
138 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
141 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
142 static const unsigned int HEADER_LENGTH_TO_READ;
143 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
145 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
146 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
148 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
153 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
154 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
156 void LoadDocEntry (DocEntry *e);
157 void FindDocEntryLength (DocEntry *e) throw ( FormatError );
158 uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
159 std::string FindDocEntryVR();
160 bool CheckDocEntryVR (VRKey k);
162 std::string GetDocEntryValue (DocEntry *entry);
163 std::string GetDocEntryUnvalue(DocEntry *entry);
166 void SkipDocEntry (DocEntry *entry);
167 void SkipToNextDocEntry (DocEntry *entry);
169 void FixDocEntryFoundLength(DocEntry *entry,uint32_t l);
170 bool IsDocEntryAnInteger (DocEntry *entry);
174 void SwitchByteSwapCode();
175 void SetMaxSizeLoadEntry(long);
176 void SetMaxSizePrintEntry(long);
178 // DocEntry related utilities
179 DocEntry *ReadNextDocEntry();
181 void HandleBrokenEndian (uint16_t &group, uint16_t &elem);
182 void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
185 /// Public dictionary used to parse this header
187 /// \brief Optional "shadow dictionary" (private elements) used to parse
191 /// \brief Size threshold above which an element value will NOT be loaded
192 /// in memory (to avoid loading the image/volume itself). By default,
193 /// this upper bound is fixed to 1024 bytes (which might look reasonable
194 /// when one considers the definition of the various VR contents).
195 uint32_t MaxSizeLoadEntry;
197 /// \brief Size threshold above which an element value will NOT be *printed*
198 /// in order no to polute the screen output. By default, this upper bound
199 /// is fixed to 64 bytes.
200 uint32_t MaxSizePrintEntry;
202 // uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
203 // void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
204 // DocEntrySet *set );
207 } // end namespace gdcm
209 //-----------------------------------------------------------------------------