-guint32 gdcmHeader::ReadInt32(void) {
- guint32 g;
- size_t item_read;
- item_read = fread (&g, (size_t)4,(size_t)1, fp);
- if ( item_read != 1 ) {
- //dbg.Verbose(0, "gdcmHeader::ReadInt32", " Failed to read :");
- //if(feof(fp))
- // dbg.Verbose(0, "gdcmHeader::ReadInt32", " End of File encountered");
- if(ferror(fp))
- dbg.Verbose(0, "gdcmHeader::ReadInt32", " File Error");
- errno = 1;
- return 0;
- }
- errno = 0;
- g = SwapLong(g);
- return g;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief
- *
- * @return
- */
- gdcmElValue* gdcmHeader::GetElValueByNumber(guint16 Group, guint16 Elem) {
-
- gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
- if (!elValue) {
- dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
- "failed to Locate gdcmElValue");
- return (gdcmElValue*)0;
- }
- return elValue;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Build a new Element Value from all the low level arguments.
- * Check for existence of dictionary entry, and build
- * a default one when absent.
- * @param Group group of the underlying DictEntry
- * @param Elem element of the underlying DictEntry
- */
-gdcmElValue* gdcmHeader::NewElValueByNumber(guint16 Group, guint16 Elem) {
- // Find out if the tag we encountered is in the dictionaries:
- gdcmDictEntry * NewTag = GetDictEntryByNumber(Group, Elem);
- if (!NewTag)
- NewTag = new gdcmDictEntry(Group, Elem);
-
- gdcmElValue* NewElVal = new gdcmElValue(NewTag);
- if (!NewElVal) {
- dbg.Verbose(1, "gdcmHeader::NewElValueByNumber",
- "failed to allocate gdcmElValue");
- return (gdcmElValue*)0;
- }
- return NewElVal;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief TODO
- * @param Value
- * @param Group
- * @param Elem
- * \return integer acts as a boolean
- */
-int gdcmHeader::ReplaceOrCreateByNumber(std::string Value,
- guint16 Group, guint16 Elem ) {
-
- // TODO : FIXME JPRx
- // curieux, non ?
- // on (je) cree une Elvalue ne contenant pas de valeur
- // on l'ajoute au ElValSet
- // on affecte une valeur a cette ElValue a l'interieur du ElValSet
- // --> devrait pouvoir etre fait + simplement ???
-
- gdcmElValue* nvElValue=NewElValueByNumber(Group, Elem);
- PubElValSet.Add(nvElValue);
- PubElValSet.SetElValueByNumber(Value, Group, Elem);
- return(1);
-}
-
-
-/**
- * \ingroup gdcmHeader
- * \brief Modify (or Creates if not found) an element
- * @param Value new value
- * @param Group
- * @param Elem
- * \return integer acts as a boolean
- *
- */
-int gdcmHeader::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) {
-
- gdcmElValue* nvElValue=NewElValueByNumber(Group, Elem);
- PubElValSet.Add(nvElValue);
- std::string v = Value;
- PubElValSet.SetElValueByNumber(v, Group, Elem);
- return(1);
-}
-
-
-/**
- * \ingroup gdcmHeader
- * \brief Set a new value if the invoked element exists
- * @param Value
- * @param Group
- * @param Elem
- * \return integer acts as a boolean
- */
-int gdcmHeader::ReplaceIfExistByNumber(char* Value, guint16 Group, guint16 Elem ) {
-
- gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);
- std::string v = Value;
- PubElValSet.SetElValueByNumber(v, Group, Elem);
- return 1;
-}
-
-
-/**
- * \ingroup gdcmHeader
- * \brief Checks if a given ElValue (group,number)
- * \ exists in the Public ElValSet
- * @param Group
- * @param Elem
- * @return integer acts as a boolean
- */
-
-int gdcmHeader::CheckIfExistByNumber(guint16 Group, guint16 Elem ) {
- return (PubElValSet.CheckIfExistByNumber(Group, Elem));
- }
-
-/**
- * \ingroup gdcmHeader
- * \brief Build a new Element Value from all the low level arguments.
- * Check for existence of dictionary entry, and build
- * a default one when absent.
- * @param Name Name of the underlying DictEntry
- */
-gdcmElValue* gdcmHeader::NewElValueByName(std::string Name) {
-
- gdcmDictEntry * NewTag = GetDictEntryByName(Name);
- if (!NewTag)
- NewTag = new gdcmDictEntry(0xffff, 0xffff, "LO", "Unknown", Name);
-
- gdcmElValue* NewElVal = new gdcmElValue(NewTag);
- if (!NewElVal) {
- dbg.Verbose(1, "gdcmHeader::ObtainElValueByName",
- "failed to allocate gdcmElValue");
- return (gdcmElValue*)0;
+ModalityType gdcmHeader::GetModality()
+{
+ // 0008 0060 CS ID Modality
+ std::string strModality = GetEntryByNumber(0x0008,0x0060);
+ if ( strModality != GDCM_UNFOUND )
+ {
+ if ( strModality.find("AU") < strModality.length()) return AU;
+ else if ( strModality.find("AS") < strModality.length()) return AS;
+ else if ( strModality.find("BI") < strModality.length()) return BI;
+ else if ( strModality.find("CF") < strModality.length()) return CF;
+ else if ( strModality.find("CP") < strModality.length()) return CP;
+ else if ( strModality.find("CR") < strModality.length()) return CR;
+ else if ( strModality.find("CT") < strModality.length()) return CT;
+ else if ( strModality.find("CS") < strModality.length()) return CS;
+ else if ( strModality.find("DD") < strModality.length()) return DD;
+ else if ( strModality.find("DF") < strModality.length()) return DF;
+ else if ( strModality.find("DG") < strModality.length()) return DG;
+ else if ( strModality.find("DM") < strModality.length()) return DM;
+ else if ( strModality.find("DS") < strModality.length()) return DS;
+ else if ( strModality.find("DX") < strModality.length()) return DX;
+ else if ( strModality.find("ECG") < strModality.length()) return ECG;
+ else if ( strModality.find("EPS") < strModality.length()) return EPS;
+ else if ( strModality.find("FA") < strModality.length()) return FA;
+ else if ( strModality.find("FS") < strModality.length()) return FS;
+ else if ( strModality.find("HC") < strModality.length()) return HC;
+ else if ( strModality.find("HD") < strModality.length()) return HD;
+ else if ( strModality.find("LP") < strModality.length()) return LP;
+ else if ( strModality.find("LS") < strModality.length()) return LS;
+ else if ( strModality.find("MA") < strModality.length()) return MA;
+ else if ( strModality.find("MR") < strModality.length()) return MR;
+ else if ( strModality.find("NM") < strModality.length()) return NM;
+ else if ( strModality.find("OT") < strModality.length()) return OT;
+ else if ( strModality.find("PT") < strModality.length()) return PT;
+ else if ( strModality.find("RF") < strModality.length()) return RF;
+ else if ( strModality.find("RG") < strModality.length()) return RG;
+ else if ( strModality.find("RTDOSE") < strModality.length()) return RTDOSE;
+ else if ( strModality.find("RTIMAGE") < strModality.length()) return RTIMAGE;
+ else if ( strModality.find("RTPLAN") < strModality.length()) return RTPLAN;
+ else if ( strModality.find("RTSTRUCT") < strModality.length()) return RTSTRUCT;
+ else if ( strModality.find("SM") < strModality.length()) return SM;
+ else if ( strModality.find("ST") < strModality.length()) return ST;
+ else if ( strModality.find("TG") < strModality.length()) return TG;
+ else if ( strModality.find("US") < strModality.length()) return US;
+ else if ( strModality.find("VF") < strModality.length()) return VF;
+ else if ( strModality.find("XA") < strModality.length()) return XA;
+ else if ( strModality.find("XC") < strModality.length()) return XC;
+
+ else
+ {
+ /// \todo throw error return value ???
+ /// specified <> unknow in our database
+ return Unknow;
+ }