}
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+clitk::DicomRT_ROI* clitk::DicomRT_StructureSet::GetROIFromROIName(const std::string& name)
+{
+ std::map<int, std::string>::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<int, std::string>::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<int, std::string>::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
typedef itk::SmartPointer<Self> Pointer;
itkNewMacro(Self);
- typedef std::map<int, clitk::DicomRT_ROI::Pointer>::iterator ROIIteratorType;
- typedef std::map<int, clitk::DicomRT_ROI::Pointer>::const_iterator ROIConstIteratorType;
+ typedef std::map<int, clitk::DicomRT_ROI::Pointer> ROIMapContainer;
+ typedef ROIMapContainer::iterator ROIIteratorType;
+ typedef ROIMapContainer::const_iterator ROIConstIteratorType;
void Print(std::ostream & os = std::cout) const;
void Read(const std::string & filename);
void Write(const std::string & filename);
clitk::DicomRT_ROI * GetROIFromROINumber(int n);
- std::map<int, clitk::DicomRT_ROI::Pointer> & 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;
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; i<s->GetListOfROI().size(); i++) {
filter.SetOutputImageFilename(n);
filter.Update();
}*/
- }
+ //}
// This is the end my friend
return 0;
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