Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmDocument.h

Go to the documentation of this file.
00001 /*=========================================================================
00002  
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDocument.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/06 14:39:35 $
00007   Version:   $Revision: 1.105 $
00008  
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012  
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
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 "gdcmCommon.h"
00027 
00028 #include <map>
00029 #include <list>
00030 #include <fstream>
00031 
00032 namespace gdcm 
00033 {
00034 class ValEntry;
00035 class BinEntry;
00036 class SeqEntry;
00037 class Dict;
00038 
00039 //-----------------------------------------------------------------------------
00043 class GDCM_EXPORT Document : public ElementSet
00044 {
00045 public:
00046 
00047 typedef std::list<Element> ListElements;
00048 
00049 // Dictionaries
00050    Dict *GetPubDict();
00051    Dict *GetShaDict();
00052    bool SetShaDict(Dict *dict);
00053    bool SetShaDict(DictKey const &dictName);
00054 
00055 // Informations contained in the gdcm::Document
00056    virtual bool IsReadable();
00057    bool IsDicomV3();
00058    bool IsPapyrus();
00059    FileType GetFileType();
00060    std::string GetTransferSyntax();
00062    std::string GetTransferSyntaxName();
00063 
00064 // Swap code
00066    int GetSwapCode() { return SwapCode; }
00067    // System access (meaning endian related !?)
00068    uint16_t SwapShort(uint16_t);
00069    uint32_t SwapLong(uint32_t);
00072    uint16_t UnswapShort(uint16_t a) { return SwapShort(a);}
00075    uint32_t UnswapLong(uint32_t a) { return SwapLong(a);}
00076    
00077 // File I/O
00079    const std::string &GetFileName() const { return Filename; }
00081    void SetFileName(std::string const &fileName) { Filename = fileName; }
00082 
00083    std::ifstream *OpenFile();
00084    bool CloseFile();
00085    void WriteContent( std::ofstream *fp, FileType type );
00086 
00087 // Content entries
00088    virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
00089    virtual void LoadEntryBinArea(BinEntry *entry);
00090 
00091    void LoadDocEntrySafe(DocEntry *entry);
00092  
00093 // Ordering of Documents
00094    bool operator<(Document &document);
00095 
00096 protected:
00097 // Methods
00098    // Constructor and destructor are protected to forbid end user 
00099    // to instanciate from this class Document (only gdcm::File and
00100    // gdcm::DicomDir are meaningfull).
00101    Document();
00102    Document( std::string const &filename );
00103    virtual ~Document();
00104    
00105    uint16_t ReadInt16() throw ( FormatError );
00106    uint32_t ReadInt32() throw ( FormatError );
00107    void     SkipBytes(uint32_t);
00108    int ComputeGroup0002Length( FileType filetype );
00109 
00110 // Variables
00112    std::string Filename;
00113 
00126    int SwapCode;
00127 
00129    bool Group0002Parsed;
00130 
00132    bool HasDCMPreamble;
00133 
00135    std::ifstream *Fp;
00136 
00138    FileType Filetype;  
00139 
00141    static const unsigned int HEADER_LENGTH_TO_READ; 
00144    static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
00147    static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
00148 
00150    ListElements AnonymizeList;
00151 
00152 private:
00153 // Methods
00154    void Initialize();
00155 
00156    // Read
00157    void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
00158    void ParseSQ (SeqEntry *seq,   long offset, long l_max, bool delim_mode);
00159 
00160    void LoadDocEntry         (DocEntry *e);
00161    void FindDocEntryLength   (DocEntry *e) throw ( FormatError );
00162    uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected );
00163    std::string FindDocEntryVR();
00164    bool CheckDocEntryVR      (VRKey k);
00165 
00166    std::string GetDocEntryValue  (DocEntry *entry);
00167    std::string GetDocEntryUnvalue(DocEntry *entry);
00168 
00169    void SkipDocEntry          (DocEntry *entry);
00170    void SkipToNextDocEntry    (DocEntry *entry);
00171 
00172    void FixDocEntryFoundLength(DocEntry *entry,uint32_t l);
00173    bool IsDocEntryAnInteger   (DocEntry *entry);
00174 
00175    bool CheckSwap();
00176    void SwitchByteSwapCode();
00177    void SetMaxSizeLoadEntry(long);
00178    void SetMaxSizePrintEntry(long);
00179 
00180    // DocEntry related utilities
00181    DocEntry *ReadNextDocEntry();
00182 
00183    void HandleBrokenEndian  (uint16_t &group, uint16_t &elem);
00184    void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
00185 
00186 // Variables
00188    Dict *RefPubDict;
00191    Dict *RefShaDict;
00192 
00197    uint32_t MaxSizeLoadEntry;
00198    
00202    uint32_t MaxSizePrintEntry;   
00203 
00204 
00205 //  uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
00206 //  void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
00207 //                                   DocEntrySet *set );
00208 
00209 };
00210 
00211 } // end namespace gdcm
00212 
00213 //-----------------------------------------------------------------------------
00214 #endif

Generated on Thu Feb 10 22:17:58 2005 for gdcm by doxygen 1.3.6