X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOTreeDescriptor.cpp;h=6849b10bd6740f84cc36774381a551473c0c25ff;hb=cc5a912f64e8de1f90d9ef0956633515a46d31ae;hp=5b2a447d78cc6a2b26f9b6948a7fb75b6f6643b6;hpb=4f05b9a3ab42185e11fdcc3d55d71a5111ef9c2a;p=creaImageIO.git diff --git a/src2/creaImageIOTreeDescriptor.cpp b/src2/creaImageIOTreeDescriptor.cpp index 5b2a447..6849b10 100644 --- a/src2/creaImageIOTreeDescriptor.cpp +++ b/src2/creaImageIOTreeDescriptor.cpp @@ -1,4 +1,10 @@ #include +#include +#include +#include + + + namespace creaImageIO @@ -50,8 +56,7 @@ namespace creaImageIO // 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 @@ -61,8 +66,7 @@ namespace creaImageIO // 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 @@ -134,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 =="") + { //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. + { + Add(AttributeDescriptor( descriptors[1].c_str(),descriptors[2].c_str(),flag), ilevel); + } + } + } + } + + //================================================================== //==================================================================