From: Romulo Pinho Date: Fri, 8 Feb 2013 12:13:13 +0000 (+0100) Subject: clitkDicomRTStruct2Image: new features X-Git-Tag: v1.4.0~247^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=21cad80313d6f22daabe815127b7c31b907982f7;p=clitk.git clitkDicomRTStruct2Image: new features - support conversion given ROI name or substring --- diff --git a/common/clitkDicomRT_StructureSet.cxx b/common/clitkDicomRT_StructureSet.cxx index bbbcfd6..761ea23 100644 --- a/common/clitkDicomRT_StructureSet.cxx +++ b/common/clitkDicomRT_StructureSet.cxx @@ -118,6 +118,101 @@ clitk::DicomRT_ROI* clitk::DicomRT_StructureSet::GetROIFromROINumber(int n) } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +clitk::DicomRT_ROI* clitk::DicomRT_StructureSet::GetROIFromROIName(const std::string& name) +{ + std::map::iterator it = mMapOfROIName.begin(); + int number = -1; + while (it != mMapOfROIName.end() && number == -1) { + if (it->second == name) + number = it->first; + else + it++; + } + + if (number == -1) { + std::cerr << "No ROI name " << name << std::endl; + return NULL; + } + + return mROIs[number]; +} +//-------------------------------------------------------------------- +/* +// RP: 08/02/2013 +// RegEx version shall be available when C++x11 supports it propely +// +//-------------------------------------------------------------------- +clitk::DicomRT_ROI* clitk::DicomRT_StructureSet::GetROIFromROINameRegEx(const std::string& regEx) +{ + std::map::iterator it = mMapOfROIName.begin(); + int number = -1; + + while (it != mMapOfROIName.end() && number == -1) { + if (std::tr1::regex_match (it->second, std::tr1::regex(regEx))) + number = it->first; + else + it++; + } + + if (number == -1) { + std::cerr << "No ROI name " << number << std::endl; + return NULL; + } + + return mROIs[number]; +} +//-------------------------------------------------------------------- +*/ +//-------------------------------------------------------------------- +clitk::DicomRT_ROI* clitk::DicomRT_StructureSet::GetROIFromROINameSubstr(const std::string& s) +{ + std::map::iterator it = mMapOfROIName.begin(); + int number = -1; + + while (it != mMapOfROIName.end() && number == -1) { + if (it->second.find(s) != std::string::npos) + number = it->first; + else + it++; + } + + if (number == -1) { + std::cerr << "No ROI name " << s << std::endl; + return NULL; + } + + return mROIs[number]; +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +clitk::DicomRT_StructureSet::ROIMapContainer * +clitk::DicomRT_StructureSet::GetROIsFromROINameSubstr(const std::string& s) +{ + static ROIMapContainer rois; + rois.clear(); + + ROIMapContainer::iterator it = mROIs.begin(); + int number = -1; + + while (it != mROIs.end()) { + if (it->second->GetName().find(s) != std::string::npos) { + number = it->first; + rois[number] = it->second; + } + it++; + } + + if (number == -1) { + std::cerr << "No ROI name " << s << std::endl; + return NULL; + } + + return &rois; + +} +//-------------------------------------------------------------------- //-------------------------------------------------------------------- void clitk::DicomRT_StructureSet::Print(std::ostream & os) const diff --git a/common/clitkDicomRT_StructureSet.h b/common/clitkDicomRT_StructureSet.h index 5761e14..9994608 100644 --- a/common/clitkDicomRT_StructureSet.h +++ b/common/clitkDicomRT_StructureSet.h @@ -44,8 +44,9 @@ public: typedef itk::SmartPointer Pointer; itkNewMacro(Self); - typedef std::map::iterator ROIIteratorType; - typedef std::map::const_iterator ROIConstIteratorType; + typedef std::map ROIMapContainer; + typedef ROIMapContainer::iterator ROIIteratorType; + typedef ROIMapContainer::const_iterator ROIConstIteratorType; void Print(std::ostream & os = std::cout) const; void Read(const std::string & filename); @@ -53,7 +54,11 @@ public: void Write(const std::string & filename); clitk::DicomRT_ROI * GetROIFromROINumber(int n); - std::map & GetROIs() { return mROIs; } + clitk::DicomRT_ROI* GetROIFromROIName(const std::string& name); + //clitk::DicomRT_ROI* GetROIFromROINameRegEx(const std::string& regEx); + clitk::DicomRT_ROI* GetROIFromROINameSubstr(const std::string& s); + ROIMapContainer * GetROIsFromROINameSubstr(const std::string& s); + ROIMapContainer & GetROIs() { return mROIs; } const std::string & GetStudyID() const; const std::string & GetStudyTime() const; const std::string & GetStudyDate() const; diff --git a/tools/clitkDicomRTStruct2Image.cxx b/tools/clitkDicomRTStruct2Image.cxx index 88d480d..b713d94 100644 --- a/tools/clitkDicomRTStruct2Image.cxx +++ b/tools/clitkDicomRTStruct2Image.cxx @@ -38,34 +38,70 @@ int main(int argc, char * argv[]) { clitk::DicomRTStruct2ImageFilter filter; filter.SetCropMaskEnabled(args_info.crop_flag); filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin - if (args_info.roi_arg != -1) { + if (args_info.roiName_given) { + filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); + filter.SetOutputImageFilename(args_info.output_arg); + filter.Update(); + } + else if (args_info.roi_given && args_info.roi_arg != -1) { filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); filter.SetOutputImageFilename(args_info.output_arg); filter.Update(); } else { + clitk::DicomRT_StructureSet::ROIMapContainer* rois; + if (args_info.roiNameSubstr_given) + rois = s->GetROIsFromROINameSubstr(args_info.roiNameSubstr_arg); + else + rois = &s->GetROIs(); + clitk::DicomRT_StructureSet::ROIConstIteratorType iter; - for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) { - clitk::DicomRT_ROI::Pointer roi = iter->second; - // Create the filter - clitk::DicomRTStruct2ImageFilter filter; - filter.SetCropMaskEnabled(args_info.crop_flag); - filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin - std::string name = roi->GetName(); - int num = roi->GetROINumber(); - filter.SetROI(roi); - name.erase(remove_if(name.begin(), name.end(), isspace), name.end()); - std::string n = std::string(args_info.output_arg).append - (clitk::toString(num)).append - ("_").append - (name).append - (".mhd"); - if (args_info.verbose_flag) { - std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl; + if (rois) { + for(iter = rois->begin(); iter != rois->end(); iter++) { + clitk::DicomRT_ROI::Pointer roi = iter->second; + clitk::DicomRTStruct2ImageFilter filter; + std::string name = roi->GetName(); + int num = roi->GetROINumber(); + filter.SetROI(roi); + filter.SetCropMaskEnabled(args_info.crop_flag); + filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin + name.erase(remove_if(name.begin(), name.end(), isspace), name.end()); + std::string n = std::string(args_info.output_arg).append + (clitk::toString(num)).append + ("_").append + (name).append + (".mhd"); + if (args_info.verbose_flag) { + std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl; + } + filter.SetOutputImageFilename(n); + filter.Update(); } - filter.SetOutputImageFilename(n); - filter.Update(); } + } +// else { +// clitk::DicomRT_StructureSet::ROIConstIteratorType iter; +// for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) { +// clitk::DicomRT_ROI::Pointer roi = iter->second; +// // Create the filter +// clitk::DicomRTStruct2ImageFilter filter; +// filter.SetCropMaskEnabled(args_info.crop_flag); +// filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin +// std::string name = roi->GetName(); +// int num = roi->GetROINumber(); +// filter.SetROI(roi); +// name.erase(remove_if(name.begin(), name.end(), isspace), name.end()); +// std::string n = std::string(args_info.output_arg).append +// (clitk::toString(num)).append +// ("_").append +// (name).append +// (".mhd"); +// if (args_info.verbose_flag) { +// std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl; +// } +// filter.SetOutputImageFilename(n); +// filter.Update(); +// } /* for(unsigned int i=0; iGetListOfROI().size(); i++) { @@ -87,7 +123,7 @@ int main(int argc, char * argv[]) { filter.SetOutputImageFilename(n); filter.Update(); }*/ - } + //} // This is the end my friend return 0; diff --git a/tools/clitkDicomRTStruct2Image.ggo b/tools/clitkDicomRTStruct2Image.ggo index d403f06..06211bb 100644 --- a/tools/clitkDicomRTStruct2Image.ggo +++ b/tools/clitkDicomRTStruct2Image.ggo @@ -7,9 +7,13 @@ option "verbose" v "Verbose" flag off option "verboseFile" - "Verbose file content" flag off option "input" i "Input Dicom file" string yes option "image" j "Used to read image info (spacing, origin)" string yes -option "roi" r "ROI to binarize (if -1 = all roi)" int no default="-1" option "output" o "Output image filename" string yes +defgroup "ROIoption" groupdesc="an option of this group is required" +groupoption "roi" r "ROI to binarize (if -1 = all roi)" int no default="-1" group="ROIoption" +groupoption "roiName" n "ROI name to binarize (be wary of spaces in ROI names; if blank, use given 'roi' value)" string no default="" group="ROIoption" +groupoption "roiNameSubstr" s "Substring of ROI name to binarize (reuturns the first match; if blank, use given 'roiName' value)" string no default="" group="ROIoption" + option "crop" c "Crop binary mask" flag off #option "roi" r "ROI to print (ID)" int no