Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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/11/29 17:21:34 $
00007   Version:   $Revision: 1.137 $
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 
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    //GDCM_LEGACY(  virtual bool Load( std::string const &filename )  ); 
00052    //virtual bool Load( std::string const &filename );
00053    virtual bool Load( ); 
00054 
00055 // Dictionaries
00056    Dict *GetPubDict();
00057    Dict *GetShaDict();
00058    bool SetShaDict(Dict *dict);
00059    bool SetShaDict(DictKey const &dictName);
00060 
00061 // Informations contained in the gdcm::Document
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 // Swap code
00073    int GetSwapCode() { return SwapCode; }
00074    
00075 // File I/O
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 // Content entries
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 // Ordering of Documents
00095    bool operator<(Document &document);
00096 
00106    void SetLoadMode (int mode) { if (LoadMode != mode) 
00107                                      LoadMode=mode, IsDocumentModified = true; }
00108 
00109 protected:
00110 // Methods
00111    // Constructor and destructor are protected to forbid end user 
00112    // to instanciate from this class Document (only gdcm::File and
00113    // gdcm::DicomDir are meaningfull).
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 // Variables
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; // FIXME : probabely useless now
00178 
00180    bool IsDocumentModified;
00181 
00182 private:
00183 // Methods
00184    void Initialize();
00185    bool DoTheLoadingDocumentJob(); 
00186      
00187       // System access (meaning endian related !?)
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    // Read
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    // DocEntry related utilities
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 // Variables
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 //  uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
00249 //  void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
00250 //                                  DocEntrySet *set );
00251 
00252 };
00253 
00254 } // end namespace gdcm
00255 
00256 //-----------------------------------------------------------------------------
00257 #endif

Generated on Fri Jan 20 10:14:25 2006 for gdcm by  doxygen 1.4.4