2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
9 #include "gdcmException.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmDocEntry.h"
15 #include "gdcmDocEntrySet.h"
16 #include "gdcmElementSet.h"
21 //-----------------------------------------------------------------------------
22 typedef std::string VRKey;
23 typedef std::string VRAtr;
24 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
26 //-----------------------------------------------------------------------------
28 * \brief used by both gdcmHeader and gdcmDicomDir
30 class GDCM_EXPORT gdcmDocument : public gdcmElementSet
33 /// Public dictionary used to parse this header
36 /// \brief Optional "shadow dictionary" (private elements) used to parse
40 /// \brief Equals =1 if user wants to skip shadow groups while parsing
44 /// \brief Size threshold above which an element value will NOT be loaded
45 /// in memory (to avoid loading the image/volume itself). By default,
46 /// this upper bound is fixed to 1024 bytes (which might look reasonable
47 /// when one considers the definition of the various VR contents).
48 guint32 MaxSizeLoadEntry;
50 /// \brief Size threshold above which an element value will NOT be *printed*
51 /// in order no to polute the screen output. By default, this upper bound
52 /// is fixed to 64 bytes.
53 guint32 MaxSizePrintEntry;
56 /// Refering underlying filename.
59 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
60 /// Bad Little Endian) according to the processor Endianity and
61 /// what is written on disc.
64 /// File Pointer, opened during Header parsing.
67 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
70 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
71 static const unsigned int HEADER_LENGTH_TO_READ;
73 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
75 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
77 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
79 /// \todo Currently not used since collides with #define in
80 /// \ref gdcmDocEntry.cxx. See also
81 /// \ref gdcmDocument::SetMaxSizePrintEntry()
82 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
84 /// Will be set 1 if user asks to 'go inside' the 'sequences' (VR = "SQ")
87 /// \brief Amount of printed details for each Header Entry (Dicom Element):
88 /// 0 : stands for the least detail level.
95 // Canonical Printing method (see also gdcmDocument::SetPrintLevel)
96 // virtual void Print (std::ostream &os = std::cout);
99 // no more Print method for gdcmDocument (inherits from gdcmElementSet
100 // virtual void PrintEntry (std::ostream &os = std::cout)
101 // { return Print(os);};
103 // the 2 following will be merged
104 virtual void PrintPubDict (std::ostream &os = std::cout);
105 virtual void PrintShaDict (std::ostream &os = std::cout);
108 gdcmDict *GetPubDict(void);
109 gdcmDict *GetShaDict(void);
110 bool SetShaDict(gdcmDict *dict);
111 bool SetShaDict(DictKey dictName);
113 // Informations contained in the parser
114 virtual bool IsReadable(void);
115 bool IsImplicitVRLittleEndianTransferSyntax(void);
116 bool IsExplicitVRLittleEndianTransferSyntax(void);
117 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
118 bool IsExplicitVRBigEndianTransferSyntax(void);
119 FileType GetFileType(void);
121 // Read (used in gdcmFile, gdcmDicomDir)
122 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
123 bool CloseFile(void);
125 // Write (used in gdcmFile, gdcmDicomDir)
126 virtual bool Write(FILE *, FileType);
127 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
128 FILE *_fp, FileType type);
129 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
130 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
131 virtual bool WriteEntries(FILE *_fp,FileType type);
133 gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value,
134 guint16 Group, guint16 Elem);
135 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
137 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
138 void LoadVLEntry (gdcmDocEntry *entry);
141 guint16 SwapShort(guint16); // needed by gdcmFile
142 guint32 SwapLong(guint32); // needed by gdcmFile
143 guint16 UnswapShort(guint16); // needed by gdcmFile
144 guint32 UnswapLong(guint32); // needed by gdcmFile
147 // Constructor and destructor are protected to forbid end user
148 // to instanciate from this class gdcmDocument (only gdcmHeader and
149 // gdcmDicomDir are meaningfull).
150 gdcmDocument(bool exception_on_error = false);
151 gdcmDocument(const char *inFilename,
152 bool exception_on_error = false,
153 bool enable_sequences = false,
154 bool ignore_shadow = false);
155 virtual ~gdcmDocument(void);
157 void gdcmDocument::Parse7FE0 (void);
159 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
160 virtual std::string GetEntryByName (std::string tagName);
161 virtual std::string GetEntryVRByName (std::string tagName);
162 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
163 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
164 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
166 virtual bool SetEntryByName (std::string content, std::string tagName);
167 virtual bool SetEntryByNumber(std::string content,
168 guint16 group, guint16 element);
169 virtual bool SetEntryLengthByNumber(guint32 length,
170 guint16 group, guint16 element);
172 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
173 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
174 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
176 virtual void UpdateShaEntries(void);
179 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
180 gdcmDocEntry *GetDocEntryByName (std::string Name);
182 void LoadDocEntrySafe(gdcmDocEntry *);
185 //void UpdateGroupLength(bool SkipSequence = false,
186 // FileType type = ImplicitVR);
188 //void AddDocEntry (gdcmDocEntry *);
193 //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError);
194 // remplacé par ParseDES.
195 // What about exception_on_error ?
197 long ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
198 // long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
199 long ParseSQ(gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode);
201 void LoadDocEntry (gdcmDocEntry *);
202 void FindDocEntryLength(gdcmDocEntry *);
203 void FindDocEntryVR (gdcmDocEntry *);
204 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
206 std::string GetDocEntryValue (gdcmDocEntry *);
207 std::string GetDocEntryUnvalue(gdcmDocEntry *);
209 void SkipDocEntry (gdcmDocEntry *);
210 void SkipToNextDocEntry (gdcmDocEntry *);
212 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
213 bool IsDocEntryAnInteger (gdcmDocEntry *);
215 guint32 FindDocEntryLengthOB(void);
217 guint16 ReadInt16(void);
218 guint32 ReadInt32(void);
219 void SkipBytes(guint32);
221 void Initialise(void);
222 bool CheckSwap(void);
223 void SwitchSwapToBigEndian(void);
224 void SetMaxSizeLoadEntry(long);
225 void SetMaxSizePrintEntry(long);
227 // DictEntry related utilities
229 gdcmDictEntry *GetDictEntryByName (std::string Name);
230 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
231 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
233 std::string vr = "unkn",
234 std::string fourth = "unkn",
235 std::string name = "unkn");
236 //gdcmDictEntry *NewVirtualDictEntry(gdcmDocEntry *); // never defined
238 // DocEntry related utilities
240 gdcmDocEntry *ReadNextDocEntry (void);
241 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
243 gdcmDocEntry *NewDocEntryByName (std::string Name);
245 // Deprecated (Not used) --> commented out
246 //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName,
249 guint32 GenerateFreeTagKeyInGroup(guint16 group);
253 /// Accessor to \ref printLevel
254 void SetPrintLevel(int level) { printLevel = level; };
256 /// Accessor to \ref filename
257 inline std::string GetFileName(void) {return filename;}
259 /// Accessor to \ref filename
260 inline void SetFileName(char* fileName) {filename = fileName;}
262 /// Accessor to \ref gdcmElementSet::tagHT
263 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
265 /// Accessor to \ref gdcmDocument::listEntries
266 //inline ListTag &GetListEntry(void) { return listEntries; };
268 /// 'Swap code' accessor (see \ref sw )
269 inline int GetSwapCode(void) { return sw; }
272 inline FILE * GetFP(void) { return fp; }
276 //-----------------------------------------------------------------------------