]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOTreeAttributeDescriptor.cpp
move directory
[creaImageIO.git] / src2 / creaImageIOTreeAttributeDescriptor.cpp
index 54c56b87e2308f22d5d77c15ea97bcd170a72a0c..3e09a4f51c1f2523fd520eefb076cfa0166bc04b 100644 (file)
@@ -1,8 +1,17 @@
 #include <creaImageIOTreeAttributeDescriptor.h>
 #include <creaImageIOSystem.h>
 
+
+#if defined(USE_GDCM)
 #include <gdcmGlobal.h>
 #include <gdcmDictSet.h>
+#endif
+
+#if defined(USE_GDCM2)
+#include <gdcmGlobal.h>
+#include <gdcmDicts.h>
+#include <gdcmDict.h>
+#endif
 
 #include <boost/algorithm/string/replace.hpp>
 
@@ -65,6 +74,7 @@ namespace creaImageIO
       GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
                          <<"' ["<<flags<<"]"<<std::endl);
 
+#if defined(USE_GDCM)
       // Retrieve the name from gdcm dict
       GDCM_NAME_SPACE::DictEntry* entry =
        GDCM_NAME_SPACE::Global::GetDicts()
@@ -85,7 +95,35 @@ namespace creaImageIO
          mName = "UNKNOWN";
          mGroup = mElement = 0;
        }
-      
+#endif
+
+
+         
+         
+#if defined(USE_GDCM2)
+      // Retrieve the name from gdcm dict
+       const gdcm::Global& g = gdcm::Global::GetInstance(); 
+        const gdcm::Dicts &dicts = g.GetDicts();
+  const gdcm::Dict &dict = dicts.GetPublicDict();
+         gdcm::DictEntry dictentry =  dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
+         
+      mName = dictentry.GetName();
+         if(!mName.empty())
+         {
+                 CleanName(mName);
+                 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
+         }
+      else
+         {
+               GimmickMessage(1,"!! WARNING : tag '"<<mKey
+                        <<"' is not in DICOM dictionnary ! "
+                        <<"Considering it as a user attribute"
+                        << std::endl);
+               mName = "UNKNOWN";
+               mGroup = mElement = 0;
+               }
+#endif
+
     }
     //=====================================================================
 
@@ -100,12 +138,9 @@ namespace creaImageIO
       if ( (key.size()==10) &&
           (key[0] == 'D') &&
           (key[5] == '_') )
-       {
-         std::string g = key.substr(1,4);
-         sscanf(key.c_str(),"D %04x _ %04x ",&group,&elem);  
-         sscanf(g.c_str(),"%04x",&group);
-         GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<g<<"' : "
-                        <<group<<"|"<<elem<<std::endl);
+         {
+        sscanf(key.c_str(),"D%04hx_%04hx ",&group,&elem);  
+         GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : "                     <<group<<"|"<<elem<<std::endl);
        }
       else 
        { 
@@ -115,12 +150,81 @@ namespace creaImageIO
       return;
     }
 
+       //=====================================================================
+       /// test if the type is a date
+       bool AttributeDescriptor::isDateEntry() const
+       {
+                
+               bool btest = false;
+               // Retrieve the name from gdcm dict
+#if defined(USE_GDCM)
+               GDCM_NAME_SPACE::DictEntry* entry =     GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
+               if(     entry != 0)
+               {
+                       if( entry->GetVR().str() == "DA" )
+                       {
+                               btest = true;
+                       }
+               }
+#endif
+#if defined(USE_GDCM2)
+        const gdcm::Global& g = gdcm::Global::GetInstance(); 
+        const gdcm::Dicts &dicts = g.GetDicts();
+  const gdcm::Dict &dict = dicts.GetPublicDict();
+         if(mGroup != 0 && mElement != 0)
+         {
+                 gdcm::DictEntry dictentry =  dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
+               if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
+               {
+                               btest = true;
+               }
+         }
+#endif
+               return btest;
+       }
+
+       //=====================================================================
+       /// test if the type is a time
+       bool AttributeDescriptor::isTimeEntry() const
+       {
+                
+               bool btest = false;
+#if defined(USE_GDCM)
+               // Retrieve the name from gdcm dict
+               GDCM_NAME_SPACE::DictEntry* entry =     GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
+               if(     entry != 0)
+               {
+                       if( entry->GetVR().str() == "TM" )
+                       {
+                               btest = true;
+                       }
+               }
+#endif
+
+#if defined(USE_GDCM2)
+        const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
+        const gdcm::Dicts &dicts = g.GetDicts();
+  const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
+         if(mGroup != 0 && mElement != 0)
+         {
+               gdcm::DictEntry dictentry =  dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
+               if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
+               {
+                               btest = true;
+               }
+         }
+#endif
+
+               return btest;
+       }
+
+
     //=====================================================================
        /// Decodes the type of the attribute
      void AttributeDescriptor::DecodeType(unsigned int& typ) const
          {
-                 
-               
+                std::string type=""; 
+#if defined(USE_GDCM)  
                  // Retrieve the name from gdcm dict
                GDCM_NAME_SPACE::DictEntry* entry =
                GDCM_NAME_SPACE::Global::GetDicts()
@@ -131,7 +235,16 @@ namespace creaImageIO
                        typ = 2;
                        return;
                }
-               std::string type = entry->GetVR().str();
+                type = entry->GetVR().str();
+#endif
+#if defined(USE_GDCM2)
+        const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
+        const gdcm::Dicts &dicts = g.GetDicts();
+  const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
+         gdcm::DictEntry dictentry =  dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
+         type = gdcm::VR::GetVRString(dictentry.GetVR());
+#endif
+
                GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
                if(type=="AS" ||
                type=="DA" ||
@@ -146,15 +259,11 @@ namespace creaImageIO
                {
                        // Numerical 
                        typ = 1;
-//                     type="1";
-//                      sscanf(type.c_str(),"%u",&typ);
                }
                else
                {
                        // String
                        typ = 2;
-                       //                      type="2";
-//                      sscanf(type.c_str(),"%u",&typ);
                }
                
          }