1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/08/31 14:24:47 $
7 Version: $Revision: 1.32 $
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.htm 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
22 #include "gdcmCommon.h"
25 #include "gdcmException.h"
26 #include "gdcmDictSet.h"
27 #include "gdcmDocEntry.h"
33 #include "gdcmDocEntrySet.h"
34 #include "gdcmElementSet.h"
39 //-----------------------------------------------------------------------------
41 * \brief Derived by both gdcmHeader and gdcmDicomDir
43 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
45 friend class gdcmFile;
47 /// Public dictionary used to parse this header
50 /// \brief Optional "shadow dictionary" (private elements) used to parse
54 /// \brief Equals =1 if user wants to skip shadow groups while parsing
58 /// \brief Size threshold above which an element value will NOT be loaded
59 /// in memory (to avoid loading the image/volume itself). By default,
60 /// this upper bound is fixed to 1024 bytes (which might look reasonable
61 /// when one considers the definition of the various VR contents).
62 uint32_t MaxSizeLoadEntry;
64 /// \brief Size threshold above which an element value will NOT be *printed*
65 /// in order no to polute the screen output. By default, this upper bound
66 /// is fixed to 64 bytes.
67 uint32_t MaxSizePrintEntry;
70 /// Refering underlying filename.
73 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
74 /// Bad Little Endian) according to the processor Endianity and
75 /// what is written on disc.
78 /// File Pointer, opened during Header parsing.
81 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
84 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
85 static const unsigned int HEADER_LENGTH_TO_READ;
87 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
89 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
91 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
93 /// \todo Currently not used since collides with #define in
94 /// \ref gdcmDocEntry.cxx. See also
95 /// \ref gdcmDocument::SetMaxSizePrintEntry()
96 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
98 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
101 /// \brief Amount of printed details for each Header Entry (Dicom Element):
102 /// 0 : stands for the least detail level.
106 // the 2 following will be merged
107 virtual void PrintPubDict (std::ostream &os = std::cout);
108 virtual void PrintShaDict (std::ostream &os = std::cout);
111 gdcmDict *GetPubDict();
112 gdcmDict *GetShaDict();
113 bool SetShaDict(gdcmDict *dict);
114 bool SetShaDict(DictKey const & dictName);
116 // Informations contained in the parser
117 virtual bool IsReadable();
118 bool IsGivenTransferSyntax(std::string const & syntaxToCheck);
119 bool IsImplicitVRLittleEndianTransferSyntax();
120 bool IsExplicitVRLittleEndianTransferSyntax();
121 bool IsDeflatedExplicitVRLittleEndianTransferSyntax();
122 bool IsExplicitVRBigEndianTransferSyntax();
123 bool IsJPEGBaseLineProcess1TransferSyntax();
124 bool IsJPEGExtendedProcess2_4TransferSyntax();
125 bool IsJPEGExtendedProcess3_5TransferSyntax();
126 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax();
127 bool IsRLELossLessTransferSyntax();
128 bool IsJPEGLossless();
132 FileType GetFileType();
137 void Write(FILE* fp, FileType type);
139 gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value,
140 uint16_t group, uint16_t elem);
142 gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth,
143 uint16_t group, uint16_t elem);
144 gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
145 bool ReplaceIfExistByNumber ( std::string const & value,
149 virtual void* LoadEntryVoidArea(uint16_t group, uint16_t elem);
150 virtual void* LoadEntryVoidArea(gdcmBinEntry* entry);
152 // System access (meaning endian related !?)
153 uint16_t SwapShort(uint16_t); // needed by gdcmFile
154 uint32_t SwapLong(uint32_t); // needed by gdcmFile
155 uint16_t UnswapShort(uint16_t); // needed by gdcmFile
156 uint32_t UnswapLong(uint32_t); // needed by gdcmFile
159 // Constructor and destructor are protected to forbid end user
160 // to instanciate from this class gdcmDocument (only gdcmHeader and
161 // gdcmDicomDir are meaningfull).
163 gdcmDocument( std::string const & filename );
164 virtual ~gdcmDocument();
168 int CheckIfEntryExistByNumber(uint16_t group, uint16_t elem ); // int !
170 virtual std::string GetEntryByName (TagName const & tagName);
171 virtual std::string GetEntryVRByName (TagName const & tagName);
172 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
173 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
174 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
176 virtual bool SetEntryByName (std::string const & content,
177 std::string const & tagName);
178 virtual bool SetEntryByNumber(std::string const & content,
179 uint16_t group, uint16_t element);
180 virtual bool SetEntryByNumber(void *content, int lgth,
181 uint16_t group, uint16_t element);
182 virtual bool SetEntryLengthByNumber(uint32_t length,
183 uint16_t group, uint16_t element);
185 virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
186 virtual void* GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem);
187 virtual bool SetEntryVoidAreaByNumber(void* a, uint16_t group,
190 virtual void UpdateShaEntries();
193 gdcmDocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
194 gdcmDocEntry* GetDocEntryByName (std::string const & tagName);
196 gdcmValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
197 gdcmBinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
199 void LoadDocEntrySafe(gdcmDocEntry* entry);
203 long ParseDES(gdcmDocEntrySet *set,long offset, long l_max, bool delim_mode);
204 long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
206 void LoadDocEntry (gdcmDocEntry *);
207 void FindDocEntryLength(gdcmDocEntry *) throw ( gdcmFormatError );
208 void FindDocEntryVR (gdcmDocEntry *);
209 bool CheckDocEntryVR (gdcmDocEntry *, gdcmVRKey);
211 std::string GetDocEntryValue (gdcmDocEntry *);
212 std::string GetDocEntryUnvalue(gdcmDocEntry *);
214 void SkipDocEntry (gdcmDocEntry *);
215 void SkipToNextDocEntry (gdcmDocEntry *);
217 void FixDocEntryFoundLength(gdcmDocEntry *, uint32_t);
218 bool IsDocEntryAnInteger (gdcmDocEntry *);
220 uint32_t FindDocEntryLengthOB() throw( gdcmFormatUnexpected );
222 uint16_t ReadInt16() throw ( gdcmFormatError );
223 uint32_t ReadInt32() throw ( gdcmFormatError );
224 void SkipBytes(uint32_t);
225 bool ReadTag(uint16_t, uint16_t);
226 uint32_t ReadTagLength(uint16_t, uint16_t);
230 void SwitchSwapToBigEndian();
231 void SetMaxSizeLoadEntry(long);
232 void SetMaxSizePrintEntry(long);
234 // DocEntry related utilities
235 gdcmDocEntry* ReadNextDocEntry();
237 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
241 /// Accessor to \ref PrintLevel
242 void SetPrintLevel(int level) { PrintLevel = level; }
244 /// Accessor to \ref Filename
245 const std::string &GetFileName() { return Filename; }
247 /// Accessor to \ref Filename
248 void SetFileName(std::string const & fileName) { Filename = fileName; }
250 /// 'Swap code' accessor (see \ref SwapCode )
251 int GetSwapCode() { return SwapCode; }
254 FILE * GetFP() { return Fp; }
256 bool operator<(gdcmDocument &document);
260 //-----------------------------------------------------------------------------