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_NAME_SPACE
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
00054 virtual bool Load( );
00055
00056
00057 Dict *GetPubDict();
00058 Dict *GetShaDict();
00059 bool SetShaDict(Dict *dict);
00060 bool SetShaDict(DictKey const &dictName);
00061
00062
00063 bool IsParsable();
00064 virtual bool IsReadable();
00065 bool IsDicomV3();
00066 bool IsPapyrus();
00067 FileType GetFileType();
00068 std::string GetTransferSyntax();
00070 std::string GetTransferSyntaxName();
00071
00072
00074 int GetSwapCode() { return SwapCode; }
00075
00076
00078 const std::string &GetFileName() const { return Filename; }
00080 virtual void SetFileName(std::string const &fileName)
00081 { if (Filename != fileName)
00082 Filename = fileName, IsDocumentModified = true; }
00083
00084 std::ifstream *OpenFile();
00085 bool CloseFile();
00086 void WriteContent( std::ofstream *fp, FileType type );
00087
00088
00089 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
00090 virtual void LoadEntryBinArea(DataEntry *entry);
00091
00092 void SetMaxSizeLoadEntry(long);
00093 void AddForceLoadElement(uint16_t group, uint16_t elem);
00094
00095
00096 bool operator<(Document &document);
00097
00107 void SetLoadMode (int mode) { if (LoadMode != mode)
00108 LoadMode=mode, IsDocumentModified = true; }
00109
00110 protected:
00111
00112
00113
00114
00115 Document();
00116 virtual ~Document();
00117
00118 virtual void CallStartMethod();
00119 virtual void CallProgressMethod();
00120 virtual void CallEndMethod();
00121
00122 uint16_t ReadInt16() throw ( FormatError );
00123 uint32_t ReadInt32() throw ( FormatError );
00124
00126 void SkipBytes(uint32_t nBytes) { Fp->seekg((long)nBytes, std::ios::cur);}
00127 int ComputeGroup0002Length( );
00128
00129
00131 std::string Filename;
00132
00145 int SwapCode;
00146
00148 bool Group0002Parsed;
00149
00151 bool HasDCMPreamble;
00152
00154 std::ifstream *Fp;
00155
00157 FileType Filetype;
00158
00160 static const unsigned int HEADER_LENGTH_TO_READ;
00163 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
00164
00166 ListElements UserAnonymizeList;
00167
00169 ListElements UserForceLoadList;
00170
00175 int LoadMode;
00176
00180 bool IsDocumentAlreadyLoaded;
00181
00183 bool IsDocumentModified;
00184
00185 private:
00186
00187 void Initialize();
00188 bool DoTheLoadingDocumentJob();
00189
00190
00191 void ReadBegBuffer(size_t l) throw ( FormatError );
00192 uint16_t SwapShort(uint16_t);
00193 uint32_t SwapLong(uint32_t);
00194 double SwapDouble(double);
00197 uint16_t UnswapShort(uint16_t a) { return SwapShort(a);}
00200 uint32_t UnswapLong(uint32_t a) { return SwapLong(a);}
00201
00202
00203 void ParseDES(DocEntrySet *set, long offset, long l_max, bool delim_mode);
00204 bool ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
00205
00206 void LoadDocEntry (DocEntry *e, bool forceLoad = false);
00207 void FindDocEntryLength (DocEntry *e) throw ( FormatError );
00208 uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
00209 VRKey FindDocEntryVR();
00210 bool CheckDocEntryVR (const VRKey &k);
00211
00212 void SkipDocEntry (DocEntry *entry);
00213 void SkipToNextDocEntry (DocEntry *entry);
00214
00215 void FixDocEntryFoundLength(DocEntry *entry, uint32_t l);
00216 bool IsDocEntryAnInteger (DocEntry *entry);
00217
00218 bool CheckSwap();
00219 void SwitchByteSwapCode();
00220
00221
00222 DocEntry *ReadNextDocEntry();
00223 uint16_t GetInt16();
00224 uint32_t GetInt32();
00225
00226 void HandleBrokenEndian (uint16_t &group, uint16_t &elem);
00227 void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
00228 DocEntry *Backtrack(DocEntry *docEntry);
00229
00230
00231
00232 protected:
00234 float Progress;
00235 mutable bool Abort;
00236
00238 Dict *RefPubDict;
00241 Dict *RefShaDict;
00242
00247 uint32_t MaxSizeLoadEntry;
00248
00250 uint16_t CurrentGroup;
00252 uint16_t CurrentElem;
00253
00254
00255
00256
00257
00258 private:
00260 char BegBuffer[8];
00261 char *PtrBegBuffer;
00263 size_t CurrentOffsetPosition;
00266 bool changeFromUN;
00268 bool UnexpectedEOF;
00269 };
00270
00271 }
00272
00273
00274 #endif