2 //-----------------------------------------------------------------------------
6 #include "gdcmCommon.h"
10 #include "gdcmException.h"
11 #include "gdcmDictSet.h"
12 #include "gdcmDocEntry.h"
13 #include "gdcmDocEntrySet.h"
20 //-----------------------------------------------------------------------------
21 typedef std::string VRKey;
22 typedef std::string VRAtr;
23 typedef std::map<VRKey, VRAtr> VRHT; // Value Representation Hash Table
25 typedef std::map<TagKey, gdcmDocEntry *> TagDocEntryHT;
26 typedef std::pair<TagKey, gdcmDocEntry *> PairHT;
27 typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
28 /// for linking together the Elements
29 typedef std::list<gdcmDocEntry *> ListTag;
31 typedef std::string GroupKey;
32 typedef std::map<GroupKey, int> GroupHT;
34 //-----------------------------------------------------------------------------
36 * \brief used by both gdcmHeader and gdcmDicomDir
38 class GDCM_EXPORT gdcmDocument
41 /// Public dictionary used to parse this header
44 /// \brief Optional "shadow dictionary" (private elements) used to parse
48 /// \brief Equals =1 if user wants to skip shadow groups while parsing
52 /// \brief Size threshold above which an element value will NOT be loaded
53 /// in memory (to avoid loading the image/volume itself). By default,
54 /// this upper bound is fixed to 1024 bytes (which might look reasonable
55 /// when one considers the definition of the various VR contents).
56 guint32 MaxSizeLoadEntry;
58 /// \brief Size threshold above which an element value will NOT be *printed*
59 /// in order no to polute the screen output. By default, this upper bound
60 /// is fixed to 64 bytes.
61 guint32 MaxSizePrintEntry;
64 /// Refering underlying filename.
67 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
68 /// Bad Little Endian) according to the processor Endianity and
69 /// what is written on disc.
72 /// File Pointer, opened during Header parsing.
75 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
78 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
79 static const unsigned int HEADER_LENGTH_TO_READ;
81 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
83 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
85 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
87 /// \todo Currently not used since collides with #define in
88 /// \ref gdcmDocEntry.cxx. See also
89 /// \ref gdcmDocument::SetMaxSizePrintEntry()
90 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
92 /// Hash Table (multimap), to provide fast access
95 /// Chained list, to keep the 'spacial' ordering
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.
109 /// Canonical Printing method (see also gdcmDocument::SetPrintLevel)
110 virtual void Print (std::ostream &os = std::cout)
112 virtual void PrintEntry (std::ostream &os = std::cout);
114 // the 2 following will be merged
115 virtual void PrintPubDict (std::ostream &os = std::cout);
116 virtual void PrintShaDict (std::ostream &os = std::cout);
119 gdcmDict *GetPubDict(void);
120 gdcmDict *GetShaDict(void);
121 bool SetShaDict(gdcmDict *dict);
122 bool SetShaDict(DictKey dictName);
124 // Informations contained in the parser
125 virtual bool IsReadable(void);
126 bool IsImplicitVRLittleEndianTransferSyntax(void);
127 bool IsExplicitVRLittleEndianTransferSyntax(void);
128 bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
129 bool IsExplicitVRBigEndianTransferSyntax(void);
130 FileType GetFileType(void);
132 // Read (used in gdcmFile, gdcmDicomDir)
133 FILE *OpenFile(bool exception_on_error = false) throw(gdcmFileError);
134 bool CloseFile(void);
136 // Write (used in gdcmFile, gdcmDicomDir)
137 virtual bool Write(FILE *, FileType);
138 virtual void WriteEntryTagVRLength(gdcmDocEntry *tag,
139 FILE *_fp, FileType type);
140 virtual void WriteEntryValue(gdcmDocEntry *tag,FILE *_fp,FileType type);
141 virtual bool WriteEntry(gdcmDocEntry *tag,FILE *_fp,FileType type);
142 virtual bool WriteEntries(FILE *_fp,FileType type);
143 void WriteEntriesDeprecated(FILE *_fp,FileType type); // JPR
145 gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value,
146 guint16 Group, guint16 Elem);
147 bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem);
149 virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element);
152 guint16 SwapShort(guint16); // needed by gdcmFile
153 guint32 SwapLong(guint32); // needed by gdcmFile
154 guint16 UnswapShort(guint16); // needed by gdcmFile
155 guint32 UnswapLong(guint32); // needed by gdcmFile
158 // Constructor and destructor are protected to forbid end user
159 // to instanciate from this class gdcmDocument (only gdcmHeader and
160 // gdcmDicomDir are meaningfull).
161 gdcmDocument(bool exception_on_error = false);
162 gdcmDocument(const char *inFilename,
163 bool exception_on_error = false,
164 bool enable_sequences = false,
165 bool ignore_shadow = false);
166 virtual ~gdcmDocument(void);
168 int CheckIfEntryExistByNumber(guint16 Group, guint16 Elem ); // int !
169 virtual std::string GetEntryByName (std::string tagName);
170 virtual std::string GetEntryVRByName (std::string tagName);
171 virtual std::string GetEntryByNumber (guint16 group, guint16 element);
172 virtual std::string GetEntryVRByNumber(guint16 group, guint16 element);
173 virtual int GetEntryLengthByNumber(guint16 group, guint16 element);
175 virtual bool SetEntryByName (std::string content, std::string tagName);
176 virtual bool SetEntryByNumber(std::string content,
177 guint16 group, guint16 element);
178 virtual bool SetEntryLengthByNumber(guint32 length,
179 guint16 group, guint16 element);
181 virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem);
182 virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem);
183 virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem);
185 virtual void UpdateShaEntries(void);
188 gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element);
189 gdcmDocEntry *GetDocEntryByName (std::string Name);
190 IterHT GetDocEntrySameNumber(guint16 group, guint16 element);
191 // IterHT GetDocEntrySameName (std::string Name);
193 void LoadDocEntrySafe(gdcmDocEntry *);
196 //void UpdateGroupLength(bool SkipSequence = false,
197 // FileType type = ImplicitVR);
199 void AddDocEntry (gdcmDocEntry *);
204 //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError);
205 // remplacé par ParseES.
206 // What about exception_on_error ?
208 long ParseES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
209 long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode);
212 void LoadDocEntry (gdcmDocEntry *);
213 void FindDocEntryLength(gdcmDocEntry *);
214 void FindDocEntryVR (gdcmDocEntry *);
215 bool CheckDocEntryVR (gdcmDocEntry *, VRKey);
217 std::string GetDocEntryValue (gdcmDocEntry *);
218 std::string GetDocEntryUnvalue(gdcmDocEntry *);
220 void SkipDocEntry (gdcmDocEntry *);
221 void FixDocEntryFoundLength(gdcmDocEntry *, guint32);
222 bool IsDocEntryAnInteger (gdcmDocEntry *);
224 guint32 FindDocEntryLengthOB(void);
226 guint16 ReadInt16(void);
227 guint32 ReadInt32(void);
228 void SkipBytes(guint32);
230 void Initialise(void);
231 bool CheckSwap(void);
232 void SwitchSwapToBigEndian(void);
233 void SetMaxSizeLoadEntry(long);
234 void SetMaxSizePrintEntry(long);
236 // DictEntry related utilities
237 gdcmDictEntry *GetDictEntryByName (std::string Name);
238 gdcmDictEntry *GetDictEntryByNumber(guint16, guint16);
239 gdcmDictEntry *NewVirtualDictEntry(guint16 group,
241 std::string vr = "unkn",
242 std::string fourth = "unkn",
243 std::string name = "unkn");
244 //gdcmDictEntry *NewVirtualDictEntry(gdcmDocEntry *); // never defined
246 // DocEntry related utilities
248 gdcmDocEntry *ReadNextDocEntry (void);
249 gdcmDocEntry *NewDocEntryByNumber(guint16 group,
251 gdcmDocEntry *NewDocEntryByName (std::string Name);
253 // Deprecated (Not used) --> commented out
254 //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName,
257 guint32 GenerateFreeTagKeyInGroup(guint16 group);
261 /// Accessor to \ref printLevel
262 void SetPrintLevel(int level) { printLevel = level; };
264 /// Accessor to \ref filename
265 inline std::string GetFileName(void) {return filename;}
267 /// Accessor to \ref filename
268 inline void SetFileName(char* fileName) {filename = fileName;}
270 /// Accessor to \ref gdcmDocument::tagHT
271 inline TagDocEntryHT &GetEntry(void) { return tagHT; };
273 /// Accessor to \ref gdcmDocument::listEntries
274 inline ListTag &GetListEntry(void) { return listEntries; };
276 /// 'Swap code' accessor (see \ref sw )
277 inline int GetSwapCode(void) { return sw; }
280 inline FILE * GetFP(void) { return fp; }
284 //-----------------------------------------------------------------------------