00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GDCMDOCUMENT_H
00020 #define GDCMDOCUMENT_H
00021
00022 #include "gdcmVR.h"
00023 #include "gdcmDict.h"
00024 #include "gdcmElementSet.h"
00025 #include "gdcmException.h"
00026 #include "gdcmDebug.h"
00027 #include "gdcmCommandManager.h"
00028
00029 #include <map>
00030 #include <list>
00031 #include <fstream>
00032
00033 namespace gdcm
00034 {
00035 class SeqEntry;
00036 class Dict;
00037
00038
00042 class GDCM_EXPORT Document : public ElementSet
00043 {
00044 gdcmTypeMacro(Document);
00045
00046 public:
00047 typedef std::list<DicomElement> ListElements;
00048
00049
00050
00051
00052
00053 virtual bool Load( );
00054
00055
00056 Dict *GetPubDict();
00057 Dict *GetShaDict();
00058 bool SetShaDict(Dict *dict);
00059 bool SetShaDict(DictKey const &dictName);
00060
00061
00062 bool IsParsable();
00063 virtual bool IsReadable();
00064 bool IsDicomV3();
00065 bool IsPapyrus();
00066 FileType GetFileType();
00067 std::string GetTransferSyntax();
00069 std::string GetTransferSyntaxName();
00070
00071
00073 int GetSwapCode() { return SwapCode; }
00074
00075
00077 const std::string &GetFileName() const { return Filename; }
00079 virtual void SetFileName(std::string const &fileName)
00080 { if (Filename != fileName)
00081 Filename = fileName, IsDocumentModified = true; }
00082
00083 std::ifstream *OpenFile();
00084 bool CloseFile();
00085 void WriteContent( std::ofstream *fp, FileType type );
00086
00087
00088 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
00089 virtual void LoadEntryBinArea(DataEntry *entry);
00090
00091 void LoadDocEntrySafe(DocEntry *entry);
00092 void AddForceLoadElement(uint16_t group, uint16_t elem);
00093
00094
00095 bool operator<(Document &document);
00096
00106 void SetLoadMode (int mode) { if (LoadMode != mode)
00107 LoadMode=mode, IsDocumentModified = true; }
00108
00109 protected:
00110
00111
00112
00113
00114 Document();
00115 virtual ~Document();
00116
00117 virtual void CallStartMethod();
00118 virtual void CallProgressMethod();
00119 virtual void CallEndMethod();
00120
00121 uint16_t ReadInt16() throw ( FormatError );
00122 uint32_t ReadInt32() throw ( FormatError );
00123 void SkipBytes(uint32_t);
00124 int ComputeGroup0002Length( );
00125
00126
00128 std::string Filename;
00129
00142 int SwapCode;
00143
00145 bool Group0002Parsed;
00146
00148 bool HasDCMPreamble;
00149
00151 std::ifstream *Fp;
00152
00154 FileType Filetype;
00155
00157 static const unsigned int HEADER_LENGTH_TO_READ;
00160 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
00161
00163 ListElements UserAnonymizeList;
00164
00166 ListElements UserForceLoadList;
00167
00172 int LoadMode;
00173
00177 bool IsDocumentAlreadyLoaded;
00178
00180 bool IsDocumentModified;
00181
00182 private:
00183
00184 void Initialize();
00185 bool DoTheLoadingDocumentJob();
00186
00187
00188 uint16_t SwapShort(uint16_t);
00189 uint32_t SwapLong(uint32_t);
00190 double SwapDouble(double);
00193 uint16_t UnswapShort(uint16_t a) { return SwapShort(a);}
00196 uint32_t UnswapLong(uint32_t a) { return SwapLong(a);}
00197
00198
00199 void ParseDES(DocEntrySet *set, long offset, long l_max, bool delim_mode);
00200 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
00201
00202 void LoadDocEntry (DocEntry *e, bool forceLoad = false);
00203 void FindDocEntryLength (DocEntry *e) throw ( FormatError );
00204 uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
00205 VRKey FindDocEntryVR();
00206 bool CheckDocEntryVR (const VRKey &k);
00207
00208 void SkipDocEntry (DocEntry *entry);
00209 void SkipToNextDocEntry (DocEntry *entry);
00210
00211 void FixDocEntryFoundLength(DocEntry *entry, uint32_t l);
00212 bool IsDocEntryAnInteger (DocEntry *entry);
00213
00214 bool CheckSwap();
00215 void SwitchByteSwapCode();
00216 void SetMaxSizeLoadEntry(long);
00217
00218
00219 DocEntry *ReadNextDocEntry();
00220
00221 void HandleBrokenEndian (uint16_t &group, uint16_t &elem);
00222 void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
00223 DocEntry *Backtrack(DocEntry *docEntry);
00224
00225
00226 protected:
00228 float Progress;
00229 mutable bool Abort;
00230
00232 Dict *RefPubDict;
00235 Dict *RefShaDict;
00236
00241 uint32_t MaxSizeLoadEntry;
00242
00244 uint16_t CurrentGroup;
00246 uint16_t CurrentElem;
00247
00248
00249
00250
00251
00252 };
00253
00254 }
00255
00256
00257 #endif