#include <creaImageIOTreeDescriptor.h>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <creaImageIOSystem.h>
+#include <boost/filesystem.hpp>
+
+
+#include <fstream>
namespace creaImageIO
const unsigned int AttributeDescriptor::PRIVATE = 1;
/// The attribute enters in unique identifier constitution
const unsigned int AttributeDescriptor::IDENTIFIER = 2;
+ /// The attribute can be edited
+ const unsigned int AttributeDescriptor::EDITABLE = 3;
const unsigned int AttributeDescriptor::LABEL = 4;
//==================================================================
// Patient level
Add(LevelDescriptor("Patient"));
- Add(AttributeDescriptor(0x1111,0x0011, // Number of Series
- AttributeDescriptor::LABEL),1);
+ Add(AttributeDescriptor("NumberOfChildren","#Series",0),1); // Number of Series
Add(AttributeDescriptor(0x0010,0x0010, // Patient name
AttributeDescriptor::LABEL),1);
Add(AttributeDescriptor(0x0010,0x0040),1); // Patient sex
// Study-series level
Add(LevelDescriptor("Series"));
- Add(AttributeDescriptor(0x1111,0x0011, // Number of Images
- AttributeDescriptor::LABEL),2);
+ Add(AttributeDescriptor("NumberOfChildren","#Images",0),2); // Number of images
Add(AttributeDescriptor(0x0008,0x0060, // Modality
AttributeDescriptor::LABEL),2);
Add(AttributeDescriptor(0x0008,0x1030),2); // Study Description
}
+
+ //////////////////////////////////////////////////////////////
+ // create a descriptor (name, attributes...) from a file) //
+ // @param : file path //
+ // return : - //
+ //////////////////////////////////////////////////////////////
+ void Descriptor::createDescriptorfromFile(const 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.
+ { boost::algorithm::replace_all(descriptors[2],"_"," ");
+ Add(AttributeDescriptor( descriptors[1].c_str(),descriptors[2].c_str(),flag), ilevel);
+ }
+ }
+ }
+ }
+
+
//==================================================================
//==================================================================