#include <creaImageIOTreeDescriptor.h>
+#include <boost/algorithm/string/split.hpp>
+#include <creaImageIOSystem.h>
+#include <boost/filesystem.hpp>
+
+
+
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);
+ }
+ }
+ }
+ }
+
+
//==================================================================
//==================================================================