X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fgdcm.h;h=3b35c7629547c70a4e09e148e47e3138c052e399;hb=331fc5679566381e5e7c90f144e5bc6ada69809c;hp=549dca9534d3740fefae9c490acf73f0514bf1c7;hpb=643fc6fe50df610993fc6fdf9a7cab65fd397c3f;p=gdcm.git diff --git a/src/gdcm.h b/src/gdcm.h index 549dca95..3b35c762 100644 --- a/src/gdcm.h +++ b/src/gdcm.h @@ -16,19 +16,41 @@ // the declaration once you provided the definition of the method... #include -#include // For size_t -#include -#include +#include +#include // For size_t +#include // FIXME For FILE on GCC only +#include // The requirement for the hash table (or map) that + // we shall use: + // 1/ First, next, last (iterators) + // 2/ should be sortable (i.e. sorted by TagKey). This + // condition shall be droped since the Win32/VC++ + // implementation doesn't look a sorted one. Pffff.... + // 3/ Make sure we can setup some default size value, + // which should be around 4500 entries which is the + // average dictionary size (said JPR) -// The requirement for the hash table (or map) that we shall use: -// 1/ First, next, last (iterators) -// 2/ should be sortable (i.e. sorted by TagKey). This condition -// shall be droped since the Win32/VC++ implementation doesn't look -// a sorted one. Pffff.... -// 3/ Make sure we can setup some default size value, which should be -// around 4500 entries which is the average dictionary size (said JPR) -#include +#define g_malloc malloc +#define g_free free +#ifdef __GNUC__ +#include +#define guint16 uint16_t +#define guint32 uint32_t +#endif +#ifdef _MSC_VER +typedef unsigned short guint16; +typedef unsigned int guint32; + +#endif + +#ifdef _MSC_VER + using namespace std; // string type lives in the std namespace on VC++ +#endif +#ifdef _MSC_VER +#define GDCM_EXPORT __declspec( dllexport ) +#else +#define GDCM_EXPORT +#endif // Tag based hash tables. // We shall use as keys the strings (as the C++ type) obtained by @@ -40,7 +62,7 @@ // gdcmDictEntry::TranslateToKey for this conversion function. typedef string TagKey; -class gdcmDictEntry { +class GDCM_EXPORT gdcmDictEntry { private: guint16 group; // e.g. 0x0010 guint16 element; // e.g. 0x0010 @@ -70,12 +92,15 @@ private: public: //CLEANME gdcmDictEntry(); gdcmDictEntry(guint16 group, guint16 element, - string vr, string fourth, string vr); + string vr = "Unknown", + string fourth = "Unknown", + string name = "Unknown"); static TagKey TranslateToKey(guint16 group, guint16 element); guint16 GetGroup(void) { return group;}; guint16 GetElement(void){return element;}; string GetVR(void) {return vr; }; - void SetVR(string in){vr = in; }; + void SetVR(string); + bool IsVrUnknown(void); string GetFourth(void) {return fourth;}; string GetName(void) {return name;}; string GetKey(void) {return key;}; @@ -87,7 +112,7 @@ typedef map TagHT; // entries. There should be a single public dictionary (THE dictionary of // the actual DICOM v3) but as many shadow dictionaries as imagers // combined with all software versions... -class gdcmDict { +class GDCM_EXPORT gdcmDict { string name; string filename; TagHT entries; @@ -104,7 +129,7 @@ public: // * having many in memory representations of the same dictionary. typedef string DictKey; typedef map DictSetHT; -class gdcmDictSet { +class GDCM_EXPORT gdcmDictSet { private: string DictPath; // Directory path to dictionaries DictSetHT dicts; @@ -128,23 +153,32 @@ public: // The dicom header of a Dicom file contains a set of such ELement VALUES // (when successfuly parsed against a given Dicom dictionary) -class ElValue { +class GDCM_EXPORT ElValue { private: gdcmDictEntry *entry; guint32 LgrElem; + bool ImplicitVr; // Even when reading explicit vr files, some + // elements happen to be implicit. Flag them here + // since we can't use the entry->vr without breaking + // the underlying dictionary. // Might prove of some interest (see _ID_DCM_ELEM) // int Swap; public: string value; // used to be char * valeurElem size_t Offset; // Offset from the begining of file for direct user access ElValue(gdcmDictEntry*); - void SetVR(string); - string GetVR(void); + void SetDictEntry(gdcmDictEntry *NewEntry) { entry = NewEntry; }; + + bool IsVrUnknown(void) { return entry->IsVrUnknown(); }; void SetLength(guint32 l){LgrElem = l; }; void SetValue(string val){ value = val; }; void SetOffset(size_t of){ Offset = of; }; + void SetImplicitVr(void) { ImplicitVr = true; }; + bool IsImplicitVr(void) { return ImplicitVr; }; + void SetVR(string); + string GetVR(void); string GetValue(void) { return value; }; - guint32 GetLength(void) { return LgrElem; }; + guint32 GetLength(void) { return LgrElem; }; size_t GetOffset(void) { return Offset; }; guint16 GetGroup(void) { return entry->GetGroup(); }; guint16 GetElement(void) { return entry->GetElement(); }; @@ -155,8 +189,8 @@ public: typedef map TagElValueHT; typedef map TagElValueNameHT; // Container for a set of succefully parsed ElValues. -class ElValSet { - // We need both accesses with a TagKey and the Dicentry.Name +class GDCM_EXPORT ElValSet { + // We need both accesses with a TagKey and the Dictentry.Name TagElValueHT tagHt; TagElValueNameHT NameHt; public: @@ -183,7 +217,7 @@ typedef map VRHT; // Value Representation Hash Table // Notes: // * the gdcmHeader::Set*Tag* family members cannot be defined as protected // (Swig limitations for as Has_a dependency between gdcmFile and gdcmHeader) -class gdcmHeader { +class GDCM_EXPORT gdcmHeader { //FIXME sw should be qn EndianType !!! //enum EndianType { //LittleEndian, @@ -191,13 +225,15 @@ class gdcmHeader { //BigEndian, //BadBigEndian}; private: - // All instances share the same value representation dictionary + // All instances share the same Value Representation dictionary static VRHT *dicom_vr; + // Dictionaries of data elements: static gdcmDictSet* Dicts; // Global dictionary container gdcmDict* RefPubDict; // Public Dictionary gdcmDict* RefShaDict; // Shadow Dictionary (optional) - ElValSet PubElVals; // Element Values parsed with Public Dictionary - ElValSet ShaElVals; // Element Values parsed with Shadow Dictionary + // Parsed element values: + ElValSet PubElVals; // parsed with Public Dictionary + ElValSet ShaElVals; // parsed with Shadow Dictionary // In order to inspect/navigate through the file string filename; FILE * fp; @@ -207,7 +243,13 @@ private: // outside of the elements: guint16 grPixel; guint16 numPixel; + // Swap code (little, big, big-bad endian): this code is not fixed + // during parsing. int sw; + // Only the elements whose size are below this bound shall be loaded. + // By default, this upper bound is limited to 1024 (which looks reasonable + // when one considers the definition of the various VR contents). + guint32 MaxSizeLoadElementValue; guint16 ReadInt16(void); guint32 ReadInt32(void); @@ -218,10 +260,15 @@ private: void FindLength(ElValue *); void FindVR(ElValue *); void LoadElementValue(ElValue *); + void LoadElementValueSafe(ElValue *); void SkipElementValue(ElValue *); void InitVRDict(void); - bool IsAnInteger(guint16, guint16, string, guint32); - ElValue * ReadNextElement(void); + void SwitchSwapToBigEndian(void); + void FixFoundLength(ElValue*, guint32); + bool IsAnInteger(ElValue *); + bool IsBigEndianTransferSyntax(void); + void SetMaxSizeLoadElementValue(long); + ElValue * ReadNextElement(void); gdcmDictEntry * IsInDicts(guint32, guint32); size_t GetPixelOffset(void); protected: @@ -263,7 +310,7 @@ public: // TODO Swig string GetPubElValRepByName(string TagName); // TODO Swig string GetPubElValRepByNumber(guint16 group, guint16 element); TagElValueHT & GetPubElVal(void) { return PubElVals.GetTagHt(); }; - void PrintPubElVal(ostream & os = std::cout); + void PrintPubElVal(ostream & os = cout); void PrintPubDict(ostream &); // Same thing with the shadow : @@ -294,7 +341,7 @@ public: ////// QUESTION: this looks still like an open question wether the ////// relationship between a gdcmFile and gdcmHeader is of ////// type IS_A or HAS_A ! -class gdcmFile: gdcmHeader +class GDCM_EXPORT gdcmFile: gdcmHeader { private: void* Data;