]> Creatis software - creaImageIO.git/commitdiff
Utilisation d'un fichier de config pour la création de la BD et des AttributeDescript...
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Mon, 27 Apr 2009 14:38:23 +0000 (14:38 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Mon, 27 Apr 2009 14:38:23 +0000 (14:38 +0000)
src2/creaImageIOGimmick.cpp
src2/creaImageIOTreeDescriptor.cpp
src2/creaImageIOTreeDescriptor.h

index 5ae843801e4952e9d89ca7e6d7b81497fe9a1959..01e49bd352d5a29bc655e57420fb98b71c89c57b 100644 (file)
@@ -49,7 +49,8 @@ namespace creaImageIO
        GimmickMessage(1,mess<<std::endl);
        
        // CREATING DEFAULT DB STRUCTURE
-       mLocalDatabase->GetTree().GetDescriptor().CreateDefault();
+//     mLocalDatabase->GetTree().GetDescriptor().CreateDefault();
+       mLocalDatabase->GetTree().GetDescriptor().createDescriptorfromFile(mCurrentDirectory + "\\.gimmick\\localdatabase_Descriptor.txt");
        
        if ( ! mLocalDatabase->Create(true) )
          {
index 602ffabac3ce2b536fc3fafc6b8bf165e5f3a308..6849b10bd6740f84cc36774381a551473c0c25ff 100644 (file)
@@ -1,4 +1,10 @@
 #include <creaImageIOTreeDescriptor.h>
+#include <boost/algorithm/string/split.hpp>
+#include <creaImageIOSystem.h>
+#include <boost/filesystem.hpp>
+
+
+
 
 
 namespace creaImageIO
@@ -132,6 +138,82 @@ namespace creaImageIO
                                                                  
      
     }
+
+       //////////////////////////////////////////////////////////////
+       // create a descriptor (name, attributes...) from a file)       //
+       // @param : file path                                                                           //
+       // return : -                                                                                           //
+       //////////////////////////////////////////////////////////////
+       void Descriptor::createDescriptorfromFile(std::string &i_name)
+       {
+               Clear();
+               
+               // read file and put in buffer
+               std::ifstream i_file(i_name.c_str());
+               std::stringstream buffer;
+               buffer << i_file.rdbuf();
+               std::string line;
+               bool bname;
+               int ilevel = -1;
+
+               
+               while(std::getline(buffer, line))
+               {
+                       if(line =="<level>")
+                       {       //increment levels.
+                               ilevel++;
+                               bname = true;
+                       }
+                       else if(bname)
+                       {
+                               // For each level, a name to describe it
+                               Add(LevelDescriptor(line));
+                               bname = false;
+                       }
+                       else
+                       { 
+                               // split line to find all tags
+                               std::vector<std::string> descriptors;
+                               std::string separator = " ";
+                               std::string::size_type last_pos = line.find_first_not_of(separator);
+                               //find first separator
+                               std::string::size_type pos = line.find_first_of(separator, last_pos);
+                               while(std::string::npos != pos || std::string::npos != last_pos)
+                               {
+                                       descriptors.push_back(line.substr(last_pos, pos - last_pos));
+                                       last_pos = line.find_first_not_of(separator, pos);
+                                       pos = line.find_first_of(separator, last_pos);
+                               }
+                               
+                               // By default, the last tag is at zero and not recorded but if take in count
+                               unsigned int flag = 0;
+                               if(descriptors.size() == 4)
+                               {
+                                       std::stringstream val;
+                                       val << std::dec << descriptors[3];
+                                       val>> flag;
+                               }
+
+                               // if Dicom tag, use "group" and "element" descriptor
+                               if(descriptors[0] == "D")
+                               {       std::stringstream val, val2;
+                                       unsigned short group;
+                                       unsigned short element;
+                                       val <<   std::dec << descriptors[1] ;
+                                       val >> std::hex >> group;
+                                       val2 << std::dec <<  descriptors[2];
+                                       val2 >> std::hex >> element;
+                                       Add(AttributeDescriptor( group,element,flag), ilevel);
+                               }
+                               else // "O" means if user's own tag.
+                               {       
+                                       Add(AttributeDescriptor( descriptors[1].c_str(),descriptors[2].c_str(),flag), ilevel);
+                               }
+                       }
+               }
+       }
+
+
     //==================================================================
 
     //==================================================================
index 26bbc5edbd7d5679d5f65f1760de9e47ba1018ac..c2fb7ae0d032fa6c3b8e343b2687f49b6e7c1ce9 100644 (file)
@@ -7,7 +7,7 @@
 
 namespace creaImageIO
 {
-
+       using namespace std;
   namespace tree
   {
     
@@ -63,6 +63,9 @@ namespace creaImageIO
       /// Clears the Descriptor
       void Clear();
 
+         //Create Attribute Descriptors from a file
+       void createDescriptorfromFile(std::string &i_file);
+
     private:
       LevelDescriptorListType mLevelDescriptorList;
       /// Creates the mandatory level 0 descriptor called "Root"