X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOTreeDescriptor.cpp;h=c1dca8e78b1d5ee575aee2bc12d6d00614a9d866;hb=9ae1b3a039da8e28aa41c6963744bfa86c382a35;hp=79e623fae610b2c6c5e82f5c1d37e09fcdf675ae;hpb=5f76a3752cd6e23874e8167f19c9ceb57223b390;p=creaImageIO.git diff --git a/src2/creaImageIOTreeDescriptor.cpp b/src2/creaImageIOTreeDescriptor.cpp index 79e623f..c1dca8e 100644 --- a/src2/creaImageIOTreeDescriptor.cpp +++ b/src2/creaImageIOTreeDescriptor.cpp @@ -1,4 +1,11 @@ #include +#include +#include +#include +#include + + +#include namespace creaImageIO @@ -12,6 +19,8 @@ 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; //================================================================== @@ -50,6 +59,7 @@ namespace creaImageIO // Patient level Add(LevelDescriptor("Patient")); + 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 @@ -59,6 +69,7 @@ namespace creaImageIO // Study-series level Add(LevelDescriptor("Series")); + Add(AttributeDescriptor("NumberOfChildren","#Images",0),2); // Number of images Add(AttributeDescriptor(0x0008,0x0060, // Modality AttributeDescriptor::LABEL),2); Add(AttributeDescriptor(0x0008,0x1030),2); // Study Description @@ -130,6 +141,82 @@ namespace creaImageIO } + + ////////////////////////////////////////////////////////////// + // 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 =="") + { //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 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); + } + } + } + } + + //================================================================== //==================================================================