1 /*=========================================================================
4 Module: $RCSfile: gdcmDocument.h,v $
6 Date: $Date: 2004/12/16 11:37:02 $
7 Version: $Revision: 1.69 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #ifndef GDCMDOCUMENT_H
20 #define GDCMDOCUMENT_H
24 #include "gdcmElementSet.h"
37 class JPEGFragmentsInfo;
39 enum TransferSyntaxType {
40 ImplicitVRLittleEndian = 0,
41 ImplicitVRLittleEndianDLXGE,
42 ExplicitVRLittleEndian,
43 DeflatedExplicitVRLittleEndian,
46 JPEGExtendedProcess2_4,
47 JPEGExtendedProcess3_5,
48 JPEGSpectralSelectionProcess6_8,
49 JPEGFullProgressionProcess10_12,
50 JPEGLosslessProcess14,
51 JPEGLosslessProcess14_1,
58 //-----------------------------------------------------------------------------
60 * \brief Derived by both Header and DicomDir
62 class GDCM_EXPORT Document : public ElementSet
66 /// Public dictionary used to parse this header
69 /// \brief Optional "shadow dictionary" (private elements) used to parse
73 /// \brief Size threshold above which an element value will NOT be loaded
74 /// in memory (to avoid loading the image/volume itself). By default,
75 /// this upper bound is fixed to 1024 bytes (which might look reasonable
76 /// when one considers the definition of the various VR contents).
77 uint32_t MaxSizeLoadEntry;
79 /// \brief Size threshold above which an element value will NOT be *printed*
80 /// in order no to polute the screen output. By default, this upper bound
81 /// is fixed to 64 bytes.
82 uint32_t MaxSizePrintEntry;
85 /// Refering underlying filename.
88 /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian,
89 /// Bad Little Endian) according to the processor Endianity and
90 /// what is written on disc.
93 /// File Pointer, opened during Header parsing.
96 /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
99 /// After opening the file, we read HEADER_LENGTH_TO_READ bytes.
100 static const unsigned int HEADER_LENGTH_TO_READ;
102 /// \brief Elements whose value is longer than MAX_SIZE_LOAD_ELEMENT_VALUE
104 static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
106 /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE
108 /// \todo Currently not used since collides with #define in
109 /// class DocEntry . See also
110 /// method ref Document::SetMaxSizePrintEntry()
111 static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
113 /// Store the RLE frames info obtained during parsing of pixels.
114 RLEFramesInfo* RLEInfo;
116 /// Store the JPEG fragments info obtained during parsing of pixels.
117 JPEGFragmentsInfo* JPEGInfo;
120 // the 2 following will be merged
121 virtual void PrintPubDict (std::ostream &os = std::cout);
122 virtual void PrintShaDict (std::ostream &os = std::cout);
127 bool SetShaDict(Dict* dict);
128 bool SetShaDict(DictKey const & dictName);
130 // Informations contained in the parser
131 virtual bool IsReadable();
132 TransferSyntaxType GetTransferSyntax();
133 bool IsJPEGLossless();
136 bool IsEncapsulate();
139 FileType GetFileType();
141 std::ifstream * OpenFile();
144 void WriteContent( std::ofstream* fp, FileType type );
146 ValEntry* ReplaceOrCreateByNumber(std::string const & value,
147 uint16_t group, uint16_t elem,
148 TagName const & vr = "unkn");
150 BinEntry* ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
151 uint16_t group, uint16_t elem,
152 TagName const & vr = "unkn");
154 SeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
156 bool ReplaceIfExistByNumber ( std::string const & value,
157 uint16_t group, uint16_t elem );
159 virtual void LoadEntryBinArea(uint16_t group, uint16_t elem);
160 virtual void LoadEntryBinArea(BinEntry* entry);
162 // System access (meaning endian related !?)
163 uint16_t SwapShort(uint16_t); // needed by File
164 uint32_t SwapLong(uint32_t); // needed by File
165 uint16_t UnswapShort(uint16_t); // needed by File
166 uint32_t UnswapLong(uint32_t); // needed by File
168 static std::string GetTransferSyntaxValue(TransferSyntaxType type);
171 // Constructor and destructor are protected to forbid end user
172 // to instanciate from this class Document (only Header and
173 // DicomDir are meaningfull).
175 Document( std::string const & filename );
178 void ReadAndSkipEncapsulatedBasicOffsetTable();
179 void ComputeRLEInfo();
180 void ComputeJPEGFragmentInfo();
182 bool CheckIfEntryExistByNumber(uint16_t group, uint16_t elem );
184 virtual std::string GetEntryByName (TagName const & tagName);
185 virtual std::string GetEntryVRByName (TagName const & tagName);
186 virtual std::string GetEntryByNumber (uint16_t group, uint16_t elem);
187 virtual std::string GetEntryVRByNumber(uint16_t group, uint16_t elem);
188 virtual int GetEntryLengthByNumber(uint16_t group, uint16_t elem);
190 virtual bool SetEntryByName (std::string const & content,
191 TagName const & tagName );
192 virtual bool SetEntryByNumber(std::string const & content,
193 uint16_t group, uint16_t element);
194 virtual bool SetEntryByNumber(uint8_t* content, int lgth,
195 uint16_t group, uint16_t element);
196 virtual void* GetEntryBinAreaByNumber(uint16_t group, uint16_t elem);
198 // Verify the usefull of this method... otherwise remove it
199 // It's body is commented in the .xx
200 //virtual bool SetEntryBinAreaByNumber(uint8_t* a, uint16_t group,
203 virtual void UpdateShaEntries();
206 DocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element);
207 DocEntry* GetDocEntryByName (TagName const & tagName);
209 ValEntry* GetValEntryByNumber(uint16_t group, uint16_t element);
210 //BinEntry* GetBinEntryByNumber(uint16_t group, uint16_t element);
211 RLEFramesInfo* GetRLEInfo() { return RLEInfo; }
212 JPEGFragmentsInfo* GetJPEGInfo() { return JPEGInfo; }
214 void LoadDocEntrySafe(DocEntry* entry);
215 TagDocEntryHT* BuildFlatHashTable();
219 void ParseDES(DocEntrySet *set,long offset, long l_max, bool delim_mode);
220 void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode);
222 void LoadDocEntry (DocEntry *);
223 void FindDocEntryLength(DocEntry *) throw ( FormatError );
224 void FindDocEntryVR (DocEntry *);
225 bool CheckDocEntryVR (DocEntry *, VRKey);
227 std::string GetDocEntryValue (DocEntry *);
228 std::string GetDocEntryUnvalue(DocEntry *);
230 void SkipDocEntry (DocEntry *);
231 void SkipToNextDocEntry (DocEntry *);
233 void FixDocEntryFoundLength(DocEntry *, uint32_t);
234 bool IsDocEntryAnInteger (DocEntry *);
236 uint32_t FindDocEntryLengthOB() throw( FormatUnexpected );
238 uint16_t ReadInt16() throw ( FormatError );
239 uint32_t ReadInt32() throw ( FormatError );
240 void SkipBytes(uint32_t);
241 bool ReadTag(uint16_t, uint16_t);
242 uint32_t ReadTagLength(uint16_t, uint16_t);
246 void SwitchSwapToBigEndian();
247 void SetMaxSizeLoadEntry(long);
248 void SetMaxSizePrintEntry(long);
250 // DocEntry related utilities
251 DocEntry* ReadNextDocEntry();
253 uint32_t GenerateFreeTagKeyInGroup(uint16_t group);
254 void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
257 void HandleBrokenEndian(uint16_t group, uint16_t elem);
260 /// Accessor to \ref Filename
261 const std::string &GetFileName() const { return Filename; }
263 /// Accessor to \ref Filename
264 void SetFileName(std::string const & fileName) { Filename = fileName; }
266 /// 'Swap code' accessor (see \ref SwapCode )
267 int GetSwapCode() { return SwapCode; }
269 bool operator<(Document &document);
271 } // end namespace gdcm
273 //-----------------------------------------------------------------------------