]> Creatis software - gdcm.git/commitdiff
add
authorjpr <jpr>
Thu, 5 Feb 2009 09:50:09 +0000 (09:50 +0000)
committerjpr <jpr>
Thu, 5 Feb 2009 09:50:09 +0000 (09:50 +0000)
    bool DataEntry::IsNumerical();
    bool DataEntry::GetNumerical(std::vector <double> &valueVector);
to avoid people to re-progrm them each time

src/gdcmDataEntry.cxx
src/gdcmDataEntry.h

index 833be232f3c7efc3d1f29f4f3fad5c568ca0987c..fc36ec5666dcf64eeb30580d350c382d17e81519 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/10 12:15:35 $
-  Version:   $Revision: 1.54 $
+  Date:      $Date: 2009/02/05 09:50:09 $
+  Version:   $Revision: 1.55 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -130,6 +130,99 @@ void DataEntry::CopyBinArea( uint8_t *area, uint32_t length )
    }
 }
 
+/**
+ * \brief Checks wether the current DataEntry contains number(s)
+ */
+
+bool DataEntry::IsNumerical()
+{
+   const VRKey &vr = GetVR();
+   
+   return 
+          vr == "DS" ||
+          vr == "FL" ||
+          vr == "FD" ||
+          vr == "IS" || 
+          vr == "SH" ||
+          vr == "SL" ||
+          vr == "SS" ||
+          vr == "UI" ||
+          vr == "UL" ||
+          vr == "US" ;      
+}
+
+/**
+ * \brief Gets a std::vector of 'double' holding the value(s) of any 'numerical' DataEntry
+ * @param valueVector std::vector double of value(s)
+ * \return false if VR not "a 'numerical" one
+ */
+ bool DataEntry::GetNumerical(std::vector <double> &valueVector)
+ {
+    valueVector.clear();
+    
+    if (!IsNumerical()) // never trust a user !
+       return false;    
+
+    const VRKey &vr = GetVR();
+    int loop;
+    if (vr == "IS" || vr == "DS")
+    {
+       /// \todo rewrite the whole method, in order *not to use* std::string !
+       std::vector<std::string> tokens;
+           
+       Util::Tokenize ( GetString().c_str(), tokens, "\\" );
+        
+       int nbValues= tokens.size();
+       if (nbValues == 0)
+          return false;
+
+       if (vr == "DS")        
+          for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(atof(tokens[loop].c_str()));
+       else
+          for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(atoi(tokens[loop].c_str()));
+               
+       return true;     
+    }    
+    
+    uint32_t nbValues = GetValueCount();
+    if (nbValues == 0)
+       return false;
+       
+    if( vr == "US") {
+       for (loop=0; loop<nbValues; loop++)
+             valueVector.push_back(((uint16_t *)BinArea)[loop]);  
+       return true;
+    }
+    if( vr == "SS" ) {
+       for (loop=0; loop<nbValues; loop++)
+             valueVector.push_back(((int16_t *)BinArea)[loop]);  
+       return true;
+    }
+    if( vr == "UL") {
+       for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(((uint32_t *)BinArea)[loop]);      
+       return true;
+    }
+    if(vr == "SL" ) {
+       for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(((int32_t *)BinArea)[loop]);      
+       return true;
+    }       
+    if( vr == "FL" ) {
+       for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(((float *)BinArea)[loop]);     
+       return true;
+    }
+    if( vr == "FD" ) {
+       for (loop=0; loop<nbValues; loop++) 
+             valueVector.push_back(((double *)BinArea)[loop]);
+       return true;
+    }     
+    return false;   // ?!? 
+ }
+
 /**
  * \brief Inserts the elementary (non string) value into the current DataEntry
  * @param id index of the elementary value to be set
index dbad01c2826c1a000ca4801a81759edc9549738e..891f7d5cc3b912e9a0b5a91b87c45166e814b6c1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDataEntry.h,v $
   Language:  C++
-  Date:      $Date: 2007/09/18 16:07:20 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2009/02/05 09:50:09 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -74,7 +74,10 @@ public:
    std::string const &GetString() const;
 
    std::string const &GetHexaRepresentation() const;
-   
+
+   bool IsNumerical();
+   bool GetNumerical(std::vector <double> &valueVector);
+    
    /// \brief Sets SelfArea
    void SetSelfArea(bool area) { SelfArea = area; }
    /// \brief True if Entry owns its BinArea