]> Creatis software - creaImageIO.git/blobdiff - src/creaImageIODicomImageReader2.cpp
some re-indent
[creaImageIO.git] / src / creaImageIODicomImageReader2.cpp
index 3dd8120f299a35ea3c47e965202eda047be4f369..fc7f56b7cee601b21c03d7eb3bc53a0bd177d5d9 100644 (file)
@@ -1,5 +1,5 @@
 #include <creaImageIODicomImageReader2.h>
-
+#include "gdcmStringFilter.h"
 
 
 #include <creaImageIOSystem.h>
@@ -19,8 +19,8 @@ namespace creaImageIO
   //=====================================================================
   DicomImageReader::DicomImageReader()
   {
-         mReader =  vtkGDCMImageReader::New();
-    SetName ( "Dicom" );
+      mReader =  vtkGDCMImageReader::New();
+      SetName ( "Dicom" );
        
   };
   //=====================================================================
@@ -28,14 +28,14 @@ namespace creaImageIO
   //=====================================================================
   DicomImageReader::~DicomImageReader()
   {
-         mReader->Delete();
+      mReader->Delete();
   }
   //=====================================================================
 
   //=====================================================================  
   bool DicomImageReader::CanRead(const std::string& filename)
   { 
-         gdcm::Reader reader;
+      gdcm::Reader reader;
       reader.SetFileName( filename.c_str() );
       return  reader.Read();
         
@@ -67,8 +67,7 @@ namespace creaImageIO
     v.push_back("dcm");
     v.push_back("");
   }
-  //=====================================================================
-  
   //========================================================================
   std::string irclean(const std::string& str)
   {
@@ -91,7 +90,30 @@ namespace creaImageIO
     return str;
   }
   //========================================================================
+  //=====================================================================
+  
+
+       void DicomImageReader::getAttributes(const std::string filename, 
+               std::map <std::string , std::string> &infos, std::vector<std::string> i_attr)
+       {
+               gdcm::Reader reader;
+               reader.SetFileName( filename.c_str() );
+               if (reader.Read())
+               {
+                       std::vector<std::string>::iterator it = i_attr.begin();
+                       for(;it != i_attr.end(); it++)
+                       {
+                               unsigned short el;
+                               unsigned short gr;
+                               sscanf((*it).c_str(),"D%04hx_%04hx",&gr,&el);
+                               if ( ( gr!=0 ) && ( el!=0 ) )
+                               {
+                                       infos[(*it)] =  ( GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el))) );
+                               }
+                       }
+               }
+       }
+
   //=====================================================================
   void DicomImageReader::ReadAttributes(const std::string& filename, 
                      std::map<std::string,std::string>& attr)
@@ -100,50 +122,54 @@ namespace creaImageIO
                   <<filename<<"'"<<std::endl);
 
    
-        gdcm::Reader reader;
+      gdcm::Reader reader;
       reader.SetFileName( filename.c_str() );
-         if (reader.Read())
+      if (reader.Read())
       {
-       std::map<std::string,std::string>::iterator i;
-       for (i=attr.begin();i!=attr.end();++i)
-         {
-           if ( i->first == "D0004_1500" )
-             {
-               boost::filesystem::path full_path(filename);
-               std::string f = full_path.leaf();
-               i->second = f;
-             }
-           else if ( i->first == "FullFileName" )
-             {
-               i->second = filename;
-             }
-                 else if ( i->first == "FullFileDirectory" )
-             {
-                         std::string::size_type last_pos = filename.find_last_of("//");
-                         //find first separator
-                         i->second = filename.substr(0, last_pos);
-             }
-           else
+                 gdcm::StringFilter sf;
+                 sf.SetFile(reader.GetFile());
+                 std::map<std::string,std::string>::iterator i;
+                 for (i=attr.begin();i!=attr.end();++i)
              {
-               uint16_t el;
-               uint16_t gr;
-               
-               tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el);
-               if ( ( gr!=0 ) && ( el!=0 ) )
-                 {
-                          gdcm::DataElement de( gdcm::Tag(gr,el) );
-                          std::string val = GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el)));
-                   i->second = irclean(val);
+                         if ( i->first == "D0004_1500" )
+                         {
+                                 boost::filesystem::path full_path(filename);
+                                 std::string f = full_path.leaf();
+                                 i->second = f;
+                         }
+                         else if ( i->first == "FullFileName" )
+                         {
+                               i->second = filename;
+                         }
+                         else if ( i->first == "FullFileDirectory" )
+                         {
+                                std::string::size_type last_pos = filename.find_last_of("//");
+                                //find first separator
+                                i->second = filename.substr(0, last_pos);
+                         }
+                         else
+                         {
+                                 uint16_t el;
+                                 uint16_t gr;
+                                 tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el);
+                                 //if ( ( gr!=0 ) && ( el!=0 ) )
+                                 const gdcm::Tag tag(gr, el);
+                                 if( reader.GetFile().GetDataSet().FindDataElement( tag ) )
+                                 {
+                                         i->second = irclean(sf.ToString(tag));
+                                 }
+                                 else
+                                 {
+                                         i->second = "";
+                                 }
+                         }
                  }
-             }
          }
-      }
   }
 
 void DicomImageReader::ReadAttributes2(const std::string& filename, 
                      std::map<std::string,std::string>& attr)
   {
-      
        if(!b_loaded)
        {
                std::map<std::string,std::string>::iterator i;
@@ -197,22 +223,7 @@ void DicomImageReader::ReadAttributes2(const std::string& filename,
         }
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-  const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de)
+const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de)
 {
   static std::string buffer;
   buffer = "";  // cleanup previous call
@@ -225,7 +236,6 @@ void DicomImageReader::ReadAttributes2(const std::string& filename,
       // Will be padded with at least one \0
       }
 
-
   // Since return is a const char* the very first \0 will be considered
   return buffer.c_str();
 }