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: 2007/08/22 16:14:04 $
00007   Version:   $Revision: 1.146 $
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 "gdcmDebug.h"  // for LEGACY
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 // Loading
00050    //Deprecated : use SetFileName() + Load()
00051 //#ifndef GDCM_LEGACY_REMOVE 
00052 //   virtual bool Load( std::string const &filename ); 
00053 //#endif
00054    virtual bool Load( ); 
00055 
00056 // Dictionaries
00057    Dict *GetPubDict();
00058    Dict *GetShaDict();
00059    bool SetShaDict(Dict *dict);
00060    bool SetShaDict(DictKey const &dictName);
00061 
00062 // Informations contained in the gdcm::Document
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 // Swap code
00074    int GetSwapCode() { return SwapCode; }
00075    
00076 // File I/O
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 // Data entries
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 // Ordering of Documents
00096    bool operator<(Document &document);
00097 
00107    void SetLoadMode (int mode) { if (LoadMode != mode) 
00108                                      LoadMode=mode, IsDocumentModified = true; }
00109 
00110 protected:
00111 // Methods
00112    // Constructor and destructor are protected to forbid end user 
00113    // to instanciate from this class Document (only gdcm::File and
00114    // gdcm::DicomDir are meaningfull).
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 // Variables
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; // FIXME : probabely useless now
00181 
00183    bool IsDocumentModified;
00184 
00185 private:
00186 // Methods
00187    void Initialize();
00188    bool DoTheLoadingDocumentJob();
00189      
00190       // System access (meaning endian related !?)
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    // Read
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    // DocEntry related utilities
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 // Variables
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 //  uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
00255 //  void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
00256 //                                  DocEntrySet *set );
00257 
00258 private:
00260    char BegBuffer[8];
00261    char *PtrBegBuffer;
00263    size_t CurrentOffsetPosition;
00266    bool changeFromUN;
00268    bool UnexpectedEOF;
00269 };
00270 
00271 } // end namespace gdcm
00272 
00273 //-----------------------------------------------------------------------------
00274 #endif

Generated on Fri Aug 24 12:59:30 2007 for gdcm by  doxygen 1.4.6