]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOTreeAttributeDescriptor.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOTreeAttributeDescriptor.cpp
index 799cb12cc2210b357912d40d78e805234f53f1d9..231b045e003bc715a518e594e10ab3cbb226be2f 100644 (file)
@@ -43,7 +43,6 @@ namespace creaImageIO
       GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
                          <<"' ["<<flags<<"]"<<std::endl);
       GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
-         DecodeType();
     }
 
     //=====================================================================
@@ -75,7 +74,6 @@ namespace creaImageIO
        {
          mName = entry->GetName();
          CleanName(mName);
-         DecodeType();
          GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
        }
       else
@@ -85,8 +83,7 @@ namespace creaImageIO
                         <<"Considering it as a user attribute"
                         << std::endl);
          mName = "UNKNOWN";
-         mGroup = mElement = mType = 0;
-         DecodeType();
+         mGroup = mElement = 0;
        }
       
     }
@@ -103,12 +100,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_s(key.c_str(),"D%04hx_%04hx ",&group,&elem);  
+         GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : "                     <<group<<"|"<<elem<<std::endl);
        }
       else 
        { 
@@ -117,17 +111,61 @@ namespace creaImageIO
        }
       return;
     }
-    //=====================================================================
-       ///Decodes the type of attribute into the valid groups
-       void AttributeDescriptor::DecodeType()
+
+       //=====================================================================
+       /// test if the type is a date
+       bool AttributeDescriptor::isDateEntry() const
+       {
+                
+               bool btest = false;
+               // 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() == "DA" )
+                       {
+                               btest = true;
+                       }
+               }
+               return btest;
+       }
+
+       //=====================================================================
+       /// test if the type is a time
+       bool AttributeDescriptor::isTimeEntry() const
        {
+                
+               bool btest = false;
                // 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;
+                       }
+               }
+               return btest;
+       }
+
+
+    //=====================================================================
+       /// Decodes the type of the attribute
+     void AttributeDescriptor::DecodeType(unsigned int& typ) const
+         {
+                 
+               
+                 // Retrieve the name from gdcm dict
                GDCM_NAME_SPACE::DictEntry* entry =
                GDCM_NAME_SPACE::Global::GetDicts()
-               ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
+               ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
 
+               if (entry==0) 
+               {
+                       typ = 2;
+                       return;
+               }
                std::string type = entry->GetVR().str();
-               CleanName(type);
                GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
                if(type=="AS" ||
                type=="DA" ||
@@ -140,14 +178,17 @@ namespace creaImageIO
                type=="US" ||
                type=="SH")
                {
-                       mType=1;
+                       // Numerical 
+                       typ = 1;
                }
                else
                {
-                       mType=2;
+                       // String
+                       typ = 2;
                }
-
-       }
+               
+         }
+         //=====================================================================
 
   } // EO namespace tree