2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmDocEntry.h"
17 #include "gdcmDocEntrySet.h"
18 #include "gdcmElementSet.h"
23 //-----------------------------------------------------------------------------
24 typedef std::string VRKey;
25 typedef std::string VRAtr;
26 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
28 //-----------------------------------------------------------------------------
30 * \brief Derived by both gdcmHeader and gdcmDicomDir
32 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
34 friend class gdcmFile;
36 /// Public dictionary used to parse this header
39 /// \brief Optional "shadow dictionary" (private elements) used to parse
43 /// \brief Equals =1 if user wants to skip shadow groups while parsing
47 /// \brief Size threshold above which an element value will NOT be loaded
48 /// in memory (to avoid loading the image/volume itself). By default,
49 /// this upper bound is fixed to 1024 bytes (which might look reasonable
50 /// when one considers the definition of the various VR contents).
51 guint32 MaxSizeLoadEntry;
53 /// \brief Size threshold above which an element value will NOT be *printed*
54 /// in order no to polute the screen output. By default, this upper bound
55 /// is fixed to 64 bytes.
56 guint32 MaxSizePrintEntry;
59 /// Refering underlying filename.
62 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
63 /// Bad Little Endian) according to the processor Endianity and
64 /// what is written on disc.
67 /// File Pointer, opened during Header parsing.
70 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
73 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
74 static const unsigned int HEADER_LENGTH_TO_READ;
76 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
78 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
80 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
82 /// \todo Currently not used since collides with #define in
83 /// \ref gdcmDocEntry.cxx. See also
84 /// \ref gdcmDocument::SetMaxSizePrintEntry()
85 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
87 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
90 /// \brief Amount of printed details for each Header Entry (Dicom Element):
91 /// 0 : stands for the least detail level.
95 // the 2 following will be merged
96 virtual void PrintPubDict (std::ostream &os = std::cout);
97 virtual void PrintShaDict (std::ostream &os = std::cout);
100 gdcmDict *GetPubDict(void);
101 gdcmDict *GetShaDict(void);
102 bool SetShaDict(gdcmDict *dict);
103 bool SetShaDict(DictKey dictName);
105 // Informations contained in the parser
106 virtual bool IsReadable(void);
107 bool IsGivenTransferSyntax(const std::string & SyntaxToCheck);
108 bool IsImplicitVRLittleEndianTransferSyntax(void);
109 bool IsExplicitVRLittleEndianTransferSyntax(void);
110 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
111 bool IsExplicitVRBigEndianTransferSyntax(void);
112 bool IsJPEGBaseLineProcess1TransferSyntax(void);
113 bool IsJPEGExtendedProcess2_4TransferSyntax(void);
114 bool IsJPEGExtendedProcess3_5TransferSyntax(void);
115 bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);
116 bool IsRLELossLessTransferSyntax(void);
117 bool IsJPEGLossless(void);
118 bool IsJPEG2000(void);
119 bool IsDicomV3(void);
121 FileType GetFileType(void);
123 // Read (used in gdcmFile, gdcmDicomDir)
124 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
125 bool CloseFile(void);
127 // Write (used in gdcmFile, gdcmDicomDir)
128 virtual bool Write(FILE *, FileType);
129 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
130 FILE *_fp, FileType type);
131 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
132 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
133 virtual bool WriteEntries(FILE *_fp,FileType type);
135 gdcmValEntry * ReplaceOrCreateByNumber(std::string Value,
136 guint16 Group, guint16 Elem);
138 gdcmBinEntry * ReplaceOrCreateByNumber(void *voidArea, int lgth,
139 guint16 Group, guint16 Elem);
140 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
142 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
143 void LoadVLEntry (gdcmDocEntry *entry);
146 guint16 SwapShort(guint16); // needed by gdcmFile
147 guint32 SwapLong(guint32); // needed by gdcmFile
148 guint16 UnswapShort(guint16); // needed by gdcmFile
149 guint32 UnswapLong(guint32); // needed by gdcmFile
152 // Constructor and destructor are protected to forbid end user
153 // to instanciate from this class gdcmDocument (only gdcmHeader and
154 // gdcmDicomDir are meaningfull).
155 gdcmDocument(bool exception_on_error = false);
156 gdcmDocument(const char *inFilename,
157 bool exception_on_error = false,
158 bool enable_sequences = false,
159 bool ignore_shadow = false);
160 virtual ~gdcmDocument(void);
162 void gdcmDocument::Parse7FE0 (void);
164 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
166 virtual std::string GetEntryByName (std::string tagName);
167 virtual std::string GetEntryVRByName (std::string tagName);
168 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
169 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
170 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
172 virtual bool SetEntryByName (std::string content, std::string tagName);
173 virtual bool SetEntryByNumber(std::string content,
174 guint16 group, guint16 element);
175 virtual bool SetEntryByNumber(void *content, int lgth,
176 guint16 group, guint16 element);
177 virtual bool SetEntryLengthByNumber(guint32 length,
178 guint16 group, guint16 element);
180 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
181 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
182 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
184 virtual void UpdateShaEntries(void);
187 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
188 gdcmDocEntry *GetDocEntryByName (std::string Name);
190 gdcmValEntry *GetValEntryByNumber (guint16 group, guint16 element);
191 gdcmBinEntry *GetBinEntryByNumber (guint16 group, guint16 element);
193 void LoadDocEntrySafe(gdcmDocEntry *);
197 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode);
198 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
200 void LoadDocEntry (gdcmDocEntry *);
201 void FindDocEntryLength(gdcmDocEntry *);
202 void FindDocEntryVR (gdcmDocEntry *);
203 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
205 std::string GetDocEntryValue (gdcmDocEntry *);
206 std::string GetDocEntryUnvalue(gdcmDocEntry *);
208 void SkipDocEntry (gdcmDocEntry *);
209 void SkipToNextDocEntry (gdcmDocEntry *);
211 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
212 bool IsDocEntryAnInteger (gdcmDocEntry *);
214 guint32 FindDocEntryLengthOB(void);
216 guint16 ReadInt16(void);
217 guint32 ReadInt32(void);
218 void SkipBytes(guint32);
219 guint32 ReadTagLength(guint16, guint16);
220 guint32 ReadItemTagLength(void);
221 guint32 ReadSequenceDelimiterTagLength(void);
223 void Initialise(void);
224 bool CheckSwap(void);
225 void SwitchSwapToBigEndian(void);
226 void SetMaxSizeLoadEntry(long);
227 void SetMaxSizePrintEntry(long);
229 // DictEntry related utilities
231 gdcmDictEntry *GetDictEntryByName (std::string Name);
232 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
233 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
235 std::string vr = "unkn",
236 std::string fourth = "unkn",
237 std::string name = "unkn");
238 // DocEntry related utilities
239 gdcmDocEntry *ReadNextDocEntry (void);
240 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
242 gdcmDocEntry *NewDocEntryByName (std::string Name);
244 gdcmValEntry *NewValEntryByNumber(guint16 group,
246 gdcmBinEntry *NewBinEntryByNumber(guint16 group,
248 guint32 GenerateFreeTagKeyInGroup(guint16 group);
252 /// Accessor to \ref printLevel
253 void SetPrintLevel(int level) { printLevel = level; };
255 /// Accessor to \ref filename
256 inline std::string GetFileName(void) {return filename;}
258 /// Accessor to \ref filename
259 inline void SetFileName(char* fileName) {filename = fileName;}
261 /// Accessor to \ref gdcmElementSet::tagHT
262 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
264 /// 'Swap code' accessor (see \ref sw )
265 inline int GetSwapCode(void) { return sw; }
268 inline FILE * GetFP(void) { return fp; }
270 bool operator<(gdcmDocument &document);
274 //-----------------------------------------------------------------------------